summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Benkard <code@mail.matthias.benkard.de>2008-02-10 14:46:54 +0100
committerMatthias Benkard <code@mail.matthias.benkard.de>2008-02-10 14:46:54 +0100
commit3170b6d37b051f42fe0b28ba2dfa54344e1c85e6 (patch)
tree630d20e53eb35af86c4274e0ebccb35d492155d1
parent7d44a3313c9be065f962975b362d29684bcd3418 (diff)
Add NSObject category ObjectiveCLWrapperLink.
darcs-hash:0a90de7a76127351a989662a577b5688fe39654c
-rw-r--r--Objective-C/GNUmakefile2
-rw-r--r--Objective-C/NSObject-ObjectiveCLWrapperLink.h22
-rw-r--r--Objective-C/NSObject-ObjectiveCLWrapperLink.m47
-rw-r--r--Objective-C/libobjcl.m39
4 files changed, 95 insertions, 15 deletions
diff --git a/Objective-C/GNUmakefile b/Objective-C/GNUmakefile
index 598c79f..2680426 100644
--- a/Objective-C/GNUmakefile
+++ b/Objective-C/GNUmakefile
@@ -33,7 +33,7 @@ LIBRARY_NAME = libobjcl
RPM_DISABLE_RELOCATABLE = YES
ADDITIONAL_OBJCFLAGS = -Wall -g -DVERSION=\"$(VERSION)\" -I/usr/local/include
-libobjcl_OBJC_FILES = JIGS/ObjcRuntimeUtilities2.m libobjcl.m PyObjC/objc_support.m PyObjC/objc-runtime-apple.m PyObjC/objc-runtime-gnu.m PyObjC/objc-runtime-compat.m
+libobjcl_OBJC_FILES = JIGS/ObjcRuntimeUtilities2.m libobjcl.m NSObject-ObjectiveCLWrapperLink.m PyObjC/objc_support.m PyObjC/objc-runtime-apple.m PyObjC/objc-runtime-gnu.m PyObjC/objc-runtime-compat.m
libobjcl_C_FILES = JIGS/ObjcRuntimeUtilities.c
LIBRARIES_DEPEND_UPON = $(FND_LIBS) $(GUI_LIBS) $(OBJC_LIBS) $(SYSTEM_LIBS) $(CONFIG_SYSTEM_LIBS)
diff --git a/Objective-C/NSObject-ObjectiveCLWrapperLink.h b/Objective-C/NSObject-ObjectiveCLWrapperLink.h
new file mode 100644
index 0000000..9bdf902
--- /dev/null
+++ b/Objective-C/NSObject-ObjectiveCLWrapperLink.h
@@ -0,0 +1,22 @@
+/* -*- mode: objc; coding: utf-8 -*- */
+
+#import <Foundation/NSObject.h>
+
+void
+objcl_initialise_instance_wrappers (void);
+
+void
+objcl_shutdown_instance_wrappers (void);
+
+@interface NSObject (ObjectiveCLWrapperLink)
+-(const char *) __objectiveCLWrapperID;
+-(void) __setObjectiveCLWrapperID: (const char *)wrapper_id;
+-(void) __removeObjectiveCLWrapperID;
+
+/* Classes can't be wrapped at the moment. */
+/*
++(const char *) __objectiveCLWrapperID;
++(const char *) __setObjectiveCLWrapperID: (const char *)wrapper_id;
++(const char *) __removeObjectiveCLWrapperID;
+*/
+@end /* NSObject (ObjectiveCL) */
diff --git a/Objective-C/NSObject-ObjectiveCLWrapperLink.m b/Objective-C/NSObject-ObjectiveCLWrapperLink.m
new file mode 100644
index 0000000..5dac3a7
--- /dev/null
+++ b/Objective-C/NSObject-ObjectiveCLWrapperLink.m
@@ -0,0 +1,47 @@
+/* -*- mode: objc; coding: utf-8 -*- */
+
+#import "NSObject-ObjectiveCLWrapperLink.h"
+#import <Foundation/NSDictionary.h>
+#import <Foundation/NSObject.h>
+#import <Foundation/NSString.h>
+
+static NSMutableDictionary *instance_wrappers = NULL;
+
+void
+objcl_initialise_instance_wrappers (void)
+{
+ if (!instance_wrappers)
+ instance_wrappers = [[NSMutableDictionary alloc] init];
+}
+
+void
+objcl_shutdown_instance_wrappers (void)
+{
+ if (instance_wrappers)
+ {
+ [instance_wrappers release];
+ instance_wrappers = NULL;
+ }
+}
+
+@implementation NSObject (ObjectiveCLWrapperLink)
+-(const char *) __objectiveCLWrapperID
+{
+ NSString *string = [instance_wrappers objectForKey: self];
+ if (string != nil)
+ return [string UTF8String];
+ else
+ return NULL;
+}
+
+-(void) __setObjectiveCLWrapperID: (const char *)wrapper_id
+{
+ [instance_wrappers setObject: [NSString stringWithUTF8String: wrapper_id]
+ forKey: self];
+}
+
+-(void) __removeObjectiveCLWrapperID
+{
+ [instance_wrappers removeObjectForKey: self];
+}
+@end /* NSObject (ObjectiveCL) */
diff --git a/Objective-C/libobjcl.m b/Objective-C/libobjcl.m
index c75ebea..94a3663 100644
--- a/Objective-C/libobjcl.m
+++ b/Objective-C/libobjcl.m
@@ -18,6 +18,7 @@
*/
#import "libobjcl.h"
+#import "NSObject-ObjectiveCLWrapperLink.h"
#import "PyObjC/libffi_support.h"
#import "JIGS/ObjcRuntimeUtilities.h"
@@ -79,25 +80,33 @@ objcl_initialise_runtime (void)
if (!method_list_lengths)
method_list_lengths = [[NSMutableDictionary alloc] init];
+
+ objcl_initialise_instance_wrappers ();
}
-void
-objcl_shutdown_runtime (void)
+static void
+release_unless_null (id *object)
{
- if (objcl_autorelease_pool)
+ if (*object)
{
- [objcl_autorelease_pool release];
- objcl_autorelease_pool = NULL;
- }
- if (objcl_oom_exception)
- {
- [objcl_oom_exception release];
- objcl_oom_exception = NULL;
+ [*object release];
+ *object = NULL;
}
}
+void
+objcl_shutdown_runtime (void)
+{
+ release_unless_null (&objcl_autorelease_pool);
+ release_unless_null (&objcl_oom_exception);
+ release_unless_null (&method_lists);
+ release_unless_null (&method_list_lengths);
+ objcl_shutdown_instance_wrappers ();
+}
+
+
#ifdef USE_LIBFFI
id
objcl_invoke_with_types (int argc,
@@ -661,14 +670,16 @@ objcl_create_class (const char *class_name,
objcl_alignof_type (ivar_typespecs[i]),
ivar_typespecs[i]);
+#ifdef __OBJC2__
+ /* FIXME: What to do for the NeXT Objective-C 1.0 and GNU runtimes
+ here? */
for (i = 0; i < protocol_number; i++)
preclass_addProtocol (class,
-#ifdef __OBJC2__
objc_getProtocol ((char *) protocol_names[i])
-#else
- objc_getClass (protocol_names[i])
-#endif
+ /* ??? !__OBJC2__ ???
+ objc_getClass (protocol_names[i]) */
);
+#endif
return class;
#else