[macruby-changes] [405] MacRuby/branches/lrz_unstable
source_changes at macosforge.org
source_changes at macosforge.org
Sun Aug 3 22:38:20 PDT 2008
Revision: 405
http://trac.macosforge.org/projects/ruby/changeset/405
Author: lsansonetti at apple.com
Date: 2008-08-03 22:38:19 -0700 (Sun, 03 Aug 2008)
Log Message:
-----------
wip
Modified Paths:
--------------
MacRuby/branches/lrz_unstable/class.c
MacRuby/branches/lrz_unstable/gc.c
MacRuby/branches/lrz_unstable/include/ruby/ruby.h
MacRuby/branches/lrz_unstable/sample/test.rb
Modified: MacRuby/branches/lrz_unstable/class.c
===================================================================
--- MacRuby/branches/lrz_unstable/class.c 2008-08-03 21:08:32 UTC (rev 404)
+++ MacRuby/branches/lrz_unstable/class.c 2008-08-04 05:38:19 UTC (rev 405)
@@ -35,14 +35,17 @@
do {
if (ocsuper == (Class)rb_cArray) {
rb_objc_install_array_primitives(ocklass);
+ RCLASS_SET_VERSION_FLAG(ocklass, RCLASS_IS_ARRAY_SUBCLASS);
return true;
}
if (ocsuper == (Class)rb_cHash) {
rb_objc_install_hash_primitives(ocklass);
+ RCLASS_SET_VERSION_FLAG(ocklass, RCLASS_IS_HASH_SUBCLASS);
return true;
}
if (ocsuper == (Class)rb_cString) {
rb_objc_install_string_primitives(ocklass);
+ RCLASS_SET_VERSION_FLAG(ocklass, RCLASS_IS_STRING_SUBCLASS);
return true;
}
ocsuper = class_getSuperclass(ocsuper);
Modified: MacRuby/branches/lrz_unstable/gc.c
===================================================================
--- MacRuby/branches/lrz_unstable/gc.c 2008-08-03 21:08:32 UTC (rev 404)
+++ MacRuby/branches/lrz_unstable/gc.c 2008-08-04 05:38:19 UTC (rev 405)
@@ -2251,6 +2251,48 @@
int count;
};
+static int
+rb_objc_yield_classes(VALUE of)
+{
+ int i, count, rcount;
+ Class *buf;
+
+ count = objc_getClassList(NULL, 0);
+ assert(count > 0);
+
+ buf = (Class *)alloca(sizeof(Class) * count);
+ objc_getClassList(buf, count);
+
+ for (i = rcount = 0; i < count; i++) {
+ Class sk, k = buf[i];
+ bool nsobject_based;
+
+ if (class_getName(k)[0] == '_')
+ continue;
+
+ if (of == rb_cModule && !RCLASS_MODULE(k))
+ continue;
+
+ nsobject_based = false;
+ sk = k;
+ do {
+ sk = (Class)RCLASS_SUPER(sk);
+ if (sk == (Class)rb_cNSObject) {
+ nsobject_based = true;
+ break;
+ }
+ }
+ while (sk != NULL);
+
+ if (nsobject_based) {
+ rb_yield((VALUE)k);
+ rcount++;
+ }
+ }
+
+ return rcount;
+}
+
static void
rb_objc_recorder(task_t task, void *context, unsigned type_mask,
vm_range_t *ranges, unsigned range_count)
@@ -2266,48 +2308,29 @@
auto_zone_get_layout_type_no_lock(__auto_zone, (void *)r->address);
if (type != AUTO_OBJECT_SCANNED && type != AUTO_OBJECT_UNSCANNED)
continue;
+ if (*(Class *)r->address == NULL)
+ continue;
if (ctx->class_of != 0) {
-#if 0
- if (ctx->class_of == rb_cClass || ctx->class_of == rb_cModule) {
- /* Class/Module are a special case. */
- if (NATIVE(r->address)
- || FL_TEST(r->address, FL_SINGLETON))
- continue;
- if (ctx->class_of == rb_cClass) {
- /* Only match classes. */
- if (BUILTIN_TYPE(r->address) != T_CLASS)
- continue;
+ bool ok = false;
+ for (c = *(Class *)r->address; c != NULL;
+ c = class_getSuperclass(c)) {
+ if (c ==(Class)ctx->class_of) {
+ ok = true;
+ break;
}
- else {
- /* Match classes & modules. */
- if (BUILTIN_TYPE(r->address) != T_CLASS
- && BUILTIN_TYPE(r->address) != T_MODULE)
- continue;
- }
}
- else
-#endif
- {
- unsigned ok = 0;
- for (c = *(Class *)r->address; c != NULL;
- c = class_getSuperclass(c)) {
- if (c ==(Class)ctx->class_of) {
- ok = 1;
- break;
- }
- }
- if (!ok)
- continue;
- }
+ if (!ok)
+ continue;
}
- switch (BUILTIN_TYPE(r->address)) {
+ switch (TYPE(r->address)) {
case T_NONE:
- case T_ICLASS:
case T_NODE:
continue;
+ case T_ICLASS:
case T_CLASS:
- if (RCLASS_SINGLETON(r->address))
- continue;
+ case T_MODULE:
+ rb_bug("object %p of type %d should not be recorded",
+ (void *)r->address, TYPE(r->address));
case T_NATIVE:
if (rb_objc_is_placeholder((void *)r->address))
continue;
@@ -2408,11 +2431,20 @@
}
RETURN_ENUMERATOR(os, 1, &of);
#if WITH_OBJC
- struct rb_objc_recorder_context ctx = {of, 0};
- (((malloc_zone_t *)__auto_zone)->introspect->enumerator)(
+ /* Class/Module are a special case, because they are not auto objects */
+ int count = rb_objc_yield_classes(of);
+
+ if (of != rb_cClass && of != rb_cModule) {
+ struct rb_objc_recorder_context ctx = {of, count};
+
+ (((malloc_zone_t *)__auto_zone)->introspect->enumerator)(
mach_task_self(), (void *)&ctx, MALLOC_PTR_IN_USE_RANGE_TYPE,
(vm_address_t)__auto_zone, NULL, rb_objc_recorder);
- return INT2FIX(ctx.count);
+
+ count = ctx.count;
+ }
+
+ return INT2FIX(count);
#else
return os_obj_of(&rb_objspace, of);
#endif
Modified: MacRuby/branches/lrz_unstable/include/ruby/ruby.h
===================================================================
--- MacRuby/branches/lrz_unstable/include/ruby/ruby.h 2008-08-03 21:08:32 UTC (rev 404)
+++ MacRuby/branches/lrz_unstable/include/ruby/ruby.h 2008-08-04 05:38:19 UTC (rev 405)
@@ -502,6 +502,9 @@
# define RCLASS_IS_SINGLETON 0x800 /* class represents a singleton/metaclass */
# define RCLASS_IS_FROZEN 0x1000 /* class is frozen */
# define RCLASS_IS_TAINTED 0x2000 /* class is tainted */
+# define RCLASS_IS_STRING_SUBCLASS 0x10000 /* class is a subclass of NSCFString */
+# define RCLASS_IS_ARRAY_SUBCLASS 0x20000 /* class is a subclass of NSCFArray */
+# define RCLASS_IS_HASH_SUBCLASS 0x40000 /* class is a subclass of NSCFDictionary */
# if __OBJC2__
# define RCLASS_VERSION(m) (class_getVersion((Class)m))
# define RCLASS_SET_VERSION_FLAG(m,f) (class_setVersion((Class)m, (RCLASS_VERSION(m) | f)))
@@ -1198,9 +1201,18 @@
else return T_CLASS;
}
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 (k == (Class)rb_cCFString
+ || (RCLASS_VERSION(k) & RCLASS_IS_STRING_SUBCLASS)
+ == RCLASS_IS_STRING_SUBCLASS)
+ return T_STRING;
+ if (k == (Class)rb_cCFArray
+ || (RCLASS_VERSION(k) & RCLASS_IS_ARRAY_SUBCLASS)
+ == RCLASS_IS_ARRAY_SUBCLASS)
+ return T_ARRAY;
+ if (k == (Class)rb_cCFHash
+ || (RCLASS_VERSION(k) & RCLASS_IS_HASH_SUBCLASS)
+ == RCLASS_IS_HASH_SUBCLASS)
+ return T_HASH;
if (NATIVE(obj)) return T_NATIVE;
}
#endif
Modified: MacRuby/branches/lrz_unstable/sample/test.rb
===================================================================
--- MacRuby/branches/lrz_unstable/sample/test.rb 2008-08-03 21:08:32 UTC (rev 404)
+++ MacRuby/branches/lrz_unstable/sample/test.rb 2008-08-04 05:38:19 UTC (rev 405)
@@ -1879,7 +1879,6 @@
false
end
-=begin
for script in Dir["#{dir}{lib,sample,ext,test}/**/*.rb"]
unless valid_syntax? IO::read(script), script
STDERR.puts script
@@ -1887,7 +1886,6 @@
end
end
test_ok(!$bad)
-=end
test_check "const"
TEST1 = 1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080803/dcaf959f/attachment-0001.html
More information about the macruby-changes
mailing list