Modified: MacRuby/branches/testing/marshal.c (588 => 589)
--- MacRuby/branches/testing/marshal.c 2008-09-09 03:26:36 UTC (rev 588)
+++ MacRuby/branches/testing/marshal.c 2008-09-09 03:30:58 UTC (rev 589)
@@ -536,7 +536,18 @@
static void
w_objivar(VALUE obj, struct dump_call_arg *arg)
{
-#if !WITH_OBJC /* TODO */
+#if WITH_OBJC
+ VALUE ary = rb_obj_instance_variables(obj);
+ int i, len = RARRAY_LEN(ary);
+
+ w_encoding(obj, len, arg);
+
+ for (i = 0; i < len; i++) {
+ ID var_id = SYM2ID(RARRAY_AT(ary, i));
+ VALUE var_val = rb_ivar_get(obj, var_id);
+ w_obj_each(var_id, var_val, arg);
+ }
+#else
VALUE *ptr;
long i, len, num;
@@ -899,11 +910,13 @@
{
VALUE obj, port, a1, a2;
int limit = -1;
- struct dump_arg arg;
- struct dump_call_arg c_arg;
+ struct dump_arg *arg;
+ struct dump_call_arg *c_arg;
port = Qnil;
rb_scan_args(argc, argv, "12", &obj, &a1, &a2);
+ arg = (struct dump_arg *)xmalloc(sizeof(struct dump_arg));
+ c_arg = (struct dump_call_arg *)xmalloc(sizeof(struct dump_call_arg));
if (argc == 3) {
if (!NIL_P(a2)) limit = NUM2INT(a2);
if (NIL_P(a1)) goto type_error;
@@ -914,39 +927,39 @@
else if (NIL_P(a1)) goto type_error;
else port = a1;
}
- arg.dest = 0;
+ arg->dest = 0;
if (!NIL_P(port)) {
if (!rb_obj_respond_to(port, s_write, Qtrue)) {
type_error:
rb_raise(rb_eTypeError, "instance of IO needed");
}
- arg.str = rb_str_buf_new(0);
- arg.dest = port;
+ GC_WB(&arg->str, rb_str_buf_new(0));
+ GC_WB(&arg->dest, port);
if (rb_obj_respond_to(port, s_binmode, Qtrue)) {
rb_funcall2(port, s_binmode, 0, 0);
}
}
else {
port = rb_str_buf_new(0);
- arg.str = port;
+ GC_WB(&arg->str, port);
}
- RSTRING_BYTEPTR(arg.str); /* force bytestring creation */
+ RSTRING_BYTEPTR(arg->str); /* force bytestring creation */
- arg.symbols = st_init_numtable();
- arg.data = st_init_numtable();
- arg.taint = Qfalse;
- arg.compat_tbl = st_init_numtable();
- arg.wrapper = Data_Wrap_Struct(rb_cData, mark_dump_arg, 0, &arg);
- arg.encodings = 0;
- c_arg.obj = obj;
- c_arg.arg = &arg;
- c_arg.limit = limit;
+ GC_WB(&arg->symbols, st_init_numtable());
+ GC_WB(&arg->data, st_init_numtable());
+ arg->taint = Qfalse;
+ GC_WB(&arg->compat_tbl, st_init_numtable());
+ GC_WB(&arg->wrapper, Data_Wrap_Struct(rb_cData, mark_dump_arg, 0, arg));
+ arg->encodings = 0;
+ GC_WB(&c_arg->obj, obj);
+ GC_WB(&c_arg->arg, arg);
+ c_arg->limit = limit;
- w_byte(MARSHAL_MAJOR, &arg);
- w_byte(MARSHAL_MINOR, &arg);
+ w_byte(MARSHAL_MAJOR, arg);
+ w_byte(MARSHAL_MINOR, arg);
- rb_ensure(dump, (VALUE)&c_arg, dump_ensure, (VALUE)&arg);
+ rb_ensure(dump, (VALUE)c_arg, dump_ensure, (VALUE)arg);
return port;
}
@@ -1655,34 +1668,31 @@
VALUE port, proc;
int major, minor;
VALUE v;
- struct load_arg arg;
+ struct load_arg *arg;
+ arg = (struct load_arg *)xmalloc(sizeof(struct load_arg));
rb_scan_args(argc, argv, "11", &port, &proc);
v = rb_check_string_type(port);
if (!NIL_P(v)) {
- arg.taint = OBJ_TAINTED(port); /* original taintedness */
+ arg->taint = OBJ_TAINTED(port); /* original taintedness */
port = v;
}
else if (rb_obj_respond_to(port, s_getbyte, Qtrue) && rb_obj_respond_to(port, s_read, Qtrue)) {
if (rb_obj_respond_to(port, s_binmode, Qtrue)) {
rb_funcall2(port, s_binmode, 0, 0);
}
- arg.taint = Qtrue;
+ arg->taint = Qtrue;
}
else {
rb_raise(rb_eTypeError, "instance of IO needed");
}
- arg.src = port;
- arg.offset = 0;
- arg.compat_tbl = st_init_numtable();
-#if WITH_OBJC
- arg.compat_tbl_wrapper = Data_Wrap_Struct(rb_cData, NULL, 0, arg.compat_tbl);
-#else
- arg.compat_tbl_wrapper = Data_Wrap_Struct(rb_cData, rb_mark_tbl, 0, arg.compat_tbl);
-#endif
+ GC_WB(&arg->src, port);
+ arg->offset = 0;
+ GC_WB(&arg->compat_tbl, st_init_numtable());
+ GC_WB(&arg->compat_tbl_wrapper, Data_Wrap_Struct(rb_cData, NULL/*rb_mark_tbl*/, 0, arg->compat_tbl));
- major = r_byte(&arg);
- minor = r_byte(&arg);
+ major = r_byte(arg);
+ minor = r_byte(arg);
if (major != MARSHAL_MAJOR || minor > MARSHAL_MINOR) {
rb_raise(rb_eTypeError, "incompatible marshal file format (can't be read)\n\
\tformat version %d.%d required; %d.%d given",
@@ -1694,11 +1704,11 @@
MARSHAL_MAJOR, MARSHAL_MINOR, major, minor);
}
- arg.symbols = st_init_numtable();
- arg.data = rb_hash_new();
- if (NIL_P(proc)) arg.proc = 0;
- else arg.proc = proc;
- v = rb_ensure(load, (VALUE)&arg, load_ensure, (VALUE)&arg);
+ GC_WB(&arg->symbols, st_init_numtable());
+ GC_WB(&arg->data, rb_hash_new());
+ if (NIL_P(proc)) arg->proc = 0;
+ else arg->proc = proc;
+ v = rb_ensure(load, (VALUE)arg, load_ensure, (VALUE)arg);
return v;
}
@@ -1764,6 +1774,7 @@
rb_gc_register_address(&compat_allocator_tbl_wrapper);
compat_allocator_tbl_wrapper =
Data_Wrap_Struct(rb_cData, mark_marshal_compat_t, 0, compat_allocator_tbl);
+ rb_objc_retain((void *)compat_allocator_tbl_wrapper);
}
VALUE
Modified: MacRuby/branches/testing/object.c (588 => 589)
--- MacRuby/branches/testing/object.c 2008-09-09 03:26:36 UTC (rev 588)
+++ MacRuby/branches/testing/object.c 2008-09-09 03:30:58 UTC (rev 589)
@@ -1499,6 +1499,12 @@
rb_raise(rb_eTypeError, "can't create instance of singleton class");
}
obj = rb_funcall(klass, ID_ALLOCATOR, 0, 0);
+
+ bool rb_objc_is_placeholder(void *obj);
+ if (rb_objc_is_placeholder((void *)obj)) {
+ obj = (VALUE)objc_msgSend((void *)obj, selInit);
+ }
+
return obj;
}
@@ -2532,6 +2538,8 @@
rb_define_global_function("String", rb_f_string, 1);
rb_define_global_function("Array", rb_f_array, 1);
+ rb_const_set(rb_cObject, rb_intern("NSNull"), (VALUE)objc_getClass("NSNull"));
+
rb_cNilClass = rb_define_class("NilClass", rb_cObject);
rb_define_method(rb_cNilClass, "to_i", nil_to_i, 0);
rb_define_method(rb_cNilClass, "to_f", nil_to_f, 0);
Modified: MacRuby/branches/testing/string.c (588 => 589)
--- MacRuby/branches/testing/string.c 2008-09-09 03:26:36 UTC (rev 588)
+++ MacRuby/branches/testing/string.c 2008-09-09 03:30:58 UTC (rev 589)
@@ -413,6 +413,8 @@
CFMakeCollectable((CFTypeRef)dup);
+ rb_gc_malloc_increase(32 + (sizeof(UniChar) * RSTRING_LEN(dup)));
+
return dup;
}
@@ -822,6 +824,7 @@
data = (CFMutableDataRef)rb_str_cfdata2(str);
if (data != NULL) {
CFDataAppendBytes(data, (const UInt8 *)ptr, len);
+ rb_gc_malloc_increase(sizeof(UniChar) * len);
}
else {
long slen;
@@ -5243,7 +5246,7 @@
if (range.location + range.length > RSYMBOL(rcv)->len)
rb_bug("[Symbol getCharacters:range:] out of bounds");
- for (i = range.location; i < range.length; i++) {
+ for (i = range.location; i < range.location + range.length; i++) {
*buffer = RSYMBOL(rcv)->str[i];
buffer++;
}
@@ -5278,6 +5281,7 @@
Init_String(void)
{
rb_cCFString = (VALUE)objc_getClass("NSCFString");
+ rb_const_set(rb_cObject, rb_intern("NSCFString"), rb_cCFString);
rb_cString = rb_cNSString = (VALUE)objc_getClass("NSString");
rb_cNSMutableString = (VALUE)objc_getClass("NSMutableString");
rb_const_set(rb_cObject, rb_intern("String"), rb_cNSMutableString);