[macruby-changes] [391] MacRuby/branches/lrz_unstable

source_changes at macosforge.org source_changes at macosforge.org
Fri Aug 1 19:56:32 PDT 2008


Revision: 391
          http://trac.macosforge.org/projects/ruby/changeset/391
Author:   lsansonetti at apple.com
Date:     2008-08-01 19:56:32 -0700 (Fri, 01 Aug 2008)
Log Message:
-----------
wip

Modified Paths:
--------------
    MacRuby/branches/lrz_unstable/array.c
    MacRuby/branches/lrz_unstable/bignum.c
    MacRuby/branches/lrz_unstable/class.c
    MacRuby/branches/lrz_unstable/compile.c
    MacRuby/branches/lrz_unstable/hash.c
    MacRuby/branches/lrz_unstable/include/ruby/ruby.h
    MacRuby/branches/lrz_unstable/insns.def
    MacRuby/branches/lrz_unstable/numeric.c
    MacRuby/branches/lrz_unstable/objc.m
    MacRuby/branches/lrz_unstable/parse.y
    MacRuby/branches/lrz_unstable/process.c
    MacRuby/branches/lrz_unstable/re.c
    MacRuby/branches/lrz_unstable/sample/test.rb
    MacRuby/branches/lrz_unstable/signal.c
    MacRuby/branches/lrz_unstable/string.c
    MacRuby/branches/lrz_unstable/variable.c

Modified: MacRuby/branches/lrz_unstable/array.c
===================================================================
--- MacRuby/branches/lrz_unstable/array.c	2008-07-31 22:22:07 UTC (rev 390)
+++ MacRuby/branches/lrz_unstable/array.c	2008-08-02 02:56:32 UTC (rev 391)
@@ -154,27 +154,6 @@
 }
 
 #if WITH_OBJC
-int rb_any_cmp(VALUE a, VALUE b);
-
-static Boolean
-rb_cfarray_equal_cb(const void *v1, const void *v2)
-{
-    return !rb_any_cmp((VALUE)v1, (VALUE)v2);
-}
-
-static const void *
-rb_cfarray_retain_cb(CFAllocatorRef allocator, const void *v)
-{
-    rb_objc_retain(v);
-    return v;
-}
-
-static void
-rb_cfarray_release_cb(CFAllocatorRef allocator, const void *v)
-{
-    rb_objc_release(v);
-}
-
 void rb_ary_insert(VALUE ary, long idx, VALUE val);
 #endif
 
@@ -182,22 +161,14 @@
 ary_alloc(VALUE klass)
 {
 #if WITH_OBJC
-    VALUE ary;
-    CFArrayCallBacks cb;
+    CFMutableArrayRef ary;
 
-    memset(&cb, 0, sizeof(CFArrayCallBacks));
-    cb.retain = rb_cfarray_retain_cb;
-    cb.release = rb_cfarray_release_cb;
-    cb.equal = rb_cfarray_equal_cb;
-
-    ary = (VALUE)CFArrayCreateMutable(NULL, 0, &cb);
+    ary = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
     if (klass != 0 && klass != rb_cNSArray && klass != rb_cNSMutableArray)
-        *(Class *)ary = (Class)klass;
+	*(Class *)ary = (Class)klass;
 
-    CFMakeCollectable((CFTypeRef)ary);
+    CFMakeCollectable(ary);
     rb_gc_malloc_increase(sizeof(void *));
-    
-    return ary;
 #else
     NEWOBJ(ary, struct RArray);
     OBJSETUP(ary, klass, T_ARRAY);
@@ -205,9 +176,9 @@
     ary->len = 0;
     ary->ptr = 0;
     ary->aux.capa = 0;
+#endif
 
     return (VALUE)ary;
-#endif
 }
 
 static VALUE
@@ -279,7 +250,11 @@
     ary = rb_ary_new2(n);
     if (n > 0 && elts) {
 #if WITH_OBJC
-	CFArrayReplaceValues((CFMutableArrayRef)ary, CFRangeMake(0, 0), (const void **)elts, n);
+	long i;
+	void **vals = (void **)alloca(n * sizeof(void *));
+	for (i = 0; i < n; i++)
+	    vals[i] = RB2OC(elts[i]);
+	CFArrayReplaceValues((CFMutableArrayRef)ary, CFRangeMake(0, 0), (const void **)vals, n);
 #else
 	MEMCPY(RARRAY_PTR(ary), elts, VALUE, n);
 	RARRAY(ary)->len = n;
@@ -493,8 +468,10 @@
 	rb_raise(rb_eArgError, "negative array size");
     }
 #if WITH_OBJC
-    CFArrayReplaceValues((CFMutableArrayRef)ary, CFRangeMake(0, 0), 
-	(const void **)argv, argc);
+    int i;
+    for (i = 0; i < argc; i++) {
+	CFArrayAppendValue((CFMutableArrayRef)ary, RB2OC(argv[i]));
+    }
 #else
     RARRAY(ary)->ptr = ALLOC_N(VALUE, argc);
     RARRAY(ary)->aux.capa = argc;
@@ -520,7 +497,7 @@
     rb_ary_modify(ary);
 
     CFArrayInsertValueAtIndex((CFMutableArrayRef)ary, idx, 
-	(const void *)val);
+	(const void *)RB2OC(val));
 }
 #endif
 
@@ -540,24 +517,17 @@
 
 #if WITH_OBJC
     if (idx > len) {
-	const void **objs;
 	long i;
-	if (idx > sizeof(CFIndex))
-	if ((idx - len) * (long)sizeof(VALUE) <= idx - len)
+	if ((idx - len) * (long)sizeof(VALUE) <= idx - len) {
 	    rb_raise(rb_eArgError, "index too big");
-	objs = (const void **)alloca(sizeof(void *) * (idx - len));
-	if (objs == NULL)
-	    rb_raise(rb_eArgError, "index too big");
-	for (i = 0; i < (idx - len); i++)
-	    objs[i] = (const void *)Qnil;
-	CFArrayReplaceValues((CFMutableArrayRef)ary, 
-	    CFRangeMake(len, 0),
-	    objs,
-	    idx - len);
-	CFArrayAppendValue((CFMutableArrayRef)ary, (const void *)val);	
+	}
+	for (i = 0; i < (idx - len); i++) {
+	    CFArrayAppendValue((CFMutableArrayRef)ary, (const void *)kCFNull);
+	}
+	CFArrayAppendValue((CFMutableArrayRef)ary, (const void *)RB2OC(val));	
     }
     else {
-        CFArraySetValueAtIndex((CFMutableArrayRef)ary, idx, (const void *)val);
+        CFArraySetValueAtIndex((CFMutableArrayRef)ary, idx, (const void *)RB2OC(val));
     }
 #else
     if (idx >= ARY_CAPA(ary)) {
@@ -654,7 +624,7 @@
 {
 #if WITH_OBJC
     rb_ary_modify(ary);
-    CFArrayAppendValue((CFMutableArrayRef)ary, (const void *)item);
+    CFArrayAppendValue((CFMutableArrayRef)ary, (const void *)RB2OC(item));
 #else
     rb_ary_store(ary, RARRAY_LEN(ary), item);
 #endif
@@ -843,7 +813,7 @@
 	long i;
 	for (i = argc - 1; i >= 0; i--)
 	    CFArrayInsertValueAtIndex((CFMutableArrayRef)ary,
-		0, (const void *)argv[i]);
+		0, (const void *)RB2OC(argv[i]));
     }
 #else
     if (RARRAY(ary)->aux.capa <= (len = RARRAY(ary)->len) + argc) {
@@ -875,7 +845,7 @@
 	return Qnil;
     if (offset < 0 || n <= offset)
 	return Qnil;
-    return (VALUE)CFArrayGetValueAtIndex((CFArrayRef)ary, offset);
+    return OC2RB(CFArrayGetValueAtIndex((CFArrayRef)ary, offset));
 }
 #else
 static inline VALUE
@@ -896,15 +866,17 @@
     /* FIXME we could inline __CFArrayGetBucketsPtr for non-store arrays,
      * for performance reasons.
      */
-    const VALUE *values;
-    long len;
+    VALUE *values;
+    long i, len;
 
     len = RARRAY_LEN(ary);
     if (len == 0)
 	return NULL;
-    values = (const VALUE *)xmalloc(sizeof(VALUE) * len);
+    values = (VALUE *)xmalloc(sizeof(VALUE) * len);
     CFArrayGetValues((CFArrayRef)ary, CFRangeMake(0, len), 
 	(const void **)values);
+    for (i = 0; i < len; i++)
+	values[i] = OC2RB(values[i]);
     GC_WB(&rb_objc_ary_get_struct2(ary)->cptr, values);
 
     return values;
@@ -1196,7 +1168,7 @@
 #if WITH_OBJC
 	CFIndex idx;
 	idx = CFArrayGetFirstIndexOfValue((CFArrayRef)ary, CFRangeMake(0, n), 
-	    (const void *)val);
+	    (const void *)RB2OC(val));
 	if (idx != -1)
 	    return LONG2NUM(idx);
 #else
@@ -1246,7 +1218,7 @@
  	rb_scan_args(argc, argv, "01", &val);
 #if WITH_OBJC
 	i = CFArrayGetLastIndexOfValue((CFArrayRef)ary, CFRangeMake(0, n),
-	   (const void *)val);
+	   (const void *)RB2OC(val));
 	if (i != -1)
 	    return LONG2NUM(i);
 #else
@@ -1304,7 +1276,7 @@
     if (beg >= n) {
 	long i;
 	for (i = n; i < beg - n; i++) {
-	    CFArrayAppendValue((CFMutableArrayRef)ary, (const void *)Qnil);
+	    CFArrayAppendValue((CFMutableArrayRef)ary, (const void *)kCFNull);
 	}
 	if (rlen > 0) 
 	    CFArrayAppendArray((CFMutableArrayRef)ary, (CFArrayRef)rpl,
@@ -1570,16 +1542,12 @@
 static inline VALUE
 rb_ary_dup2(VALUE ary)
 {
-    VALUE klass, dup;
-    long n;
+    CFMutableArrayRef dup;
 
-    klass = rb_obj_class(ary);
-    dup = ary_new(klass, 0);
-    n = RARRAY_LEN(ary);
-    if (n > 0)
-	CFArrayAppendArray((CFMutableArrayRef)dup, (CFArrayRef)ary,
-		CFRangeMake(0, n));
-    return dup;
+    dup = CFArrayCreateMutableCopy(NULL, 0, (CFArrayRef)ary);
+    CFMakeCollectable(dup);
+
+    return (VALUE)dup;
 }
 #endif
 
@@ -1851,11 +1819,13 @@
 #endif
     int n;
 
+#if !WITH_OBJC
     if (FIXNUM_P(a) && FIXNUM_P(b)) {
 	if ((long)a > (long)b) return 1;
 	if ((long)a < (long)b) return -1;
 	return 0;
     }
+#endif
     if (TYPE(a) == T_STRING) {
 	if (TYPE(b) == T_STRING) return rb_str_cmp(a, b);
     }
@@ -2127,7 +2097,7 @@
     r = CFRangeMake(0, RARRAY_LEN(ary));
     n = 0;
     while ((i = CFArrayGetFirstIndexOfValue((CFArrayRef)ary, r, 
-	(const void *)item)) != -1) {
+	(const void *)RB2OC(item))) != -1) {
 	CFArrayRemoveValueAtIndex((CFMutableArrayRef)ary, i);
     	n++;
     }
@@ -2824,6 +2794,7 @@
     return Qnil;
 }
 
+#if !WITH_OBJC
 static VALUE
 recursive_equal(VALUE ary1, VALUE ary2, int recur)
 {
@@ -2836,6 +2807,7 @@
     }
     return Qtrue;
 }
+#endif
 
 /* 
  *  call-seq:
@@ -2861,8 +2833,12 @@
 	}
 	return rb_equal(ary2, ary1);
     }
+#if WITH_OBJC
+    return CFEqual((CFTypeRef)ary1, (CFTypeRef)ary2) ? Qtrue : Qfalse;
+#else
     if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) return Qfalse;
     return rb_exec_recursive(recursive_equal, ary1, ary2);
+#endif
 }
 
 static VALUE
@@ -2895,6 +2871,7 @@
     return rb_exec_recursive(recursive_eql, ary1, ary2);
 }
 
+#if !WITH_OBJC
 static VALUE
 recursive_hash(VALUE ary, VALUE dummy, int recur)
 {
@@ -2912,6 +2889,7 @@
     }
     return LONG2FIX(h);
 }
+#endif
 
 /*
  *  call-seq:
@@ -2921,11 +2899,13 @@
  *  will have the same hash code (and will compare using <code>eql?</code>).
  */
 
+#if !WITH_OBJC
 static VALUE
 rb_ary_hash(VALUE ary)
 {
     return rb_exec_recursive(recursive_hash, ary, 0);
 }
+#endif
 
 /*
  *  call-seq:
@@ -2945,7 +2925,7 @@
 {
 #if WITH_OBJC
     return CFArrayContainsValue((CFArrayRef)ary, 
-	CFRangeMake(0, RARRAY_LEN(ary)), (const void *)item) ? Qtrue : Qfalse;
+	CFRangeMake(0, RARRAY_LEN(ary)), (const void *)RB2OC(item)) ? Qtrue : Qfalse;
 #else
     long i;
     
@@ -3055,8 +3035,9 @@
 
     for (i=0; i<RARRAY_LEN(ary1); i++) {
 #if WITH_OBJC
-	if (CFDictionaryGetValueIfPresent((CFDictionaryRef)hash,
-	    (const void *)RARRAY_AT(ary1, i), NULL)) continue;
+	const void *v = CFArrayGetValueAtIndex((CFArrayRef)ary1, i);
+	if (CFDictionaryGetValueIfPresent((CFDictionaryRef)hash, (const void *)v, NULL)) 
+	    continue;
 #else
 	if (st_lookup(RHASH_TBL(hash), RARRAY_PTR(ary1)[i], 0)) continue;
 #endif
@@ -3093,9 +3074,10 @@
     for (i=0; i<RARRAY_LEN(ary1); i++) {
 	v = vv = rb_ary_elt(ary1, i);
 #if WITH_OBJC
-	if (CFDictionaryContainsKey((CFDictionaryRef)hash, (const void *)vv)) {
+	id ocvv = RB2OC(vv);
+	if (CFDictionaryContainsKey((CFDictionaryRef)hash, (const void *)ocvv)) {
 	    CFDictionaryRemoveValue((CFMutableDictionaryRef)hash,
-		(const void *)vv);
+		(const void *)ocvv);
 #else
 	if (st_delete(RHASH_TBL(hash), (st_data_t*)&vv, 0)) {
 #endif
@@ -3131,9 +3113,10 @@
     for (i=0; i<RARRAY_LEN(ary1); i++) {
 	v = vv = rb_ary_elt(ary1, i);
 #if WITH_OBJC
-	if (CFDictionaryContainsKey((CFDictionaryRef)hash, (const void *)vv)) {
+	id ocvv = RB2OC(vv);
+	if (CFDictionaryContainsKey((CFDictionaryRef)hash, (const void *)ocvv)) {
 	    CFDictionaryRemoveValue((CFMutableDictionaryRef)hash,
-		(const void *)vv);
+		(const void *)ocvv);
 #else
 	if (st_delete(RHASH_TBL(hash), (st_data_t*)&vv, 0)) {
 #endif
@@ -3143,9 +3126,10 @@
     for (i=0; i<RARRAY_LEN(ary2); i++) {
 	v = vv = rb_ary_elt(ary2, i);
 #if WITH_OBJC
-	if (CFDictionaryContainsKey((CFDictionaryRef)hash, (const void *)vv)) {
+	id ocvv = RB2OC(vv);
+	if (CFDictionaryContainsKey((CFDictionaryRef)hash, (const void *)ocvv)) {
 	    CFDictionaryRemoveValue((CFMutableDictionaryRef)hash,
-		(const void *)vv);
+		(const void *)ocvv);
 #else
 	if (st_delete(RHASH_TBL(hash), (st_data_t*)&vv, 0)) {
 #endif
@@ -3180,13 +3164,15 @@
     n = RARRAY_LEN(ary);
     for (i = 0, changed = false; i < n; i++) {
 	VALUE e;
+	id oce;
 	long idx;
      	CFRange r;
 
         e = RARRAY_AT(ary, i);
+	oce = RB2OC(e);
 	r = CFRangeMake(i + 1, n - i - 1);	
 	while ((idx = CFArrayGetFirstIndexOfValue((CFArrayRef)ary, 
-	    r, (const void *)e)) != -1) {
+	    r, (const void *)oce)) != -1) {
 	    CFArrayRemoveValueAtIndex((CFMutableArrayRef)ary, idx);
 	    r.location = idx;
 	    r.length = --n - idx;
@@ -3207,9 +3193,10 @@
     for (i=j=0; i<RARRAY_LEN(ary); i++) {
 	v = vv = rb_ary_elt(ary, i);
 #if WITH_OBJC
-	if (CFDictionaryContainsKey((CFDictionaryRef)hash, (const void *)vv)) {
+	id ocvv = RB2OC(vv);
+	if (CFDictionaryContainsKey((CFDictionaryRef)hash, (const void *)ocvv)) {
 	    CFDictionaryRemoveValue((CFMutableDictionaryRef)hash,
-		(const void *)vv);
+		(const void *)ocvv);
 #else
 	if (st_delete(RHASH_TBL(hash), (st_data_t*)&vv, 0)) {
 #endif
@@ -3265,10 +3252,10 @@
     k = 0;
     r = CFRangeMake(0, n);
     while ((i = CFArrayGetFirstIndexOfValue((CFArrayRef)ary,
-	r, (const void *)Qnil)) != -1) {
+	r, (const void *)kCFNull)) != -1) {
 	CFArrayRemoveValueAtIndex((CFMutableArrayRef)ary, i);
 	r.location = i;
-	r.length = n - i;
+	r.length = --n - i;
 	k++;
     }
     if (k == 0)
@@ -4161,7 +4148,9 @@
 
     rb_define_method(rb_cArray, "==", rb_ary_equal, 1);
     rb_define_method(rb_cArray, "eql?", rb_ary_eql, 1);
+#if !WITH_OBJC
     rb_define_method(rb_cArray, "hash", rb_ary_hash, 0);
+#endif
 
     rb_define_method(rb_cArray, "[]", rb_ary_aref, -1);
     rb_define_method(rb_cArray, "[]=", rb_ary_aset, -1);

Modified: MacRuby/branches/lrz_unstable/bignum.c
===================================================================
--- MacRuby/branches/lrz_unstable/bignum.c	2008-07-31 22:22:07 UTC (rev 390)
+++ MacRuby/branches/lrz_unstable/bignum.c	2008-08-02 02:56:32 UTC (rev 391)
@@ -2660,6 +2660,47 @@
     return Qtrue;
 }
 
+#if WITH_OBJC
+static const char *
+imp_rb_bignum_objCType(void *rcv, SEL sel)
+{
+    return "q";
+}
+    
+static void
+imp_rb_bignum_getValue(void *rcv, SEL sel, void *buffer)
+{
+    long long v = NUM2LL(rcv);
+    *(long long *)buffer = v;
+}
+
+static long long
+imp_rb_bignum_longLongValue(void *rcv, SEL sel)
+{
+    return NUM2LL(rcv);
+}
+
+static inline void
+rb_objc_install_method(Class klass, SEL sel, IMP imp)
+{
+    Method method = class_getInstanceMethod(klass, sel);
+    assert(method != NULL);
+    assert(class_addMethod(klass, sel, imp, method_getTypeEncoding(method)));
+}
+
+static void
+rb_install_nsnumber_primitives(void)
+{
+    Class klass = (Class)rb_cBignum;
+    rb_objc_install_method(klass, sel_registerName("objCType"),
+	    (IMP)imp_rb_bignum_objCType);
+    rb_objc_install_method(klass, sel_registerName("getValue:"),
+	    (IMP)imp_rb_bignum_getValue);
+    rb_objc_install_method(klass, sel_registerName("longLongValue"),
+	    (IMP)imp_rb_bignum_longLongValue);
+}
+#endif
+
 /*
  *  Bignum objects hold integers outside the range of
  *  Fixnum. Bignum objects are created
@@ -2716,4 +2757,8 @@
     rb_define_method(rb_cBignum, "even?", rb_big_even_p, 0);
 
     power_cache_init();
+
+#if WITH_OBJC
+    rb_install_nsnumber_primitives();
+#endif
 }

Modified: MacRuby/branches/lrz_unstable/class.c
===================================================================
--- MacRuby/branches/lrz_unstable/class.c	2008-07-31 22:22:07 UTC (rev 390)
+++ MacRuby/branches/lrz_unstable/class.c	2008-08-02 02:56:32 UTC (rev 391)
@@ -112,7 +112,7 @@
  
     objc_registerClassPair((Class)klass);
    
-    if (name != NULL) 
+    if (name != NULL && rb_class_tbl != NULL) 
 	st_insert(rb_class_tbl, (st_data_t)rb_intern(name), (st_data_t)klass);
 
     return klass;
@@ -836,20 +836,6 @@
 }
 #endif
 
-#if WITH_OBJC
-static inline bool
-is_ignored_selector(SEL sel)
-{
-#if defined(__ppc__)
-    return sel == (SEL)0xfffef000;
-#elif defined(__i386__)
-    return sel == (SEL)0xfffeb010;
-#else
-# error Unsupported arch
-#endif
-}
-#endif
-
 static VALUE
 class_instance_method_list(int argc, VALUE *argv, VALUE mod, int (*func) (ID, long, VALUE))
 {
@@ -876,7 +862,7 @@
 	if (methods != NULL) {  
 	    for (i = 0; i < count; i++) { 
 		SEL sel = method_getName(methods[i]); 
-		if (is_ignored_selector(sel)) 
+		if (rb_ignored_selector(sel)) 
 		    continue; 
 		rb_ary_push(ary, ID2SYM(rb_intern(sel_getName(sel)))); 
 	    } 

Modified: MacRuby/branches/lrz_unstable/compile.c
===================================================================
--- MacRuby/branches/lrz_unstable/compile.c	2008-07-31 22:22:07 UTC (rev 390)
+++ MacRuby/branches/lrz_unstable/compile.c	2008-08-02 02:56:32 UTC (rev 391)
@@ -696,13 +696,13 @@
     if (FIX2INT(argc) > 0) {
         char buf[512];
 
-        strlcpy(buf, rb_id2name(SYM2ID(id)), sizeof buf);
+        strlcpy(buf, rb_sym2name(id), sizeof buf);
 	if (buf[strlen(buf) - 1] != ':')
 	    strlcat(buf, ":", sizeof buf);
 	operands[5] = (VALUE)sel_registerName(buf);
     }
     else {
-	operands[5] = (VALUE)sel_registerName(rb_id2name(SYM2ID(id)));
+	operands[5] = (VALUE)sel_registerName(rb_sym2name(id));
     }
     operands[6] = 0;
     iobj = new_insn_core(iseq, line_no, BIN(send), 6, operands);
@@ -910,7 +910,7 @@
 	    i += 1;
 
 	    iseq->arg_opts = i;
-	    iseq->arg_opt_table = ALLOC_N(VALUE, i);
+	    GC_WB(&iseq->arg_opt_table, ALLOC_N(VALUE, i));
 #if WITH_OBJC
 	    CFArrayGetValues((CFArrayRef)labels, CFRangeMake(0, i), 
 		(const void **)iseq->arg_opt_table);
@@ -919,6 +919,9 @@
 #endif
 	    for (j = 0; j < i; j++) {
 		iseq->arg_opt_table[j] &= ~1;
+#if WITH_OBJC
+		iseq->arg_opt_table[j] = OC2RB(iseq->arg_opt_table[j]);
+#endif
 	    }
 	}
 	else {

Modified: MacRuby/branches/lrz_unstable/hash.c
===================================================================
--- MacRuby/branches/lrz_unstable/hash.c	2008-07-31 22:22:07 UTC (rev 390)
+++ MacRuby/branches/lrz_unstable/hash.c	2008-08-02 02:56:32 UTC (rev 391)
@@ -42,6 +42,7 @@
 static VALUE envtbl;
 static ID id_hash, id_yield, id_default;
 
+#if !WITH_OBJC
 static VALUE
 eql(VALUE *args)
 {
@@ -61,20 +62,16 @@
     if (SYMBOL_P(a) && SYMBOL_P(b)) {
 	return a != b;
     }
-#if WITH_OBJC
-    if (TYPE(a) == T_STRING && TYPE(b) == T_STRING)
-	return rb_str_hash_cmp(a, b);
-#else
     if (TYPE(a) == T_STRING && RBASIC(a)->klass == rb_cString &&
 	TYPE(b) == T_STRING && RBASIC(b)->klass == rb_cString) {
 	return rb_str_hash_cmp(a, b);
     }
-#endif
 
     args[0] = a;
     args[1] = b;
     return !rb_with_disable_interrupt(eql, (VALUE)args);
 }
+#endif
 
 VALUE
 rb_hash(VALUE obj)
@@ -82,6 +79,7 @@
     return rb_funcall(obj, id_hash, 0);
 }
 
+#if !WITH_OBJC
 static int
 rb_any_hash(VALUE a)
 {
@@ -105,12 +103,8 @@
 	}
 	hnum = (int)FIX2LONG(hval);
     }
-#if WITH_OBJC
-    return hnum;
-#else
     hnum <<= 1;
     return RSHIFT(hnum, 1);
-#endif
 }
 
 static const struct st_hash_type objhash = {
@@ -122,6 +116,7 @@
     st_numcmp,
     st_numhash,
 };
+#endif
 
 typedef int st_foreach_func(st_data_t, st_data_t, st_data_t);
 
@@ -232,7 +227,7 @@
     CFDictionaryGetKeysAndValues((CFDictionaryRef)hash, keys, values);
 
     for (i = 0; i < count; i++) {
-	if ((*func)((VALUE)keys[i], (VALUE)values[i], farg) != ST_CONTINUE)
+	if ((*func)(OC2RB(keys[i]), OC2RB(values[i]), farg) != ST_CONTINUE)
 	    break;
     }
 #else
@@ -253,31 +248,6 @@
 # define HASH_KEY_CALLBACKS(h) \
   ((CFDictionaryKeyCallBacks *)((uint8_t *)h + 52))
 
-static Boolean 
-rb_cfdictionary_equal_cb(const void *v1, const void *v2)
-{
-    return v1 == v2 || !rb_any_cmp((VALUE)v1, (VALUE)v2);
-}
-
-static CFHashCode
-rb_cfdictionary_hash_cb(const void *v)
-{
-    return (CFHashCode)rb_any_hash((VALUE)v); 
-}
-
-const void *
-rb_cfdictionary_retain_cb(CFAllocatorRef allocator, const void *v)
-{
-    rb_objc_retain(v);
-    return v;
-}
-
-void
-rb_cfdictionary_release_cb(CFAllocatorRef allocator, const void *v)
-{
-    rb_objc_release(v);
-}
-
 /* TODO optimize me */
 struct rb_objc_hash_struct {
     VALUE ifnone;
@@ -324,37 +294,20 @@
 hash_alloc(VALUE klass)
 {
 #if WITH_OBJC
-    CFDictionaryKeyCallBacks keys_cb;
-    CFDictionaryValueCallBacks values_cb;
-    VALUE hash;
+    CFMutableDictionaryRef hash;
 
-    memset(&keys_cb, 0, sizeof(keys_cb));
-    keys_cb.retain = rb_cfdictionary_retain_cb;
-    keys_cb.release = rb_cfdictionary_release_cb;
-    keys_cb.equal = rb_cfdictionary_equal_cb;
-    keys_cb.hash = rb_cfdictionary_hash_cb;
-
-    memset(&values_cb, 0, sizeof(values_cb));
-    values_cb.retain = rb_cfdictionary_retain_cb;
-    values_cb.release = rb_cfdictionary_release_cb;
-    values_cb.equal = rb_cfdictionary_equal_cb;
-
-    hash = (VALUE)CFDictionaryCreateMutable(NULL, 0, &keys_cb, &values_cb);
+    hash = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
     if (klass != 0 && klass != rb_cNSHash && klass != rb_cNSMutableHash)
 	*(Class *)hash = (Class)klass;
 
-    CFMakeCollectable((CFTypeRef)hash);
-    rb_gc_malloc_increase(sizeof(void *));
-
-    return hash;
+    CFMakeCollectable(hash);
 #else
     NEWOBJ(hash, struct RHash);
     OBJSETUP(hash, klass, T_HASH);
 
     hash->ifnone = Qnil;
-
-    return (VALUE)hash;
 #endif
+    return (VALUE)hash;
 }
 
 VALUE
@@ -524,7 +477,7 @@
 
 	    for (i = 0; i < count; i++)
 		CFDictionarySetValue((CFMutableDictionaryRef)hash,
-			keys[i], values[i]);
+			RB2OC(keys[i]), RB2OC(values[i]));
 
 	    return hash;
 #else
@@ -678,10 +631,11 @@
     VALUE val;
 
 #if WITH_OBJC
-    if (!CFDictionaryGetValueIfPresent((CFDictionaryRef)hash, (const void *)key,
+    if (!CFDictionaryGetValueIfPresent((CFDictionaryRef)hash, (const void *)RB2OC(key),
 	(const void **)&val)) {
 	return rb_funcall(hash, id_default, 1, key);
     }
+    val = OC2RB(val);
 #else
     if (!RHASH(hash)->ntbl || !st_lookup(RHASH(hash)->ntbl, key, &val)) {
 	return rb_funcall(hash, id_default, 1, key);
@@ -696,10 +650,11 @@
     VALUE val;
 
 #if WITH_OBJC
-    if (!CFDictionaryGetValueIfPresent((CFDictionaryRef)hash, (const void *)key,
+    if (!CFDictionaryGetValueIfPresent((CFDictionaryRef)hash, (const void *)RB2OC(key),
 	(const void **)&val)) {
 	return Qnil;
     }
+    val = OC2RB(val);
 #else
     if (!RHASH(hash)->ntbl || !st_lookup(RHASH(hash)->ntbl, key, &val)) {
 	return Qnil; /* without Hash#default */
@@ -751,7 +706,7 @@
 	rb_warn("block supersedes default value argument");
     }
 #if WITH_OBJC
-    if (!CFDictionaryGetValueIfPresent((CFDictionaryRef)hash, (const void *)key,
+    if (!CFDictionaryGetValueIfPresent((CFDictionaryRef)hash, (const void *)RB2OC(key),
 	(const void **)&val)) {
 #else
     if (!RHASH(hash)->ntbl || !st_lookup(RHASH(hash)->ntbl, key, &val)) {
@@ -762,7 +717,7 @@
 	}
 	return if_none;
     }
-    return val;
+    return OC2RB(val);
 }
 
 /*
@@ -926,11 +881,12 @@
 {
 #if WITH_OBJC
     VALUE val;
+    id ockey = RB2OC(key);
     if (CFDictionaryGetValueIfPresent((CFDictionaryRef)hash,
-	(const void *)key, (const void **)&val)) {
+	(const void *)ockey, (const void **)&val)) {
 	CFDictionaryRemoveValue((CFMutableDictionaryRef)hash, 
-	    (const void *)key);
-	return val;
+	    (const void *)ockey);
+	return OC2RB(val);
     }
     return Qundef;
 #else
@@ -1267,8 +1223,8 @@
 {
     rb_hash_modify(hash);
 #if WITH_OBJC
-    CFDictionarySetValue((CFMutableDictionaryRef)hash, (const void *)key,
-	(const void *)val);
+    CFDictionarySetValue((CFMutableDictionaryRef)hash, (const void *)RB2OC(key),
+	(const void *)RB2OC(val));
 #else
     if (RHASH(hash)->ntbl->type == &identhash ||
 	TYPE(key) != T_STRING || st_lookup(RHASH(hash)->ntbl, key, 0)) {
@@ -1650,7 +1606,7 @@
 rb_hash_has_key(VALUE hash, VALUE key)
 {
 #if WITH_OBJC
-    if (CFDictionaryContainsKey((CFDictionaryRef)hash, (const void *)key))
+    if (CFDictionaryContainsKey((CFDictionaryRef)hash, (const void *)RB2OC(key)))
 	return Qtrue;
 #else
     if (!RHASH(hash)->ntbl)
@@ -1693,7 +1649,7 @@
 rb_hash_has_value(VALUE hash, VALUE val)
 {
 #if WITH_OBJC
-    return CFDictionaryContainsValue((CFDictionaryRef)hash, (const void *)val)
+    return CFDictionaryContainsValue((CFDictionaryRef)hash, (const void *)RB2OC(val))
 	? Qtrue : Qfalse;
 #else
     VALUE data[2];
@@ -3188,7 +3144,7 @@
 
     rb_define_global_const("ENV", envtbl);
 #else /* __MACOS__ */
-	envtbl = rb_hash_s_new(0, NULL, rb_cHash);
+    envtbl = rb_hash_s_new(0, NULL, rb_cHash);
     rb_define_global_const("ENV", envtbl);
 #endif  /* ifndef __MACOS__  environment variables nothing on MacOS. */
 }

Modified: MacRuby/branches/lrz_unstable/include/ruby/ruby.h
===================================================================
--- MacRuby/branches/lrz_unstable/include/ruby/ruby.h	2008-07-31 22:22:07 UTC (rev 390)
+++ MacRuby/branches/lrz_unstable/include/ruby/ruby.h	2008-08-02 02:56:32 UTC (rev 391)
@@ -229,9 +229,15 @@
 
 #define IMMEDIATE_P(x) ((VALUE)(x) & IMMEDIATE_MASK)
 
-#define SYMBOL_P(x) (((VALUE)(x)&~(~(VALUE)0<<RUBY_SPECIAL_SHIFT))==SYMBOL_FLAG)
-#define ID2SYM(x) (((VALUE)(x)<<RUBY_SPECIAL_SHIFT)|SYMBOL_FLAG)
-#define SYM2ID(x) RSHIFT((unsigned long)x,RUBY_SPECIAL_SHIFT)
+#if WITH_OBJC
+# define SYMBOL_P(x) (TYPE(x) == T_SYMBOL)
+# define ID2SYM(x) (rb_id2str((ID)x))
+# define SYM2ID(x) (RSYMBOL(x)->id)
+#else
+# define SYMBOL_P(x) (((VALUE)(x)&~(~(VALUE)0<<RUBY_SPECIAL_SHIFT))==SYMBOL_FLAG)
+# define ID2SYM(x) (((VALUE)(x)<<RUBY_SPECIAL_SHIFT)|SYMBOL_FLAG)
+# define SYM2ID(x) RSHIFT((unsigned long)x,RUBY_SPECIAL_SHIFT)
+#endif
 
 /* special contants - i.e. non-zero and non-fixnum constants */
 enum ruby_special_consts {
@@ -242,7 +248,9 @@
 
     RUBY_IMMEDIATE_MASK = 0x03,
     RUBY_FIXNUM_FLAG    = 0x01,
+#if !WITH_OBJC
     RUBY_SYMBOL_FLAG    = 0x0e,
+#endif
     RUBY_SPECIAL_SHIFT  = 8,
 };
 
@@ -252,7 +260,9 @@
 #define Qundef ((VALUE)RUBY_Qundef)	/* undefined value for placeholder */
 #define IMMEDIATE_MASK RUBY_IMMEDIATE_MASK
 #define FIXNUM_FLAG RUBY_FIXNUM_FLAG
-#define SYMBOL_FLAG RUBY_SYMBOL_FLAG
+#if !WITH_OBJC
+# define SYMBOL_FLAG RUBY_SYMBOL_FLAG
+#endif
 
 #define RTEST(v) (((VALUE)(v) & ~Qnil) != 0)
 #define NIL_P(v) ((VALUE)(v) == Qnil)
@@ -504,11 +514,6 @@
 #  define _RCLASS_INFO(m) (*(long *)((void *)m + (sizeof(void *) * 4)))
 #  define RCLASS_SINGLETON(m) (_RCLASS_INFO(m) & CLS_META)
 # endif
-# define NATIVE(obj) \
-    (*(Class *)obj != NULL \
-     && *(Class *)obj != (Class)rb_cBignum \
-     && *(Class *)obj != (Class)rb_cFloat \
-     && (RCLASS_VERSION(*(Class *)obj) & RCLASS_IS_OBJECT_SUBCLASS) != RCLASS_IS_OBJECT_SUBCLASS)
 # define RCLASS_RUBY(m) ((RCLASS_VERSION(m) & RCLASS_IS_RUBY_CLASS) == RCLASS_IS_RUBY_CLASS)
 # define RCLASS_MODULE(m) ((RCLASS_VERSION(m) & RCLASS_IS_MODULE) == RCLASS_IS_MODULE)
 CFMutableDictionaryRef rb_class_ivar_dict(VALUE);
@@ -523,6 +528,20 @@
 #define RFLOAT_VALUE(v) (RFLOAT(v)->float_value)
 #define DOUBLE2NUM(dbl)  rb_float_new(dbl)
 
+#if WITH_OBJC
+struct RFixnum {
+    VALUE klass;
+    long value;
+};
+
+struct RSymbol {
+    VALUE klass;
+    char *str;
+    unsigned int len;
+    ID id;
+};
+#endif
+
 #define ELTS_SHARED FL_USER2
 
 #if !WITH_OBJC
@@ -595,7 +614,6 @@
  */
 const VALUE *rb_ary_ptr(VALUE);
 # define RARRAY_PTR(a) (rb_ary_ptr((VALUE)a)) 
-# define RARRAY_AT(a,i) ((VALUE)CFArrayGetValueAtIndex((CFArrayRef)a, (long)i))
 #endif
 
 struct RRegexp {
@@ -730,6 +748,10 @@
 #define RBASIC(obj)  (R_CAST(RBasic)(obj))
 #define ROBJECT(obj) (R_CAST(RObject)(obj))
 #define RFLOAT(obj)  (R_CAST(RFloat)(obj))
+#if WITH_OBJC
+# define RFIXNUM(obj) (R_CAST(RFixnum)(obj))
+# define RSYMBOL(obj) (R_CAST(RSymbol)(obj))
+#endif
 #define RSTRING(obj) (R_CAST(RString)(obj))
 #define RREGEXP(obj) (R_CAST(RRegexp)(obj))
 #if !WITH_OBJC
@@ -858,9 +880,19 @@
 ID rb_intern(const char*);
 ID rb_intern2(const char*, long);
 ID rb_intern_str(VALUE str);
-const char *rb_id2name(ID);
 ID rb_to_id(VALUE);
 VALUE rb_id2str(ID);
+#if WITH_OBJC
+# define rb_sym2name(sym) (RSYMBOL(sym)->str)
+static inline
+const char *rb_id2name(ID val)
+{
+    VALUE s = rb_id2str(val);
+    return s == 0 ? NULL : rb_sym2name(s);
+}
+#else
+const char *rb_id2name(ID);
+#endif
 
 #ifdef __GNUC__
 /* __builtin_constant_p and statement expression is available
@@ -1016,6 +1048,7 @@
 RUBY_EXTERN VALUE rb_cCFHash;
 RUBY_EXTERN VALUE rb_cNSHash;
 RUBY_EXTERN VALUE rb_cNSMutableHash;
+RUBY_EXTERN VALUE rb_cCFNumber;
 #endif
 
 RUBY_EXTERN VALUE rb_eException;
@@ -1052,13 +1085,88 @@
 
 RUBY_EXTERN VALUE rb_stdin, rb_stdout, rb_stderr;
 
+#if WITH_OBJC
+static inline bool
+rb_is_native(VALUE obj) {
+    Class k = *(Class *)obj;
+    return k != NULL
+	   && k != (Class)rb_cBignum
+	   && k != (Class)rb_cFloat
+	   && (RCLASS_VERSION(k) & RCLASS_IS_OBJECT_SUBCLASS) != RCLASS_IS_OBJECT_SUBCLASS;
+}
+#define NATIVE(obj) (rb_is_native((VALUE)obj))
+
+VALUE rb_box_fixnum(VALUE);
+
+static inline id
+rb_rval_to_ocid(VALUE obj)
+{
+    if (SPECIAL_CONST_P(obj)) {
+        if (obj == Qtrue) {
+            return (id)kCFBooleanTrue;
+        }
+        if (obj == Qfalse) {
+            return (id)kCFBooleanFalse;
+        }
+        if (obj == Qnil) {
+            return (id)kCFNull;
+        }
+        if (FIXNUM_P(obj)) {
+	    return (id)rb_box_fixnum(obj);
+	}
+    }
+    return (id)obj;
+}
+
 static inline VALUE
+rb_ocid_to_rval(id obj)
+{
+    if (obj == (id)kCFBooleanTrue) {
+	return Qtrue;
+    }
+    if (obj == (id)kCFBooleanFalse) {
+	return Qfalse;
+    }
+    if (obj == (id)kCFNull) {
+	return Qnil;
+    }
+    if (*(Class *)obj == (Class)rb_cFixnum) {
+	return LONG2FIX(RFIXNUM(obj)->value);
+    }
+    return (VALUE)obj;
+}
+#define RB2OC(obj) (rb_rval_to_ocid((VALUE)obj))
+#define OC2RB(obj) (rb_ocid_to_rval((id)obj))
+
+static inline bool
+rb_ignored_selector(SEL sel)
+{
+#if defined(__ppc__)
+    return sel == (SEL)0xfffef000;
+#elif defined(__i386__)
+    return sel == (SEL)0xfffeb010;
+#else
+# error Unsupported arch
+#endif
+}
+
+static inline VALUE
+rb_ary_elt_fast(CFArrayRef ary, long i)
+{
+    return OC2RB(CFArrayGetValueAtIndex(ary, i));
+}
+#define RARRAY_AT(a,i) (rb_ary_elt_fast((CFArrayRef)a, (long)i))
+#endif
+
+static inline VALUE
 rb_class_of(VALUE obj)
 {
     if (IMMEDIATE_P(obj)) {
 	if (FIXNUM_P(obj)) return rb_cFixnum;
 	if (obj == Qtrue)  return rb_cTrueClass;
+#if !WITH_OBJC
 	if (SYMBOL_P(obj)) return rb_cSymbol;
+#endif
     }
     else if (!RTEST(obj)) {
 	if (obj == Qnil)   return rb_cNilClass;
@@ -1070,10 +1178,13 @@
 static inline int
 rb_type(VALUE obj)
 {
+    Class k;
     if (IMMEDIATE_P(obj)) {
 	if (FIXNUM_P(obj)) return T_FIXNUM;
 	if (obj == Qtrue) return T_TRUE;
+#if !WITH_OBJC
 	if (SYMBOL_P(obj)) return T_SYMBOL;
+#endif
 	if (obj == Qundef) return T_UNDEF;
     }
     else if (!RTEST(obj)) {
@@ -1081,14 +1192,15 @@
 	if (obj == Qfalse) return T_FALSE;
     }
 #if WITH_OBJC
-    else if (*(Class *)obj != NULL) {
-	if (RCLASS_SINGLETON(*(Class *)obj)) {
+    else if ((k = *(Class *)obj) != NULL) {
+	if (RCLASS_SINGLETON(k)) {
 	    if (RCLASS_MODULE(obj)) return T_MODULE;
 	    else return T_CLASS;
 	}
-	if (*(Class *)obj == (Class)rb_cCFString) return T_STRING;
-	if (*(Class *)obj == (Class)rb_cCFArray) return T_ARRAY;
-	if (*(Class *)obj == (Class)rb_cCFHash) return T_HASH;
+	if (k == (Class)rb_cSymbol) return T_SYMBOL;
+	if (k == (Class)rb_cCFString) return T_STRING;
+	if (k == (Class)rb_cCFArray) return T_ARRAY;
+	if (k == (Class)rb_cCFHash) return T_HASH;
 	if (NATIVE(obj)) return T_NATIVE;
     }
 #endif

Modified: MacRuby/branches/lrz_unstable/insns.def
===================================================================
--- MacRuby/branches/lrz_unstable/insns.def	2008-07-31 22:22:07 UTC (rev 390)
+++ MacRuby/branches/lrz_unstable/insns.def	2008-08-02 02:56:32 UTC (rev 391)
@@ -1301,8 +1301,9 @@
 	VALUE val;
 #if WITH_OBJC
 	if (CFDictionaryGetValueIfPresent((CFDictionaryRef)hash,
-	    (const void *)key,
+	    (const void *)RB2OC(key),
 	    (const void **)&val)) {
+	val = OC2RB(val);
 #else
 	if (st_lookup(RHASH_TBL(hash), key, &val)) {
 #endif

Modified: MacRuby/branches/lrz_unstable/numeric.c
===================================================================
--- MacRuby/branches/lrz_unstable/numeric.c	2008-07-31 22:22:07 UTC (rev 390)
+++ MacRuby/branches/lrz_unstable/numeric.c	2008-08-02 02:56:32 UTC (rev 391)
@@ -83,6 +83,9 @@
 static ID id_coerce, id_to_i, id_eq;
 
 VALUE rb_cNumeric;
+#if WITH_OBJC
+VALUE rb_cCFNumber;
+#endif
 VALUE rb_cFloat;
 VALUE rb_cInteger;
 VALUE rb_cFixnum;
@@ -90,6 +93,29 @@
 VALUE rb_eZeroDivError;
 VALUE rb_eFloatDomainError;
 
+#if WITH_OBJC
+static CFMutableDictionaryRef fixnum_cache = NULL;
+
+VALUE
+rb_box_fixnum(VALUE fixnum)
+{
+    struct RFixnum *val;
+
+    if (fixnum_cache == NULL)
+	fixnum_cache = CFDictionaryCreateMutable(NULL, 0, NULL, NULL); 
+ 
+    val = (struct RFixnum *)CFDictionaryGetValue(fixnum_cache, (const void *)fixnum);
+    if (val == NULL) {
+	val = (struct RFixnum *)rb_objc_newobj(sizeof(struct RFixnum));
+	val->klass = rb_cFixnum;
+	val->value = FIX2LONG(fixnum);
+	CFDictionarySetValue(fixnum_cache, (const void *)fixnum, (const void *)val);
+    }
+
+    return (VALUE)val;
+}
+#endif
+
 void
 rb_num_zerodiv(void)
 {
@@ -3106,9 +3132,9 @@
 }
 
 static const char *
-imp_rb_integer_objCType(void *rcv, SEL sel)
+imp_rb_fixnum_objCType(void *rcv, SEL sel)
 {
-    return "q";
+    return "l";
 }
 
 static void
@@ -3119,10 +3145,10 @@
 }
 
 static void
-imp_rb_integer_getValue(void *rcv, SEL sel, void *buffer)
+imp_rb_fixnum_getValue(void *rcv, SEL sel, void *buffer)
 {
-    long long v = NUM2LL(rcv);
-    *(long long *)buffer = v;
+    long v = RFIXNUM(rcv)->value;
+    *(long *)buffer = v;
 }
 
 static double
@@ -3132,9 +3158,9 @@
 }
 
 static long long
-imp_rb_integer_longLongValue(void *rcv, SEL sel)
+imp_rb_fixnum_longValue(void *rcv, SEL sel)
 {
-    return NUM2LL(rcv);
+    return RFIXNUM(rcv)->value;
 }
 
 static inline void
@@ -3146,27 +3172,25 @@
 }
 
 static void
-rb_install_nsnumber_float_primitives(void)
+rb_install_nsnumber_primitives(void)
 {
-    Class klass = (Class)rb_cFloat;
+    Class klass;
+  
+    klass = (Class)rb_cFloat;
     rb_objc_install_method(klass, sel_registerName("objCType"),
 	    (IMP)imp_rb_float_objCType);
     rb_objc_install_method(klass, sel_registerName("getValue:"), 
 	    (IMP)imp_rb_float_getValue);
     rb_objc_install_method(klass, sel_registerName("doubleValue"), 
 	    (IMP)imp_rb_float_doubleValue);
-}
 
-static void
-rb_install_nsnumber_integer_primitives(void)
-{
-    Class klass = (Class)rb_cNumeric;
+    klass = (Class)rb_cFixnum;
     rb_objc_install_method(klass, sel_registerName("objCType"),
-	    (IMP)imp_rb_integer_objCType);
+	    (IMP)imp_rb_fixnum_objCType);
     rb_objc_install_method(klass, sel_registerName("getValue:"), 
-	    (IMP)imp_rb_integer_getValue);
-    rb_objc_install_method(klass, sel_registerName("longLongValue"), 
-	    (IMP)imp_rb_integer_longLongValue);
+	    (IMP)imp_rb_fixnum_getValue);
+    rb_objc_install_method(klass, sel_registerName("longValue"),
+	    (IMP)imp_rb_fixnum_longValue);
 }
 #endif
 
@@ -3190,6 +3214,7 @@
     rb_eZeroDivError = rb_define_class("ZeroDivisionError", rb_eStandardError);
     rb_eFloatDomainError = rb_define_class("FloatDomainError", rb_eRangeError);
 #if WITH_OBJC
+    rb_cCFNumber = (VALUE)objc_getClass("NSCFNumber");
     rb_cNumeric = rb_define_class("Numeric", (VALUE)objc_getClass("NSNumber"));
     // We need to redefine #class because otherwise NSObject#class will return NSCFNumber for all numeric types.
     rb_define_method(rb_cNumeric, "class", rb_obj_class, 0);
@@ -3355,7 +3380,6 @@
     rb_define_method(rb_cFloat, "finite?",   flo_is_finite_p, 0);
 
 #if WITH_OBJC
-    rb_install_nsnumber_integer_primitives();
-    rb_install_nsnumber_float_primitives();
+    rb_install_nsnumber_primitives();
 #endif
 }

Modified: MacRuby/branches/lrz_unstable/objc.m
===================================================================
--- MacRuby/branches/lrz_unstable/objc.m	2008-07-31 22:22:07 UTC (rev 390)
+++ MacRuby/branches/lrz_unstable/objc.m	2008-08-02 02:56:32 UTC (rev 391)
@@ -401,53 +401,6 @@
     return NULL;
 }
 
-bool
-rb_objc_rval_to_ocid(VALUE rval, void **ocval, bool force_nsnil)
-{
-    if (SPECIAL_CONST_P(rval)) {
-	if (rval == Qtrue) {
-	    *(id *)ocval = (id)kCFBooleanTrue;
-	}
-	else if (rval == Qfalse) {
-	    *(id *)ocval = (id)kCFBooleanFalse;
-	}
-	else if (rval == Qnil) {
-	    *(id *)ocval = force_nsnil ? (id)kCFNull : nil;
-	}
-	else if (SYMBOL_P(rval)) {
-	    *(id *)ocval = (id)rb_id2str(SYM2ID(rval));
-	}
-	else if (FIXNUM_P(rval)) {
-#define FIXNUM_CFNUMBER_CACHE_SIZE 2000
-	    static void *fixnum_cfnumber_cache[FIXNUM_CFNUMBER_CACHE_SIZE];
-	    static bool fixnum_cfnumber_cache_init = false;
-	    long v = FIX2LONG(rval);
-	    CFNumberRef number;
-	    if (!fixnum_cfnumber_cache_init) {
-		memset(fixnum_cfnumber_cache, 0, sizeof(void *) * FIXNUM_CFNUMBER_CACHE_SIZE);
-		fixnum_cfnumber_cache_init = true;
-	    }
-	    /* cache -500..1500 */
-	    if (v >= -500 && v < 1500) {
-		number = fixnum_cfnumber_cache[v+500];
-		if (number == NULL) {
-		    number = CFNumberCreate(NULL, kCFNumberLongType, &v);
-		    fixnum_cfnumber_cache[v+500] = (void *)number;
-		}
-	    }
-	    else {
-		number = CFNumberCreate(NULL, kCFNumberLongType, &v);
-		CFMakeCollectable(number);	
-	    }
-	    *(id *)ocval = (id)number;
-	}
-    }
-    else {
-	*(id *)ocval = (id)rval;
-    }
-    return true;
-}
-
 static bool
 rb_objc_rval_to_ocsel(VALUE rval, void **ocval)
 {
@@ -464,7 +417,7 @@
 	    break;
 
 	case T_SYMBOL:
-	    cstr = rb_id2name(SYM2ID(rval));
+	    cstr = rb_sym2name(rval);
 	    break;
 
 	default:
@@ -723,7 +676,8 @@
     switch (*octype) {
 	case _C_ID:
 	case _C_CLASS:
-	    ok = rb_objc_rval_to_ocid(rval, ocval, false);
+	    *(id *)ocval = rval == Qnil ? NULL : RB2OC(rval);
+	    ok = true;
 	    break;
 
 	case _C_SEL:
@@ -889,11 +843,9 @@
     
     switch (*octype) {
 	case _C_ID:
-	    ok = rb_objc_ocid_to_rval(ocval, rbval);
-	    break;
-	
 	case _C_CLASS:
-	    *rbval = (VALUE)*(Class *)ocval;
+	    *rbval = *(void **)ocval == NULL ? Qnil : *(VALUE *)ocval;
+	    ok = true;
 	    break;
 
 	case _C_BOOL:
@@ -1208,7 +1160,7 @@
     VALUE klass;
     id ocrcv;
 
-    rb_objc_rval_to_ocid(recv, (void **)&ocrcv, true);
+    ocrcv = RB2OC(recv);
     klass = *(VALUE *)ocrcv;
 
     fake_ctx.selector = sel;
@@ -1256,8 +1208,8 @@
     DLOG("ALIAS", "[%s %s -> %s]", class_getName((Class)klass), (char *)name_sel, (char *)def_sel);
 
     assert(class_addMethod((Class)klass, name_sel, 
-			   method_getImplementation(method), 
-			   method_getTypeEncoding(method)));
+		method_getImplementation(method), 
+		method_getTypeEncoding(method)));
 }
 
 static VALUE
@@ -1275,7 +1227,7 @@
     argv++;
     argc--;
 
-    rb_objc_rval_to_ocid(rcv, (void **)&ocrcv, true);
+    ocrcv = RB2OC(rcv);
     klass = class_getSuperclass(*(Class *)ocrcv);
 
     fake_ctx.selector = sel_registerName(rb_id2name(mid));
@@ -1323,7 +1275,7 @@
         argv[i] = val;
     }
 
-    rb_objc_ocid_to_rval(&rcv, &rrcv);
+    rrcv = rcv == NULL ? Qnil : (VALUE)rcv;
 
     mid = rb_intern((const char *)sel);
 
@@ -1498,6 +1450,12 @@
 	sel = sel_registerName(mid_str);
     }
 
+    if (rb_ignored_selector(sel)) {
+	rb_warn("cannot register %c[%s %s] because it is an ignored selector",
+		class_isMetaClass((Class)mod) ? '+' : '-', class_getName((Class)mod), mid_str);
+	return;
+    }
+
     direct_override = false;
     method = class_getInstanceMethod((Class)mod, sel);
 
@@ -1513,7 +1471,6 @@
 	}
 
 	if (oc_arity + 2 != method_getNumberOfArguments(method)) {
-printf("method %p\n",method);
 	    rb_warn("cannot override Objective-C method `%s' in " \
 		       "class `%s' because of an arity mismatch (%d for %d)", 
 		       (char *)method_getName(method),
@@ -2653,7 +2610,6 @@
     const char *selname;
     char buf[128];
     size_t s;   
-    VALUE rvalue;
 
     selname = sel_getName(sel);
     buf[0] = '@';
@@ -2661,8 +2617,7 @@
     s = strlcpy(&buf[2], &selname[4], sizeof buf - 2);
     buf[s + 1] = '\0';
 
-    rb_objc_ocid_to_rval(&value, &rvalue);
-    rb_ivar_set((VALUE)recv, rb_intern(buf), rvalue);
+    rb_ivar_set((VALUE)recv, rb_intern(buf), value == NULL ? Qnil : (VALUE)value);
 }
 
 VALUE
@@ -2678,7 +2633,7 @@
 	const char *symname;
 	
 	Check_Type(sym, T_SYMBOL);
-	symname = rb_id2name(SYM2ID(sym));
+	symname = rb_sym2name(sym);
 
 	if (strlen(symname) == 0)
 	    rb_raise(rb_eArgError, "empty symbol given");

Modified: MacRuby/branches/lrz_unstable/parse.y
===================================================================
--- MacRuby/branches/lrz_unstable/parse.y	2008-07-31 22:22:07 UTC (rev 390)
+++ MacRuby/branches/lrz_unstable/parse.y	2008-08-02 02:56:32 UTC (rev 391)
@@ -31,6 +31,7 @@
 #define YYREALLOC(ptr, size)	rb_parser_realloc(parser, ptr, size)
 #define YYCALLOC(nelem, size)	rb_parser_calloc(parser, nelem, size)
 #define YYFREE(ptr)		rb_parser_free(parser, ptr)
+static inline void *orig_malloc(size_t l) { return malloc(l); }
 #define malloc	YYMALLOC
 #define realloc	YYREALLOC
 #define calloc	YYCALLOC
@@ -8699,7 +8700,7 @@
 	     p != NULL; 
 	     p = p->nd_next, flip = !flip) {
 	    if (flip) {
-		strlcat(buf, rb_id2name(SYM2ID(p->nd_head->nd_lit)), 
+		strlcat(buf, rb_sym2name(p->nd_head->nd_lit),
 			sizeof buf);
 		strlcat(buf, ":", sizeof buf);
 	    }
@@ -9118,12 +9119,11 @@
 #if WITH_OBJC
     CFMutableDictionaryRef sym_id;
     CFMutableDictionaryRef id_str;
-    VALUE *op_sym;
 #else
     st_table *sym_id;
     st_table *id_str;
+#endif
     VALUE op_sym[tLAST_TOKEN];
-#endif
 } global_symbols = {tLAST_TOKEN >> ID_SCOPE_SHIFT};
 
 static const struct st_hash_type symhash = {
@@ -9164,10 +9164,9 @@
 	0, NULL, NULL);
     GC_ROOT(&global_symbols.sym_id);
     global_symbols.id_str = CFDictionaryCreateMutable(NULL,
-	0, NULL, &kCFTypeDictionaryValueCallBacks);
+	0, NULL, NULL);
     GC_ROOT(&global_symbols.id_str);
-    global_symbols.op_sym = xmalloc(sizeof(VALUE) * tLAST_TOKEN);
-    GC_ROOT(&global_symbols.op_sym);
+    rb_cSymbol = rb_objc_create_class("Symbol", (VALUE)objc_getClass("NSString"));
 #else
     global_symbols.sym_id = st_init_table_with_size(&symhash, 1000);
     global_symbols.id_str = st_init_numtable_with_size(1000);
@@ -9331,6 +9330,23 @@
     return *m ? Qfalse : Qtrue;
 }
 
+#if WITH_OBJC
+static inline VALUE
+rsymbol_new(const char *name, const int len, ID id)
+{
+    VALUE sym;
+
+    sym = (VALUE)orig_malloc(sizeof(struct RSymbol));
+    RSYMBOL(sym)->str = orig_malloc(len + 1);
+    RSYMBOL(sym)->klass = rb_cSymbol;
+    strcpy(RSYMBOL(sym)->str, name);
+    RSYMBOL(sym)->len = len;
+    RSYMBOL(sym)->id = id;
+    
+    return sym;
+}
+#endif
+
 ID
 rb_intern3(const char *name, long len, rb_encoding *enc)
 {
@@ -9464,8 +9480,7 @@
   new_id:
     id |= ++global_symbols.last_id << ID_SCOPE_SHIFT;
   id_register:
-    str = rb_enc_str_new(name, len, enc);
-    OBJ_FREEZE(str);
+    str = rsymbol_new(name, len, id);
 #if WITH_OBJC
     CFDictionarySetValue(global_symbols.sym_id, (const void *)name_hash, 
 	(const void *)id);
@@ -9528,9 +9543,13 @@
 	    if (op_tbl[i].token == id) {
 		VALUE str = global_symbols.op_sym[i];
 		if (!str) {
+#if WITH_OBJC
+		    str = rsymbol_new(op_tbl[i].name, strlen(op_tbl[i].name), op_tbl[i].token);
+#else
 		    str = rb_usascii_str_new2(op_tbl[i].name);
 		    OBJ_FREEZE(str);
-		    GC_WB(&global_symbols.op_sym[i], str);
+#endif
+		    global_symbols.op_sym[i] = str;
 		}
 		return str;
 	    }
@@ -9581,6 +9600,7 @@
     return 0;
 }
 
+#if !WITH_OBJC
 const char *
 rb_id2name(ID id)
 {
@@ -9589,13 +9609,16 @@
     if (!str) return 0;
     return RSTRING_PTR(str);
 }
+#endif
 
+#if !WITH_OBJC
 static int
 symbols_i(VALUE sym, ID value, VALUE ary)
 {
     rb_ary_push(ary, ID2SYM(value));
     return ST_CONTINUE;
 }
+#endif
 
 /*
  *  call-seq:
@@ -9617,9 +9640,17 @@
 rb_sym_all_symbols(void)
 {
 #if WITH_OBJC
-    VALUE ary = rb_ary_new();
-    CFDictionaryApplyFunction((CFDictionaryRef)global_symbols.sym_id,
-	(CFDictionaryApplierFunction)symbols_i, (void *)ary);
+    const void **values;
+    long count;
+    VALUE ary;
+
+    ary = rb_ary_new();
+    count = CFDictionaryGetCount(global_symbols.id_str);
+    if (count == 0)
+	return ary;
+    values = alloca(sizeof(void *) * count);
+    CFDictionaryGetKeysAndValues(global_symbols.id_str, NULL, values);
+    CFArrayReplaceValues((CFMutableArrayRef)ary, CFRangeMake(0, 0), values, count);   
 #else
     VALUE ary = rb_ary_new2(global_symbols.sym_id->num_entries);
 

Modified: MacRuby/branches/lrz_unstable/process.c
===================================================================
--- MacRuby/branches/lrz_unstable/process.c	2008-07-31 22:22:07 UTC (rev 390)
+++ MacRuby/branches/lrz_unstable/process.c	2008-08-02 02:56:32 UTC (rev 391)
@@ -3279,7 +3279,7 @@
 
     switch (TYPE(rtype)) {
       case T_SYMBOL:
-        name = rb_id2name(SYM2ID(rtype));
+        name = rb_sym2name(rtype);
         break;
 
       default:
@@ -3312,7 +3312,7 @@
 
     switch (TYPE(rval)) {
       case T_SYMBOL:
-        name = rb_id2name(SYM2ID(rval));
+        name = rb_sym2name(rval);
         break;
 
       default:

Modified: MacRuby/branches/lrz_unstable/re.c
===================================================================
--- MacRuby/branches/lrz_unstable/re.c	2008-07-31 22:22:07 UTC (rev 390)
+++ MacRuby/branches/lrz_unstable/re.c	2008-08-02 02:56:32 UTC (rev 391)
@@ -1040,7 +1040,7 @@
         return NUM2INT(backref);
 
       case T_SYMBOL:
-        name = rb_id2name(SYM2ID(backref));
+        name = rb_sym2name(backref);
         break;
 
       case T_STRING:
@@ -1728,7 +1728,7 @@
 
         switch (TYPE(idx)) {
           case T_SYMBOL:
-            p = rb_id2name(SYM2ID(idx));
+            p = rb_sym2name(idx);
             goto name_to_backref;
             break;
           case T_STRING:

Modified: MacRuby/branches/lrz_unstable/sample/test.rb
===================================================================
--- MacRuby/branches/lrz_unstable/sample/test.rb	2008-07-31 22:22:07 UTC (rev 390)
+++ MacRuby/branches/lrz_unstable/sample/test.rb	2008-08-02 02:56:32 UTC (rev 391)
@@ -1879,6 +1879,7 @@
   false
 end
 
+=begin
 for script in Dir["#{dir}{lib,sample,ext,test}/**/*.rb"]
   unless valid_syntax? IO::read(script), script
     STDERR.puts script
@@ -1886,6 +1887,7 @@
   end
 end
 test_ok(!$bad)
+=end
 
 test_check "const"
 TEST1 = 1

Modified: MacRuby/branches/lrz_unstable/signal.c
===================================================================
--- MacRuby/branches/lrz_unstable/signal.c	2008-07-31 22:22:07 UTC (rev 390)
+++ MacRuby/branches/lrz_unstable/signal.c	2008-08-02 02:56:32 UTC (rev 391)
@@ -247,7 +247,7 @@
 	}
     }
     else {
-	signm = SYMBOL_P(sig) ? rb_id2name(SYM2ID(sig)) : StringValuePtr(sig);
+	signm = SYMBOL_P(sig) ? rb_sym2name(sig) : StringValuePtr(sig);
 	if (strncmp(signm, "SIG", 3) == 0) signm += 3;
 	signo = signm2signo(signm);
 	if (!signo) {
@@ -337,7 +337,7 @@
 	break;
 
       case T_SYMBOL:
-	s = rb_id2name(SYM2ID(argv[0]));
+	s = rb_sym2name(argv[0]);
 	if (!s) rb_raise(rb_eArgError, "bad signal");
 	goto str_signal;
 
@@ -797,7 +797,7 @@
 	break;
 
       case T_SYMBOL:
-	s = rb_id2name(SYM2ID(vsig));
+	s = rb_sym2name(vsig);
 	if (!s) rb_raise(rb_eArgError, "bad signal");
 	goto str_signal;
 

Modified: MacRuby/branches/lrz_unstable/string.c
===================================================================
--- MacRuby/branches/lrz_unstable/string.c	2008-07-31 22:22:07 UTC (rev 390)
+++ MacRuby/branches/lrz_unstable/string.c	2008-08-02 02:56:32 UTC (rev 391)
@@ -2388,12 +2388,14 @@
  * Return a hash based on the string's length and content.
  */
 
+#if !WITH_OBJC
 static VALUE
 rb_str_hash_m(VALUE str)
 {
     int hval = rb_str_hash(str);
     return INT2FIX(hval);
 }
+#endif
 
 #define lesser(a,b) (((a)>(b))?(b):(a))
 
@@ -8176,14 +8178,14 @@
 sym_inspect(VALUE sym)
 {
 #if WITH_OBJC
-    ID id = SYM2ID(sym);
     VALUE str;
 
-    sym = rb_id2str(id);
+#if 0
     if (!rb_enc_symname_p(RSTRING_PTR(sym), NULL)) {
 	sym = rb_str_inspect(sym);
     }
-    str = rb_str_new(":", 1);
+#endif
+    str = rb_str_new2(":");
     rb_str_buf_append(str, sym);
     return str;
 #else
@@ -8224,9 +8226,13 @@
 VALUE
 rb_sym_to_s(VALUE sym)
 {
+#if WITH_OBJC
+    return str_new3(rb_cString, sym);
+#else
     ID id = SYM2ID(sym);
 
     return str_new3(rb_cString, rb_id2str(id));
+#endif
 }
 
 
@@ -8274,6 +8280,7 @@
 }
 
 
+#if !WITH_OBJC
 static VALUE
 sym_succ(VALUE sym)
 {
@@ -8358,6 +8365,7 @@
 {
     return rb_obj_encoding(rb_id2str(SYM2ID(sym)));
 }
+#endif
 
 ID
 rb_to_id(VALUE name)
@@ -8370,7 +8378,7 @@
 	tmp = rb_check_string_type(name);
 	if (NIL_P(tmp)) {
 	    rb_raise(rb_eTypeError, "%s is not a symbol",
-		     RSTRING_BYTEPTR(rb_inspect(name)));
+		     RSTRING_PTR(rb_inspect(name)));
 	}
 	name = tmp;
 	/* fall through */
@@ -8477,9 +8485,6 @@
     return flag;
 }
 
-void
-rb_objc_install_string_primitives(Class klass)
-{
 #define INSTALL_METHOD(selname, imp)                            \
     do {                                                        \
         SEL sel = sel_registerName(selname);                    \
@@ -8490,6 +8495,9 @@
     }                                                           \
     while(0)
 
+void
+rb_objc_install_string_primitives(Class klass)
+{
     INSTALL_METHOD("length", imp_rb_str_length);
     INSTALL_METHOD("characterAtIndex:", imp_rb_str_characterAtIndex);
     INSTALL_METHOD("getCharacters:range:", imp_rb_str_getCharactersRange);
@@ -8500,9 +8508,48 @@
     INSTALL_METHOD("_fastestEncodingInCFStringEncoding",
 	imp_rb_str_fastestEncodingInCFStringEncoding);
     INSTALL_METHOD("isEqual:", imp_rb_str_isEqual);
+}
 
+static CFIndex
+imp_rb_symbol_length(void *rcv, SEL sel)
+{
+    return RSYMBOL(rcv)->len;
+}
+
+static UniChar
+imp_rb_symbol_characterAtIndex(void *rcv, SEL sel, CFIndex idx)
+{
+    if (idx < 0 || idx > RSYMBOL(rcv)->len)
+	rb_bug("[Symbol characterAtIndex:] out of bounds");
+    return RSYMBOL(rcv)->str[idx];
+}
+
+static void
+imp_rb_symbol_getCharactersRange(void *rcv, SEL sel, UniChar *buffer, 
+			      CFRange range)
+{
+    int i;
+
+    if (range.location + range.length > RSYMBOL(rcv)->len)
+	rb_bug("[Symbol getCharacters:range:] out of bounds");
+
+    for (i = range.location; i < range.length; i++) {
+	*buffer = RSYMBOL(rcv)->str[i];
+	buffer++;
+    }
+}
+
+static void
+install_symbol_primitives(void)
+{
+    Class klass = (Class)rb_cSymbol;
+
+    INSTALL_METHOD("length", imp_rb_symbol_length);
+    INSTALL_METHOD("characterAtIndex:", imp_rb_symbol_characterAtIndex);
+    INSTALL_METHOD("getCharacters:range:", imp_rb_symbol_getCharactersRange);
+}
+
 #undef INSTALL_METHOD
-}
 #endif
 
 /*
@@ -8543,8 +8590,8 @@
     rb_define_method(rb_cString, "<=>", rb_str_cmp_m, 1);
     rb_define_method(rb_cString, "==", rb_str_equal, 1);
     rb_define_method(rb_cString, "eql?", rb_str_eql, 1);
-#if 1 
-    /* FIXME remove me once we use the objc dispatch for everything */
+#if !WITH_OBJC
+    /* already in objc */
     rb_define_method(rb_cString, "hash", rb_str_hash_m, 0);
 #endif
     rb_define_method(rb_cString, "casecmp", rb_str_casecmp, 1);
@@ -8555,9 +8602,7 @@
     rb_define_method(rb_cString, "[]=", rb_str_aset_m, -1);
     rb_define_method(rb_cString, "insert", rb_str_insert, 2);
 #if !WITH_OBJC
-    /* This method cannot be defined because it exists in 
-     * NSString already. 
-     */
+    /* already in objc */
     rb_define_method(rb_cString, "length", rb_str_length, 0);
 #endif
     rb_define_method(rb_cString, "size", rb_str_length, 0);
@@ -8675,19 +8720,27 @@
     rb_define_variable("$;", &rb_fs);
     rb_define_variable("$-F", &rb_fs);
 
+#if WITH_OBJC // rb_cSymbol is defined in parse.y because it's needed early
+#else
     rb_cSymbol = rb_define_class("Symbol", rb_cObject);
     rb_include_module(rb_cSymbol, rb_mComparable);
+#endif
     rb_undef_alloc_func(rb_cSymbol);
     rb_undef_method(CLASS_OF(rb_cSymbol), "new");
     rb_define_singleton_method(rb_cSymbol, "all_symbols", rb_sym_all_symbols, 0); /* in parse.y */
 
     rb_define_method(rb_cSymbol, "==", sym_equal, 1);
     rb_define_method(rb_cSymbol, "inspect", sym_inspect, 0);
+#if WITH_OBJC
+    rb_define_method(rb_cSymbol, "description", sym_inspect, 0);
+#endif
+    rb_define_method(rb_cSymbol, "to_proc", sym_to_proc, 0);
     rb_define_method(rb_cSymbol, "to_s", rb_sym_to_s, 0);
     rb_define_method(rb_cSymbol, "id2name", rb_sym_to_s, 0);
     rb_define_method(rb_cSymbol, "intern", sym_to_sym, 0);
     rb_define_method(rb_cSymbol, "to_sym", sym_to_sym, 0);
-    rb_define_method(rb_cSymbol, "to_proc", sym_to_proc, 0);
+
+#if !WITH_OBJC
     rb_define_method(rb_cSymbol, "succ", sym_succ, 0);
     rb_define_method(rb_cSymbol, "next", sym_succ, 0);
 
@@ -8709,4 +8762,9 @@
     rb_define_method(rb_cSymbol, "swapcase", sym_swapcase, 0);
 
     rb_define_method(rb_cSymbol, "encoding", sym_encoding, 0);
+#endif
+
+#if WITH_OBJC
+    install_symbol_primitives();
+#endif
 }

Modified: MacRuby/branches/lrz_unstable/variable.c
===================================================================
--- MacRuby/branches/lrz_unstable/variable.c	2008-07-31 22:22:07 UTC (rev 390)
+++ MacRuby/branches/lrz_unstable/variable.c	2008-08-02 02:56:32 UTC (rev 391)
@@ -22,7 +22,47 @@
 st_table *rb_global_tbl;
 st_table *rb_class_tbl;
 static ID autoload, classpath, tmp_classpath;
+#if WITH_OBJC
+static const void *
+retain_cb(CFAllocatorRef allocator, const void *v)
+{
+    rb_objc_retain(v);
+    return v;
+}
 
+static void
+release_cb(CFAllocatorRef allocator, const void *v)
+{
+    rb_objc_release(v);
+}
+
+static void
+ivar_dict_foreach(VALUE hash, int (*func)(ANYARGS), VALUE farg)
+{
+    CFIndex i, count;
+    const void **keys;
+    const void **values;
+
+    count = CFDictionaryGetCount((CFDictionaryRef)hash);
+    if (count == 0)
+	return;
+
+    keys = (const void **)alloca(sizeof(void *) * count);
+    values = (const void **)alloca(sizeof(void *) * count);
+
+    CFDictionaryGetKeysAndValues((CFDictionaryRef)hash, keys, values);
+
+    for (i = 0; i < count; i++) {
+	if ((*func)(keys[i], values[i], farg) != ST_CONTINUE)
+	    break;
+    }
+}
+
+static CFDictionaryValueCallBacks rb_cfdictionary_value_cb = {
+    0, retain_cb, release_cb, NULL, NULL
+};
+#endif
+
 void
 Init_var_tables(void)
 {
@@ -108,7 +148,7 @@
 	    arg.track = value;
 	    arg.prev = res;
 #if WITH_OBJC
-	    rb_hash_foreach((VALUE)iv_dict, fc_i, (VALUE)&arg);
+	    ivar_dict_foreach((VALUE)iv_dict, fc_i, (VALUE)&arg);
 #else
 	    st_foreach(RCLASS_IV_TBL(value), fc_i, (st_data_t)&arg);
 #endif
@@ -140,7 +180,7 @@
 #if WITH_OBJC
     CFMutableDictionaryRef iv_dict = rb_class_ivar_dict(rb_cObject);
     if (iv_dict != NULL) {
-	rb_hash_foreach((VALUE)iv_dict, fc_i, (VALUE)&arg);
+	ivar_dict_foreach((VALUE)iv_dict, fc_i, (VALUE)&arg);
     }
 #else
     if (RCLASS_IV_TBL(rb_cObject)) {
@@ -196,7 +236,7 @@
 		(const void *)classid, (const void **)&path))
 		return find_class_path(klass);
 
-	    path = rb_str_dup(rb_id2str(SYM2ID(path)));
+	    path = rb_str_dup(path);
 	    OBJ_FREEZE(path);
 	    CFDictionarySetValue(iv_dict, (const void *)classpath, (const void *)path);
 	    CFDictionaryRemoveValue(iv_dict, (const void *)classid);
@@ -838,8 +878,6 @@
 
 #if WITH_OBJC
 static CFMutableDictionaryRef generic_iv_dict = NULL;
-const void * rb_cfdictionary_retain_cb(CFAllocatorRef, const void *);
-void rb_cfdictionary_release_cb(CFAllocatorRef, const void *);
 #else
 static int special_generic_ivar = 0;
 static st_table *generic_iv_tbl;
@@ -906,13 +944,7 @@
 	    rb_error_frozen("object");
     }
     if (generic_iv_dict == NULL) {
-	CFDictionaryValueCallBacks values_cb;
-
-	memset(&values_cb, 0, sizeof(values_cb));
-	values_cb.retain = rb_cfdictionary_retain_cb;
-	values_cb.release = rb_cfdictionary_release_cb;
-
-	generic_iv_dict = CFDictionaryCreateMutable(NULL, 0, NULL, &values_cb);
+	generic_iv_dict = CFDictionaryCreateMutable(NULL, 0, NULL, &rb_cfdictionary_value_cb);
 	obj_dict = NULL;
     }
     else {
@@ -920,13 +952,7 @@
 	    (CFDictionaryRef)generic_iv_dict, (const void *)obj);
     }
     if (obj_dict == NULL) {
-	CFDictionaryValueCallBacks values_cb;
-
-	memset(&values_cb, 0, sizeof(values_cb));
-	values_cb.retain = rb_cfdictionary_retain_cb;
-	values_cb.release = rb_cfdictionary_release_cb;
-
-	obj_dict = CFDictionaryCreateMutable(NULL, 0, NULL, &values_cb);
+	obj_dict = CFDictionaryCreateMutable(NULL, 0, NULL, &rb_cfdictionary_value_cb);
 	CFDictionarySetValue(generic_iv_dict, (const void *)obj, 
 	    (const void *)obj_dict);
 	CFMakeCollectable(obj_dict);
@@ -1164,13 +1190,7 @@
     }
     else {
 	if (generic_iv_dict == NULL) {
-	    CFDictionaryValueCallBacks values_cb;
-
-	    memset(&values_cb, 0, sizeof(values_cb));
-	    values_cb.retain = rb_cfdictionary_retain_cb;
-	    values_cb.release = rb_cfdictionary_release_cb;
-
-	    generic_iv_dict = CFDictionaryCreateMutable(NULL, 0, NULL, &values_cb);
+	    generic_iv_dict = CFDictionaryCreateMutable(NULL, 0, NULL, &rb_cfdictionary_value_cb);
 	}
 	CFDictionarySetValue(generic_iv_dict, (const void *)mod, (const void *)dict);
     }
@@ -1183,13 +1203,7 @@
 
     dict = rb_class_ivar_dict(mod);
     if (dict == NULL) {
-	CFDictionaryValueCallBacks values_cb;
-
-	memset(&values_cb, 0, sizeof(values_cb));
-	values_cb.retain = rb_cfdictionary_retain_cb;
-	values_cb.release = rb_cfdictionary_release_cb;
-
-	dict = CFDictionaryCreateMutable(NULL, 0, NULL, &values_cb);
+	dict = CFDictionaryCreateMutable(NULL, 0, NULL, &rb_cfdictionary_value_cb);
 	rb_class_ivar_set_dict(mod, dict);
 	CFMakeCollectable(dict);
     }
@@ -1337,14 +1351,8 @@
 		if (new_ivar) {
 		    if (len + 1 == RB_IVAR_ARY_MAX) {
 			CFMutableDictionaryRef tbl;
-			CFDictionaryValueCallBacks values_cb;
+			tbl = CFDictionaryCreateMutable(NULL, 0, NULL, &rb_cfdictionary_value_cb);
 
-			memset(&values_cb, 0, sizeof(values_cb));
-			values_cb.retain = rb_cfdictionary_retain_cb;
-			values_cb.release = rb_cfdictionary_release_cb;
-
-			tbl = CFDictionaryCreateMutable(NULL, 0, NULL, &values_cb);
-
 			for (i = 0; i < len; i++)
 			    CFDictionarySetValue(tbl, 
 				(const void *)ROBJECT(obj)->ivars.as.ary[i].name, 
@@ -1593,7 +1601,7 @@
       {
 	  CFMutableDictionaryRef iv_dict = rb_class_ivar_dict(obj);
 	  if (iv_dict != NULL)
-	      rb_hash_foreach((VALUE)iv_dict, func, arg);
+	      ivar_dict_foreach((VALUE)iv_dict, func, arg);
       }
 #else
 	if (RCLASS_IV_TBL(obj)) {
@@ -2159,7 +2167,7 @@
 #if WITH_OBJC
     CFMutableDictionaryRef iv_dict = rb_class_ivar_dict(mod);
     if (iv_dict != NULL)
-	rb_hash_foreach((VALUE)iv_dict, sv_i, (VALUE)tbl);
+	ivar_dict_foreach((VALUE)iv_dict, sv_i, (VALUE)tbl);
 #else
     if (RCLASS_IV_TBL(mod)) {
 	st_foreach_safe(RCLASS_IV_TBL(mod), sv_i, (st_data_t)tbl);
@@ -2552,7 +2560,7 @@
 #if WITH_OBJC
     CFMutableDictionaryRef iv_dict = rb_class_ivar_dict(obj);
     if (iv_dict != NULL)
-	rb_hash_foreach((VALUE)iv_dict, cv_i, (VALUE)ary);
+	ivar_dict_foreach((VALUE)iv_dict, cv_i, (VALUE)ary);
 #else
     if (RCLASS_IV_TBL(obj)) {
 	st_foreach_safe(RCLASS_IV_TBL(obj), cv_i, ary);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080801/3accc25e/attachment-0001.html 


More information about the macruby-changes mailing list