Revision: 586 http://trac.macosforge.org/projects/ruby/changeset/586 Author: lsansonetti@apple.com Date: 2008-09-08 17:20:56 -0700 (Mon, 08 Sep 2008) Log Message: ----------- mark NSNull as a NSObject constant, make sure we do not return placeholder objects off #allocate Modified Paths: -------------- MacRuby/trunk/gc.c MacRuby/trunk/object.c Modified: MacRuby/trunk/gc.c =================================================================== --- MacRuby/trunk/gc.c 2008-09-09 00:20:07 UTC (rev 585) +++ MacRuby/trunk/gc.c 2008-09-09 00:20:56 UTC (rev 586) @@ -687,18 +687,21 @@ * */ -static bool +bool rb_objc_is_placeholder(void *obj) { + static void *placeholder_str = NULL; static void *placeholder_dict = NULL; static void *placeholder_ary = NULL; void *obj_klass; + if (placeholder_str == NULL) + placeholder_str = objc_getClass("NSPlaceholderMutableString"); if (placeholder_dict == NULL) placeholder_dict = objc_getClass("__NSPlaceholderDictionary"); if (placeholder_ary == NULL) placeholder_ary = objc_getClass("__NSPlaceholderArray"); obj_klass = *(void **)obj; - return obj_klass == placeholder_dict || obj_klass == placeholder_ary; + return obj_klass == placeholder_str || obj_klass == placeholder_dict || obj_klass == placeholder_ary; } struct rb_objc_recorder_context { Modified: MacRuby/trunk/object.c =================================================================== --- MacRuby/trunk/object.c 2008-09-09 00:20:07 UTC (rev 585) +++ MacRuby/trunk/object.c 2008-09-09 00:20:56 UTC (rev 586) @@ -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);