[macruby-changes] [2590] MacRuby/trunk/array.c

source_changes at macosforge.org source_changes at macosforge.org
Sat Sep 19 21:09:57 PDT 2009


Revision: 2590
          http://trac.macosforge.org/projects/ruby/changeset/2590
Author:   vincent.isambart at gmail.com
Date:     2009-09-19 21:09:54 -0700 (Sat, 19 Sep 2009)
Log Message:
-----------
fixed a 10.5-only bug in Array#delete (patch written by Laurent)

Modified Paths:
--------------
    MacRuby/trunk/array.c

Modified: MacRuby/trunk/array.c
===================================================================
--- MacRuby/trunk/array.c	2009-09-20 03:22:04 UTC (rev 2589)
+++ MacRuby/trunk/array.c	2009-09-20 04:09:54 UTC (rev 2590)
@@ -4134,6 +4134,8 @@
 }
 
 #if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
+// This is to work around a bug where CF will try to call an non-existing
+// method.
 static CFIndex
 imp_rb_array_cfindexOfObjectInRange(void *rcv, SEL sel, void *obj, 
     CFRange range)
@@ -4223,6 +4225,24 @@
     rary_append(RARY(rcv), OC2RB(obj));
 }
 
+#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
+// This is to work around a bug where CF will try to call an non-existing
+// method.
+static CFIndex
+imp_rary_cfindexOfObjectInRange(void *rcv, SEL sel, void *obj, CFRange range)
+{
+    assert(range.location + range.length <= RARY(rcv)->len);
+    VALUE item = OC2RB(obj);
+    for (size_t i = range.location; i < range.location + range.length; i++) {
+	VALUE item2 = rary_elt(RARY(rcv), i);
+	if (rb_equal_fast(item, item2) == Qtrue) {
+	    return i;
+	}
+    }
+    return -1;
+}
+#endif
+
 /* Arrays are ordered, integer-indexed collections of any object. 
  * Array indexing starts at 0, as in C or Java.  A negative index is 
  * assumed to be relative to the end of the array---that is, an index of -1 
@@ -4363,4 +4383,14 @@
 	    (IMP)imp_rary_replaceObjectAtIndexWithObject);
     rb_objc_install_method2((Class)rb_cRubyArray, "addObject:",
 	    (IMP)imp_rary_addObject);
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
+    rb_objc_install_method2((Class)rb_cRubyArray, "_cfindexOfObject:range:",
+	    (IMP)imp_rary_cfindexOfObjectInRange);
+    Method m = class_getInstanceMethod((Class)rb_cRubyArray,
+	    sel_registerName("_cfindexOfObject:range:"));
+    class_addMethod((Class)rb_cRubyArray,
+	    sel_registerName("_cfindexOfObject:inRange:"),
+	    method_getImplementation(m), method_getTypeEncoding(m));
+#endif
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090919/228d0d41/attachment.html>


More information about the macruby-changes mailing list