Skip to content

Commit b077ef9

Browse files
committed
RUBY-182 Rubinius compatibility; use rb_ary_entry() in lieu of RARRAY_PTR
1 parent 8139537 commit b077ef9

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

ext/cbson/cbson.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
# define RSTRING_LEN(v) RSTRING(v)->len
3232
#endif
3333

34-
#ifndef RARRAY_PTR
35-
# define RARRAY_PTR(v) RARRAY(v)->ptr
36-
#endif
37-
3834
#ifndef RARRAY_LEN
3935
# define RARRAY_LEN(v) RARRAY(v)->len
4036
#endif
@@ -311,13 +307,12 @@ static int write_element(VALUE key, VALUE value, VALUE extra, int allow_id) {
311307
}
312308

313309
items = RARRAY_LEN(value);
314-
values = RARRAY_PTR(value);
315310
for(i = 0; i < items; i++) {
316311
char* name;
317312
VALUE key;
318313
INT2STRING(&name, i);
319314
key = rb_str_new2(name);
320-
write_element_with_id(key, values[i], pack_extra(buffer, check_keys));
315+
write_element_with_id(key, rb_ary_entry(value, i), pack_extra(buffer, check_keys));
321316
free(name);
322317
}
323318

@@ -398,7 +393,7 @@ static int write_element(VALUE key, VALUE value, VALUE extra, int allow_id) {
398393
int i;
399394
write_name_and_type(buffer, key, 0x07);
400395
for (i = 0; i < 12; i++) {
401-
char byte = (char)FIX2INT(RARRAY_PTR(as_array)[i]);
396+
char byte = (char)FIX2INT(rb_ary_entry(as_array, i));
402397
SAFE_WRITE(buffer, &byte, 1);
403398
}
404399
break;
@@ -571,7 +566,7 @@ static void write_doc(buffer_t buffer, VALUE hash, VALUE check_keys, VALUE move_
571566
VALUE keys = rb_funcall(hash, rb_intern("keys"), 0);
572567
int i;
573568
for(i = 0; i < RARRAY_LEN(keys); i++) {
574-
VALUE key = RARRAY_PTR(keys)[i];
569+
VALUE key = rb_ary_entry(keys, i);
575570
VALUE value = rb_hash_aref(hash, key);
576571

577572
write_function(key, value, pack_extra(buffer, check_keys));
@@ -877,16 +872,19 @@ static VALUE method_deserialize(VALUE self, VALUE bson) {
877872
static VALUE fast_pack(VALUE self)
878873
{
879874
VALUE res;
880-
long i;
875+
long i, len;
881876
char c;
877+
char *buf;
882878

883-
res = rb_str_buf_new(0);
879+
len = RARRAY_LEN(self);
880+
buf = malloc(len * sizeof(char));
884881

885-
for (i = 0; i < RARRAY_LEN(self); i++) {
886-
c = FIX2LONG(RARRAY_PTR(self)[i]);
887-
rb_str_buf_cat(res, &c, sizeof(char));
882+
for (i = 0; i < len; i++) {
883+
buf[i] = FIX2INT(rb_ary_entry(self, i));
888884
}
889885

886+
res = rb_str_new(buf, len);
887+
890888
return res;
891889
}
892890

0 commit comments

Comments
 (0)