[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
GSObJCRuntime (subclasses)
From: |
Matt Rice |
Subject: |
GSObJCRuntime (subclasses) |
Date: |
Sat, 16 Oct 2004 11:03:22 -0700 (PDT) |
here's 2 additions for GSObjCRuntime
for finding subclasses of a class, and a tweak for
objc-load.m for it to work with classes loaded from
bundles.
unless there are any objections i'll hopefully commit
this in 24 hours... (including an appropriate
ChangeLog entry, that it seems i forgot.)
matt
__________________________________
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail
Index: ./Headers/Additions/GNUstepBase/GSObjCRuntime.h
===================================================================
RCS file:
/cvsroot/gnustep/gnustep/core/base/Headers/Additions/GNUstepBase/GSObjCRuntime.h,v
retrieving revision 1.14
diff -u -r1.14 GSObjCRuntime.h
--- ./Headers/Additions/GNUstepBase/GSObjCRuntime.h 16 Sep 2004 08:08:08
-0000 1.14
+++ ./Headers/Additions/GNUstepBase/GSObjCRuntime.h 16 Oct 2004 17:34:32
-0000
@@ -715,6 +715,12 @@
unsigned size,
int offset) GS_ATTRIB_DEPRECATED;
+GS_EXPORT NSArray *
+GSObjCAllSubclassesOfClass(Class cls);
+
+GS_EXPORT NSArray *
+GSObjCDirectSubclassesOfClass(Class cls);
+
/** ## deprecated ##
*/
GS_STATIC_INLINE const char*
Index: ./Source/Additions/GSObjCRuntime.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/base/Source/Additions/GSObjCRuntime.m,v
retrieving revision 1.50
diff -u -r1.50 GSObjCRuntime.m
--- ./Source/Additions/GSObjCRuntime.m 16 Sep 2004 16:13:16 -0000 1.50
+++ ./Source/Additions/GSObjCRuntime.m 16 Oct 2004 17:34:36 -0000
@@ -2124,6 +2124,53 @@
}
+/** Returns an autoreleased array of subclasses of Class cls, including
+ * subclasses of subclasses. */
+NSArray *GSObjCAllSubclassesOfClass(Class cls)
+{
+ if (!cls)
+ {
+ return nil;
+ }
+ else
+ {
+ Class aClass;
+ NSMutableArray *result = [[NSMutableArray alloc] init];
+
+#ifdef GNU_RUNTIME
+ for (aClass = cls->subclass_list; aClass; aClass=aClass->sibling_class)
+ {
+ [result addObject:aClass];
+ [result addObjectsFromArray: GSObjCAllSubclassesOfClass(aClass)];
+ }
+#endif
+ return AUTORELEASE(result);
+ }
+}
+
+/** Returns an autoreleased array containing subclasses directly descendent of
+ * Class cls. */
+NSArray *GSObjCDirectSubclassesOfClass(Class cls)
+{
+ if (!cls)
+ {
+ return nil;
+ }
+ else
+ {
+ NSMutableArray *result=[[NSMutableArray alloc] init];
+ Class aClass;
+
+#ifdef GNU_RUNTIME
+ for (aClass = cls->subclass_list;aClass;aClass=aClass->sibling_class)
+ {
+ [result addObject:aClass];
+ }
+#endif
+ return AUTORELEASE(result);
+ }
+}
+
void *
GSAutoreleasedBuffer(unsigned size)
{
Index: ./Source/objc-load.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/base/Source/objc-load.m,v
retrieving revision 1.17
diff -u -r1.17 objc-load.m
--- ./Source/objc-load.m 31 Jul 2003 23:49:32 -0000 1.17
+++ ./Source/objc-load.m 16 Oct 2004 17:34:36 -0000
@@ -152,6 +152,7 @@
#else
typedef void (*void_fn)();
dl_handle_t handle;
+ void __objc_resolve_class_links(void);
#if !defined(__ELF__) && !defined(CON_AUTOLOAD)
void_fn *ctor_list;
int i;
@@ -218,10 +219,11 @@
}
#endif /* not __ELF__ */
+ __objc_resolve_class_links(); /* fill in subclass_list and sibling_class */
_objc_load_callback = 0;
_objc_load_load_callback = 0;
return 0;
-#endif
+#endif /* not NeXT_RUNTIME */
}
long
- GSObJCRuntime (subclasses),
Matt Rice <=