[macruby-changes] [407] MacRuby/branches/lrz_unstable
source_changes at macosforge.org
source_changes at macosforge.org
Mon Aug 4 17:36:42 PDT 2008
Revision: 407
http://trac.macosforge.org/projects/ruby/changeset/407
Author: lsansonetti at apple.com
Date: 2008-08-04 17:36:41 -0700 (Mon, 04 Aug 2008)
Log Message:
-----------
wip
Modified Paths:
--------------
MacRuby/branches/lrz_unstable/array.c
MacRuby/branches/lrz_unstable/compile.c
MacRuby/branches/lrz_unstable/hash.c
MacRuby/branches/lrz_unstable/id.c
MacRuby/branches/lrz_unstable/id.h
MacRuby/branches/lrz_unstable/numeric.c
MacRuby/branches/lrz_unstable/object.c
MacRuby/branches/lrz_unstable/string.c
MacRuby/branches/lrz_unstable/vm_method.c
Modified: MacRuby/branches/lrz_unstable/array.c
===================================================================
--- MacRuby/branches/lrz_unstable/array.c 2008-08-04 21:45:36 UTC (rev 406)
+++ MacRuby/branches/lrz_unstable/array.c 2008-08-05 00:36:41 UTC (rev 407)
@@ -4243,5 +4243,10 @@
rb_define_method(rb_cArray, "drop", rb_ary_drop, 1);
rb_define_method(rb_cArray, "drop_while", rb_ary_drop_while, 0);
+#if WITH_OBJC
+ /* to return a mutable copy */
+ rb_define_method(rb_cArray, "dup", rb_ary_dup, 0);
+#endif
+
id_cmp = rb_intern("<=>");
}
Modified: MacRuby/branches/lrz_unstable/compile.c
===================================================================
--- MacRuby/branches/lrz_unstable/compile.c 2008-08-04 21:45:36 UTC (rev 406)
+++ MacRuby/branches/lrz_unstable/compile.c 2008-08-05 00:36:41 UTC (rev 407)
@@ -918,10 +918,10 @@
MEMCPY(iseq->arg_opt_table, RARRAY_PTR(labels), VALUE, i);
#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
+ iseq->arg_opt_table[j] &= ~1;
}
}
else {
Modified: MacRuby/branches/lrz_unstable/hash.c
===================================================================
--- MacRuby/branches/lrz_unstable/hash.c 2008-08-04 21:45:36 UTC (rev 406)
+++ MacRuby/branches/lrz_unstable/hash.c 2008-08-05 00:36:41 UTC (rev 407)
@@ -311,6 +311,14 @@
}
VALUE
+rb_hash_dup(VALUE rcv)
+{
+ VALUE dup = (VALUE)CFDictionaryCreateMutableCopy(NULL, 0, (CFDictionaryRef)rcv);
+ CFMakeCollectable((CFTypeRef)dup);
+ return dup;
+}
+
+VALUE
rb_hash_new(void)
{
#if WITH_OBJC
@@ -1918,7 +1926,7 @@
static VALUE
rb_hash_merge(VALUE hash1, VALUE hash2)
{
- return rb_hash_update(rb_obj_dup(hash1), hash2);
+ return rb_hash_update(rb_hash_dup(hash1), hash2);
}
static int
@@ -3035,6 +3043,8 @@
#if WITH_OBJC
/* required because Hash.new can accept a block */
rb_define_singleton_method(rb_cHash, "new", rb_class_new_instance, -1);
+ /* to return a mutable copy */
+ rb_define_method(rb_cHash, "dup", rb_hash_dup, 0);
#else
rb_define_alloc_func(rb_cHash, hash_alloc);
#endif
Modified: MacRuby/branches/lrz_unstable/id.c
===================================================================
--- MacRuby/branches/lrz_unstable/id.c 2008-08-04 21:45:36 UTC (rev 406)
+++ MacRuby/branches/lrz_unstable/id.c 2008-08-05 00:36:41 UTC (rev 407)
@@ -59,6 +59,7 @@
selSucc = sel_registerName("succ");
selNot = sel_registerName("!");
selInit = sel_registerName("init");
+ selCopy = sel_registerName("copy");
#endif
idAREF = rb_intern("[]");
Modified: MacRuby/branches/lrz_unstable/id.h
===================================================================
--- MacRuby/branches/lrz_unstable/id.h 2008-08-04 21:45:36 UTC (rev 406)
+++ MacRuby/branches/lrz_unstable/id.h 2008-08-05 00:36:41 UTC (rev 407)
@@ -71,6 +71,7 @@
extern SEL selSucc;
extern SEL selNot;
extern SEL selInit;
+extern SEL selCopy;
extern ID idIncludedModules;
extern ID idIncludedInClasses;
#endif
Modified: MacRuby/branches/lrz_unstable/numeric.c
===================================================================
--- MacRuby/branches/lrz_unstable/numeric.c 2008-08-04 21:45:36 UTC (rev 406)
+++ MacRuby/branches/lrz_unstable/numeric.c 2008-08-05 00:36:41 UTC (rev 407)
@@ -3216,8 +3216,9 @@
#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.
+ /* overriding NSObject methods */
rb_define_method(rb_cNumeric, "class", rb_obj_class, 0);
+ rb_define_method(rb_cNumeric, "dup", rb_obj_dup, 0);
#else
rb_cNumeric = rb_define_class("Numeric", rb_cObject);
#endif
Modified: MacRuby/branches/lrz_unstable/object.c
===================================================================
--- MacRuby/branches/lrz_unstable/object.c 2008-08-04 21:45:36 UTC (rev 406)
+++ MacRuby/branches/lrz_unstable/object.c 2008-08-05 00:36:41 UTC (rev 407)
@@ -15,6 +15,7 @@
#include "ruby/st.h"
#include "ruby/util.h"
#include "debug.h"
+#include "id.h"
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
@@ -352,7 +353,7 @@
{
VALUE dup;
- if (rb_special_const_p(obj)) {
+ if (rb_special_const_p(obj) || TYPE(obj) == T_SYMBOL) {
rb_raise(rb_eTypeError, "can't dup %s", rb_obj_classname(obj));
}
dup = rb_obj_alloc(rb_obj_class(obj));
@@ -361,6 +362,14 @@
return dup;
}
+#if WITH_OBJC
+static VALUE
+rb_nsobj_dup(VALUE obj)
+{
+ return (VALUE)objc_msgSend((id)obj, selCopy);
+}
+#endif
+
/* :nodoc: */
VALUE
rb_obj_init_copy(VALUE obj, VALUE orig)
@@ -2640,9 +2649,18 @@
// #class is already defined in NSObject
rb_define_method(rb_mKernel, "class", rb_obj_class, 0);
#endif
+
+#if WITH_OBJC
+ rb_define_method(rb_cObject, "clone", rb_obj_clone, 0);
+ rb_define_method(rb_cObject, "dup", rb_obj_dup, 0);
+ rb_define_method(rb_cObject, "copy", rb_obj_dup, 0);
+ rb_define_method(rb_cObject, "initialize_copy", rb_obj_init_copy, 1);
+ rb_define_method(rb_cNSObject, "dup", rb_nsobj_dup, 0);
+#else
rb_define_method(rb_mKernel, "clone", rb_obj_clone, 0);
rb_define_method(rb_mKernel, "dup", rb_obj_dup, 0);
rb_define_method(rb_mKernel, "initialize_copy", rb_obj_init_copy, 1);
+#endif
rb_define_method(rb_mKernel, "taint", rb_obj_taint, 0);
rb_define_method(rb_mKernel, "tainted?", rb_obj_tainted, 0);
Modified: MacRuby/branches/lrz_unstable/string.c
===================================================================
--- MacRuby/branches/lrz_unstable/string.c 2008-08-04 21:45:36 UTC (rev 406)
+++ MacRuby/branches/lrz_unstable/string.c 2008-08-05 00:36:41 UTC (rev 407)
@@ -891,15 +891,22 @@
VALUE
rb_str_dup(VALUE str)
{
+#if WITH_OBJC
+ VALUE dup;
+ void *data;
+
+ dup = (VALUE)CFStringCreateMutableCopy(NULL, 0, (CFStringRef)str);
+
+ data = rb_str_cfdata2(str);
+ if (data != NULL)
+ rb_str_cfdata_set(dup, data);
+
+ CFMakeCollectable((CFTypeRef)dup);
+#else
VALUE dup = str_alloc(rb_obj_class(str));
rb_str_replace(dup, str);
-#if WITH_OBJC
- {
- void *data = rb_str_cfdata2(str);
- if (data != NULL)
- rb_str_cfdata_set(dup, data);
- }
#endif
+
return dup;
}
@@ -8714,6 +8721,9 @@
#if WITH_OBJC
rb_define_method(rb_cString, "transform", rb_str_transform, 1);
rb_define_method(rb_cString, "transform!", rb_str_transform_bang, 1);
+
+ /* to return a mutable copy */
+ rb_define_method(rb_cString, "dup", rb_str_dup, 0);
#endif
id_to_s = rb_intern("to_s");
@@ -8723,6 +8733,7 @@
rb_define_variable("$-F", &rb_fs);
#if WITH_OBJC // rb_cSymbol is defined in parse.y because it's needed early
+ rb_set_class_path(rb_cSymbol, rb_cObject, "Symbol");
#else
rb_cSymbol = rb_define_class("Symbol", rb_cObject);
rb_include_module(rb_cSymbol, rb_mComparable);
@@ -8735,6 +8746,7 @@
rb_define_method(rb_cSymbol, "inspect", sym_inspect, 0);
#if WITH_OBJC
rb_define_method(rb_cSymbol, "description", sym_inspect, 0);
+ rb_define_method(rb_cSymbol, "dup", rb_obj_dup, 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);
Modified: MacRuby/branches/lrz_unstable/vm_method.c
===================================================================
--- MacRuby/branches/lrz_unstable/vm_method.c 2008-08-04 21:45:36 UTC (rev 406)
+++ MacRuby/branches/lrz_unstable/vm_method.c 2008-08-05 00:36:41 UTC (rev 407)
@@ -437,12 +437,25 @@
origin = rb_method_node(RCLASS_SUPER(klass), name) == fbody
? RCLASS_SUPER(klass) : klass;
}
+ if (fbody == NULL) {
+ rb_print_undef(klass, name, 0);
+ }
+ if (fbody->nd_noex != noex) {
+ if (nd_type(fbody->nd_body) == NODE_CFUNC) {
+ rb_vm_check_redefinition_opt_method(fbody);
+ }
+ if (klass == origin) {
+ fbody->nd_noex = noex;
+ }
+ else {
+ rb_add_method(klass, name, NEW_ZSUPER(), noex);
+ }
+ }
#else
fbody = search_method(klass, name, &origin);
if (!fbody && TYPE(klass) == T_MODULE) {
fbody = search_method(rb_cObject, name, &origin);
}
-#endif
if (!fbody || !fbody->nd_body) {
rb_print_undef(klass, name, 0);
}
@@ -457,6 +470,7 @@
rb_add_method(klass, name, NEW_ZSUPER(), noex);
}
}
+#endif
}
int
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080804/7585b196/attachment-0001.html
More information about the macruby-changes
mailing list