diff --git a/internal/struct.h b/internal/struct.h index c081bdba377..0153828d1e6 100644 --- a/internal/struct.h +++ b/internal/struct.h @@ -29,7 +29,7 @@ struct RStruct { VALUE fields_obj; union { struct { - long len; + rb_len_t len; const VALUE *ptr; } heap; /* This is a length 1 array because: @@ -49,22 +49,22 @@ VALUE rb_struct_lookup(VALUE s, VALUE idx); VALUE rb_struct_s_keyword_init(VALUE klass); void rb_struct_define_aref_method(VALUE nstr, ID name, unsigned int off); -static inline long RSTRUCT_EMBED_LEN(VALUE st); -static inline long RSTRUCT_LEN_RAW(VALUE st); +static inline rb_len_t RSTRUCT_EMBED_LEN(VALUE st); +static inline rb_len_t RSTRUCT_LEN_RAW(VALUE st); static inline int RSTRUCT_LENINT(VALUE st); static inline const VALUE *RSTRUCT_CONST_PTR(VALUE st); -static inline void RSTRUCT_SET_RAW(VALUE st, long k, VALUE v); -static inline VALUE RSTRUCT_GET_RAW(VALUE st, long k); +static inline void RSTRUCT_SET_RAW(VALUE st, rb_len_t k, VALUE v); +static inline VALUE RSTRUCT_GET_RAW(VALUE st, rb_len_t k); -static inline long +static inline rb_len_t RSTRUCT_EMBED_LEN(VALUE st) { - long ret = FL_TEST_RAW(st, RSTRUCT_EMBED_LEN_MASK); + rb_len_t ret = FL_TEST_RAW(st, RSTRUCT_EMBED_LEN_MASK); ret >>= RSTRUCT_EMBED_LEN_SHIFT; return ret; } -static inline long +static inline rb_len_t RSTRUCT_LEN_RAW(VALUE st) { if (FL_TEST_RAW(st, RSTRUCT_EMBED_LEN_MASK)) { @@ -78,7 +78,7 @@ RSTRUCT_LEN_RAW(VALUE st) static inline int RSTRUCT_LENINT(VALUE st) { - return rb_long2int(RSTRUCT_LEN_RAW(st)); + return rb_len2int(RSTRUCT_LEN_RAW(st)); } static inline const VALUE * @@ -95,13 +95,13 @@ RSTRUCT_CONST_PTR(VALUE st) } static inline void -RSTRUCT_SET_RAW(VALUE st, long k, VALUE v) +RSTRUCT_SET_RAW(VALUE st, rb_len_t k, VALUE v) { RB_OBJ_WRITE(st, &RSTRUCT_CONST_PTR(st)[k], v); } static inline VALUE -RSTRUCT_GET_RAW(VALUE st, long k) +RSTRUCT_GET_RAW(VALUE st, rb_len_t k) { return RSTRUCT_CONST_PTR(st)[k]; } diff --git a/struct.c b/struct.c index 16f5e7c7818..bda66d70c8c 100644 --- a/struct.c +++ b/struct.c @@ -84,21 +84,21 @@ rb_struct_members(VALUE s) VALUE members = rb_struct_s_members(rb_obj_class(s)); if (RSTRUCT_LEN_RAW(s) != RARRAY_LEN(members)) { - rb_raise(rb_eTypeError, "struct size differs (%ld required %ld given)", + rb_raise(rb_eTypeError, "struct size differs (%"PRIdLEN" required %"PRIdLEN" given)", RARRAY_LEN(members), RSTRUCT_LEN_RAW(s)); } return members; } -static long -struct_member_pos_ideal(VALUE name, long mask) +static rb_len_t +struct_member_pos_ideal(VALUE name, rb_len_t mask) { /* (id & (mask/2)) * 2 */ return (SYM2ID(name) >> (ID_SCOPE_SHIFT - 1)) & mask; } -static long -struct_member_pos_probe(long prev, long mask) +static rb_len_t +struct_member_pos_probe(rb_len_t prev, rb_len_t mask) { /* (((prev/2) * AREF_HASH_UNIT + 1) & (mask/2)) * 2 */ return (prev * AREF_HASH_UNIT + 2) & mask; @@ -108,13 +108,13 @@ static VALUE struct_set_members(VALUE klass, VALUE /* frozen hidden array */ members) { VALUE back; - const long members_length = RARRAY_LEN(members); + const rb_len_t members_length = RARRAY_LEN(members); if (members_length <= AREF_HASH_THRESHOLD) { back = members; } else { - long i, j, mask = 64; + rb_len_t i, j, mask = 64; VALUE name; while (mask < members_length * AREF_HASH_UNIT) mask *= 2; @@ -149,7 +149,7 @@ static inline int struct_member_pos(VALUE s, VALUE name) { VALUE back = struct_ivar_get(rb_obj_class(s), id_back_members); - long j, mask; + rb_len_t j, mask; if (UNLIKELY(NIL_P(back))) { rb_raise(rb_eTypeError, "uninitialized struct"); @@ -163,7 +163,7 @@ struct_member_pos(VALUE s, VALUE name) if (mask <= AREF_HASH_THRESHOLD) { if (UNLIKELY(RSTRUCT_LEN_RAW(s) != mask)) { rb_raise(rb_eTypeError, - "struct size differs (%ld required %ld given)", + "struct size differs (%"PRIdLEN" required %"PRIdLEN" given)", mask, RSTRUCT_LEN_RAW(s)); } for (j = 0; j < mask; j++) { @@ -174,7 +174,7 @@ struct_member_pos(VALUE s, VALUE name) } if (UNLIKELY(RSTRUCT_LEN_RAW(s) != FIX2INT(RARRAY_AREF(back, mask-1)))) { - rb_raise(rb_eTypeError, "struct size differs (%d required %ld given)", + rb_raise(rb_eTypeError, "struct size differs (%d required %"PRIdLEN" given)", FIX2INT(RARRAY_AREF(back, mask-1)), RSTRUCT_LEN_RAW(s)); } @@ -322,7 +322,7 @@ rb_data_s_new(int argc, const VALUE *argv, VALUE klass) rb_check_arity(argc, 0, num_members); VALUE arg_hash = rb_hash_new_capa(argc); - for (long i=0; i argc) { @@ -833,10 +833,10 @@ struct_heap_alloc(VALUE st, size_t len) STATIC_ASSERT(robject_rstruct_fields_offset, offsetof(struct RObject, as.extended) == offsetof(struct RStruct, fields_obj)); static inline bool -struct_embedded_p(long n) +struct_embedded_p(rb_len_t n) { size_t embedded_size = offsetof(struct RStruct, as.ary) + (sizeof(VALUE) * n); - const long embed_len_max = RSTRUCT_EMBED_LEN_MASK >> RSTRUCT_EMBED_LEN_SHIFT; + const rb_len_t embed_len_max = RSTRUCT_EMBED_LEN_MASK >> RSTRUCT_EMBED_LEN_SHIFT; return n > 0 && n <= embed_len_max && rb_gc_size_allocatable_p(embedded_size); } @@ -849,7 +849,7 @@ rb_zjit_struct_embedded_p(long num_members) static VALUE struct_alloc(VALUE klass) { - long n = num_members(klass); + rb_len_t n = num_members(klass); size_t embedded_size = offsetof(struct RStruct, as.ary) + (sizeof(VALUE) * n); VALUE flags = T_STRUCT; @@ -909,7 +909,7 @@ rb_struct_new(VALUE klass, ...) int size, i; va_list args; - size = rb_long2int(num_members(klass)); + size = rb_len2int(num_members(klass)); if (size > numberof(tmpargs)) { tmpargs[0] = rb_ary_hidden_new(size); mem = RARRAY_PTR(tmpargs[0]); @@ -954,7 +954,7 @@ struct_enum_size(VALUE s, VALUE args, VALUE eobj) static VALUE rb_struct_each(VALUE s) { - long i; + rb_len_t i; RETURN_SIZED_ENUMERATOR(s, 0, 0, struct_enum_size); for (i=0; i 0)) { rb_ary_compact_bang(missing); - RUBY_ASSERT(RARRAY_LEN(missing) == arg.missing_count, "missing_count=%ld but %ld", arg.missing_count, RARRAY_LEN(missing)); + RUBY_ASSERT(RARRAY_LEN(missing) == arg.missing_count, "missing_count=%"PRIdLEN" but %"PRIdLEN, arg.missing_count, RARRAY_LEN(missing)); RBASIC_SET_CLASS_RAW(missing, rb_cArray); rb_exc_raise(rb_keyword_error_new("missing", missing)); }