summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--array.c746
-rw-r--r--dir.c2
-rw-r--r--enum.c16
-rw-r--r--enumerator.c16
-rw-r--r--error.c4
-rw-r--r--eval.c121
-rw-r--r--ext/Win32API/Win32API.c10
-rw-r--r--ext/dbm/dbm.c10
-rw-r--r--ext/dl/cfunc.c6
-rw-r--r--ext/gdbm/gdbm.c10
-rw-r--r--ext/iconv/iconv.c8
-rw-r--r--ext/openssl/ossl.c2
-rw-r--r--ext/openssl/ossl_ocsp.c8
-rw-r--r--ext/openssl/ossl_ssl.c8
-rw-r--r--ext/openssl/ossl_x509cert.c8
-rw-r--r--ext/openssl/ossl_x509crl.c16
-rw-r--r--ext/openssl/ossl_x509req.c8
-rw-r--r--ext/openssl/ossl_x509revoked.c8
-rw-r--r--ext/racc/cparse/cparse.c64
-rw-r--r--ext/readline/readline.c8
-rw-r--r--ext/sdbm/init.c10
-rw-r--r--ext/socket/socket.c22
-rw-r--r--ext/syck/rubyext.c12
-rw-r--r--ext/tk/tcltklib.c45
-rw-r--r--ext/win32ole/win32ole.c18
-rw-r--r--file.c29
-rw-r--r--gc.c28
-rw-r--r--hash.c34
-rw-r--r--io.c46
-rw-r--r--marshal.c14
-rw-r--r--numeric.c6
-rw-r--r--object.c8
-rw-r--r--pack.c18
-rw-r--r--process.c12
-rw-r--r--ruby.c6
-rw-r--r--ruby.h28
-rw-r--r--string.c11
-rw-r--r--struct.c54
39 files changed, 804 insertions, 684 deletions
diff --git a/ChangeLog b/ChangeLog
index a9fa274..cb8b172 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Sat Sep 2 23:37:29 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * ruby.h (struct RArray): embed small arrays.
+ (RARRAY_LEN): defined for accessing array members.
+ (RARRAY_PTR): ditto.
+
+ * array.c: use RARRAY_LEN and RARRAY_PTR.
+
Sat Sep 2 13:23:01 2006 Tanaka Akira <akr@fsij.org>
* common.mk (ia64.o): use the compiler driver to assemble ia64.s
diff --git a/array.c b/array.c
index d50df15..508c123 100644
--- a/array.c
+++ b/array.c
@@ -39,7 +39,55 @@ memfill(register VALUE *mem, register long size, register VALUE val)
}
}
-#define ARY_TMPLOCK FL_USER1
+#define ARY_TMPLOCK FL_USER1
+#define ARY_NOEMBED FL_USER3
+#define ARY_SHARED_P(a) FL_TEST(a, ELTS_SHARED)
+
+#define ARY_SET_NOEMBED(ary) do {\
+ FL_SET(ary, ARY_NOEMBED);\
+ ARY_SET_EMBED_LEN(ary, 0);\
+} while (0)
+#define ARY_SET_EMBED(str) FL_UNSET(str, ARY_NOEMBED)
+#define ARY_EMBED_P(ary) (!FL_TEST(ary, ARY_NOEMBED))
+#define ARY_SET_EMBED_LEN(ary, n) do { \
+ long tmp_n = (n);\
+ RBASIC(ary)->flags &= ~RARRAY_EMBED_LEN_MASK;\
+ RBASIC(ary)->flags |= (tmp_n) << RARRAY_EMBED_LEN_SHIFT;\
+} while (0)
+
+#define ARY_SET_LEN(ary, n) do { \
+ if (ARY_EMBED_P(ary)) {\
+ ARY_SET_EMBED_LEN(ary, n);\
+ }\
+ else {\
+ RARRAY(ary)->as.heap.len = (n);\
+ }\
+} while (0)
+
+#define ARY_CAPA(ary) ((ARY_EMBED_P(ary)) ? RARRAY_EMBED_LEN_MAX : RARRAY(ary)->as.heap.aux.capa)
+#define RESIZE_CAPA(ary,capacity) do {\
+ if (ARY_EMBED_P(ary)) {\
+ if ((capacity) > RARRAY_EMBED_LEN_MAX) {\
+ VALUE *tmp = ALLOC_N(VALUE, capacity);\
+ long len = RARRAY_LEN(ary);\
+ MEMCPY(tmp, RARRAY_PTR(ary), VALUE, len);\
+ RARRAY(ary)->as.heap.ptr = tmp;\
+ RARRAY(ary)->as.heap.len = len;\
+ ARY_SET_NOEMBED(ary);\
+ RARRAY(ary)->as.heap.aux.capa = (capacity);\
+ }\
+ }\
+ else {\
+ REALLOC_N(RARRAY(ary)->as.heap.ptr, VALUE, (capacity));\
+ RARRAY(ary)->as.heap.aux.capa = (capacity);\
+ }\
+} while (0)
+
+static VALUE *
+rb_ary_ptr(VALUE ary)
+{
+ return RARRAY_PTR(ary);
+}
static inline void
rb_ary_modify_check(VALUE ary)
@@ -57,12 +105,13 @@ rb_ary_modify(VALUE ary)
VALUE *ptr;
rb_ary_modify_check(ary);
- if (FL_TEST(ary, ELTS_SHARED)) {
- ptr = ALLOC_N(VALUE, RARRAY(ary)->len);
+ if (ARY_EMBED_P(ary)) return;
+ if (ARY_SHARED_P(ary)) {
+ ptr = ALLOC_N(VALUE, RARRAY_LEN(ary));
FL_UNSET(ary, ELTS_SHARED);
- RARRAY(ary)->aux.capa = RARRAY(ary)->len;
- MEMCPY(ptr, RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len);
- RARRAY(ary)->ptr = ptr;
+ RARRAY(ary)->as.heap.aux.capa = RARRAY_LEN(ary);
+ MEMCPY(ptr, RARRAY_PTR(ary), VALUE, RARRAY_LEN(ary));
+ RARRAY(ary)->as.heap.ptr = ptr;
}
}
@@ -94,9 +143,9 @@ ary_alloc(VALUE klass)
NEWOBJ(ary, struct RArray);
OBJSETUP(ary, klass, T_ARRAY);
- ary->len = 0;
- ary->ptr = 0;
- ary->aux.capa = 0;
+ ary->as.heap.len = 0;
+ ary->as.heap.ptr = 0;
+ ary->as.heap.aux.capa = 0;
return (VALUE)ary;
}
@@ -112,11 +161,16 @@ ary_new(VALUE klass, long len)
if (len > 0 && len * sizeof(VALUE) <= len) {
rb_raise(rb_eArgError, "array size too big");
}
- if (len == 0) len++;
-
ary = ary_alloc(klass);
- RARRAY(ary)->ptr = ALLOC_N(VALUE, len);
- RARRAY(ary)->aux.capa = len;
+ if (len <= RARRAY_EMBED_LEN_MAX) {
+ ARY_SET_EMBED_LEN(ary, 0);
+ }
+ else {
+ if (len == 0) len++;
+ ARY_SET_NOEMBED(ary);
+ RARRAY(ary)->as.heap.ptr = ALLOC_N(VALUE, len);
+ RARRAY(ary)->as.heap.aux.capa = len;
+ }
return ary;
}
@@ -147,11 +201,11 @@ rb_ary_new3(long n, ...)
va_start(ar, n);
for (i=0; i<n; i++) {
- RARRAY(ary)->ptr[i] = va_arg(ar, VALUE);
+ RARRAY_PTR(ary)[i] = va_arg(ar, VALUE);
}
va_end(ar);
- RARRAY(ary)->len = n;
+ ARY_SET_LEN(ary, n);
return ary;
}
@@ -162,8 +216,8 @@ rb_ary_new4(long n, const VALUE *elts)
ary = rb_ary_new2(n);
if (n > 0 && elts) {
- MEMCPY(RARRAY(ary)->ptr, elts, VALUE, n);
- RARRAY(ary)->len = n;
+ MEMCPY(RARRAY_PTR(ary), elts, VALUE, n);
+ ARY_SET_LEN(ary, n);
}
return ary;
@@ -172,34 +226,23 @@ rb_ary_new4(long n, const VALUE *elts)
static VALUE
ary_make_shared(VALUE ary)
{
- if (!FL_TEST(ary, ELTS_SHARED)) {
+ if (ARY_EMBED_P(ary)) abort();
+ if (ARY_SHARED_P(ary)) {
+ return RARRAY(ary)->as.heap.aux.shared;
+ }
+ else {
NEWOBJ(shared, struct RArray);
- OBJSETUP(shared, rb_cArray, T_ARRAY);
+ OBJSETUP(shared, 0, T_ARRAY);
- shared->len = RARRAY(ary)->len;
- shared->ptr = RARRAY(ary)->ptr;
- shared->aux.capa = RARRAY(ary)->aux.capa;
- RARRAY(ary)->aux.shared = (VALUE)shared;
+ ARY_SET_NOEMBED(shared);
+ shared->as.heap.len = RARRAY(ary)->as.heap.len;
+ shared->as.heap.ptr = RARRAY(ary)->as.heap.ptr;
+ shared->as.heap.aux.capa = RARRAY(ary)->as.heap.aux.capa;
+ RARRAY(ary)->as.heap.aux.shared = (VALUE)shared;
FL_SET(ary, ELTS_SHARED);
OBJ_FREEZE(shared);
return (VALUE)shared;
}
- else {
- return RARRAY(ary)->aux.shared;
- }
-}
-
-static VALUE
-ary_shared_array(VALUE klass, VALUE ary)
-{
- VALUE val = ary_alloc(klass);
-
- ary_make_shared(ary);
- RARRAY(val)->ptr = RARRAY(ary)->ptr;
- RARRAY(val)->len = RARRAY(ary)->len;
- RARRAY(val)->aux.shared = RARRAY(ary)->aux.shared;
- FL_SET(val, ELTS_SHARED);
- return val;
}
VALUE
@@ -272,8 +315,13 @@ rb_ary_initialize(int argc, VALUE *argv, VALUE ary)
long len;
VALUE size, val;
+ rb_ary_modify(ary);
if (rb_scan_args(argc, argv, "02", &size, &val) == 0) {
- RARRAY(ary)->len = 0;
+ if (!ARY_EMBED_P(ary) && RARRAY_PTR(ary) && !ARY_SHARED_P(ary)) {
+ free(RARRAY(ary)->as.heap.ptr);
+ }
+ ARY_SET_EMBED(ary);
+ ARY_SET_LEN(ary, 0);
if (rb_block_given_p()) {
rb_warning("given block not used");
}
@@ -296,9 +344,20 @@ rb_ary_initialize(int argc, VALUE *argv, VALUE ary)
rb_raise(rb_eArgError, "array size too big");
}
rb_ary_modify(ary);
- if (len > RARRAY(ary)->aux.capa) {
- REALLOC_N(RARRAY(ary)->ptr, VALUE, len);
- RARRAY(ary)->aux.capa = len;
+ if (len <= RARRAY_EMBED_LEN_MAX) {
+ if (!ARY_EMBED_P(ary)) {
+ xfree(RARRAY(ary)->as.heap.ptr);
+ ARY_SET_EMBED(ary);
+ }
+ ARY_SET_EMBED_LEN(ary, len);
+ }
+ else {
+ if (ARY_EMBED_P(ary)) {
+ ARY_SET_NOEMBED(ary);
+ RARRAY(ary)->as.heap.len = 0;
+ RARRAY(ary)->as.heap.ptr = 0;
+ }
+ RESIZE_CAPA(ary, len);
}
if (rb_block_given_p()) {
long i;
@@ -308,14 +367,13 @@ rb_ary_initialize(int argc, VALUE *argv, VALUE ary)
}
for (i=0; i<len; i++) {
rb_ary_store(ary, i, rb_yield(LONG2NUM(i)));
- RARRAY(ary)->len = i + 1;
+ ARY_SET_LEN(ary, i+1);
}
}
else {
- memfill(RARRAY(ary)->ptr, len, val);
- RARRAY(ary)->len = len;
+ memfill(RARRAY_PTR(ary), len, val);
+ ARY_SET_LEN(ary, len);
}
-
return ary;
}
@@ -333,11 +391,16 @@ rb_ary_s_create(int argc, VALUE *argv, VALUE klass)
{
VALUE ary = ary_alloc(klass);
- if (argc > 0) {
- RARRAY(ary)->ptr = ALLOC_N(VALUE, argc);
- MEMCPY(RARRAY(ary)->ptr, argv, VALUE, argc);
+ if (argc < 0) {
+ rb_raise(rb_eArgError, "negative array size");
+ }
+ if (argc > RARRAY_EMBED_LEN_MAX) {
+ ARY_SET_NOEMBED(ary);
+ RARRAY(ary)->as.heap.ptr = ALLOC_N(VALUE, argc);
+ RARRAY(ary)->as.heap.aux.capa = argc;
}
- RARRAY(ary)->len = RARRAY(ary)->aux.capa = argc;
+ MEMCPY(RARRAY_PTR(ary), argv, VALUE, argc);
+ ARY_SET_LEN(ary, argc);
return ary;
}
@@ -346,63 +409,78 @@ void
rb_ary_store(VALUE ary, long idx, VALUE val)
{
if (idx < 0) {
- idx += RARRAY(ary)->len;
+ idx += RARRAY_LEN(ary);
if (idx < 0) {
rb_raise(rb_eIndexError, "index %ld out of array",
- idx - RARRAY(ary)->len);
+ idx - RARRAY_LEN(ary));
}
}
rb_ary_modify(ary);
- if (idx >= RARRAY(ary)->aux.capa) {
- long new_capa = RARRAY(ary)->aux.capa / 2;
+ if (idx >= ARY_CAPA(ary)) {
+ long new_capa = ARY_CAPA(ary) / 2;
if (new_capa < ARY_DEFAULT_SIZE) {
new_capa = ARY_DEFAULT_SIZE;
}
+ if (new_capa + idx < new_capa) {
+ rb_raise(rb_eArgError, "index too big");
+ }
new_capa += idx;
if (new_capa * (long)sizeof(VALUE) <= new_capa) {
rb_raise(rb_eArgError, "index too big");
}
- REALLOC_N(RARRAY(ary)->ptr, VALUE, new_capa);
- RARRAY(ary)->aux.capa = new_capa;
+ RESIZE_CAPA(ary, new_capa);
}
- if (idx > RARRAY(ary)->len) {
- rb_mem_clear(RARRAY(ary)->ptr + RARRAY(ary)->len,
- idx-RARRAY(ary)->len + 1);
+ if (idx > RARRAY_LEN(ary)) {
+ rb_mem_clear(RARRAY_PTR(ary) + RARRAY_LEN(ary),
+ idx-RARRAY_LEN(ary) + 1);
}
- if (idx >= RARRAY(ary)->len) {
- RARRAY(ary)->len = idx + 1;
+ if (idx >= RARRAY_LEN(ary)) {
+ ARY_SET_LEN(ary, idx + 1);
}
- RARRAY(ary)->ptr[idx] = val;
+ RARRAY_PTR(ary)[idx] = val;
}
static VALUE
-ary_shared_first(int argc, VALUE *argv, VALUE ary)
+ary_shared_array(VALUE klass, VALUE ary)
+{
+ VALUE val = ary_alloc(klass);
+
+ ary_make_shared(ary);
+ RARRAY(val)->as.heap.ptr = RARRAY(ary)->as.heap.ptr;
+ RARRAY(val)->as.heap.len = RARRAY(ary)->as.heap.len;
+ RARRAY(val)->as.heap.aux.shared = RARRAY(ary)->as.heap.aux.shared;
+ FL_SET(val, ELTS_SHARED);
+ return val;
+}
+
+static VALUE
+ary_shared_first(int argc, VALUE *argv, VALUE ary, int last)
{
VALUE nv, result;
long n;
+ long offset = 0;
rb_scan_args(argc, argv, "1", &nv);
n = NUM2LONG(nv);
- if (n > RARRAY(ary)->len) {
- n = RARRAY(ary)->len;
+ if (n > RARRAY_LEN(ary)) {
+ n = RARRAY_LEN(ary);
}
else if (n < 0) {
rb_raise(rb_eArgError, "negative array size");
}
- result = ary_shared_array(rb_cArray, ary);
- RARRAY(result)->len = n;
- return result;
-}
-
-static VALUE
-ary_shared_last(int argc, VALUE *argv, VALUE ary)
-{
- VALUE result = ary_shared_first(argc, argv, ary);
-
- RARRAY(result)->ptr += RARRAY(ary)->len - RARRAY(result)->len;
+ if (last) {
+ offset = RARRAY_LEN(ary) - n;
+ }
+ if (ARY_EMBED_P(ary)) {
+ return rb_ary_new4(n, RARRAY_PTR(ary)+offset);
+ }
+ else {
+ result = ary_shared_array(rb_cArray, ary);
+ RARRAY(result)->as.heap.len = n;
+ }
return result;
}
@@ -422,7 +500,7 @@ ary_shared_last(int argc, VALUE *argv, VALUE ary)
VALUE
rb_ary_push(VALUE ary, VALUE item)
{
- rb_ary_store(ary, RARRAY(ary)->len, item);
+ rb_ary_store(ary, RARRAY_LEN(ary), item);
return ary;
}
@@ -451,15 +529,17 @@ rb_ary_push_m(int argc, VALUE *argv, VALUE ary)
VALUE
rb_ary_pop(VALUE ary)
{
+ long n;
rb_ary_modify_check(ary);
- if (RARRAY(ary)->len == 0) return Qnil;
+ if (RARRAY_LEN(ary) == 0) return Qnil;
if (!FL_TEST(ary, ELTS_SHARED) &&
- RARRAY(ary)->len * 3 < RARRAY(ary)->aux.capa &&
- RARRAY(ary)->aux.capa > ARY_DEFAULT_SIZE) {
- RARRAY(ary)->aux.capa = RARRAY(ary)->len * 2;
- REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->aux.capa);
+ RARRAY_LEN(ary) * 3 < ARY_CAPA(ary) &&
+ ARY_CAPA(ary) > ARY_DEFAULT_SIZE) {
+ RESIZE_CAPA(ary, RARRAY_LEN(ary) * 2);
}
- return RARRAY(ary)->ptr[--RARRAY(ary)->len];
+ n = RARRAY_LEN(ary)-1;
+ ARY_SET_LEN(ary, n);
+ return RARRAY_PTR(ary)[n];
}
/*
@@ -485,9 +565,8 @@ rb_ary_pop_m(int argc, VALUE *argv, VALUE ary)
}
rb_ary_modify_check(ary);
-
- result = ary_shared_last(argc, argv, ary);
- RARRAY(ary)->len -= RARRAY(result)->len;
+ result = ary_shared_first(argc, argv, ary, Qtrue);
+ ARY_SET_LEN(ary, RARRAY_LEN(ary) - RARRAY_LEN(result));
return result;
}
@@ -497,11 +576,17 @@ rb_ary_shift(VALUE ary)
VALUE top;
rb_ary_modify_check(ary);
- if (RARRAY(ary)->len == 0) return Qnil;
- top = RARRAY(ary)->ptr[0];
- ary_make_shared(ary);
- RARRAY(ary)->ptr++; /* shift ptr */
- RARRAY(ary)->len--;
+ if (RARRAY_LEN(ary) == 0) return Qnil;
+ top = RARRAY_PTR(ary)[0];
+ if (ARY_EMBED_P(ary)) {
+ MEMMOVE(RARRAY_PTR(ary), RARRAY_PTR(ary)+1, VALUE, RARRAY_LEN(ary));
+ ARY_SET_EMBED_LEN(ary, RARRAY_LEN(ary)-1);
+ }
+ else {
+ ary_make_shared(ary);
+ RARRAY(ary)->as.heap.ptr++; /* shift ptr */
+ RARRAY(ary)->as.heap.len--;
+ }
return top;
}
@@ -534,11 +619,20 @@ rb_ary_shift_m(int argc, VALUE *argv, VALUE ary)
}
rb_ary_modify_check(ary);
+ if (ARY_EMBED_P(ary)) {
+
+ }
- result = ary_shared_first(argc, argv, ary);
- n = RARRAY(result)->len;
- RARRAY(ary)->ptr += n;
- RARRAY(ary)->len -= n;
+ result = ary_shared_first(argc, argv, ary, Qfalse);
+ n = RARRAY_LEN(result);
+ if (ARY_SHARED_P(ary)) {
+ RARRAY(ary)->as.heap.ptr += n;
+ RARRAY(ary)->as.heap.len -= n;
+ }
+ else {
+ MEMMOVE(RARRAY_PTR(ary), RARRAY_PTR(ary)+n, VALUE, RARRAY_LEN(ary)-n);
+ ARY_SET_LEN(ary, RARRAY_LEN(ary)-n);
+ }
return result;
}
@@ -547,20 +641,18 @@ VALUE
rb_ary_unshift(VALUE ary, VALUE item)
{
rb_ary_modify(ary);
- if (RARRAY(ary)->len == RARRAY(ary)->aux.capa) {
- long capa_inc = RARRAY(ary)->aux.capa / 2;
+ if (RARRAY_LEN(ary) == ARY_CAPA(ary)) {
+ long capa_inc = ARY_CAPA(ary) / 2;
if (capa_inc < ARY_DEFAULT_SIZE) {
capa_inc = ARY_DEFAULT_SIZE;
}
- RARRAY(ary)->aux.capa += capa_inc;
- REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->aux.capa);
+ RESIZE_CAPA(ary, ARY_CAPA(ary)+capa_inc);
}
/* sliding items */
- MEMMOVE(RARRAY(ary)->ptr + 1, RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len);
-
- RARRAY(ary)->len++;
- RARRAY(ary)->ptr[0] = item;
+ MEMMOVE(RARRAY_PTR(ary) + 1, RARRAY_PTR(ary), VALUE, RARRAY_LEN(ary));
+ ARY_SET_LEN(ary, RARRAY_LEN(ary)+1);
+ RARRAY_PTR(ary)[0] = item;
return ary;
}
@@ -580,7 +672,7 @@ rb_ary_unshift(VALUE ary, VALUE item)
static VALUE
rb_ary_unshift_m(int argc, VALUE *argv, VALUE ary)
{
- long len = RARRAY(ary)->len;
+ long len = RARRAY_LEN(ary);
if (argc == 0) return ary;
@@ -588,8 +680,8 @@ rb_ary_unshift_m(int argc, VALUE *argv, VALUE ary)
rb_ary_store(ary, len + argc - 1, Qnil);
/* sliding items */
- MEMMOVE(RARRAY(ary)->ptr + argc, RARRAY(ary)->ptr, VALUE, len);
- MEMCPY(RARRAY(ary)->ptr, argv, VALUE, argc);
+ MEMMOVE(RARRAY_PTR(ary) + argc, RARRAY_PTR(ary), VALUE, len);
+ MEMCPY(RARRAY_PTR(ary), argv, VALUE, argc);
return ary;
}
@@ -598,18 +690,18 @@ rb_ary_unshift_m(int argc, VALUE *argv, VALUE ary)
static inline VALUE
rb_ary_elt(VALUE ary, long offset)
{
- if (RARRAY(ary)->len == 0) return Qnil;
- if (offset < 0 || RARRAY(ary)->len <= offset) {
+ if (RARRAY_LEN(ary) == 0) return Qnil;
+ if (offset < 0 || RARRAY_LEN(ary) <= offset) {
return Qnil;
}
- return RARRAY(ary)->ptr[offset];
+ return RARRAY_PTR(ary)[offset];
}
VALUE
rb_ary_entry(VALUE ary, long offset)
{
if (offset < 0) {
- offset += RARRAY(ary)->len;
+ offset += RARRAY_LEN(ary);
}
return rb_ary_elt(ary, offset);
}
@@ -620,26 +712,31 @@ rb_ary_subseq(VALUE ary, long beg, long len)
VALUE klass, ary2, shared;
VALUE *ptr;
- if (beg > RARRAY(ary)->len) return Qnil;
+ if (beg > RARRAY_LEN(ary)) return Qnil;
if (beg < 0 || len < 0) return Qnil;
- if (beg + len > RARRAY(ary)->len) {
- len = RARRAY(ary)->len - beg;
+ if (beg + len > RARRAY_LEN(ary)) {
+ len = RARRAY_LEN(ary) - beg;
if (len < 0)
len = 0;
}
klass = rb_obj_class(ary);
if (len == 0) return ary_new(klass, 0);
- shared = ary_make_shared(ary);
- ptr = RARRAY(ary)->ptr;
- ary2 = ary_alloc(klass);
- RARRAY(ary2)->ptr = ptr + beg;
- RARRAY(ary2)->len = len;
- RARRAY(ary2)->aux.shared = shared;
- FL_SET(ary2, ELTS_SHARED);
-
- return ary2;
+ if (ARY_EMBED_P(ary) && len <= RARRAY_EMBED_LEN_MAX) {
+ return rb_ary_new4(len, RARRAY_PTR(ary)+beg);
+ }
+ else {
+ shared = ary_make_shared(ary);
+ ptr = RARRAY_PTR(ary);
+ ary2 = ary_alloc(klass);
+ ARY_SET_NOEMBED(ary2);
+ RARRAY(ary2)->as.heap.ptr = ptr + beg;
+ RARRAY(ary2)->as.heap.len = len;
+ RARRAY(ary2)->as.heap.aux.shared = shared;
+ FL_SET(ary2, ELTS_SHARED);
+ return ary2;
+ }
}
/*
@@ -684,7 +781,7 @@ rb_ary_aref(int argc, VALUE *argv, VALUE ary)
beg = NUM2LONG(argv[0]);
len = NUM2LONG(argv[1]);
if (beg < 0) {
- beg += RARRAY(ary)->len;
+ beg += RARRAY_LEN(ary);
}
return rb_ary_subseq(ary, beg, len);
}
@@ -697,7 +794,7 @@ rb_ary_aref(int argc, VALUE *argv, VALUE ary)
return rb_ary_entry(ary, FIX2LONG(arg));
}
/* check if idx is Range */
- switch (rb_range_beg_len(arg, &beg, &len, RARRAY(ary)->len, 0)) {
+ switch (rb_range_beg_len(arg, &beg, &len, RARRAY_LEN(ary), 0)) {
case Qfalse:
break;
case Qnil:
@@ -747,11 +844,11 @@ static VALUE
rb_ary_first(int argc, VALUE *argv, VALUE ary)
{
if (argc == 0) {
- if (RARRAY(ary)->len == 0) return Qnil;
- return RARRAY(ary)->ptr[0];
+ if (RARRAY_LEN(ary) == 0) return Qnil;
+ return RARRAY_PTR(ary)[0];
}
else {
- return ary_shared_first(argc, argv, ary);
+ return ary_shared_first(argc, argv, ary, Qfalse);
}
}
@@ -772,11 +869,11 @@ static VALUE
rb_ary_last(int argc, VALUE *argv, VALUE ary)
{
if (argc == 0) {
- if (RARRAY(ary)->len == 0) return Qnil;
- return RARRAY(ary)->ptr[RARRAY(ary)->len-1];
+ if (RARRAY_LEN(ary) == 0) return Qnil;
+ return RARRAY_PTR(ary)[RARRAY_LEN(ary)-1];
}
else {
- return ary_shared_last(argc, argv, ary);
+ return ary_shared_first(argc, argv, ary, Qtrue);
}
}
@@ -815,16 +912,16 @@ rb_ary_fetch(int argc, VALUE *argv, VALUE ary)
idx = NUM2LONG(pos);
if (idx < 0) {
- idx += RARRAY(ary)->len;
+ idx += RARRAY_LEN(ary);
}
- if (idx < 0 || RARRAY(ary)->len <= idx) {
+ if (idx < 0 || RARRAY_LEN(ary) <= idx) {
if (block_given) return rb_yield(pos);
if (argc == 1) {
rb_raise(rb_eIndexError, "index %ld out of array", idx);
}
return ifnone;
}
- return RARRAY(ary)->ptr[idx];
+ return RARRAY_PTR(ary)[idx];
}
/*
@@ -851,15 +948,15 @@ rb_ary_index(int argc, VALUE *argv, VALUE ary)
if (rb_scan_args(argc, argv, "01", &val) == 0) {
RETURN_ENUMERATOR(ary, 0, 0);
- for (i=0; i<RARRAY(ary)->len; i++) {
- if (RTEST(rb_yield(RARRAY(ary)->ptr[i]))) {
+ for (i=0; i<RARRAY_LEN(ary); i++) {
+ if (RTEST(rb_yield(RARRAY_PTR(ary)[i]))) {
return LONG2NUM(i);
}
}
}
else {
- for (i=0; i<RARRAY(ary)->len; i++) {
- if (rb_equal(RARRAY(ary)->ptr[i], val))
+ for (i=0; i<RARRAY_LEN(ary); i++) {
+ if (rb_equal(RARRAY_PTR(ary)[i], val))
return LONG2NUM(i);
}
}
@@ -885,24 +982,24 @@ static VALUE
rb_ary_rindex(int argc, VALUE *argv, VALUE ary)
{
VALUE val;
- long i = RARRAY(ary)->len;
+ long i = RARRAY_LEN(ary);
if (rb_scan_args(argc, argv, "01", &val) == 0) {
while (i--) {
RETURN_ENUMERATOR(ary, 0, 0);
- if (RTEST(rb_yield(RARRAY(ary)->ptr[i])))
+ if (RTEST(rb_yield(RARRAY_PTR(ary)[i])))
return LONG2NUM(i);
- if (i > RARRAY(ary)->len) {
- i = RARRAY(ary)->len;
+ if (i > RARRAY_LEN(ary)) {
+ i = RARRAY_LEN(ary);
}
}
}
else {
while (i--) {
- if (rb_equal(RARRAY(ary)->ptr[i], val))
+ if (rb_equal(RARRAY_PTR(ary)[i], val))
return LONG2NUM(i);
- if (i > RARRAY(ary)->len) {
- i = RARRAY(ary)->len;
+ if (i > RARRAY_LEN(ary)) {
+ i = RARRAY_LEN(ary);
}
}
}
@@ -928,14 +1025,14 @@ rb_ary_splice(VALUE ary, long beg, long len, VALUE rpl)
if (len < 0) rb_raise(rb_eIndexError, "negative length (%ld)", len);
if (beg < 0) {
- beg += RARRAY(ary)->len;
+ beg += RARRAY_LEN(ary);
if (beg < 0) {
- beg -= RARRAY(ary)->len;
+ beg -= RARRAY_LEN(ary);
rb_raise(rb_eIndexError, "index %ld out of array", beg);
}
}
- if (beg + len > RARRAY(ary)->len) {
- len = RARRAY(ary)->len - beg;
+ if (beg + len > RARRAY_LEN(ary)) {
+ len = RARRAY_LEN(ary) - beg;
}
if (rpl == Qundef) {
@@ -943,42 +1040,39 @@ rb_ary_splice(VALUE ary, long beg, long len, VALUE rpl)
}
else {
rpl = rb_ary_to_ary(rpl);
- rlen = RARRAY(rpl)->len;
+ rlen = RARRAY_LEN(rpl);
}
rb_ary_modify(ary);
-
- if (beg >= RARRAY(ary)->len) {
+ if (beg >= RARRAY_LEN(ary)) {
len = beg + rlen;
- if (len >= RARRAY(ary)->aux.capa) {
- REALLOC_N(RARRAY(ary)->ptr, VALUE, len);
- RARRAY(ary)->aux.capa = len;
+ if (len >= ARY_CAPA(ary)) {
+ RESIZE_CAPA(ary, len);
}
- rb_mem_clear(RARRAY(ary)->ptr + RARRAY(ary)->len, beg - RARRAY(ary)->len);
+ rb_mem_clear(RARRAY_PTR(ary) + RARRAY_LEN(ary), beg - RARRAY_LEN(ary));
if (rlen > 0) {
- MEMCPY(RARRAY(ary)->ptr + beg, RARRAY(rpl)->ptr, VALUE, rlen);
+ MEMCPY(RARRAY_PTR(ary) + beg, RARRAY_PTR(rpl), VALUE, rlen);
}
- RARRAY(ary)->len = len;
+ ARY_SET_LEN(ary, len);
}
else {
long alen;
- if (beg + len > RARRAY(ary)->len) {
- len = RARRAY(ary)->len - beg;
+ if (beg + len > RARRAY_LEN(ary)) {
+ len = RARRAY_LEN(ary) - beg;
}
- alen = RARRAY(ary)->len + rlen - len;
- if (alen >= RARRAY(ary)->aux.capa) {
- REALLOC_N(RARRAY(ary)->ptr, VALUE, alen);
- RARRAY(ary)->aux.capa = alen;
+ alen = RARRAY_LEN(ary) + rlen - len;
+ if (alen >= ARY_CAPA(ary)) {
+ RESIZE_CAPA(ary, alen);
}
if (len != rlen) {
- MEMMOVE(RARRAY(ary)->ptr + beg + rlen, RARRAY(ary)->ptr + beg + len,
- VALUE, RARRAY(ary)->len - (beg + len));
- RARRAY(ary)->len = alen;
+ MEMMOVE(RARRAY_PTR(ary) + beg + rlen, RARRAY_PTR(ary) + beg + len,
+ VALUE, RARRAY_LEN(ary) - (beg + len));
+ ARY_SET_LEN(ary, alen);
}
if (rlen > 0) {
- MEMMOVE(RARRAY(ary)->ptr + beg, RARRAY(rpl)->ptr, VALUE, rlen);
+ MEMMOVE(RARRAY_PTR(ary) + beg, RARRAY_PTR(rpl), VALUE, rlen);
}
}
}
@@ -1027,7 +1121,7 @@ rb_ary_aset(int argc, VALUE *argv, VALUE ary)
offset = FIX2LONG(argv[0]);
goto fixnum;
}
- if (rb_range_beg_len(argv[0], &beg, &len, RARRAY(ary)->len, 1)) {
+ if (rb_range_beg_len(argv[0], &beg, &len, RARRAY_LEN(ary), 1)) {
/* check if idx is Range */
rb_ary_splice(ary, beg, len, argv[1]);
return argv[1];
@@ -1062,7 +1156,7 @@ rb_ary_insert(int argc, VALUE *argv, VALUE ary)
}
pos = NUM2LONG(argv[0]);
if (pos == -1) {
- pos = RARRAY(ary)->len;
+ pos = RARRAY_LEN(ary);
}
if (pos < 0) {
pos++;
@@ -1092,8 +1186,8 @@ rb_ary_each(VALUE ary)
long i;
RETURN_ENUMERATOR(ary, 0, 0);
- for (i=0; i<RARRAY(ary)->len; i++) {
- rb_yield(RARRAY(ary)->ptr[i]);
+ for (i=0; i<RARRAY_LEN(ary); i++) {
+ rb_yield(RARRAY_PTR(ary)[i]);
}
return ary;
}
@@ -1119,7 +1213,7 @@ rb_ary_each_index(VALUE ary)
long i;
RETURN_ENUMERATOR(ary, 0, 0);
- for (i=0; i<RARRAY(ary)->len; i++) {
+ for (i=0; i<RARRAY_LEN(ary); i++) {
rb_yield(LONG2NUM(i));
}
return ary;
@@ -1143,13 +1237,13 @@ rb_ary_each_index(VALUE ary)
static VALUE
rb_ary_reverse_each(VALUE ary)
{
- long len = RARRAY(ary)->len;
+ long len = RARRAY_LEN(ary);
RETURN_ENUMERATOR(ary, 0, 0);
while (len--) {
- rb_yield(RARRAY(ary)->ptr[len]);
- if (RARRAY(ary)->len < len) {
- len = RARRAY(ary)->len;
+ rb_yield(RARRAY_PTR(ary)[len]);
+ if (RARRAY_LEN(ary) < len) {
+ len = RARRAY_LEN(ary);
}
}
return ary;
@@ -1167,7 +1261,8 @@ rb_ary_reverse_each(VALUE ary)
static VALUE
rb_ary_length(VALUE ary)
{
- return LONG2NUM(RARRAY(ary)->len);
+ long len = RARRAY_LEN(ary);
+ return LONG2NUM(len);
}
/*
@@ -1182,7 +1277,7 @@ rb_ary_length(VALUE ary)
static VALUE
rb_ary_empty_p(VALUE ary)
{
- if (RARRAY(ary)->len == 0)
+ if (RARRAY_LEN(ary) == 0)
return Qtrue;
return Qfalse;
}
@@ -1190,11 +1285,12 @@ rb_ary_empty_p(VALUE ary)
VALUE
rb_ary_dup(VALUE ary)
{
- VALUE dup = rb_ary_new2(RARRAY(ary)->len);
+ VALUE dup = rb_ary_new2(RARRAY_LEN(ary));
+
+ MEMCPY(RARRAY_PTR(dup), RARRAY_PTR(ary), VALUE, RARRAY_LEN(ary));
+ ARY_SET_LEN(dup, RARRAY_LEN(ary));
+ OBJ_INFECT(dup, ary);
- DUPSETUP(dup, ary);
- MEMCPY(RARRAY(dup)->ptr, RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len);
- RARRAY(dup)->len = RARRAY(ary)->len;
return dup;
}
@@ -1217,20 +1313,20 @@ rb_ary_join(VALUE ary, VALUE sep)
int taint = Qfalse;
VALUE result, tmp;
- if (RARRAY(ary)->len == 0) return rb_str_new(0, 0);
+ if (RARRAY_LEN(ary) == 0) return rb_str_new(0, 0);
if (OBJ_TAINTED(ary) || OBJ_TAINTED(sep)) taint = Qtrue;
- for (i=0; i<RARRAY(ary)->len; i++) {
- tmp = rb_check_string_type(RARRAY(ary)->ptr[i]);
+ for (i=0; i<RARRAY_LEN(ary); i++) {
+ tmp = rb_check_string_type(RARRAY_PTR(ary)[i]);
len += NIL_P(tmp) ? 10 : RSTRING_LEN(tmp);
}
if (!NIL_P(sep)) {
StringValue(sep);
- len += RSTRING_LEN(sep) * (RARRAY(ary)->len - 1);
+ len += RSTRING_LEN(sep) * (RARRAY_LEN(ary) - 1);
}
result = rb_str_buf_new(len);
- for (i=0; i<RARRAY(ary)->len; i++) {
- tmp = RARRAY(ary)->ptr[i];
+ for (i=0; i<RARRAY_LEN(ary); i++) {
+ tmp = RARRAY_PTR(ary)[i];
switch (TYPE(tmp)) {
case T_STRING:
break;
@@ -1291,7 +1387,7 @@ rb_ary_join_m(int argc, VALUE *argv, VALUE ary)
VALUE
rb_ary_to_s(VALUE ary)
{
- if (RARRAY(ary)->len == 0) return rb_str_new(0, 0);
+ if (RARRAY_LEN(ary) == 0) return rb_str_new(0, 0);
return rb_ary_join(ary, rb_output_fs);
}
@@ -1305,8 +1401,8 @@ inspect_ary(VALUE ary, VALUE dummy, int recur)
if (recur) return rb_tainted_str_new2("[...]");
str = rb_str_buf_new2("[");
- for (i=0; i<RARRAY(ary)->len; i++) {
- s = rb_inspect(RARRAY(ary)->ptr[i]);
+ for (i=0; i<RARRAY_LEN(ary); i++) {
+ s = rb_inspect(RARRAY_PTR(ary)[i]);
if (OBJ_TAINTED(s)) tainted = Qtrue;
if (i > 0) rb_str_buf_cat2(str, ", ");
rb_str_buf_append(str, s);
@@ -1326,7 +1422,7 @@ inspect_ary(VALUE ary, VALUE dummy, int recur)
static VALUE
rb_ary_inspect(VALUE ary)
{
- if (RARRAY(ary)->len == 0) return rb_str_new2("[]");
+ if (RARRAY_LEN(ary) == 0) return rb_str_new2("[]");
return rb_exec_recursive(inspect_ary, ary, 0);
}
@@ -1342,7 +1438,7 @@ static VALUE
rb_ary_to_a(VALUE ary)
{
if (rb_obj_class(ary) != rb_cArray) {
- VALUE dup = rb_ary_new2(RARRAY(ary)->len);
+ VALUE dup = rb_ary_new2(RARRAY_LEN(ary));
rb_ary_replace(dup, ary);
return dup;
}
@@ -1369,9 +1465,9 @@ rb_ary_reverse(VALUE ary)
VALUE tmp;
rb_ary_modify(ary);
- if (RARRAY(ary)->len > 1) {
- p1 = RARRAY(ary)->ptr;
- p2 = p1 + RARRAY(ary)->len - 1; /* points last item */
+ if (RARRAY_LEN(ary) > 1) {
+ p1 = RARRAY_PTR(ary);
+ p2 = p1 + RARRAY_LEN(ary) - 1; /* points last item */
while (p1 < p2) {
tmp = *p1;
@@ -1424,7 +1520,7 @@ struct ary_sort_data {
static void
ary_sort_check(struct ary_sort_data *data)
{
- if (RARRAY(data->ary)->ptr != data->ptr || RARRAY(data->ary)->len != data->len) {
+ if (RARRAY_PTR(data->ary) != data->ptr || RARRAY_LEN(data->ary) != data->len) {
rb_raise(rb_eRuntimeError, "array modified during sort");
}
}
@@ -1470,8 +1566,8 @@ sort_internal(VALUE ary)
struct ary_sort_data data;
data.ary = ary;
- data.ptr = RARRAY(ary)->ptr; data.len = RARRAY(ary)->len;
- ruby_qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE),
+ data.ptr = RARRAY_PTR(ary); data.len = RARRAY_LEN(ary);
+ ruby_qsort(RARRAY_PTR(ary), RARRAY_LEN(ary), sizeof(VALUE),
rb_block_given_p()?sort_1:sort_2, &data);
return ary;
}
@@ -1503,7 +1599,7 @@ VALUE
rb_ary_sort_bang(VALUE ary)
{
rb_ary_modify(ary);
- if (RARRAY(ary)->len > 1) {
+ if (RARRAY_LEN(ary) > 1) {
FL_SET(ary, ARY_TMPLOCK); /* prohibit modification during sort */
rb_ensure(sort_internal, ary, sort_unlock, ary);
}
@@ -1555,9 +1651,9 @@ rb_ary_collect(VALUE ary)
VALUE collect;
RETURN_ENUMERATOR(ary, 0, 0);
- collect = rb_ary_new2(RARRAY(ary)->len);
- for (i = 0; i < RARRAY(ary)->len; i++) {
- rb_ary_push(collect, rb_yield(RARRAY(ary)->ptr[i]));
+ collect = rb_ary_new2(RARRAY_LEN(ary));
+ for (i = 0; i < RARRAY_LEN(ary); i++) {
+ rb_ary_push(collect, rb_yield(RARRAY_PTR(ary)[i]));
}
return collect;
}
@@ -1583,8 +1679,8 @@ rb_ary_collect_bang(VALUE ary)
RETURN_ENUMERATOR(ary, 0, 0);
rb_ary_modify(ary);
- for (i = 0; i < RARRAY(ary)->len; i++) {
- rb_ary_store(ary, i, rb_yield(RARRAY(ary)->ptr[i]));
+ for (i = 0; i < RARRAY_LEN(ary); i++) {
+ rb_ary_store(ary, i, rb_yield(RARRAY_PTR(ary)[i]));
}
return ary;
}
@@ -1636,7 +1732,7 @@ rb_get_values_at(VALUE obj, long olen, int argc, VALUE *argv, VALUE (*func) (VAL
static VALUE
rb_ary_values_at(int argc, VALUE *argv, VALUE ary)
{
- return rb_get_values_at(ary, RARRAY(ary)->len, argc, argv, rb_ary_entry);
+ return rb_get_values_at(ary, RARRAY_LEN(ary), argc, argv, rb_ary_entry);
}
/*
@@ -1658,9 +1754,9 @@ rb_ary_select(VALUE ary)
long i;
RETURN_ENUMERATOR(ary, 0, 0);
- result = rb_ary_new2(RARRAY(ary)->len);
- for (i = 0; i < RARRAY(ary)->len; i++) {
- if (RTEST(rb_yield(RARRAY(ary)->ptr[i]))) {
+ result = rb_ary_new2(RARRAY_LEN(ary));
+ for (i = 0; i < RARRAY_LEN(ary); i++) {
+ if (RTEST(rb_yield(RARRAY_PTR(ary)[i]))) {
rb_ary_push(result, rb_ary_elt(ary, i));
}
}
@@ -1689,8 +1785,8 @@ rb_ary_delete(VALUE ary, VALUE item)
{
long i1, i2;
- for (i1 = i2 = 0; i1 < RARRAY(ary)->len; i1++) {
- VALUE e = RARRAY(ary)->ptr[i1];
+ for (i1 = i2 = 0; i1 < RARRAY_LEN(ary); i1++) {
+ VALUE e = RARRAY_PTR(ary)[i1];
if (rb_equal(e, item)) continue;
if (i1 != i2) {
@@ -1698,7 +1794,7 @@ rb_ary_delete(VALUE ary, VALUE item)
}
i2++;
}
- if (RARRAY(ary)->len == i2) {
+ if (RARRAY_LEN(ary) == i2) {
if (rb_block_given_p()) {
return rb_yield(item);
}
@@ -1706,12 +1802,11 @@ rb_ary_delete(VALUE ary, VALUE item)
}
rb_ary_modify(ary);
- if (RARRAY(ary)->len > i2) {
- RARRAY(ary)->len = i2;
- if (i2 * 2 < RARRAY(ary)->aux.capa &&
- RARRAY(ary)->aux.capa > ARY_DEFAULT_SIZE) {
- REALLOC_N(RARRAY(ary)->ptr, VALUE, i2 * 2);
- RARRAY(ary)->aux.capa = i2 * 2;
+ if (RARRAY_LEN(ary) > i2) {
+ ARY_SET_LEN(ary, i2);
+ if (i2 * 2 < ARY_CAPA(ary) &&
+ ARY_CAPA(ary) > ARY_DEFAULT_SIZE) {
+ RESIZE_CAPA(ary, i2*2);
}
}
@@ -1721,7 +1816,7 @@ rb_ary_delete(VALUE ary, VALUE item)
VALUE
rb_ary_delete_at(VALUE ary, long pos)
{
- long i, len = RARRAY(ary)->len;
+ long i, len = RARRAY_LEN(ary);
VALUE del;
if (pos >= len) return Qnil;
@@ -1731,11 +1826,11 @@ rb_ary_delete_at(VALUE ary, long pos)
}
rb_ary_modify(ary);
- del = RARRAY(ary)->ptr[pos];
+ del = RARRAY_PTR(ary)[pos];
for (i = pos + 1; i < len; i++, pos++) {
- RARRAY(ary)->ptr[pos] = RARRAY(ary)->ptr[i];
+ RARRAY_PTR(ary)[pos] = RARRAY_PTR(ary)[i];
}
- RARRAY(ary)->len = pos;
+ ARY_SET_LEN(ary, pos);
return del;
}
@@ -1796,14 +1891,14 @@ rb_ary_slice_bang(int argc, VALUE *argv, VALUE ary)
len = NUM2LONG(arg2);
delete_pos_len:
if (pos < 0) {
- pos = RARRAY(ary)->len + pos;
+ pos = RARRAY_LEN(ary) + pos;
}
arg2 = rb_ary_subseq(ary, pos, len);
rb_ary_splice(ary, pos, len, Qundef); /* Qnil/rb_ary_new2(0) */
return arg2;
}
- if (!FIXNUM_P(arg1) && rb_range_beg_len(arg1, &pos, &len, RARRAY(ary)->len, 1)) {
+ if (!FIXNUM_P(arg1) && rb_range_beg_len(arg1, &pos, &len, RARRAY_LEN(ary), 1)) {
goto delete_pos_len;
}
@@ -1827,17 +1922,17 @@ rb_ary_reject_bang(VALUE ary)
RETURN_ENUMERATOR(ary, 0, 0);
rb_ary_modify(ary);
- for (i1 = i2 = 0; i1 < RARRAY(ary)->len; i1++) {
- VALUE v = RARRAY(ary)->ptr[i1];
+ for (i1 = i2 = 0; i1 < RARRAY_LEN(ary); i1++) {
+ VALUE v = RARRAY_PTR(ary)[i1];
if (RTEST(rb_yield(v))) continue;
if (i1 != i2) {
rb_ary_store(ary, i2, v);
}
i2++;
}
- if (RARRAY(ary)->len == i2) return Qnil;
- if (i2 < RARRAY(ary)->len)
- RARRAY(ary)->len = i2;
+ if (RARRAY_LEN(ary) == i2) return Qnil;
+ if (i2 < RARRAY_LEN(ary))
+ ARY_SET_LEN(ary, i2);
return ary;
}
@@ -1910,7 +2005,7 @@ rb_ary_zip(int argc, VALUE *argv, VALUE ary)
argv[i] = to_a(argv[i]);
}
if (rb_block_given_p()) {
- for (i=0; i<RARRAY(ary)->len; i++) {
+ for (i=0; i<RARRAY_LEN(ary); i++) {
VALUE tmp = rb_ary_new2(argc+1);
rb_ary_push(tmp, rb_ary_elt(ary, i));
@@ -1921,7 +2016,7 @@ rb_ary_zip(int argc, VALUE *argv, VALUE ary)
}
return Qnil;
}
- len = RARRAY(ary)->len;
+ len = RARRAY_LEN(ary);
result = rb_ary_new2(len);
for (i=0; i<len; i++) {
VALUE tmp = rb_ary_new2(argc+1);
@@ -1952,20 +2047,20 @@ rb_ary_transpose(VALUE ary)
long elen = -1, alen, i, j;
VALUE tmp, result = 0;
- alen = RARRAY(ary)->len;
+ alen = RARRAY_LEN(ary);
if (alen == 0) return rb_ary_dup(ary);
for (i=0; i<alen; i++) {
tmp = to_ary(rb_ary_elt(ary, i));
if (elen < 0) { /* first element */
- elen = RARRAY(tmp)->len;
+ elen = RARRAY_LEN(tmp);
result = rb_ary_new2(elen);
for (j=0; j<elen; j++) {
rb_ary_store(result, j, rb_ary_new2(alen));
}
}
- else if (elen != RARRAY(tmp)->len) {
+ else if (elen != RARRAY_LEN(tmp)) {
rb_raise(rb_eIndexError, "element size differs (%ld should be %ld)",
- RARRAY(tmp)->len, elen);
+ RARRAY_LEN(tmp), elen);
}
for (j=0; j<elen; j++) {
rb_ary_store(rb_ary_elt(result, j), i, rb_ary_elt(tmp, j));
@@ -1994,12 +2089,21 @@ rb_ary_replace(VALUE copy, VALUE orig)
rb_ary_modify(copy);
orig = to_ary(orig);
if (copy == orig) return copy;
+ if (ARY_EMBED_P(orig)) {
+ MEMCPY(RARRAY_PTR(copy), RARRAY_PTR(orig), VALUE, RARRAY_LEN(orig));
+ ARY_SET_LEN(copy, RARRAY_LEN(orig));
+ return copy;
+ }
shared = ary_make_shared(orig);
- if (RARRAY(copy)->ptr && !FL_TEST(copy, ELTS_SHARED))
- free(RARRAY(copy)->ptr);
- RARRAY(copy)->ptr = RARRAY(orig)->ptr;
- RARRAY(copy)->len = RARRAY(orig)->len;
- RARRAY(copy)->aux.shared = shared;
+ if (ARY_EMBED_P(copy)) {
+ ARY_SET_NOEMBED(copy);
+ }
+ else {
+ xfree(RARRAY(copy)->as.heap.ptr);
+ }
+ RARRAY(copy)->as.heap.ptr = RARRAY(shared)->as.heap.ptr;
+ RARRAY(copy)->as.heap.len = RARRAY(shared)->as.heap.len;
+ RARRAY(copy)->as.heap.aux.shared = shared;
FL_SET(copy, ELTS_SHARED);
return copy;
@@ -2019,10 +2123,9 @@ VALUE
rb_ary_clear(VALUE ary)
{
rb_ary_modify(ary);
- RARRAY(ary)->len = 0;
- if (ARY_DEFAULT_SIZE * 2 < RARRAY(ary)->aux.capa) {
- REALLOC_N(RARRAY(ary)->ptr, VALUE, ARY_DEFAULT_SIZE * 2);
- RARRAY(ary)->aux.capa = ARY_DEFAULT_SIZE * 2;
+ ARY_SET_LEN(ary, 0);
+ if (ARY_DEFAULT_SIZE * 2 < ARY_CAPA(ary)) {
+ RESIZE_CAPA(ary, ARY_DEFAULT_SIZE * 2);
}
return ary;
}
@@ -2070,31 +2173,30 @@ rb_ary_fill(int argc, VALUE *argv, VALUE ary)
switch (argc) {
case 1:
beg = 0;
- len = RARRAY(ary)->len;
+ len = RARRAY_LEN(ary);
break;
case 2:
- if (rb_range_beg_len(arg1, &beg, &len, RARRAY(ary)->len, 1)) {
+ if (rb_range_beg_len(arg1, &beg, &len, RARRAY_LEN(ary), 1)) {
break;
}
/* fall through */
case 3:
beg = NIL_P(arg1) ? 0 : NUM2LONG(arg1);
if (beg < 0) {
- beg = RARRAY(ary)->len + beg;
+ beg = RARRAY_LEN(ary) + beg;
if (beg < 0) beg = 0;
}
- len = NIL_P(arg2) ? RARRAY(ary)->len - beg : NUM2LONG(arg2);
+ len = NIL_P(arg2) ? RARRAY_LEN(ary) - beg : NUM2LONG(arg2);
break;
}
rb_ary_modify(ary);
end = beg + len;
- if (end > RARRAY(ary)->len) {
- if (end >= RARRAY(ary)->aux.capa) {
- REALLOC_N(RARRAY(ary)->ptr, VALUE, end);
- RARRAY(ary)->aux.capa = end;
+ if (end > RARRAY_LEN(ary)) {
+ if (end >= ARY_CAPA(ary)) {
+ RESIZE_CAPA(ary, end);
}
- rb_mem_clear(RARRAY(ary)->ptr + RARRAY(ary)->len, end - RARRAY(ary)->len);
- RARRAY(ary)->len = end;
+ rb_mem_clear(RARRAY_PTR(ary) + RARRAY_LEN(ary), end - RARRAY_LEN(ary));
+ ARY_SET_LEN(ary, end);
}
if (block_p) {
@@ -2103,12 +2205,12 @@ rb_ary_fill(int argc, VALUE *argv, VALUE ary)
for (i=beg; i<end; i++) {
v = rb_yield(LONG2NUM(i));
- if (i>=RARRAY(ary)->len) break;
- RARRAY(ary)->ptr[i] = v;
+ if (i>=RARRAY_LEN(ary)) break;
+ RARRAY_PTR(ary)[i] = v;
}
}
else {
- p = RARRAY(ary)->ptr + beg;
+ p = RARRAY_PTR(ary) + beg;
pend = p + len;
while (p < pend) {
*p++ = item;
@@ -2134,11 +2236,11 @@ rb_ary_plus(VALUE x, VALUE y)
long len;
y = to_ary(y);
- len = RARRAY(x)->len + RARRAY(y)->len;
+ len = RARRAY_LEN(x) + RARRAY_LEN(y);
z = rb_ary_new2(len);
- MEMCPY(RARRAY(z)->ptr, RARRAY(x)->ptr, VALUE, RARRAY(x)->len);
- MEMCPY(RARRAY(z)->ptr + RARRAY(x)->len, RARRAY(y)->ptr, VALUE, RARRAY(y)->len);
- RARRAY(z)->len = len;
+ MEMCPY(RARRAY_PTR(z), RARRAY_PTR(x), VALUE, RARRAY_LEN(x));
+ MEMCPY(RARRAY_PTR(z) + RARRAY_LEN(x), RARRAY_PTR(y), VALUE, RARRAY_LEN(y));
+ ARY_SET_LEN(z, len);
return z;
}
@@ -2156,8 +2258,8 @@ VALUE
rb_ary_concat(VALUE x, VALUE y)
{
y = to_ary(y);
- if (RARRAY(y)->len > 0) {
- rb_ary_splice(x, RARRAY(x)->len, 0, y);
+ if (RARRAY_LEN(y) > 0) {
+ rb_ary_splice(x, RARRAY_LEN(x), 0, y);
}
return x;
}
@@ -2194,16 +2296,16 @@ rb_ary_times(VALUE ary, VALUE times)
if (len < 0) {
rb_raise(rb_eArgError, "negative argument");
}
- if (LONG_MAX/len < RARRAY(ary)->len) {
+ if (LONG_MAX/len < RARRAY_LEN(ary)) {
rb_raise(rb_eArgError, "argument too big");
}
- len *= RARRAY(ary)->len;
+ len *= RARRAY_LEN(ary);
ary2 = ary_new(rb_obj_class(ary), len);
- RARRAY(ary2)->len = len;
+ ARY_SET_LEN(ary2, len);
- for (i=0; i<len; i+=RARRAY(ary)->len) {
- MEMCPY(RARRAY(ary2)->ptr+i, RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len);
+ for (i=0; i<len; i+=RARRAY_LEN(ary)) {
+ MEMCPY(RARRAY_PTR(ary2)+i, RARRAY_PTR(ary), VALUE, RARRAY_LEN(ary));
}
OBJ_INFECT(ary2, ary);
@@ -2236,11 +2338,11 @@ rb_ary_assoc(VALUE ary, VALUE key)
long i;
VALUE v;
- for (i = 0; i < RARRAY(ary)->len; ++i) {
- v = RARRAY(ary)->ptr[i];
+ for (i = 0; i < RARRAY_LEN(ary); ++i) {
+ v = RARRAY_PTR(ary)[i];
if (TYPE(v) == T_ARRAY &&
- RARRAY(v)->len > 0 &&
- rb_equal(RARRAY(v)->ptr[0], key))
+ RARRAY_LEN(v) > 0 &&
+ rb_equal(RARRAY_PTR(v)[0], key))
return v;
}
return Qnil;
@@ -2266,11 +2368,11 @@ rb_ary_rassoc(VALUE ary, VALUE value)
long i;
VALUE v;
- for (i = 0; i < RARRAY(ary)->len; ++i) {
- v = RARRAY(ary)->ptr[i];
+ for (i = 0; i < RARRAY_LEN(ary); ++i) {
+ v = RARRAY_PTR(ary)[i];
if (TYPE(v) == T_ARRAY &&
- RARRAY(v)->len > 1 &&
- rb_equal(RARRAY(v)->ptr[1], value))
+ RARRAY_LEN(v) > 1 &&
+ rb_equal(RARRAY_PTR(v)[1], value))
return v;
}
return Qnil;
@@ -2302,8 +2404,8 @@ rb_ary_equal(VALUE ary1, VALUE ary2)
}
return rb_equal(ary2, ary1);
}
- if (RARRAY(ary1)->len != RARRAY(ary2)->len) return Qfalse;
- for (i=0; i<RARRAY(ary1)->len; i++) {
+ if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) return Qfalse;
+ for (i=0; i<RARRAY_LEN(ary1); i++) {
if (!rb_equal(rb_ary_elt(ary1, i), rb_ary_elt(ary2, i)))
return Qfalse;
}
@@ -2325,8 +2427,8 @@ rb_ary_eql(VALUE ary1, VALUE ary2)
if (ary1 == ary2) return Qtrue;
if (TYPE(ary2) != T_ARRAY) return Qfalse;
- if (RARRAY(ary1)->len != RARRAY(ary2)->len) return Qfalse;
- for (i=0; i<RARRAY(ary1)->len; i++) {
+ if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) return Qfalse;
+ for (i=0; i<RARRAY_LEN(ary1); i++) {
if (!rb_eql(rb_ary_elt(ary1, i), rb_ary_elt(ary2, i)))
return Qfalse;
}
@@ -2342,10 +2444,10 @@ recursive_hash(VALUE ary, VALUE dummy, int recur)
if (recur) {
return LONG2FIX(0);
}
- h = RARRAY(ary)->len;
- for (i=0; i<RARRAY(ary)->len; i++) {
+ h = RARRAY_LEN(ary);
+ for (i=0; i<RARRAY_LEN(ary); i++) {
h = (h << 1) | (h<0 ? 1 : 0);
- n = rb_hash(RARRAY(ary)->ptr[i]);
+ n = rb_hash(RARRAY_PTR(ary)[i]);
h ^= NUM2LONG(n);
}
return LONG2FIX(h);
@@ -2383,8 +2485,8 @@ rb_ary_includes(VALUE ary, VALUE item)
{
long i;
- for (i=0; i<RARRAY(ary)->len; i++) {
- if (rb_equal(RARRAY(ary)->ptr[i], item)) {
+ for (i=0; i<RARRAY_LEN(ary); i++) {
+ if (rb_equal(RARRAY_PTR(ary)[i], item)) {
return Qtrue;
}
}
@@ -2418,9 +2520,9 @@ rb_ary_cmp(VALUE ary1, VALUE ary2)
long i, len;
ary2 = to_ary(ary2);
- len = RARRAY(ary1)->len;
- if (len > RARRAY(ary2)->len) {
- len = RARRAY(ary2)->len;
+ len = RARRAY_LEN(ary1);
+ if (len > RARRAY_LEN(ary2)) {
+ len = RARRAY_LEN(ary2);
}
for (i=0; i<len; i++) {
VALUE v = rb_funcall(rb_ary_elt(ary1, i), id_cmp, 1, rb_ary_elt(ary2, i));
@@ -2428,7 +2530,7 @@ rb_ary_cmp(VALUE ary1, VALUE ary2)
return v;
}
}
- len = RARRAY(ary1)->len - RARRAY(ary2)->len;
+ len = RARRAY_LEN(ary1) - RARRAY_LEN(ary2);
if (len == 0) return INT2FIX(0);
if (len > 0) return INT2FIX(1);
return INT2FIX(-1);
@@ -2440,12 +2542,12 @@ ary_make_hash(VALUE ary1, VALUE ary2)
VALUE hash = rb_hash_new();
long i;
- for (i=0; i<RARRAY(ary1)->len; i++) {
- rb_hash_aset(hash, RARRAY(ary1)->ptr[i], Qtrue);
+ for (i=0; i<RARRAY_LEN(ary1); i++) {
+ rb_hash_aset(hash, RARRAY_PTR(ary1)[i], Qtrue);
}
if (ary2) {
- for (i=0; i<RARRAY(ary2)->len; i++) {
- rb_hash_aset(hash, RARRAY(ary2)->ptr[i], Qtrue);
+ for (i=0; i<RARRAY_LEN(ary2); i++) {
+ rb_hash_aset(hash, RARRAY_PTR(ary2)[i], Qtrue);
}
}
return hash;
@@ -2473,8 +2575,8 @@ rb_ary_diff(VALUE ary1, VALUE ary2)
hash = ary_make_hash(to_ary(ary2), 0);
ary3 = rb_ary_new();
- for (i=0; i<RARRAY(ary1)->len; i++) {
- if (st_lookup(RHASH(hash)->tbl, RARRAY(ary1)->ptr[i], 0)) continue;
+ for (i=0; i<RARRAY_LEN(ary1); i++) {
+ if (st_lookup(RHASH(hash)->tbl, RARRAY_PTR(ary1)[i], 0)) continue;
rb_ary_push(ary3, rb_ary_elt(ary1, i));
}
return ary3;
@@ -2498,11 +2600,11 @@ rb_ary_and(VALUE ary1, VALUE ary2)
long i;
ary2 = to_ary(ary2);
- ary3 = rb_ary_new2(RARRAY(ary1)->len < RARRAY(ary2)->len ?
- RARRAY(ary1)->len : RARRAY(ary2)->len);
+ ary3 = rb_ary_new2(RARRAY_LEN(ary1) < RARRAY_LEN(ary2) ?
+ RARRAY_LEN(ary1) : RARRAY_LEN(ary2));
hash = ary_make_hash(ary2, 0);
- for (i=0; i<RARRAY(ary1)->len; i++) {
+ for (i=0; i<RARRAY_LEN(ary1); i++) {
v = vv = rb_ary_elt(ary1, i);
if (st_delete(RHASH(hash)->tbl, (st_data_t*)&vv, 0)) {
rb_ary_push(ary3, v);
@@ -2531,16 +2633,16 @@ rb_ary_or(VALUE ary1, VALUE ary2)
long i;
ary2 = to_ary(ary2);
- ary3 = rb_ary_new2(RARRAY(ary1)->len+RARRAY(ary2)->len);
+ ary3 = rb_ary_new2(RARRAY_LEN(ary1)+RARRAY_LEN(ary2));
hash = ary_make_hash(ary1, ary2);
- for (i=0; i<RARRAY(ary1)->len; i++) {
+ for (i=0; i<RARRAY_LEN(ary1); i++) {
v = vv = rb_ary_elt(ary1, i);
if (st_delete(RHASH(hash)->tbl, (st_data_t*)&vv, 0)) {
rb_ary_push(ary3, v);
}
}
- for (i=0; i<RARRAY(ary2)->len; i++) {
+ for (i=0; i<RARRAY_LEN(ary2); i++) {
v = vv = rb_ary_elt(ary2, i);
if (st_delete(RHASH(hash)->tbl, (st_data_t*)&vv, 0)) {
rb_ary_push(ary3, v);
@@ -2571,16 +2673,16 @@ rb_ary_uniq_bang(VALUE ary)
hash = ary_make_hash(ary, 0);
- if (RARRAY(ary)->len == RHASH(hash)->tbl->num_entries) {
+ if (RARRAY_LEN(ary) == RHASH(hash)->tbl->num_entries) {
return Qnil;
}
- for (i=j=0; i<RARRAY(ary)->len; i++) {
+ for (i=j=0; i<RARRAY_LEN(ary); i++) {
v = vv = rb_ary_elt(ary, i);
if (st_delete(RHASH(hash)->tbl, (st_data_t*)&vv, 0)) {
rb_ary_store(ary, j++, v);
}
}
- RARRAY(ary)->len = j;
+ ARY_SET_LEN(ary, j);
return ary;
}
@@ -2618,20 +2720,22 @@ static VALUE
rb_ary_compact_bang(VALUE ary)
{
VALUE *p, *t, *end;
+ long n;
rb_ary_modify(ary);
- p = t = RARRAY(ary)->ptr;
- end = p + RARRAY(ary)->len;
+ p = t = RARRAY_PTR(ary);
+ end = p + RARRAY_LEN(ary);
while (t < end) {
if (NIL_P(*t)) t++;
else *p++ = *t++;
}
- if (RARRAY(ary)->len == (p - RARRAY(ary)->ptr)) {
+ if (RARRAY_LEN(ary) == (p - RARRAY_PTR(ary))) {
return Qnil;
}
- RARRAY(ary)->len = RARRAY(ary)->aux.capa = (p - RARRAY(ary)->ptr);
- REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len);
+ n = p - RARRAY_PTR(ary);
+ RESIZE_CAPA(ary, n);
+ ARY_SET_LEN(ary, n);
return ary;
}
@@ -2677,14 +2781,14 @@ rb_ary_nitems(VALUE ary)
if (rb_block_given_p()) {
long i;
- for (i=0; i<RARRAY(ary)->len; i++) {
- VALUE v = RARRAY(ary)->ptr[i];
+ for (i=0; i<RARRAY_LEN(ary); i++) {
+ VALUE v = RARRAY_PTR(ary)[i];
if (RTEST(rb_yield(v))) n++;
}
}
else {
- VALUE *p = RARRAY(ary)->ptr;
- VALUE *pend = p + RARRAY(ary)->len;
+ VALUE *p = RARRAY_PTR(ary);
+ VALUE *pend = p + RARRAY_LEN(ary);
while (p < pend) {
if (!NIL_P(*p)) n++;
@@ -2699,7 +2803,7 @@ flatten(VALUE ary, long idx, VALUE ary2, VALUE memo, int level)
{
VALUE id;
long i = idx;
- long n, lim = idx + RARRAY(ary2)->len;
+ long n, lim = idx + RARRAY_LEN(ary2);
level--;
id = rb_obj_id(ary2);
@@ -2755,8 +2859,8 @@ rb_ary_flatten_bang(int argc, VALUE *argv, VALUE ary)
rb_scan_args(argc, argv, "01", &lv);
if (!NIL_P(lv)) level = FIX2INT(lv);
if (level == 0) return ary;
- while (i<RARRAY(ary)->len) {
- VALUE ary2 = RARRAY(ary)->ptr[i];
+ while (i<RARRAY_LEN(ary)) {
+ VALUE ary2 = RARRAY_PTR(ary)[i];
VALUE tmp;
tmp = rb_check_array_type(ary2);
@@ -2810,13 +2914,13 @@ rb_ary_flatten(int argc, VALUE *argv, VALUE ary)
static VALUE
rb_ary_shuffle_bang(VALUE ary)
{
- long i = RARRAY(ary)->len;
+ long i = RARRAY_LEN(ary);
while (i) {
long j = genrand_real()*i;
- VALUE tmp = RARRAY(ary)->ptr[--i];
- RARRAY(ary)->ptr[i] = RARRAY(ary)->ptr[j];
- RARRAY(ary)->ptr[j] = tmp;
+ VALUE tmp = RARRAY_PTR(ary)[--i];
+ RARRAY_PTR(ary)[i] = RARRAY_PTR(ary)[j];
+ RARRAY_PTR(ary)[j] = tmp;
}
return ary;
}
diff --git a/dir.c b/dir.c
index 90b23c6..144d903 100644
--- a/dir.c
+++ b/dir.c
@@ -1630,7 +1630,7 @@ dir_s_glob(int argc, VALUE *argv, VALUE obj)
}
else {
volatile VALUE v = ary;
- ary = dir_globs(RARRAY(ary)->len, RARRAY(ary)->ptr, flags);
+ ary = dir_globs(RARRAY_LEN(ary), RARRAY_PTR(ary), flags);
}
if (rb_block_given_p()) {
diff --git a/enum.c b/enum.c
index 4c7ec67..419a2b9 100644
--- a/enum.c
+++ b/enum.c
@@ -644,21 +644,21 @@ enum_sort_by(VALUE obj)
RETURN_ENUMERATOR(obj, 0, 0);
if (TYPE(obj) == T_ARRAY) {
- ary = rb_ary_new2(RARRAY(obj)->len);
+ ary = rb_ary_new2(RARRAY_LEN(obj));
}
else {
ary = rb_ary_new();
}
RBASIC(ary)->klass = 0;
rb_block_call(obj, id_each, 0, 0, sort_by_i, ary);
- if (RARRAY(ary)->len > 1) {
- ruby_qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE), sort_by_cmp, 0);
+ if (RARRAY_LEN(ary) > 1) {
+ ruby_qsort(RARRAY_PTR(ary), RARRAY_LEN(ary), sizeof(VALUE), sort_by_cmp, 0);
}
if (RBASIC(ary)->klass) {
rb_raise(rb_eRuntimeError, "sort_by reentered");
}
- for (i=0; i<RARRAY(ary)->len; i++) {
- RARRAY(ary)->ptr[i] = RNODE(RARRAY(ary)->ptr[i])->u2.value;
+ for (i=0; i<RARRAY_LEN(ary); i++) {
+ RARRAY_PTR(ary)[i] = RNODE(RARRAY_PTR(ary)[i])->u2.value;
}
RBASIC(ary)->klass = rb_cArray;
return ary;
@@ -1131,10 +1131,10 @@ zip_i(VALUE val, VALUE *memo)
VALUE tmp;
int i;
- tmp = rb_ary_new2(RARRAY(args)->len + 1);
+ tmp = rb_ary_new2(RARRAY_LEN(args) + 1);
rb_ary_store(tmp, 0, val);
- for (i=0; i<RARRAY(args)->len; i++) {
- rb_ary_push(tmp, rb_ary_entry(RARRAY(args)->ptr[i], idx));
+ for (i=0; i<RARRAY_LEN(args); i++) {
+ rb_ary_push(tmp, rb_ary_entry(RARRAY_PTR(args)[i], idx));
}
if (rb_block_given_p()) {
rb_yield(tmp);
diff --git a/enumerator.c b/enumerator.c
index 94e32df..ec348de 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -122,7 +122,7 @@ each_slice_i(VALUE val, VALUE *memo)
rb_ary_push(ary, val);
- if (RARRAY(ary)->len == size) {
+ if (RARRAY_LEN(ary) == size) {
rb_yield(ary);
memo[0] = rb_ary_new2(size);
}
@@ -159,7 +159,7 @@ enum_each_slice(VALUE obj, VALUE n)
rb_block_call(obj, rb_intern("each"), 0, 0, each_slice_i, (VALUE)args);
ary = args[0];
- if (RARRAY(ary)->len > 0) rb_yield(ary);
+ if (RARRAY_LEN(ary) > 0) rb_yield(ary);
return Qnil;
}
@@ -183,11 +183,11 @@ each_cons_i(VALUE val, VALUE *memo)
VALUE ary = memo[0];
long size = (long)memo[1];
- if (RARRAY(ary)->len == size) {
+ if (RARRAY_LEN(ary) == size) {
rb_ary_shift(ary);
}
rb_ary_push(ary, val);
- if (RARRAY(ary)->len == size) {
+ if (RARRAY_LEN(ary) == size) {
rb_yield(rb_ary_dup(ary));
}
return Qnil;
@@ -321,8 +321,8 @@ enumerator_each(VALUE obj)
if (!rb_block_given_p()) return obj;
e = enumerator_ptr(obj);
if (e->args) {
- argc = RARRAY(e->args)->len;
- argv = RARRAY(e->args)->ptr;
+ argc = RARRAY_LEN(e->args);
+ argv = RARRAY_PTR(e->args);
}
return rb_block_call(e->method, rb_intern("call"), argc, argv, e->iter, (VALUE)e);
}
@@ -352,8 +352,8 @@ enumerator_with_index(VALUE obj)
VALUE *argv = 0;
if (e->args) {
- argc = RARRAY(e->args)->len;
- argv = RARRAY(e->args)->ptr;
+ argc = RARRAY_LEN(e->args);
+ argv = RARRAY_PTR(e->args);
}
return rb_block_call(e->method, rb_intern("call"), argc, argv,
enumerator_with_index_i, (VALUE)&memo);
diff --git a/error.c b/error.c
index 38d96ba..87ac7a7 100644
--- a/error.c
+++ b/error.c
@@ -443,8 +443,8 @@ check_backtrace(VALUE bt)
if (t != T_ARRAY) {
rb_raise(rb_eTypeError, err);
}
- for (i=0;i<RARRAY(bt)->len;i++) {
- if (TYPE(RARRAY(bt)->ptr[i]) != T_STRING) {
+ for (i=0;i<RARRAY_LEN(bt);i++) {
+ if (TYPE(RARRAY_PTR(bt)[i]) != T_STRING) {
rb_raise(rb_eTypeError, err);
}
}
diff --git a/eval.c b/eval.c
index bd85e33..6f41e28 100644
--- a/eval.c
+++ b/eval.c
@@ -1238,11 +1238,11 @@ error_print(void)
else
warn_printf("%d", ruby_sourceline);
}
- else if (RARRAY(errat)->len == 0) {
+ else if (RARRAY_LEN(errat) == 0) {
error_pos();
}
else {
- VALUE mesg = RARRAY(errat)->ptr[0];
+ VALUE mesg = RARRAY_PTR(errat)[0];
if (NIL_P(mesg)) error_pos();
else {
@@ -1298,21 +1298,19 @@ error_print(void)
if (!NIL_P(errat)) {
long i;
- struct RArray *ep = RARRAY(errat);
#define TRACE_MAX (TRACE_HEAD+TRACE_TAIL+5)
#define TRACE_HEAD 8
#define TRACE_TAIL 5
- ep = RARRAY(errat);
- for (i=1; i<ep->len; i++) {
- if (TYPE(ep->ptr[i]) == T_STRING) {
- warn_printf("\tfrom %s\n", RSTRING_PTR(ep->ptr[i]));
+ for (i=1; i<RARRAY_LEN(errat); i++) {
+ if (TYPE(RARRAY_PTR(errat)[i]) == T_STRING) {
+ warn_printf("\tfrom %s\n", RSTRING_PTR(RARRAY_PTR(errat)[i]));
}
- if (i == TRACE_HEAD && ep->len > TRACE_MAX) {
+ if (i == TRACE_HEAD && RARRAY_LEN(errat) > TRACE_MAX) {
warn_printf("\t ... %ld levels...\n",
- ep->len - TRACE_HEAD - TRACE_TAIL);
- i = ep->len - TRACE_TAIL;
+ RARRAY_LEN(errat) - TRACE_HEAD - TRACE_TAIL);
+ i = RARRAY_LEN(errat) - TRACE_TAIL;
}
}
}
@@ -1793,7 +1791,7 @@ rb_eval_cmd(VALUE cmd, VALUE arg, int level)
ruby_safe_level = level;
if ((state = EXEC_TAG()) == 0) {
val = rb_funcall2(cmd, rb_intern("yield"),
- RARRAY(arg)->len, RARRAY(arg)->ptr);
+ RARRAY_LEN(arg), RARRAY_PTR(arg));
}
ruby_safe_level = safe;
POP_TAG();
@@ -1889,7 +1887,7 @@ rb_mod_nesting(void)
if (!NIL_P(cbase->nd_clss)) rb_ary_push(ary, cbase->nd_clss);
cbase = cbase->nd_next;
}
- if (ruby_wrapper && RARRAY(ary)->len == 0) {
+ if (ruby_wrapper && RARRAY_LEN(ary) == 0) {
rb_ary_push(ary, ruby_wrapper);
}
return ary;
@@ -2185,9 +2183,9 @@ copy_node_scope(NODE *node, NODE *rval)
VALUE args = rb_eval(self,n);\
if (TYPE(args) != T_ARRAY)\
args = rb_ary_to_ary(args);\
- argc = RARRAY(args)->len;\
+ argc = RARRAY_LEN(args);\
argv = TMP_ALLOC(argc+extra);\
- MEMCPY(argv, RARRAY(args)->ptr, VALUE, argc);\
+ MEMCPY(argv, RARRAY_PTR(args), VALUE, argc);\
}\
if (bpass) {\
volatile VALUE save_block = rb_eval(self, bpass->nd_body); \
@@ -2201,11 +2199,11 @@ copy_node_scope(NODE *node, NODE *rval)
argc = ruby_frame->argc;\
if (argc && DMETHOD_P()) {\
if (TYPE(RBASIC(ruby_scope)->klass) != T_ARRAY ||\
- RARRAY(RBASIC(ruby_scope)->klass)->len != argc) {\
+ RARRAY_LEN(RBASIC(ruby_scope)->klass) != argc) {\
rb_raise(rb_eRuntimeError, \
"super: specify arguments explicitly");\
}\
- argv = RARRAY(RBASIC(ruby_scope)->klass)->ptr;\
+ argv = RARRAY_PTR(RBASIC(ruby_scope)->klass);\
}\
else {\
argv = ruby_scope->local_vars + 2;\
@@ -2713,8 +2711,8 @@ when_check(NODE *tag, VALUE val, VALUE self)
break;
case NODE_SPLAT:
elm = svalue_to_avalue(rb_eval(self, tag->nd_head));
- for (i=0; i<RARRAY(elm)->len; i++) {
- if (when_cond(val, RARRAY(elm)->ptr[i])) {
+ for (i=0; i<RARRAY_LEN(elm); i++) {
+ if (when_cond(val, RARRAY_PTR(elm)[i])) {
return Qtrue;
}
}
@@ -3624,8 +3622,7 @@ rb_eval(VALUE self, NODE *n)
i = node->nd_alen;
ary = rb_ary_new2(i);
for (i=0;node;node=node->nd_next) {
- RARRAY(ary)->ptr[i++] = rb_eval(self, node->nd_head);
- RARRAY(ary)->len = i;
+ rb_ary_push(ary, rb_eval(self, node->nd_head));
}
result = ary;
@@ -3640,8 +3637,7 @@ rb_eval(VALUE self, NODE *n)
i = node->nd_alen;
val = rb_ary_new2(i);
for (i=0;node;node=node->nd_next) {
- RARRAY(val)->ptr[i++] = rb_eval(self, node->nd_head);
- RARRAY(val)->len = i;
+ rb_ary_push(val, rb_eval(self, node->nd_head));
}
result = val;
@@ -4746,16 +4742,16 @@ rb_yield_0(VALUE val, VALUE self, VALUE klass /* OK */, int flags)
if (TYPE(val) != T_ARRAY) {
rb_raise(rb_eArgError, "wrong number of arguments (1 for 0)");
}
- else if (RARRAY(val)->len != 0) {
+ else if (RARRAY_LEN(val) != 0) {
rb_raise(rb_eArgError, "wrong number of arguments (%ld for 0)",
- RARRAY(val)->len);
+ RARRAY_LEN(val));
}
}
}
else if (var == (NODE*)2) {
- if (TYPE(val) == T_ARRAY && RARRAY(val)->len != 0) {
+ if (TYPE(val) == T_ARRAY && RARRAY_LEN(val) != 0) {
rb_raise(rb_eArgError, "wrong number of arguments (%ld for 0)",
- RARRAY(val)->len);
+ RARRAY_LEN(val));
}
}
else if (!bvar && nd_type(var) == NODE_BLOCK_PASS) {
@@ -4765,7 +4761,7 @@ rb_yield_0(VALUE val, VALUE self, VALUE klass /* OK */, int flags)
}
else if (nd_type(var) == NODE_ARGS) {
if (!ary_args) val = svalue_to_avalue(val);
- formal_assign(self, var, RARRAY(val)->len, RARRAY(val)->ptr, 0);
+ formal_assign(self, var, RARRAY_LEN(val), RARRAY_PTR(val), 0);
}
else if (nd_type(var) == NODE_BLOCK) {
if (var->nd_next) {
@@ -4782,16 +4778,16 @@ rb_yield_0(VALUE val, VALUE self, VALUE klass /* OK */, int flags)
if (val == Qundef) {
rb_raise(rb_eArgError, "wrong number of arguments (0 for 1)");
}
- if (TYPE(val) == T_ARRAY && RARRAY(val)->len != 1) {
+ if (TYPE(val) == T_ARRAY && RARRAY_LEN(val) != 1) {
rb_raise(rb_eArgError, "wrong number of arguments (%ld for 1)",
- RARRAY(val)->len);
+ RARRAY_LEN(val));
}
}
if (ary_args) {
- if (RARRAY(val)->len == 0)
+ if (RARRAY_LEN(val) == 0)
val = Qnil;
else
- val = RARRAY(val)->ptr[0];
+ val = RARRAY_PTR(val)[0];
}
assign(self, var, val, lambda);
}
@@ -4811,11 +4807,11 @@ rb_yield_0(VALUE val, VALUE self, VALUE klass /* OK */, int flags)
POP_TAG();
if (state) goto pop_state;
}
- else if (lambda && ary_args && RARRAY(val)->len != 0 &&
+ else if (lambda && ary_args && RARRAY_LEN(val) != 0 &&
(!node || nd_type(node) != NODE_IFUNC ||
node->nd_cfnc != bmcall)) {
rb_raise(rb_eArgError, "wrong number of arguments (%ld for 0)",
- RARRAY(val)->len);
+ RARRAY_LEN(val));
}
if (!node) {
state = 0;
@@ -4939,9 +4935,8 @@ rb_yield_values(int n, ...)
val = rb_ary_new2(n);
va_start(args, n);
for (i=0; i<n; i++) {
- RARRAY(val)->ptr[i] = va_arg(args, VALUE);
+ rb_ary_push(val, va_arg(args, VALUE));
}
- RARRAY(val)->len = n;
va_end(args);
return rb_yield_0(val, 0, 0, 0);
}
@@ -4989,8 +4984,8 @@ massign(VALUE self, NODE *node, VALUE val, int pcall)
len = (val == Qundef) ? 0 : 1;
}
else {
- argv = RARRAY(tmp)->ptr;
- len = RARRAY(tmp)->len;
+ argv = RARRAY_PTR(tmp);
+ len = RARRAY_LEN(tmp);
}
}
list = node->nd_head;
@@ -5112,7 +5107,7 @@ assign(VALUE self, NODE *lhs, VALUE val, int pcall)
ruby_current_node = lhs;
SET_CURRENT_SOURCE();
rb_call(CLASS_OF(recv), recv, lhs->nd_mid,
- RARRAY(args)->len, RARRAY(args)->ptr, 0, scope,0);
+ RARRAY_LEN(args), RARRAY_PTR(args), 0, scope,0);
}
}
break;
@@ -5127,18 +5122,18 @@ assign(VALUE self, NODE *lhs, VALUE val, int pcall)
assign(self, lhs->nd_args, val, 0);
}
cnt = lhs->nd_head->nd_alen;
- if (RARRAY(val)->len < cnt) {
+ if (RARRAY_LEN(val) < cnt) {
if (pcall) {
rb_raise(rb_eArgError, "wrong number of arguments");
}
else {
- while (RARRAY(val)->len < cnt) {
+ while (RARRAY_LEN(val) < cnt) {
v = v->nd_next;
cnt--;
}
}
}
- p = RARRAY(val)->ptr + RARRAY(val)->len - cnt;
+ p = RARRAY_PTR(val) + RARRAY_LEN(val) - cnt;
while (cnt--) {
assign(self, v->nd_head, *p++, 0);
v = v->nd_next;
@@ -5505,10 +5500,10 @@ method_missing(VALUE obj, ID id, int argc, const VALUE *argv,
argc = -argc-1;
tmp = svalue_to_avalue(argv[argc]);
- nargv = ALLOCA_N(VALUE, argc + RARRAY(tmp)->len + 1);
+ nargv = ALLOCA_N(VALUE, argc + RARRAY_LEN(tmp) + 1);
MEMCPY(nargv+1, argv, VALUE, argc);
- MEMCPY(nargv+1+argc, RARRAY(tmp)->ptr, VALUE, RARRAY(tmp)->len);
- argc += RARRAY(tmp)->len;
+ MEMCPY(nargv+1+argc, RARRAY_PTR(tmp), VALUE, RARRAY_LEN(tmp));
+ argc += RARRAY_LEN(tmp);
}
else {
@@ -5614,7 +5609,7 @@ formal_assign(VALUE recv, NODE *node, int argc, const VALUE *argv, VALUE *local_
rb_bug("no argument-node");
}
- i = node->nd_frml ? RARRAY(node->nd_frml)->len : 0;
+ i = node->nd_frml ? RARRAY_LEN(node->nd_frml) : 0;
if (i > argc) {
rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, i);
}
@@ -5641,7 +5636,7 @@ formal_assign(VALUE recv, NODE *node, int argc, const VALUE *argv, VALUE *local_
VALUE a = node->nd_frml;
for (j=0; j<i; j++) {
- dvar_asgn_curr(SYM2ID(RARRAY(a)->ptr[j]), argv[j]);
+ dvar_asgn_curr(SYM2ID(RARRAY_PTR(a)[j]), argv[j]);
}
}
argv += i; argc -= i;
@@ -5722,11 +5717,11 @@ rb_call0(VALUE klass, VALUE recv, ID id, ID oid,
argc %= 256;
tmp = svalue_to_avalue(argv[argc]);
- nargv = TMP_ALLOC(argc + RARRAY(tmp)->len + n);
+ nargv = TMP_ALLOC(argc + RARRAY_LEN(tmp) + n);
MEMCPY(nargv, argv, VALUE, argc);
- MEMCPY(nargv+argc, RARRAY(tmp)->ptr, VALUE, RARRAY(tmp)->len);
- MEMCPY(nargv + argc + RARRAY(tmp)->len, argv + argc + 1, VALUE, n);
- argc += RARRAY(tmp)->len + n;
+ MEMCPY(nargv+argc, RARRAY_PTR(tmp), VALUE, RARRAY_LEN(tmp));
+ MEMCPY(nargv + argc + RARRAY_LEN(tmp), argv + argc + 1, VALUE, n);
+ argc += RARRAY_LEN(tmp) + n;
argv = nargv;
}
switch (nd_type(body)) {
@@ -5988,9 +5983,9 @@ rb_apply(VALUE recv, ID mid, VALUE args)
int argc;
VALUE *argv;
- argc = RARRAY(args)->len; /* Assigns LONG, but argc is INT */
+ argc = RARRAY_LEN(args); /* Assigns LONG, but argc is INT */
argv = ALLOCA_N(VALUE, argc);
- MEMCPY(argv, RARRAY(args)->ptr, VALUE, argc);
+ MEMCPY(argv, RARRAY_PTR(args), VALUE, argc);
return rb_call(CLASS_OF(recv), recv, mid, argc, argv, 0, CALLING_FUNCALL, 0);
}
@@ -6217,8 +6212,8 @@ rb_backtrace(void)
VALUE ary;
ary = backtrace(-1);
- for (i=0; i<RARRAY(ary)->len; i++) {
- printf("\tfrom %s\n", RSTRING_PTR(RARRAY(ary)->ptr[i]));
+ for (i=0; i<RARRAY_LEN(ary); i++) {
+ printf("\tfrom %s\n", RSTRING_PTR(RARRAY_PTR(ary)[i]));
}
}
@@ -6355,9 +6350,9 @@ eval(VALUE self, VALUE src, VALUE scope, const char *file, int line)
if (!NIL_P(errat) && TYPE(errat) == T_ARRAY) {
if (!NIL_P(mesg) && TYPE(mesg) == T_STRING) {
rb_str_update(mesg, 0, 0, rb_str_new2(": "));
- rb_str_update(mesg, 0, 0, RARRAY(errat)->ptr[0]);
+ rb_str_update(mesg, 0, 0, RARRAY_PTR(errat)[0]);
}
- RARRAY(errat)->ptr[0] = RARRAY(backtrace(-2))->ptr[0];
+ RARRAY_PTR(errat)[0] = RARRAY_PTR(backtrace(-2))[0];
}
}
rb_exc_raise(ruby_errinfo);
@@ -6841,8 +6836,8 @@ rb_feature_p(const char *feature, const char *ext, int rb)
len = strlen(feature);
elen = 0;
}
- for (i = 0; i < RARRAY(rb_features)->len; ++i) {
- v = RARRAY(rb_features)->ptr[i];
+ for (i = 0; i < RARRAY_LEN(rb_features); ++i) {
+ v = RARRAY_PTR(rb_features)[i];
f = StringValuePtr(v);
if (strncmp(f, feature, len) != 0) continue;
if (!*(e = f + len)) {
@@ -8465,7 +8460,7 @@ proc_invoke(VALUE proc, VALUE args /* OK */, VALUE self, VALUE klass, int call)
_block.block_obj = bvar;
if (self != Qundef) _block.frame.self = self;
if (klass) _block.frame.this_class = klass;
- _block.frame.argc = call ? RARRAY(args)->len : 1;
+ _block.frame.argc = call ? RARRAY_LEN(args) : 1;
_block.frame.flags = ruby_frame->flags;
if (_block.frame.argc && (ruby_frame->flags & FRAME_DMETH)) {
NEWOBJ(scope, struct SCOPE);
@@ -9248,7 +9243,7 @@ rb_node_arity(NODE *body)
if (nd_type(body) == NODE_BLOCK)
body = body->nd_head;
if (!body) return 0;
- n = body->nd_frml ? RARRAY(body->nd_frml)->len : 0;
+ n = body->nd_frml ? RARRAY_LEN(body->nd_frml) : 0;
if (body->nd_opt)
return -n-1;
if (body->nd_rest) {
@@ -9399,7 +9394,7 @@ bmcall(VALUE args, VALUE method)
VALUE ret;
a = svalue_to_avalue(args);
- ret = rb_method_call(RARRAY(a)->len, RARRAY(a)->ptr, method);
+ ret = rb_method_call(RARRAY_LEN(a), RARRAY_PTR(a), method);
a = Qnil; /* prevent tail call */
return ret;
}
@@ -11115,7 +11110,7 @@ rb_thread_join(rb_thread_t th, double limit)
VALUE errat = make_backtrace();
VALUE errinfo = rb_obj_dup(th->errinfo);
- if (TYPE(oldbt) == T_ARRAY && RARRAY(oldbt)->len > 0) {
+ if (TYPE(oldbt) == T_ARRAY && RARRAY_LEN(oldbt) > 0) {
rb_ary_unshift(errat, rb_ary_entry(oldbt, 0));
}
set_backtrace(errinfo, errat);
@@ -12010,7 +12005,7 @@ rb_thread_start_1(void)
if ((state = EXEC_TAG()) == 0) {
if (THREAD_SAVE_CONTEXT(th) == 0) {
new_thread.thread = 0;
- th->result = rb_proc_yield(RARRAY(arg)->len, RARRAY(arg)->ptr, proc);
+ th->result = rb_proc_yield(RARRAY_LEN(arg), RARRAY_PTR(arg), proc);
}
th = th_save;
}
diff --git a/ext/Win32API/Win32API.c b/ext/Win32API/Win32API.c
index 221a46d..9a2de01 100644
--- a/ext/Win32API/Win32API.c
+++ b/ext/Win32API/Win32API.c
@@ -72,8 +72,8 @@ Win32API_initialize(self, dllname, proc, import, export)
case T_NIL:
break;
case T_ARRAY:
- ptr = RARRAY(import)->ptr;
- for (i = 0, len = RARRAY(import)->len; i < len; i++) {
+ ptr = RARRAY_PTR(import);
+ for (i = 0, len = RARRAY_LEN(import); i < len; i++) {
SafeStringValue(ptr[i]);
switch (*(char *)RSTRING_PTR(ptr[i])) {
case 'N': case 'n': case 'L': case 'l':
@@ -107,8 +107,8 @@ Win32API_initialize(self, dllname, proc, import, export)
break;
}
- if (16 < RARRAY(a_import)->len) {
- rb_raise(rb_eRuntimeError, "too many parameters: %d\n", RARRAY(a_import)->len);
+ if (16 < RARRAY_LEN(a_import)) {
+ rb_raise(rb_eRuntimeError, "too many parameters: %d\n", RARRAY_LEN(a_import));
}
rb_iv_set(self, "__import__", a_import);
@@ -159,7 +159,7 @@ Win32API_Call(argc, argv, obj)
VALUE obj_export = rb_iv_get(obj, "__export__");
FARPROC ApiFunction = (FARPROC)NUM2ULONG(obj_proc);
int items = rb_scan_args(argc, argv, "0*", &args);
- int nimport = RARRAY(obj_import)->len;
+ int nimport = RARRAY_LEN(obj_import);
if (items != nimport)
diff --git a/ext/dbm/dbm.c b/ext/dbm/dbm.c
index 3bc1a83..e89f8b1 100644
--- a/ext/dbm/dbm.c
+++ b/ext/dbm/dbm.c
@@ -345,8 +345,8 @@ fdbm_delete_if(VALUE obj)
GetDBM2(obj, dbmp, dbm);
}
- for (i = 0; i < RARRAY(ary)->len; i++) {
- keystr = RARRAY(ary)->ptr[i];
+ for (i = 0; i < RARRAY_LEN(ary); i++) {
+ keystr = RARRAY_PTR(ary)[i];
StringValue(keystr);
key.dptr = RSTRING_PTR(keystr);
key.dsize = RSTRING_LEN(keystr);
@@ -355,7 +355,7 @@ fdbm_delete_if(VALUE obj)
}
}
if (status) rb_jump_tag(status);
- if (n > 0) dbmp->di_size = n - RARRAY(ary)->len;
+ if (n > 0) dbmp->di_size = n - RARRAY_LEN(ary);
return obj;
}
@@ -405,10 +405,10 @@ static VALUE
update_i(VALUE pair, VALUE dbm)
{
Check_Type(pair, T_ARRAY);
- if (RARRAY(pair)->len < 2) {
+ if (RARRAY_LEN(pair) < 2) {
rb_raise(rb_eArgError, "pair must be [key, value]");
}
- fdbm_store(dbm, RARRAY(pair)->ptr[0], RARRAY(pair)->ptr[1]);
+ fdbm_store(dbm, RARRAY_PTR(pair)[0], RARRAY_PTR(pair)[1]);
return Qnil;
}
diff --git a/ext/dl/cfunc.c b/ext/dl/cfunc.c
index 458132b..253c78f 100644
--- a/ext/dl/cfunc.c
+++ b/ext/dl/cfunc.c
@@ -226,7 +226,7 @@ rb_dlcfunc_inspect(VALUE self)
# define DECL_FUNC_CDECL(f,ret,args) ret (FUNC_CDECL(*f))(args)
# define DECL_FUNC_STDCALL(f,ret,args) ret (FUNC_STDCALL(*f))(args)
-#define CALL_CASE switch( RARRAY(ary)->len ){ \
+#define CALL_CASE switch( RARRAY_LEN(ary) ){ \
CASE(0); break; \
CASE(1); break; CASE(2); break; CASE(3); break; CASE(4); break; CASE(5); break; \
CASE(6); break; CASE(7); break; CASE(8); break; CASE(9); break; CASE(10);break; \
@@ -256,11 +256,11 @@ rb_dlcfunc_call(VALUE self, VALUE ary)
return Qnil;
}
- for( i = 0; i < RARRAY(ary)->len; i++ ){
+ for( i = 0; i < RARRAY_LEN(ary); i++ ){
if( i >= DLSTACK_SIZE ){
rb_raise(rb_eDLError, "too many arguments (stack overflow)");
}
- stack[i] = NUM2LONG(RARRAY(ary)->ptr[i]);
+ stack[i] = NUM2LONG(RARRAY_PTR(ary)[i]);
}
/* calltype == CFUNC_CDECL */
diff --git a/ext/gdbm/gdbm.c b/ext/gdbm/gdbm.c
index 8c9b5a7..dd7d196 100644
--- a/ext/gdbm/gdbm.c
+++ b/ext/gdbm/gdbm.c
@@ -414,10 +414,10 @@ fgdbm_delete_if(VALUE obj)
GetDBM2(obj, dbmp, dbm);
}
- for (i = 0; i < RARRAY(ary)->len; i++)
- rb_gdbm_delete(obj, RARRAY(ary)->ptr[i]);
+ for (i = 0; i < RARRAY_LEN(ary); i++)
+ rb_gdbm_delete(obj, RARRAY_PTR(ary)[i]);
if (status) rb_jump_tag(status);
- if (n > 0) dbmp->di_size = n - RARRAY(ary)->len;
+ if (n > 0) dbmp->di_size = n - RARRAY_LEN(ary);
return obj;
}
@@ -508,10 +508,10 @@ static VALUE
update_i(VALUE pair, VALUE dbm)
{
Check_Type(pair, T_ARRAY);
- if (RARRAY(pair)->len < 2) {
+ if (RARRAY_LEN(pair) < 2) {
rb_raise(rb_eArgError, "pair must be [key, value]");
}
- fgdbm_store(dbm, RARRAY(pair)->ptr[0], RARRAY(pair)->ptr[1]);
+ fgdbm_store(dbm, RARRAY_PTR(pair)[0], RARRAY_PTR(pair)[1]);
return Qnil;
}
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index 0c89c2a..0a5d0df 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -350,7 +350,7 @@ iconv_convert(iconv_t cd, VALUE str, int start, int length, struct iconv_env_t*
unsigned int i;
rescue = iconv_fail(error, Qnil, Qnil, env, 0);
if (TYPE(rescue) == T_ARRAY) {
- str = RARRAY(rescue)->len > 0 ? RARRAY(rescue)->ptr[0] : Qnil;
+ str = RARRAY_LEN(rescue) > 0 ? RARRAY_PTR(rescue)[0] : Qnil;
}
if (FIXNUM_P(str) && (i = FIX2INT(str)) <= 0xff) {
char c = i;
@@ -434,9 +434,9 @@ iconv_convert(iconv_t cd, VALUE str, int start, int length, struct iconv_env_t*
str = rb_str_derive(str, inptr, inlen);
rescue = iconv_fail(error, ret, str, env, errmsg);
if (TYPE(rescue) == T_ARRAY) {
- if ((len = RARRAY(rescue)->len) > 0)
- rb_str_concat(ret, RARRAY(rescue)->ptr[0]);
- if (len > 1 && !NIL_P(str = RARRAY(rescue)->ptr[1])) {
+ if ((len = RARRAY_LEN(rescue)) > 0)
+ rb_str_concat(ret, RARRAY_PTR(rescue)[0]);
+ if (len > 1 && !NIL_P(str = RARRAY_PTR(rescue)[1])) {
StringValue(str);
inlen = length = RSTRING_LEN(str);
instart = inptr = RSTRING_PTR(str);
diff --git a/ext/openssl/ossl.c b/ext/openssl/ossl.c
index 4000e8f..16e93bc 100644
--- a/ext/openssl/ossl.c
+++ b/ext/openssl/ossl.c
@@ -59,7 +59,7 @@ ossl_x509_ary2sk0(VALUE ary)
sk = sk_X509_new_null();
if (!sk) ossl_raise(eOSSLError, NULL);
- for (i = 0; i < RARRAY(ary)->len; i++) {
+ for (i = 0; i < RARRAY_LEN(ary); i++) {
val = rb_ary_entry(ary, i);
if (!rb_obj_is_kind_of(val, cX509Cert)) {
sk_X509_pop_free(sk, X509_free);
diff --git a/ext/openssl/ossl_ocsp.c b/ext/openssl/ossl_ocsp.c
index 45d7c6a..aa6bd61 100644
--- a/ext/openssl/ossl_ocsp.c
+++ b/ext/openssl/ossl_ocsp.c
@@ -461,8 +461,8 @@ ossl_ocspbres_add_status(VALUE self, VALUE cid, VALUE status,
if(!NIL_P(ext)){
/* All ary's members should be X509Extension */
Check_Type(ext, T_ARRAY);
- for (i = 0; i < RARRAY(ext)->len; i++)
- OSSL_Check_Kind(RARRAY(ext)->ptr[i], cX509Ext);
+ for (i = 0; i < RARRAY_LEN(ext); i++)
+ OSSL_Check_Kind(RARRAY_PTR(ext)[i], cX509Ext);
}
error = 0;
@@ -490,8 +490,8 @@ ossl_ocspbres_add_status(VALUE self, VALUE cid, VALUE status,
X509_EXTENSION *x509ext;
sk_X509_EXTENSION_pop_free(single->singleExtensions, X509_EXTENSION_free);
single->singleExtensions = NULL;
- for(i = 0; i < RARRAY(ext)->len; i++){
- x509ext = DupX509ExtPtr(RARRAY(ext)->ptr[i]);
+ for(i = 0; i < RARRAY_LEN(ext); i++){
+ x509ext = DupX509ExtPtr(RARRAY_PTR(ext)[i]);
if(!OCSP_SINGLERESP_add_ext(single, x509ext, -1)){
X509_EXTENSION_free(x509ext);
error = 1;
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
index 844a461..d956c90 100644
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -349,8 +349,8 @@ ossl_sslctx_setup(VALUE self)
val = ossl_sslctx_get_client_ca(self);
if(!NIL_P(val)){
if(TYPE(val) == T_ARRAY){
- for(i = 0; i < RARRAY(val)->len; i++){
- client_ca = GetX509CertPtr(RARRAY(val)->ptr[i]);
+ for(i = 0; i < RARRAY_LEN(val); i++){
+ client_ca = GetX509CertPtr(RARRAY_PTR(val)[i]);
if (!SSL_CTX_add_client_CA(ctx, client_ca)){
/* Copies X509_NAME => FREE it. */
ossl_raise(eSSLError, "SSL_CTX_add_client_CA");
@@ -459,12 +459,12 @@ ossl_sslctx_set_ciphers(VALUE self, VALUE v)
return v;
else if (TYPE(v) == T_ARRAY) {
str = rb_str_new(0, 0);
- for (i = 0; i < RARRAY(v)->len; i++) {
+ for (i = 0; i < RARRAY_LEN(v); i++) {
elem = rb_ary_entry(v, i);
if (TYPE(elem) == T_ARRAY) elem = rb_ary_entry(elem, 0);
elem = rb_String(elem);
rb_str_append(str, elem);
- if (i < RARRAY(v)->len-1) rb_str_cat2(str, ":");
+ if (i < RARRAY_LEN(v)-1) rb_str_cat2(str, ":");
}
} else {
str = v;
diff --git a/ext/openssl/ossl_x509cert.c b/ext/openssl/ossl_x509cert.c
index f613c80..0276764 100644
--- a/ext/openssl/ossl_x509cert.c
+++ b/ext/openssl/ossl_x509cert.c
@@ -557,14 +557,14 @@ ossl_x509_set_extensions(VALUE self, VALUE ary)
Check_Type(ary, T_ARRAY);
/* All ary's members should be X509Extension */
- for (i=0; i<RARRAY(ary)->len; i++) {
- OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Ext);
+ for (i=0; i<RARRAY_LEN(ary); i++) {
+ OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Ext);
}
GetX509(self, x509);
sk_X509_EXTENSION_pop_free(x509->cert_info->extensions, X509_EXTENSION_free);
x509->cert_info->extensions = NULL;
- for (i=0; i<RARRAY(ary)->len; i++) {
- ext = DupX509ExtPtr(RARRAY(ary)->ptr[i]);
+ for (i=0; i<RARRAY_LEN(ary); i++) {
+ ext = DupX509ExtPtr(RARRAY_PTR(ary)[i]);
if (!X509_add_ext(x509, ext, -1)) { /* DUPs ext - FREE it */
X509_EXTENSION_free(ext);
diff --git a/ext/openssl/ossl_x509crl.c b/ext/openssl/ossl_x509crl.c
index 0dc2241..be9ddac 100644
--- a/ext/openssl/ossl_x509crl.c
+++ b/ext/openssl/ossl_x509crl.c
@@ -287,14 +287,14 @@ ossl_x509crl_set_revoked(VALUE self, VALUE ary)
Check_Type(ary, T_ARRAY);
/* All ary members should be X509 Revoked */
- for (i=0; i<RARRAY(ary)->len; i++) {
- OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Rev);
+ for (i=0; i<RARRAY_LEN(ary); i++) {
+ OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Rev);
}
GetX509CRL(self, crl);
sk_X509_REVOKED_pop_free(crl->crl->revoked, X509_REVOKED_free);
crl->crl->revoked = NULL;
- for (i=0; i<RARRAY(ary)->len; i++) {
- rev = DupX509RevokedPtr(RARRAY(ary)->ptr[i]);
+ for (i=0; i<RARRAY_LEN(ary); i++) {
+ rev = DupX509RevokedPtr(RARRAY_PTR(ary)[i]);
if (!X509_CRL_add0_revoked(crl, rev)) { /* NO DUP - don't free! */
ossl_raise(eX509CRLError, NULL);
}
@@ -461,14 +461,14 @@ ossl_x509crl_set_extensions(VALUE self, VALUE ary)
Check_Type(ary, T_ARRAY);
/* All ary members should be X509 Extensions */
- for (i=0; i<RARRAY(ary)->len; i++) {
- OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Ext);
+ for (i=0; i<RARRAY_LEN(ary); i++) {
+ OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Ext);
}
GetX509CRL(self, crl);
sk_X509_EXTENSION_pop_free(crl->crl->extensions, X509_EXTENSION_free);
crl->crl->extensions = NULL;
- for (i=0; i<RARRAY(ary)->len; i++) {
- ext = DupX509ExtPtr(RARRAY(ary)->ptr[i]);
+ for (i=0; i<RARRAY_LEN(ary); i++) {
+ ext = DupX509ExtPtr(RARRAY_PTR(ary)[i]);
if(!X509_CRL_add_ext(crl, ext, -1)) { /* DUPs ext - FREE it */
X509_EXTENSION_free(ext);
ossl_raise(eX509CRLError, NULL);
diff --git a/ext/openssl/ossl_x509req.c b/ext/openssl/ossl_x509req.c
index 10f0d20..13a42dd 100644
--- a/ext/openssl/ossl_x509req.c
+++ b/ext/openssl/ossl_x509req.c
@@ -403,14 +403,14 @@ ossl_x509req_set_attributes(VALUE self, VALUE ary)
VALUE item;
Check_Type(ary, T_ARRAY);
- for (i=0;i<RARRAY(ary)->len; i++) {
- OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Attr);
+ for (i=0;i<RARRAY_LEN(ary); i++) {
+ OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Attr);
}
GetX509Req(self, req);
sk_X509_ATTRIBUTE_pop_free(req->req_info->attributes, X509_ATTRIBUTE_free);
req->req_info->attributes = NULL;
- for (i=0;i<RARRAY(ary)->len; i++) {
- item = RARRAY(ary)->ptr[i];
+ for (i=0;i<RARRAY_LEN(ary); i++) {
+ item = RARRAY_PTR(ary)[i];
attr = DupX509AttrPtr(item);
if (!X509_REQ_add1_attr(req, attr)) {
ossl_raise(eX509ReqError, NULL);
diff --git a/ext/openssl/ossl_x509revoked.c b/ext/openssl/ossl_x509revoked.c
index 3ccac8d..d0f816b 100644
--- a/ext/openssl/ossl_x509revoked.c
+++ b/ext/openssl/ossl_x509revoked.c
@@ -175,14 +175,14 @@ ossl_x509revoked_set_extensions(VALUE self, VALUE ary)
VALUE item;
Check_Type(ary, T_ARRAY);
- for (i=0; i<RARRAY(ary)->len; i++) {
- OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Ext);
+ for (i=0; i<RARRAY_LEN(ary); i++) {
+ OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Ext);
}
GetX509Rev(self, rev);
sk_X509_EXTENSION_pop_free(rev->extensions, X509_EXTENSION_free);
rev->extensions = NULL;
- for (i=0; i<RARRAY(ary)->len; i++) {
- item = RARRAY(ary)->ptr[i];
+ for (i=0; i<RARRAY_LEN(ary); i++) {
+ item = RARRAY_PTR(ary)[i];
ext = DupX509ExtPtr(item);
if(!X509_REVOKED_add_ext(rev, ext, -1)) {
ossl_raise(eX509RevError, NULL);
diff --git a/ext/racc/cparse/cparse.c b/ext/racc/cparse/cparse.c
index 197a0eb..753cfdd 100644
--- a/ext/racc/cparse/cparse.c
+++ b/ext/racc/cparse/cparse.c
@@ -88,7 +88,7 @@ num_to_long(VALUE n)
}
#define AREF(s, idx) \
- ((0 <= idx && idx < RARRAY(s)->len) ? RARRAY(s)->ptr[idx] : Qnil)
+ ((0 <= idx && idx < RARRAY_LEN(s)) ? RARRAY_PTR(s)[idx] : Qnil)
/* -----------------------------------------------------------------------
Parser Stack Interfaces
@@ -101,8 +101,8 @@ static VALUE
get_stack_tail(VALUE stack, long len)
{
if (len < 0) return Qnil; /* system error */
- if (len > RARRAY(stack)->len) len = RARRAY(stack)->len;
- return rb_ary_new4(len, RARRAY(stack)->ptr + RARRAY(stack)->len - len);
+ if (len > RARRAY_LEN(stack)) len = RARRAY_LEN(stack);
+ return rb_ary_new4(len, RARRAY_PTR(stack) + RARRAY_LEN(stack) - len);
}
static void
@@ -116,10 +116,10 @@ cut_stack_tail(VALUE stack, long len)
#define STACK_INIT_LEN 64
#define NEW_STACK() rb_ary_new2(STACK_INIT_LEN)
-#define PUSH(s, i) rb_ary_store(s, RARRAY(s)->len, i)
+#define PUSH(s, i) rb_ary_store(s, RARRAY_LEN(s), i)
#define POP(s) rb_ary_pop(s)
#define LAST_I(s) \
- ((RARRAY(s)->len > 0) ? RARRAY(s)->ptr[RARRAY(s)->len - 1] : Qnil)
+ ((RARRAY_LEN(s) > 0) ? RARRAY_PTR(s)[RARRAY_LEN(s) - 1] : Qnil)
#define GET_TAIL(s, len) get_stack_tail(s, len)
#define CUT_TAIL(s, len) cut_stack_tail(s, len)
@@ -329,23 +329,23 @@ initialize_params(VALUE vparams, VALUE parser, VALUE arg, VALUE lexer, VALUE lex
v->debug = RTEST(rb_ivar_get(parser, id_yydebug));
Check_Type(arg, T_ARRAY);
- if (!(13 <= RARRAY(arg)->len && RARRAY(arg)->len <= 14))
- rb_raise(RaccBug, "[Racc Bug] wrong arg.size %ld", RARRAY(arg)->len);
- v->action_table = assert_array (RARRAY(arg)->ptr[ 0]);
- v->action_check = assert_array (RARRAY(arg)->ptr[ 1]);
- v->action_default = assert_array (RARRAY(arg)->ptr[ 2]);
- v->action_pointer = assert_array (RARRAY(arg)->ptr[ 3]);
- v->goto_table = assert_array (RARRAY(arg)->ptr[ 4]);
- v->goto_check = assert_array (RARRAY(arg)->ptr[ 5]);
- v->goto_default = assert_array (RARRAY(arg)->ptr[ 6]);
- v->goto_pointer = assert_array (RARRAY(arg)->ptr[ 7]);
- v->nt_base = assert_integer(RARRAY(arg)->ptr[ 8]);
- v->reduce_table = assert_array (RARRAY(arg)->ptr[ 9]);
- v->token_table = assert_hash (RARRAY(arg)->ptr[10]);
- v->shift_n = assert_integer(RARRAY(arg)->ptr[11]);
- v->reduce_n = assert_integer(RARRAY(arg)->ptr[12]);
- if (RARRAY(arg)->len > 13) {
- v->use_result_var = RTEST(RARRAY(arg)->ptr[13]);
+ if (!(13 <= RARRAY_LEN(arg) && RARRAY_LEN(arg) <= 14))
+ rb_raise(RaccBug, "[Racc Bug] wrong arg.size %ld", RARRAY_LEN(arg));
+ v->action_table = assert_array (RARRAY_PTR(arg)[ 0]);
+ v->action_check = assert_array (RARRAY_PTR(arg)[ 1]);
+ v->action_default = assert_array (RARRAY_PTR(arg)[ 2]);
+ v->action_pointer = assert_array (RARRAY_PTR(arg)[ 3]);
+ v->goto_table = assert_array (RARRAY_PTR(arg)[ 4]);
+ v->goto_check = assert_array (RARRAY_PTR(arg)[ 5]);
+ v->goto_default = assert_array (RARRAY_PTR(arg)[ 6]);
+ v->goto_pointer = assert_array (RARRAY_PTR(arg)[ 7]);
+ v->nt_base = assert_integer(RARRAY_PTR(arg)[ 8]);
+ v->reduce_table = assert_array (RARRAY_PTR(arg)[ 9]);
+ v->token_table = assert_hash (RARRAY_PTR(arg)[10]);
+ v->shift_n = assert_integer(RARRAY_PTR(arg)[11]);
+ v->reduce_n = assert_integer(RARRAY_PTR(arg)[12]);
+ if (RARRAY_LEN(arg) > 13) {
+ v->use_result_var = RTEST(RARRAY_PTR(arg)[13]);
}
else {
v->use_result_var = Qtrue;
@@ -424,12 +424,12 @@ extract_user_token(struct cparse_params *v, VALUE block_args,
v->lex_is_iterator ? "yielded" : "returned",
rb_class2name(CLASS_OF(block_args)));
}
- if (RARRAY(block_args)->len != 2) {
+ if (RARRAY_LEN(block_args) != 2) {
rb_raise(rb_eArgError,
"%s() %s wrong size of array (%ld for 2)",
v->lex_is_iterator ? rb_id2name(v->lexmid) : "next_token",
v->lex_is_iterator ? "yielded" : "returned",
- RARRAY(block_args)->len);
+ RARRAY_LEN(block_args));
}
*tok = AREF(block_args, 0);
*val = AREF(block_args, 1);
@@ -565,7 +565,7 @@ parse_main(struct cparse_params *v, VALUE tok, VALUE val, int resume)
accept:
if (v->debug) rb_funcall(v->parser, id_d_accept, 0);
- v->retval = RARRAY(v->vstack)->ptr[0];
+ v->retval = RARRAY_PTR(v->vstack)[0];
v->fin = CP_FIN_ACCEPT;
return;
@@ -625,7 +625,7 @@ parse_main(struct cparse_params *v, VALUE tok, VALUE val, int resume)
error_pop:
D_puts("(err) act not found: can't handle error token; pop");
- if (RARRAY(v->state)->len <= 1) {
+ if (RARRAY_LEN(v->state) <= 1) {
v->retval = Qnil;
v->fin = CP_FIN_CANTPOP;
return;
@@ -694,9 +694,9 @@ reduce0(VALUE val, VALUE data, VALUE self)
VALUE goto_state;
Data_Get_Struct(data, struct cparse_params, v);
- reduce_len = RARRAY(v->reduce_table)->ptr[v->ruleno];
- reduce_to = RARRAY(v->reduce_table)->ptr[v->ruleno+1];
- method_id = RARRAY(v->reduce_table)->ptr[v->ruleno+2];
+ reduce_len = RARRAY_PTR(v->reduce_table)[v->ruleno];
+ reduce_to = RARRAY_PTR(v->reduce_table)[v->ruleno+1];
+ method_id = RARRAY_PTR(v->reduce_table)[v->ruleno+2];
len = NUM2LONG(reduce_len);
mid = value_to_id(method_id);
@@ -711,10 +711,10 @@ reduce0(VALUE val, VALUE data, VALUE self)
else {
if (mid != id_noreduce) {
tmp_v = GET_TAIL(v->vstack, len);
- tmp = RARRAY(tmp_v)->ptr[0];
+ tmp = RARRAY_PTR(tmp_v)[0];
}
else {
- tmp = RARRAY(v->vstack)->ptr[ RARRAY(v->vstack)->len - len ];
+ tmp = RARRAY_PTR(v->vstack)[ RARRAY_LEN(v->vstack) - len ];
}
CUT_TAIL(v->vstack, len);
if (v->debug) {
@@ -743,7 +743,7 @@ reduce0(VALUE val, VALUE data, VALUE self)
}
/* calculate transition state */
- if (RARRAY(v->state)->len == 0)
+ if (RARRAY_LEN(v->state) == 0)
rb_raise(RaccBug, "state stack unexpectedly empty");
k2 = num_to_long(LAST_I(v->state));
k1 = num_to_long(reduce_to) - v->nt_base;
diff --git a/ext/readline/readline.c b/ext/readline/readline.c
index 94aef8d..1e64675 100644
--- a/ext/readline/readline.c
+++ b/ext/readline/readline.c
@@ -170,12 +170,12 @@ readline_attempted_completion_function(const char *text, int start, int end)
ary = rb_funcall(proc, rb_intern("call"), 1, rb_tainted_str_new2(text));
if (TYPE(ary) != T_ARRAY)
ary = rb_Array(ary);
- matches = RARRAY(ary)->len;
+ matches = RARRAY_LEN(ary);
if (matches == 0)
return NULL;
result = ALLOC_N(char *, matches + 2);
for (i = 0; i < matches; i++) {
- temp = rb_obj_as_string(RARRAY(ary)->ptr[i]);
+ temp = rb_obj_as_string(RARRAY_PTR(ary)[i]);
result[i + 1] = ALLOC_N(char, RSTRING_LEN(temp) + 1);
strcpy(result[i + 1], RSTRING_PTR(temp));
}
@@ -661,7 +661,7 @@ filename_completion_proc_call(VALUE self, VALUE str)
free(matches[i]);
}
free(matches);
- if (RARRAY(result)->len >= 2)
+ if (RARRAY_LEN(result) >= 2)
rb_ary_shift(result);
}
else {
@@ -686,7 +686,7 @@ username_completion_proc_call(VALUE self, VALUE str)
free(matches[i]);
}
free(matches);
- if (RARRAY(result)->len >= 2)
+ if (RARRAY_LEN(result) >= 2)
rb_ary_shift(result);
}
else {
diff --git a/ext/sdbm/init.c b/ext/sdbm/init.c
index 758d737..08a3ab8 100644
--- a/ext/sdbm/init.c
+++ b/ext/sdbm/init.c
@@ -323,8 +323,8 @@ fsdbm_delete_if(VALUE obj)
GetDBM2(obj, dbmp, dbm);
}
- for (i = 0; i < RARRAY(ary)->len; i++) {
- keystr = RARRAY(ary)->ptr[i];
+ for (i = 0; i < RARRAY_LEN(ary); i++) {
+ keystr = RARRAY_PTR(ary)[i];
StringValue(keystr);
key.dptr = RSTRING_PTR(keystr);
key.dsize = RSTRING_LEN(keystr);
@@ -333,7 +333,7 @@ fsdbm_delete_if(VALUE obj)
}
}
if (status) rb_jump_tag(status);
- if (n > 0) dbmp->di_size = n - RARRAY(ary)->len;
+ if (n > 0) dbmp->di_size = n - RARRAY_LEN(ary);
return obj;
}
@@ -416,10 +416,10 @@ static VALUE
update_i(VALUE pair, VALUE dbm)
{
Check_Type(pair, T_ARRAY);
- if (RARRAY(pair)->len < 2) {
+ if (RARRAY_LEN(pair) < 2) {
rb_raise(rb_eArgError, "pair must be [key, value]");
}
- fsdbm_store(dbm, RARRAY(pair)->ptr[0], RARRAY(pair)->ptr[1]);
+ fsdbm_store(dbm, RARRAY_PTR(pair)[0], RARRAY_PTR(pair)[1]);
return Qnil;
}
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index e2e691a..8cc850b 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -2991,7 +2991,7 @@ make_addrinfo(struct addrinfo *res0)
for (res = res0; res; res = res->ai_next) {
ary = ipaddr(res->ai_addr, do_not_reverse_lookup);
if (res->ai_canonname) {
- RARRAY(ary)->ptr[2] = rb_str_new2(res->ai_canonname);
+ RARRAY_PTR(ary)[2] = rb_str_new2(res->ai_canonname);
}
rb_ary_push(ary, INT2FIX(res->ai_family));
rb_ary_push(ary, INT2FIX(res->ai_socktype));
@@ -3232,17 +3232,17 @@ sock_s_getnameinfo(int argc, VALUE *argv)
if (!NIL_P(tmp)) {
sa = tmp;
MEMZERO(&hints, struct addrinfo, 1);
- if (RARRAY(sa)->len == 3) {
- af = RARRAY(sa)->ptr[0];
- port = RARRAY(sa)->ptr[1];
- host = RARRAY(sa)->ptr[2];
+ if (RARRAY_LEN(sa) == 3) {
+ af = RARRAY_PTR(sa)[0];
+ port = RARRAY_PTR(sa)[1];
+ host = RARRAY_PTR(sa)[2];
}
- else if (RARRAY(sa)->len >= 4) {
- af = RARRAY(sa)->ptr[0];
- port = RARRAY(sa)->ptr[1];
- host = RARRAY(sa)->ptr[3];
+ else if (RARRAY_LEN(sa) >= 4) {
+ af = RARRAY_PTR(sa)[0];
+ port = RARRAY_PTR(sa)[1];
+ host = RARRAY_PTR(sa)[3];
if (NIL_P(host)) {
- host = RARRAY(sa)->ptr[2];
+ host = RARRAY_PTR(sa)[2];
}
else {
/*
@@ -3256,7 +3256,7 @@ sock_s_getnameinfo(int argc, VALUE *argv)
}
else {
rb_raise(rb_eArgError, "array size should be 3 or 4, %ld given",
- RARRAY(sa)->len);
+ RARRAY_LEN(sa));
}
/* host */
if (NIL_P(host)) {
diff --git a/ext/syck/rubyext.c b/ext/syck/rubyext.c
index d036d24..371ef15 100644
--- a/ext/syck/rubyext.c
+++ b/ext/syck/rubyext.c
@@ -1023,7 +1023,7 @@ syck_const_find(VALUE const_name)
VALUE tclass = rb_cObject;
VALUE tparts = rb_str_split( const_name, "::" );
int i = 0;
- for ( i = 0; i < RARRAY(tparts)->len; i++ ) {
+ for ( i = 0; i < RARRAY_LEN(tparts); i++ ) {
VALUE tpart = rb_to_id( rb_ary_entry( tparts, i ) );
if ( !rb_const_defined( tclass, tpart ) ) return Qnil;
tclass = rb_const_get( tclass, tpart );
@@ -1059,7 +1059,7 @@ syck_resolver_transfer(VALUE self, VALUE type, VALUE val)
VALUE subclass_parts = rb_ary_new();
VALUE parts = rb_str_split( type, ":" );
- while ( RARRAY(parts)->len > 1 )
+ while ( RARRAY_LEN(parts) > 1 )
{
VALUE partial;
rb_ary_unshift( subclass_parts, rb_ary_pop( parts ) );
@@ -1077,7 +1077,7 @@ syck_resolver_transfer(VALUE self, VALUE type, VALUE val)
if ( ! NIL_P( target_class ) )
{
subclass = target_class;
- if ( RARRAY(subclass_parts)->len > 0 && rb_respond_to( target_class, s_tag_subclasses ) &&
+ if ( RARRAY_LEN(subclass_parts) > 0 && rb_respond_to( target_class, s_tag_subclasses ) &&
RTEST( rb_funcall( target_class, s_tag_subclasses, 0 ) ) )
{
VALUE subclass_v;
@@ -1502,7 +1502,7 @@ syck_seq_value_set(VALUE self, VALUE val)
if ( !NIL_P( val ) ) {
int i;
syck_seq_empty( node );
- for ( i = 0; i < RARRAY( val )->len; i++ )
+ for ( i = 0; i < RARRAY_LEN( val ); i++ )
{
syck_seq_add( node, rb_ary_entry(val, i) );
}
@@ -1587,7 +1587,7 @@ syck_map_initialize(VALUE self, VALUE type_id, VALUE val, VALUE style)
}
keys = rb_funcall( hsh, s_keys, 0 );
- for ( i = 0; i < RARRAY(keys)->len; i++ )
+ for ( i = 0; i < RARRAY_LEN(keys); i++ )
{
VALUE key = rb_ary_entry(keys, i);
syck_map_add( node, key, rb_hash_aref(hsh, key) );
@@ -1622,7 +1622,7 @@ syck_map_value_set(VALUE self, VALUE val)
syck_map_empty( node );
keys = rb_funcall( hsh, s_keys, 0 );
- for ( i = 0; i < RARRAY(keys)->len; i++ )
+ for ( i = 0; i < RARRAY_LEN(keys); i++ )
{
VALUE key = rb_ary_entry(keys, i);
syck_map_add( node, key, rb_hash_aref(hsh, key) );
diff --git a/ext/tk/tcltklib.c b/ext/tk/tcltklib.c
index 6964c5f..9086f3e 100644
--- a/ext/tk/tcltklib.c
+++ b/ext/tk/tcltklib.c
@@ -1133,15 +1133,15 @@ set_max_block_time(self, time)
case T_BIGNUM:
/* time is micro-second value */
divmod = rb_funcall(time, rb_intern("divmod"), 1, LONG2NUM(1000000));
- tcl_time.sec = NUM2LONG(RARRAY(divmod)->ptr[0]);
- tcl_time.usec = NUM2LONG(RARRAY(divmod)->ptr[1]);
+ tcl_time.sec = NUM2LONG(RARRAY_PTR(divmod)[0]);
+ tcl_time.usec = NUM2LONG(RARRAY_PTR(divmod)[1]);
break;
case T_FLOAT:
/* time is second value */
divmod = rb_funcall(time, rb_intern("divmod"), 1, INT2FIX(1));
- tcl_time.sec = NUM2LONG(RARRAY(divmod)->ptr[0]);
- tcl_time.usec = (long)(NUM2DBL(RARRAY(divmod)->ptr[1]) * 1000000);
+ tcl_time.sec = NUM2LONG(RARRAY_PTR(divmod)[0]);
+ tcl_time.usec = (long)(NUM2DBL(RARRAY_PTR(divmod)[1]) * 1000000);
default:
{
@@ -2595,15 +2595,14 @@ ip_ruby_cmd(clientData, interp, argc, argv)
/* get args */
args = rb_ary_new2(argc - 2);
- RARRAY(args)->len = 0;
for(i = 3; i < argc; i++) {
#if TCL_MAJOR_VERSION >= 8
str = Tcl_GetStringFromObj(argv[i], &len);
DUMP2("arg:%s",str);
- RARRAY(args)->ptr[RARRAY(args)->len++] = rb_tainted_str_new(str, len);
+ rb_ary_push(args, rb_tainted_str_new(str, len));
#else /* TCL_MAJOR_VERSION < 8 */
DUMP2("arg:%s",argv[i]);
- RARRAY(args)->ptr[RARRAY(args)->len++] = rb_tainted_str_new2(argv[i]);
+ rb_ary_push(args, rb_tainted_str_new2(argv[i]));
#endif
}
@@ -5516,7 +5515,7 @@ call_queue_handler(evPtr, flags)
}
/* set result */
- RARRAY(q->result)->ptr[0] = ret;
+ RARRAY_PTR(q->result)[0] = ret;
/* complete */
*(q->done) = -1;
@@ -5586,8 +5585,8 @@ tk_funcall(func, argc, argv, obj)
/* allocate result obj */
result = rb_ary_new2(1);
- RARRAY(result)->ptr[0] = Qnil;
- RARRAY(result)->len = 1;
+ RARRAY_PTR(result)[0] = Qnil;
+ RARRAY_LEN(result) = 1;
/* construct event data */
callq->done = alloc_done;
@@ -5614,7 +5613,7 @@ tk_funcall(func, argc, argv, obj)
DUMP2("back from handler (current thread:%lx)", current);
/* get result & free allocated memory */
- ret = RARRAY(result)->ptr[0];
+ ret = RARRAY_PTR(result)[0];
free(alloc_done);
if (argv) free(argv);
@@ -5834,7 +5833,7 @@ eval_queue_handler(evPtr, flags)
}
/* set result */
- RARRAY(q->result)->ptr[0] = ret;
+ RARRAY_PTR(q->result)[0] = ret;
/* complete */
*(q->done) = -1;
@@ -5901,8 +5900,8 @@ ip_eval(self, str)
/* allocate result obj */
result = rb_ary_new2(1);
- RARRAY(result)->ptr[0] = Qnil;
- RARRAY(result)->len = 1;
+ RARRAY_PTR(result)[0] = Qnil;
+ RARRAY_LEN(result) = 1;
/* construct event data */
evq->done = alloc_done;
@@ -5930,7 +5929,7 @@ ip_eval(self, str)
DUMP2("back from handler (current thread:%lx)", current);
/* get result & free allocated memory */
- ret = RARRAY(result)->ptr[0];
+ ret = RARRAY_PTR(result)[0];
free(alloc_done);
free(eval_str);
@@ -6911,7 +6910,7 @@ invoke_queue_handler(evPtr, flags)
}
/* set result */
- RARRAY(q->result)->ptr[0] = ret;
+ RARRAY_PTR(q->result)[0] = ret;
/* complete */
*(q->done) = -1;
@@ -6981,8 +6980,8 @@ ip_invoke_with_position(argc, argv, obj, position)
/* allocate result obj */
result = rb_ary_new2(1);
- RARRAY(result)->ptr[0] = Qnil;
- RARRAY(result)->len = 1;
+ RARRAY_PTR(result)[0] = Qnil;
+ RARRAY_LEN(result) = 1;
/* construct event data */
ivq->done = alloc_done;
@@ -7008,7 +7007,7 @@ ip_invoke_with_position(argc, argv, obj, position)
DUMP2("back from handler (current thread:%lx)", current);
/* get result & free allocated memory */
- ret = RARRAY(result)->ptr[0];
+ ret = RARRAY_PTR(result)[0];
free(alloc_done);
Tcl_Release(ivq);
@@ -7535,11 +7534,9 @@ lib_split_tklist_core(ip_obj, list_str)
for(idx = 0; idx < objc; idx++) {
elem = get_str_from_obj(objv[idx]);
if (taint_flag) OBJ_TAINT(elem);
- RARRAY(ary)->ptr[idx] = elem;
+ rb_ary_push(ary, elem);
}
- RARRAY(ary)->len = objc;
-
if (old_gc == Qfalse) rb_gc_enable();
rb_thread_critical = thr_crit_bup;
@@ -7576,10 +7573,8 @@ lib_split_tklist_core(ip_obj, list_str)
elem = rb_str_new2(argv[idx]);
}
/* rb_ivar_set(elem, ID_at_enc, rb_str_new2("binary")); */
- RARRAY(ary)->ptr[idx] = elem;
+ rb_ary_push(ary, elem);
}
- RARRAY(ary)->len = argc;
-
if (old_gc == Qfalse) rb_gc_enable();
#endif
}
diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c
index ef30d92..34eebef 100644
--- a/ext/win32ole/win32ole.c
+++ b/ext/win32ole/win32ole.c
@@ -863,7 +863,7 @@ ole_val2variant(VALUE val, VARIANT *var)
val1 = val;
i = 0;
while(TYPE(val1) == T_ARRAY) {
- psab[i].cElements = RARRAY(val1)->len;
+ psab[i].cElements = RARRAY_LEN(val1);
psab[i].lLbound = 0;
pub[i] = psab[i].cElements;
pid[i] = 0;
@@ -1113,7 +1113,7 @@ ole_val2olevariantdata(VALUE val, VARTYPE vtype, struct olevariantdata *pvar)
val1 = val;
i = 0;
while(TYPE(val1) == T_ARRAY) {
- psab[i].cElements = RARRAY(val1)->len;
+ psab[i].cElements = RARRAY_LEN(val1);
psab[i].lLbound = 0;
pub[i] = psab[i].cElements;
pid[i] = 0;
@@ -2544,7 +2544,7 @@ ole_invoke2(VALUE self, VALUE dispid, VALUE args, VALUE types, USHORT dispkind)
VariantInit(&result);
OLEData_Get_Struct(self, pole);
- dispParams.cArgs = RARRAY(args)->len;
+ dispParams.cArgs = RARRAY_LEN(args);
dispParams.rgvarg = ALLOCA_N(VARIANTARG, dispParams.cArgs);
realargs = ALLOCA_N(VARIANTARG, dispParams.cArgs);
for (i = 0, j = dispParams.cArgs - 1; i < (int)dispParams.cArgs; i++, j--)
@@ -2575,7 +2575,7 @@ ole_invoke2(VALUE self, VALUE dispid, VALUE args, VALUE types, USHORT dispkind)
SAFEARRAYBOUND rgsabound[1];
Check_Type(param, T_ARRAY);
rgsabound[0].lLbound = 0;
- rgsabound[0].cElements = RARRAY(param)->len;
+ rgsabound[0].cElements = RARRAY_LEN(param);
v = vt & ~(VT_ARRAY | VT_BYREF);
V_ARRAY(&realargs[i]) = SafeArrayCreate(v, 1, rgsabound);
V_VT(&realargs[i]) = VT_ARRAY | v;
@@ -4060,7 +4060,7 @@ foletypelib_initialize(VALUE self, VALUE args)
VALUE retval;
HRESULT hr = S_OK;
- len = RARRAY(args)->len;
+ len = RARRAY_LEN(args);
if (len < 1 || len > 3) {
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..3)", len);
}
@@ -6233,7 +6233,7 @@ ole_search_event_at(VALUE ary, VALUE ev)
long i, len;
long ret = -1;
def_event = Qnil;
- len = RARRAY(ary)->len;
+ len = RARRAY_LEN(ary);
for(i = 0; i < len; i++) {
event = rb_ary_entry(ary, i);
event_name = rb_ary_entry(event, 1);
@@ -6260,7 +6260,7 @@ ole_search_event(VALUE ary, VALUE ev, BOOL *is_default)
int i, len;
*is_default = FALSE;
def_event = Qnil;
- len = RARRAY(ary)->len;
+ len = RARRAY_LEN(ary);
for(i = 0; i < len; i++) {
event = rb_ary_entry(ary, i);
event_name = rb_ary_entry(event, 1);
@@ -6283,7 +6283,7 @@ ary2ptr_dispparams(VALUE ary, DISPPARAMS *pdispparams)
int i;
VALUE v;
VARIANT *pvar;
- for(i = 0; i < RARRAY(ary)->len && (unsigned int) i < pdispparams->cArgs; i++) {
+ for(i = 0; i < RARRAY_LEN(ary) && (unsigned int) i < pdispparams->cArgs; i++) {
v = rb_ary_entry(ary, i);
pvar = &pdispparams->rgvarg[pdispparams->cArgs-i-1];
ole_val2ptr_variant(v, pvar);
@@ -6825,7 +6825,7 @@ folevariant_initialize(VALUE self, VALUE args)
VARTYPE vt;
struct olevariantdata *pvar;
- len = RARRAY(args)->len;
+ len = RARRAY_LEN(args);
if (len < 1 || len > 3) {
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..3)", len);
}
diff --git a/file.c b/file.c
index e49005b..712772e 100644
--- a/file.c
+++ b/file.c
@@ -125,15 +125,14 @@ apply2files(void (*func)(const char *, void *), VALUE vargs, void *arg)
{
long i;
VALUE path;
- struct RArray *args = RARRAY(vargs);
rb_secure(4);
- for (i=0; i<args->len; i++) {
- path = rb_get_path(args->ptr[i]);
+ for (i=0; i<RARRAY_LEN(vargs); i++) {
+ path = rb_get_path(RARRAY_PTR(vargs)[i]);
(*func)(StringValueCStr(path), arg);
}
- return args->len;
+ return RARRAY_LEN(vargs);
}
/*
@@ -2875,12 +2874,12 @@ rb_file_join(VALUE ary, VALUE sep)
VALUE result, tmp;
char *name, *tail;
- if (RARRAY(ary)->len == 0) return rb_str_new(0, 0);
+ if (RARRAY_LEN(ary) == 0) return rb_str_new(0, 0);
len = 1;
- for (i=0; i<RARRAY(ary)->len; i++) {
- if (TYPE(RARRAY(ary)->ptr[i]) == T_STRING) {
- len += RSTRING_LEN(RARRAY(ary)->ptr[i]);
+ for (i=0; i<RARRAY_LEN(ary); i++) {
+ if (TYPE(RARRAY_PTR(ary)[i]) == T_STRING) {
+ len += RSTRING_LEN(RARRAY_PTR(ary)[i]);
}
else {
len += 10;
@@ -2888,12 +2887,12 @@ rb_file_join(VALUE ary, VALUE sep)
}
if (!NIL_P(sep)) {
StringValue(sep);
- len += RSTRING_LEN(sep) * RARRAY(ary)->len - 1;
+ len += RSTRING_LEN(sep) * RARRAY_LEN(ary) - 1;
}
result = rb_str_buf_new(len);
OBJ_INFECT(result, ary);
- for (i=0; i<RARRAY(ary)->len; i++) {
- tmp = RARRAY(ary)->ptr[i];
+ for (i=0; i<RARRAY_LEN(ary); i++) {
+ tmp = RARRAY_PTR(ary)[i];
switch (TYPE(tmp)) {
case T_STRING:
break;
@@ -4174,8 +4173,8 @@ rb_find_file_ext(VALUE *filep, const char *const *ext)
if (!rb_load_path) return 0;
Check_Type(rb_load_path, T_ARRAY);
- for (i=0;i<RARRAY(rb_load_path)->len;i++) {
- VALUE str = RARRAY(rb_load_path)->ptr[i];
+ for (i=0;i<RARRAY_LEN(rb_load_path);i++) {
+ VALUE str = RARRAY_PTR(rb_load_path)[i];
FilePathValue(str);
if (RSTRING_LEN(str) == 0) continue;
@@ -4235,8 +4234,8 @@ rb_find_file(VALUE path)
Check_Type(rb_load_path, T_ARRAY);
tmp = rb_ary_new();
- for (i=0;i<RARRAY(rb_load_path)->len;i++) {
- VALUE str = RARRAY(rb_load_path)->ptr[i];
+ for (i=0;i<RARRAY_LEN(rb_load_path);i++) {
+ VALUE str = RARRAY_PTR(rb_load_path)[i];
FilePathValue(str);
if (RSTRING_LEN(str) > 0) {
rb_ary_push(tmp, str);
diff --git a/gc.c b/gc.c
index 9bd44f3..0ae9bb6 100644
--- a/gc.c
+++ b/gc.c
@@ -926,12 +926,12 @@ gc_mark_children(VALUE ptr, int lev)
case T_ARRAY:
if (FL_TEST(obj, ELTS_SHARED)) {
- ptr = obj->as.array.aux.shared;
+ ptr = obj->as.array.as.heap.aux.shared;
goto again;
}
else {
- long i, len = obj->as.array.len;
- VALUE *ptr = obj->as.array.ptr;
+ long i, len = RARRAY_LEN(obj);
+ VALUE *ptr = RARRAY_PTR(obj);
for (i=0; i < len; i++) {
gc_mark(*ptr++, lev);
@@ -945,9 +945,8 @@ gc_mark_children(VALUE ptr, int lev)
goto again;
case T_STRING:
-#define STR_NOEMBED FL_USER1 /* copied from string.c */
#define STR_ASSOC FL_USER3 /* copied from string.c */
- if (FL_TEST(obj, STR_NOEMBED) && FL_ANY(obj, ELTS_SHARED|STR_ASSOC)) {
+ if (FL_TEST(obj, RSTRING_NOEMBED) && FL_ANY(obj, ELTS_SHARED|STR_ASSOC)) {
ptr = obj->as.string.as.heap.aux.shared;
goto again;
}
@@ -1175,14 +1174,15 @@ obj_free(VALUE obj)
}
break;
case T_STRING:
- if (FL_TEST(obj, STR_NOEMBED) &&
+ if (FL_TEST(obj, RSTRING_NOEMBED) &&
RANY(obj)->as.string.as.heap.ptr && !FL_TEST(obj, ELTS_SHARED)) {
RUBY_CRITICAL(free(RANY(obj)->as.string.as.heap.ptr));
}
break;
case T_ARRAY:
- if (RANY(obj)->as.array.ptr && !FL_TEST(obj, ELTS_SHARED)) {
- RUBY_CRITICAL(free(RANY(obj)->as.array.ptr));
+ if (FL_TEST(obj, RARRAY_NOEMBED) &&
+ RANY(obj)->as.array.as.heap.ptr && !FL_TEST(obj, ELTS_SHARED)) {
+ RUBY_CRITICAL(free(RANY(obj)->as.array.as.heap.ptr));
}
break;
case T_HASH:
@@ -1833,17 +1833,17 @@ run_final(VALUE obj)
rb_thread_critical = Qtrue;
args[1] = 0;
args[2] = (VALUE)ruby_safe_level;
- for (i=0; i<RARRAY(finalizers)->len; i++) {
- args[0] = RARRAY(finalizers)->ptr[i];
+ for (i=0; i<RARRAY_LEN(finalizers); i++) {
+ args[0] = RARRAY_PTR(finalizers)[i];
if (!args[1]) args[1] = rb_ary_new3(1, objid);
rb_protect((VALUE(*)(VALUE))run_single_final, (VALUE)args, &status);
}
if (finalizer_table && st_delete(finalizer_table, (st_data_t*)&obj, &table)) {
- for (i=0; i<RARRAY(table)->len; i++) {
- VALUE final = RARRAY(table)->ptr[i];
- args[0] = RARRAY(final)->ptr[1];
+ for (i=0; i<RARRAY_LEN(table); i++) {
+ VALUE final = RARRAY_PTR(table)[i];
+ args[0] = RARRAY_PTR(final)[1];
if (!args[1]) args[1] = rb_ary_new3(1, objid);
- args[2] = FIX2INT(RARRAY(final)->ptr[0]);
+ args[2] = FIX2INT(RARRAY_PTR(final)[0]);
rb_protect((VALUE(*)(VALUE))run_single_final, (VALUE)args, &status);
}
}
diff --git a/hash.c b/hash.c
index 6a9ad90..866e5ce 100644
--- a/hash.c
+++ b/hash.c
@@ -1828,8 +1828,8 @@ env_each_key(VALUE ehash)
RETURN_ENUMERATOR(ehash, 0, 0);
rb_secure(4);
keys = env_keys();
- for (i=0; i<RARRAY(keys)->len; i++) {
- rb_yield(RARRAY(keys)->ptr[i]);
+ for (i=0; i<RARRAY_LEN(keys); i++) {
+ rb_yield(RARRAY_PTR(keys)[i]);
}
return ehash;
}
@@ -1863,8 +1863,8 @@ env_each_value(VALUE ehash)
RETURN_ENUMERATOR(ehash, 0, 0);
rb_secure(4);
values = env_values();
- for (i=0; i<RARRAY(values)->len; i++) {
- rb_yield(RARRAY(values)->ptr[i]);
+ for (i=0; i<RARRAY_LEN(values); i++) {
+ rb_yield(RARRAY_PTR(values)[i]);
}
return ehash;
}
@@ -1889,12 +1889,12 @@ env_each_i(VALUE ehash, int values)
}
FREE_ENVIRON(environ);
- for (i=0; i<RARRAY(ary)->len; i+=2) {
+ for (i=0; i<RARRAY_LEN(ary); i+=2) {
if (values) {
- rb_yield_values(2, RARRAY(ary)->ptr[i], RARRAY(ary)->ptr[i+1]);
+ rb_yield_values(2, RARRAY_PTR(ary)[i], RARRAY_PTR(ary)[i+1]);
}
else {
- rb_yield(rb_assoc_new(RARRAY(ary)->ptr[i], RARRAY(ary)->ptr[i+1]));
+ rb_yield(rb_assoc_new(RARRAY_PTR(ary)[i], RARRAY_PTR(ary)[i+1]));
}
}
return ehash;
@@ -1923,12 +1923,12 @@ env_reject_bang(void)
rb_secure(4);
keys = env_keys();
- for (i=0; i<RARRAY(keys)->len; i++) {
- VALUE val = rb_f_getenv(Qnil, RARRAY(keys)->ptr[i]);
+ for (i=0; i<RARRAY_LEN(keys); i++) {
+ VALUE val = rb_f_getenv(Qnil, RARRAY_PTR(keys)[i]);
if (!NIL_P(val)) {
- if (RTEST(rb_yield_values(2, RARRAY(keys)->ptr[i], val))) {
- FL_UNSET(RARRAY(keys)->ptr[i], FL_TAINT);
- env_delete(Qnil, RARRAY(keys)->ptr[i]);
+ if (RTEST(rb_yield_values(2, RARRAY_PTR(keys)[i], val))) {
+ FL_UNSET(RARRAY_PTR(keys)[i], FL_TAINT);
+ env_delete(Qnil, RARRAY_PTR(keys)[i]);
del++;
}
}
@@ -1992,10 +1992,10 @@ env_clear(void)
rb_secure(4);
keys = env_keys();
- for (i=0; i<RARRAY(keys)->len; i++) {
- VALUE val = rb_f_getenv(Qnil, RARRAY(keys)->ptr[i]);
+ for (i=0; i<RARRAY_LEN(keys); i++) {
+ VALUE val = rb_f_getenv(Qnil, RARRAY_PTR(keys)[i]);
if (!NIL_P(val)) {
- env_delete(Qnil, RARRAY(keys)->ptr[i]);
+ env_delete(Qnil, RARRAY_PTR(keys)[i]);
}
}
return envtbl;
@@ -2239,8 +2239,8 @@ env_replace(VALUE env, VALUE hash)
hash = to_hash(hash);
rb_hash_foreach(hash, env_replace_i, keys);
- for (i=0; i<RARRAY(keys)->len; i++) {
- env_delete(env, RARRAY(keys)->ptr[i]);
+ for (i=0; i<RARRAY_LEN(keys); i++) {
+ env_delete(env, RARRAY_PTR(keys)[i]);
}
return env;
}
diff --git a/io.c b/io.c
index bf3c2b9..afd80af 100644
--- a/io.c
+++ b/io.c
@@ -3163,10 +3163,10 @@ rb_io_s_popen(int argc, VALUE *argv, VALUE klass)
}
tmp = rb_check_array_type(pname);
if (!NIL_P(tmp)) {
- VALUE *argv = ALLOCA_N(VALUE, RARRAY(tmp)->len);
+ VALUE *argv = ALLOCA_N(VALUE, RARRAY_LEN(tmp));
- MEMCPY(argv, RARRAY(tmp)->ptr, VALUE, RARRAY(tmp)->len);
- port = pipe_open(RARRAY(tmp)->len, argv, mode);
+ MEMCPY(argv, RARRAY_PTR(tmp), VALUE, RARRAY_LEN(tmp));
+ port = pipe_open(RARRAY_LEN(tmp), argv, mode);
pname = tmp;
}
else {
@@ -3784,8 +3784,8 @@ io_puts_ary(VALUE ary, VALUE out, int recur)
VALUE tmp;
long i;
- for (i=0; i<RARRAY(ary)->len; i++) {
- tmp = RARRAY(ary)->ptr[i];
+ for (i=0; i<RARRAY_LEN(ary); i++) {
+ tmp = RARRAY_PTR(ary)[i];
if (recur) {
tmp = rb_str_new2("[...]");
}
@@ -4233,7 +4233,7 @@ next_argv(void)
}
if (init_p == 0) {
- if (RARRAY(rb_argv)->len > 0) {
+ if (RARRAY_LEN(rb_argv) > 0) {
next_p = 1;
}
else {
@@ -4246,7 +4246,7 @@ next_argv(void)
if (next_p == 1) {
next_p = 0;
retry:
- if (RARRAY(rb_argv)->len > 0) {
+ if (RARRAY_LEN(rb_argv) > 0) {
filename = rb_ary_shift(rb_argv);
fn = StringValuePtr(filename);
if (strlen(fn) == 1 && fn[0] == '-') {
@@ -4549,8 +4549,8 @@ select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fd
if (!NIL_P(read)) {
Check_Type(read, T_ARRAY);
- for (i=0; i<RARRAY(read)->len; i++) {
- GetOpenFile(rb_io_get_io(RARRAY(read)->ptr[i]), fptr);
+ for (i=0; i<RARRAY_LEN(read); i++) {
+ GetOpenFile(rb_io_get_io(RARRAY_PTR(read)[i]), fptr);
rb_fd_set(fptr->fd, &fds[0]);
if (READ_DATA_PENDING(fptr)) { /* check for buffered data */
pending++;
@@ -4569,8 +4569,8 @@ select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fd
if (!NIL_P(write)) {
Check_Type(write, T_ARRAY);
- for (i=0; i<RARRAY(write)->len; i++) {
- GetOpenFile(rb_io_get_io(RARRAY(write)->ptr[i]), fptr);
+ for (i=0; i<RARRAY_LEN(write); i++) {
+ GetOpenFile(rb_io_get_io(RARRAY_PTR(write)[i]), fptr);
rb_fd_set(fptr->fd, &fds[1]);
if (max < fptr->fd) max = fptr->fd;
}
@@ -4581,8 +4581,8 @@ select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fd
if (!NIL_P(except)) {
Check_Type(except, T_ARRAY);
- for (i=0; i<RARRAY(except)->len; i++) {
- GetOpenFile(rb_io_get_io(RARRAY(except)->ptr[i]), fptr);
+ for (i=0; i<RARRAY_LEN(except); i++) {
+ GetOpenFile(rb_io_get_io(RARRAY_PTR(except)[i]), fptr);
rb_fd_set(fptr->fd, &fds[2]);
if (max < fptr->fd) max = fptr->fd;
}
@@ -4607,9 +4607,9 @@ select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fd
if (interrupt_flag == 0) {
if (rp) {
- list = RARRAY(res)->ptr[0];
- for (i=0; i< RARRAY(read)->len; i++) {
- GetOpenFile(rb_io_get_io(RARRAY(read)->ptr[i]), fptr);
+ list = RARRAY_PTR(res)[0];
+ for (i=0; i< RARRAY_LEN(read); i++) {
+ GetOpenFile(rb_io_get_io(RARRAY_PTR(read)[i]), fptr);
if (rb_fd_isset(fptr->fd, &fds[0]) ||
rb_fd_isset(fptr->fd, &fds[3])) {
rb_ary_push(list, rb_ary_entry(read, i));
@@ -4618,9 +4618,9 @@ select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fd
}
if (wp) {
- list = RARRAY(res)->ptr[1];
- for (i=0; i< RARRAY(write)->len; i++) {
- GetOpenFile(rb_io_get_io(RARRAY(write)->ptr[i]), fptr);
+ list = RARRAY_PTR(res)[1];
+ for (i=0; i< RARRAY_LEN(write); i++) {
+ GetOpenFile(rb_io_get_io(RARRAY_PTR(write)[i]), fptr);
if (rb_fd_isset(fptr->fd, &fds[1])) {
rb_ary_push(list, rb_ary_entry(write, i));
}
@@ -4628,9 +4628,9 @@ select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fd
}
if (ep) {
- list = RARRAY(res)->ptr[2];
- for (i=0; i< RARRAY(except)->len; i++) {
- GetOpenFile(rb_io_get_io(RARRAY(except)->ptr[i]), fptr);
+ list = RARRAY_PTR(res)[2];
+ for (i=0; i< RARRAY_LEN(except); i++) {
+ GetOpenFile(rb_io_get_io(RARRAY_PTR(except)[i]), fptr);
if (rb_fd_isset(fptr->fd, &fds[2])) {
rb_ary_push(list, rb_ary_entry(except, i));
}
@@ -5328,7 +5328,7 @@ argf_readpartial(int argc, VALUE *argv)
}
argf_close(current_file);
next_p = 1;
- if (RARRAY(rb_argv)->len == 0)
+ if (RARRAY_LEN(rb_argv) == 0)
rb_eof_error();
if (NIL_P(str))
str = rb_str_new(NULL, 0);
diff --git a/marshal.c b/marshal.c
index 2e69af0..0d9e852 100644
--- a/marshal.c
+++ b/marshal.c
@@ -552,8 +552,8 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
w_uclass(obj, rb_cArray, arg);
w_byte(TYPE_ARRAY, arg);
{
- long len = RARRAY(obj)->len;
- VALUE *ptr = RARRAY(obj)->ptr;
+ long len = RARRAY_LEN(obj);
+ VALUE *ptr = RARRAY_PTR(obj);
w_long(len, arg);
while (len--) {
@@ -592,7 +592,7 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
w_long(len, arg);
mem = rb_struct_members(obj);
for (i=0; i<len; i++) {
- w_symbol(SYM2ID(RARRAY(mem)->ptr[i]), arg);
+ w_symbol(SYM2ID(RARRAY_PTR(mem)[i]), arg);
w_object(RSTRUCT_PTR(obj)[i], arg, limit);
}
}
@@ -963,7 +963,7 @@ r_object0(struct load_arg *arg, VALUE proc, int *ivp, VALUE extmod)
rb_ary_push(extmod, m);
v = r_object0(arg, 0, 0, extmod);
- while (RARRAY(extmod)->len > 0) {
+ while (RARRAY_LEN(extmod) > 0) {
m = rb_ary_pop(extmod);
rb_extend_object(v, m);
}
@@ -1145,11 +1145,11 @@ r_object0(struct load_arg *arg, VALUE proc, int *ivp, VALUE extmod)
for (i=0; i<len; i++) {
slot = r_symbol(arg);
- if (RARRAY(mem)->ptr[i] != ID2SYM(slot)) {
+ if (RARRAY_PTR(mem)[i] != ID2SYM(slot)) {
rb_raise(rb_eTypeError, "struct %s not compatible (:%s for :%s)",
rb_class2name(klass),
rb_id2name(slot),
- rb_id2name(SYM2ID(RARRAY(mem)->ptr[i])));
+ rb_id2name(SYM2ID(RARRAY_PTR(mem)[i])));
}
rb_struct_aset(v, LONG2FIX(i), r_object(arg));
}
@@ -1182,7 +1182,7 @@ r_object0(struct load_arg *arg, VALUE proc, int *ivp, VALUE extmod)
v = rb_obj_alloc(klass);
if (! NIL_P(extmod)) {
- while (RARRAY(extmod)->len > 0) {
+ while (RARRAY_LEN(extmod) > 0) {
VALUE m = rb_ary_pop(extmod);
rb_extend_object(v, m);
}
diff --git a/numeric.c b/numeric.c
index a330cf0..5a08f06 100644
--- a/numeric.c
+++ b/numeric.c
@@ -132,15 +132,15 @@ do_coerce(VALUE *x, VALUE *y, int err)
a[0] = *x; a[1] = *y;
ary = rb_rescue(coerce_body, (VALUE)a, err?coerce_rescue:0, (VALUE)a);
- if (TYPE(ary) != T_ARRAY || RARRAY(ary)->len != 2) {
+ if (TYPE(ary) != T_ARRAY || RARRAY_LEN(ary) != 2) {
if (err) {
rb_raise(rb_eTypeError, "coerce must return [x, y]");
}
return Qfalse;
}
- *x = RARRAY(ary)->ptr[0];
- *y = RARRAY(ary)->ptr[1];
+ *x = RARRAY_PTR(ary)[0];
+ *y = RARRAY_PTR(ary)[1];
return Qtrue;
}
diff --git a/object.c b/object.c
index 6646322..51a1736 100644
--- a/object.c
+++ b/object.c
@@ -1057,13 +1057,13 @@ sym_call(VALUE args, VALUE sym)
{
VALUE obj;
- if (RARRAY(args)->len < 1) {
+ if (RARRAY_LEN(args) < 1) {
rb_raise(rb_eArgError, "no receiver given");
}
- obj = RARRAY(args)->ptr[0];
+ obj = RARRAY_PTR(args)[0];
return rb_funcall3(obj, (ID)sym,
- RARRAY(args)->len - 1,
- RARRAY(args)->ptr + 1);
+ RARRAY_LEN(args) - 1,
+ RARRAY_PTR(args) + 1);
}
/*
diff --git a/pack.c b/pack.c
index 4a567dd..7cb6848 100644
--- a/pack.c
+++ b/pack.c
@@ -452,12 +452,12 @@ pack_pack(VALUE ary, VALUE fmt)
pend = p + RSTRING_LEN(fmt);
res = rb_str_buf_new(0);
- items = RARRAY(ary)->len;
+ items = RARRAY_LEN(ary);
idx = 0;
#define TOO_FEW (rb_raise(rb_eArgError, toofew), 0)
-#define THISFROM (items > 0 ? RARRAY(ary)->ptr[idx] : TOO_FEW)
-#define NEXTFROM (items-- > 0 ? RARRAY(ary)->ptr[idx++] : TOO_FEW)
+#define THISFROM (items > 0 ? RARRAY_PTR(ary)[idx] : TOO_FEW)
+#define NEXTFROM (items-- > 0 ? RARRAY_PTR(ary)[idx++] : TOO_FEW)
while (p < pend) {
if (RSTRING_PTR(fmt) + RSTRING_LEN(fmt) != pend) {
@@ -949,9 +949,9 @@ pack_pack(VALUE ary, VALUE fmt)
VALUE big128 = rb_uint2big(128);
while (TYPE(from) == T_BIGNUM) {
from = rb_big_divmod(from, big128);
- c = NUM2INT(RARRAY(from)->ptr[1]) | 0x80; /* mod */
+ c = NUM2INT(RARRAY_PTR(from)[1]) | 0x80; /* mod */
rb_str_buf_cat(buf, &c, sizeof(char));
- from = RARRAY(from)->ptr[0]; /* div */
+ from = RARRAY_PTR(from)[0]; /* div */
}
}
@@ -1868,8 +1868,8 @@ pack_unpack(VALUE str, VALUE fmt)
if (!(a = rb_str_associated(str))) {
rb_raise(rb_eArgError, "no associated pointer");
}
- p = RARRAY(a)->ptr;
- pend = p + RARRAY(a)->len;
+ p = RARRAY_PTR(a);
+ pend = p + RARRAY_LEN(a);
while (p < pend) {
if (TYPE(*p) == T_STRING && RSTRING_PTR(*p) == t) {
if (len < RSTRING_LEN(*p)) {
@@ -1913,8 +1913,8 @@ pack_unpack(VALUE str, VALUE fmt)
if (!(a = rb_str_associated(str))) {
rb_raise(rb_eArgError, "no associated pointer");
}
- p = RARRAY(a)->ptr;
- pend = p + RARRAY(a)->len;
+ p = RARRAY_PTR(a);
+ pend = p + RARRAY_LEN(a);
while (p < pend) {
if (TYPE(*p) == T_STRING && RSTRING_PTR(*p) == t) {
tmp = *p;
diff --git a/process.c b/process.c
index 4797f5d..8433201 100644
--- a/process.c
+++ b/process.c
@@ -1167,11 +1167,11 @@ rb_check_argv(int argc, VALUE *argv)
prog = 0;
tmp = rb_check_array_type(argv[0]);
if (!NIL_P(tmp)) {
- if (RARRAY(tmp)->len != 2) {
+ if (RARRAY_LEN(tmp) != 2) {
rb_raise(rb_eArgError, "wrong first argument");
}
- prog = RARRAY(tmp)->ptr[0];
- argv[0] = RARRAY(tmp)->ptr[1];
+ prog = RARRAY_PTR(tmp)[0];
+ argv[0] = RARRAY_PTR(tmp)[1];
SafeStringValue(prog);
}
for (i = 0; i < argc; i++) {
@@ -2647,14 +2647,14 @@ proc_setgroups(VALUE obj, VALUE ary)
Check_Type(ary, T_ARRAY);
- ngroups = RARRAY(ary)->len;
+ ngroups = RARRAY_LEN(ary);
if (ngroups > maxgroups)
rb_raise(rb_eArgError, "too many groups, %lu max", (unsigned long)maxgroups);
groups = ALLOCA_N(rb_gid_t, ngroups);
- for (i = 0; i < ngroups && i < RARRAY(ary)->len; i++) {
- VALUE g = RARRAY(ary)->ptr[i];
+ for (i = 0; i < ngroups && i < RARRAY_LEN(ary); i++) {
+ VALUE g = RARRAY_PTR(ary)[i];
if (FIXNUM_P(g)) {
groups[i] = FIX2INT(g);
diff --git a/ruby.c b/ruby.c
index 4ce58ab..300b634 100644
--- a/ruby.c
+++ b/ruby.c
@@ -390,8 +390,8 @@ process_sflag(void)
long n;
VALUE *args;
- n = RARRAY(rb_argv)->len;
- args = RARRAY(rb_argv)->ptr;
+ n = RARRAY_LEN(rb_argv);
+ args = RARRAY_PTR(rb_argv);
while (n > 0) {
VALUE v = *args++;
char *s = StringValuePtr(v);
@@ -434,7 +434,7 @@ process_sflag(void)
}
rb_gv_set(s, v);
}
- n = RARRAY(rb_argv)->len - n;
+ n = RARRAY_LEN(rb_argv) - n;
while (n--) {
rb_ary_shift(rb_argv);
}
diff --git a/ruby.h b/ruby.h
index 6a2d2db..b9943fd 100644
--- a/ruby.h
+++ b/ruby.h
@@ -390,15 +390,33 @@ struct RString {
RSTRING(str)->as.ary : \
RSTRING(str)->as.heap.ptr)
+#define RARRAY_EMBED_LEN_MAX 3
struct RArray {
struct RBasic basic;
- long len;
union {
- long capa;
- VALUE shared;
- } aux;
- VALUE *ptr;
+ struct {
+ long len;
+ union {
+ long capa;
+ VALUE shared;
+ } aux;
+ VALUE *ptr;
+ } heap;
+ VALUE ary[RARRAY_EMBED_LEN_MAX];
+ } as;
};
+#define RARRAY_NOEMBED FL_USER3
+#define RARRAY_EMBED_LEN_MASK (FL_USER4|FL_USER5)
+#define RARRAY_EMBED_LEN_SHIFT (FL_USHIFT+4)
+#define RARRAY_LEN(a) \
+ (!(RBASIC(a)->flags & RARRAY_NOEMBED) ? \
+ (long)((RBASIC(a)->flags >> RARRAY_EMBED_LEN_SHIFT) & \
+ (RARRAY_EMBED_LEN_MASK >> RARRAY_EMBED_LEN_SHIFT)) : \
+ RARRAY(a)->as.heap.len)
+#define RARRAY_PTR(a) \
+ (!(RBASIC(a)->flags & RARRAY_NOEMBED) ? \
+ RARRAY(a)->as.ary : \
+ RARRAY(a)->as.heap.ptr)
struct RRegexp {
struct RBasic basic;
diff --git a/string.c b/string.c
index 4e402d9..05d0d32 100644
--- a/string.c
+++ b/string.c
@@ -43,6 +43,7 @@ VALUE rb_cString;
FL_SET(str, STR_NOEMBED);\
STR_SET_EMBED_LEN(str, 0);\
} while (0)
+#define STR_SET_EMBED(str) FL_UNSET(str, STR_NOEMBED)
#define STR_EMBED_P(str) (!FL_TEST(str, STR_NOEMBED))
#define STR_SET_EMBED_LEN(str, n) do { \
long tmp_n = (n);\
@@ -299,7 +300,7 @@ rb_str_shared_replace(VALUE str, VALUE str2)
rb_str_modify(str);
if (OBJ_TAINTED(str2)) OBJ_TAINT(str);
if (RSTRING_LEN(str2) <= RSTRING_EMBED_LEN_MAX) {
- FL_UNSET(str, STR_NOEMBED);
+ STR_SET_EMBED(str);
memcpy(RSTRING_PTR(str), RSTRING_PTR(str2), RSTRING_LEN(str2)+1);
STR_SET_EMBED_LEN(str, RSTRING_LEN(str2));
return;
@@ -482,7 +483,7 @@ static VALUE
rb_str_format_m(VALUE str, VALUE arg)
{
if (TYPE(arg) == T_ARRAY) {
- return rb_str_format(RARRAY(arg)->len, RARRAY(arg)->ptr, str);
+ return rb_str_format(RARRAY_LEN(arg), RARRAY_PTR(arg), str);
}
return rb_str_format(1, &arg, str);
}
@@ -2301,7 +2302,7 @@ rb_str_clear(VALUE str)
if (str_independent(str)) {
free(RSTRING_PTR(str));
}
- FL_UNSET(str, STR_NOEMBED);
+ STR_SET_EMBED(str);
STR_SET_EMBED_LEN(str, 0);
RSTRING_PTR(str)[0] = 0;
return str;
@@ -3505,8 +3506,8 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
rb_ary_push(result, tmp);
}
if (NIL_P(limit) && lim == 0) {
- while (RARRAY(result)->len > 0 &&
- RSTRING_LEN(RARRAY(result)->ptr[RARRAY(result)->len-1]) == 0)
+ while (RARRAY_LEN(result) > 0 &&
+ RSTRING_LEN(RARRAY_PTR(result)[RARRAY_LEN(result)-1]) == 0)
rb_ary_pop(result);
}
diff --git a/struct.c b/struct.c
index c7ca180..b93f338 100644
--- a/struct.c
+++ b/struct.c
@@ -47,9 +47,9 @@ rb_struct_members(VALUE s)
{
VALUE members = rb_struct_s_members(rb_obj_class(s));
- if (RSTRUCT_LEN(s) != RARRAY(members)->len) {
+ if (RSTRUCT_LEN(s) != RARRAY_LEN(members)) {
rb_raise(rb_eTypeError, "struct size differs (%ld required %ld given)",
- RARRAY(members)->len, RSTRUCT_LEN(s));
+ RARRAY_LEN(members), RSTRUCT_LEN(s));
}
return members;
}
@@ -61,8 +61,8 @@ rb_struct_s_members_m(VALUE klass)
VALUE *p, *pend;
members = rb_struct_s_members(klass);
- ary = rb_ary_new2(RARRAY(members)->len);
- p = RARRAY(members)->ptr; pend = p + RARRAY(members)->len;
+ ary = rb_ary_new2(RARRAY_LEN(members));
+ p = RARRAY_PTR(members); pend = p + RARRAY_LEN(members);
while (p < pend) {
rb_ary_push(ary, rb_str_new2(rb_id2name(SYM2ID(*p))));
p++;
@@ -97,8 +97,8 @@ rb_struct_getmember(VALUE obj, ID id)
members = rb_struct_members(obj);
slot = ID2SYM(id);
- for (i=0; i<RARRAY(members)->len; i++) {
- if (RARRAY(members)->ptr[i] == slot) {
+ for (i=0; i<RARRAY_LEN(members); i++) {
+ if (RARRAY_PTR(members)[i] == slot) {
return RSTRUCT_PTR(obj)[i];
}
}
@@ -154,8 +154,8 @@ rb_struct_set(VALUE obj, VALUE val)
members = rb_struct_members(obj);
rb_struct_modify(obj);
- for (i=0; i<RARRAY(members)->len; i++) {
- slot = RARRAY(members)->ptr[i];
+ for (i=0; i<RARRAY_LEN(members); i++) {
+ slot = RARRAY_PTR(members)[i];
if (rb_id_attrset(SYM2ID(slot)) == rb_frame_this_func()) {
return RSTRUCT_PTR(obj)[i] = val;
}
@@ -191,15 +191,15 @@ make_struct(VALUE name, VALUE members, VALUE klass)
}
nstr = rb_define_class_under(klass, rb_id2name(id), klass);
}
- rb_iv_set(nstr, "__size__", LONG2NUM(RARRAY(members)->len));
+ rb_iv_set(nstr, "__size__", LONG2NUM(RARRAY_LEN(members)));
rb_iv_set(nstr, "__members__", members);
rb_define_alloc_func(nstr, struct_alloc);
rb_define_singleton_method(nstr, "new", rb_class_new_instance, -1);
rb_define_singleton_method(nstr, "[]", rb_class_new_instance, -1);
rb_define_singleton_method(nstr, "members", rb_struct_s_members_m, 0);
- for (i=0; i< RARRAY(members)->len; i++) {
- ID id = SYM2ID(RARRAY(members)->ptr[i]);
+ for (i=0; i< RARRAY_LEN(members); i++) {
+ ID id = SYM2ID(RARRAY_PTR(members)[i]);
if (rb_is_local_id(id) || rb_is_const_id(id)) {
if (i < N_REF_FUNC) {
rb_define_method_id(nstr, id, ref_func[i], 0);
@@ -278,9 +278,9 @@ rb_struct_s_def(int argc, VALUE *argv, VALUE klass)
ID id;
rb_scan_args(argc, argv, "1*", &name, &rest);
- for (i=0; i<RARRAY(rest)->len; i++) {
- id = rb_to_id(RARRAY(rest)->ptr[i]);
- RARRAY(rest)->ptr[i] = ID2SYM(id);
+ for (i=0; i<RARRAY_LEN(rest); i++) {
+ id = rb_to_id(RARRAY_PTR(rest)[i]);
+ RARRAY_PTR(rest)[i] = ID2SYM(id);
}
if (!NIL_P(name)) {
VALUE tmp = rb_check_string_type(name);
@@ -312,13 +312,13 @@ rb_struct_initialize(VALUE self, VALUE values)
rb_struct_modify(self);
size = rb_struct_iv_get(klass, "__size__");
n = FIX2LONG(size);
- if (n < RARRAY(values)->len) {
+ if (n < RARRAY_LEN(values)) {
rb_raise(rb_eArgError, "struct size differs");
}
- MEMCPY(RSTRUCT_PTR(self), RARRAY(values)->ptr, VALUE, RARRAY(values)->len);
- if (n > RARRAY(values)->len) {
- rb_mem_clear(RSTRUCT_PTR(self)+RARRAY(values)->len,
- n-RARRAY(values)->len);
+ MEMCPY(RSTRUCT_PTR(self), RARRAY_PTR(values), VALUE, RARRAY_LEN(values));
+ if (n > RARRAY_LEN(values)) {
+ rb_mem_clear(RSTRUCT_PTR(self)+RARRAY_LEN(values),
+ n-RARRAY_LEN(values));
}
return Qnil;
}
@@ -351,7 +351,7 @@ struct_alloc(VALUE klass)
VALUE
rb_struct_alloc(VALUE klass, VALUE values)
{
- return rb_class_new_instance(RARRAY(values)->len, RARRAY(values)->ptr, klass);
+ return rb_class_new_instance(RARRAY_LEN(values), RARRAY_PTR(values), klass);
}
VALUE
@@ -456,7 +456,7 @@ inspect_struct(VALUE s, VALUE dummy, int recur)
if (i > 0) {
rb_str_cat2(str, ", ");
}
- slot = RARRAY(members)->ptr[i];
+ slot = RARRAY_PTR(members)[i];
id = SYM2ID(slot);
if (rb_is_local_id(id) || rb_is_const_id(id)) {
p = rb_id2name(id);
@@ -535,9 +535,9 @@ rb_struct_aref_id(VALUE s, ID id)
long i, len;
members = rb_struct_members(s);
- len = RARRAY(members)->len;
+ len = RARRAY_LEN(members);
for (i=0; i<len; i++) {
- if (SYM2ID(RARRAY(members)->ptr[i]) == id) {
+ if (SYM2ID(RARRAY_PTR(members)[i]) == id) {
return RSTRUCT_PTR(s)[i];
}
}
@@ -592,13 +592,13 @@ rb_struct_aset_id(VALUE s, ID id, VALUE val)
members = rb_struct_members(s);
rb_struct_modify(s);
- len = RARRAY(members)->len;
- if (RSTRUCT_LEN(s) != RARRAY(members)->len) {
+ len = RARRAY_LEN(members);
+ if (RSTRUCT_LEN(s) != RARRAY_LEN(members)) {
rb_raise(rb_eTypeError, "struct size differs (%ld required %ld given)",
- RARRAY(members)->len, RSTRUCT_LEN(s));
+ RARRAY_LEN(members), RSTRUCT_LEN(s));
}
for (i=0; i<len; i++) {
- if (SYM2ID(RARRAY(members)->ptr[i]) == id) {
+ if (SYM2ID(RARRAY_PTR(members)[i]) == id) {
RSTRUCT_PTR(s)[i] = val;
return val;
}