ext/decoder.c in erlectricity-1.0.1 vs ext/decoder.c in erlectricity-1.1.0

- old
+ new

@@ -114,11 +114,12 @@ rb_raise(rb_eStandardError, "Invalid Type, not an erlang list"); } int size = read_4(pData); - VALUE array = rb_ary_new2(size); + VALUE newref_class = rb_const_get(mErlectricity, rb_intern("List")); + VALUE array = rb_funcall(newref_class, rb_intern("new"), 1, INT2NUM(size)); int i; for(i = 0; i < size; ++i) { rb_ary_store(array, i, read_any_raw(pData)); } @@ -157,11 +158,12 @@ int length = read_2(pData); unsigned char buf[length + 1]; read_string_raw(buf, pData, length); - VALUE array = rb_ary_new2(length); + VALUE newref_class = rb_const_get(mErlectricity, rb_intern("List")); + VALUE array = rb_funcall(newref_class, rb_intern("new"), 1, INT2NUM(length)); int i = 0; for(i; i < length; ++i) { rb_ary_store(array, i, INT2NUM(*(buf + i))); } @@ -178,13 +180,13 @@ unsigned char buf[length + 1]; read_string_raw(buf, pData, length); // Erlang true and false are actually atoms - if(strncmp((char *) buf, "true", length) == 0) { + if(length == 4 && strncmp((char *) buf, "true", length) == 0) { return Qtrue; - } else if(strncmp((char *) buf, "false", length) == 0) { + } else if(length == 5 && strncmp((char *) buf, "false", length) == 0) { return Qfalse; } else { return ID2SYM(rb_intern((char *) buf)); } } @@ -288,10 +290,11 @@ VALUE read_nil(unsigned char **pData) { if(read_1(pData) != ERL_NIL) { rb_raise(rb_eStandardError, "Invalid Type, not a nil list"); } - return rb_ary_new2(0); + VALUE newref_class = rb_const_get(mErlectricity, rb_intern("List")); + return rb_funcall(newref_class, rb_intern("new"), 0); } // specials VALUE read_pid(unsigned char **pData) {