summaryrefslogtreecommitdiff
path: root/Objective-C/libobjcl.m
diff options
context:
space:
mode:
authorMatthias Benkard <code@mail.matthias.benkard.de>2008-02-03 22:35:36 +0100
committerMatthias Benkard <code@mail.matthias.benkard.de>2008-02-03 22:35:36 +0100
commitb7b5bd2d3ca7f3e339512582179e355d4df71293 (patch)
tree690aae451d4b2b1b967a72d88578e7b7a39bc3ff /Objective-C/libobjcl.m
parenteda523e8135febb9005ade74c9bf2c135b2da4db (diff)
Objective-C layer: Add slot handling functions.
darcs-hash:b4ec2fb1229c4eb9f3201e378a2d3e6e5fc6b872
Diffstat (limited to 'Objective-C/libobjcl.m')
-rw-r--r--Objective-C/libobjcl.m70
1 files changed, 67 insertions, 3 deletions
diff --git a/Objective-C/libobjcl.m b/Objective-C/libobjcl.m
index 53fbaaf..f49d502 100644
--- a/Objective-C/libobjcl.m
+++ b/Objective-C/libobjcl.m
@@ -19,8 +19,6 @@
#import "libobjcl.h"
#import "PyObjC/libffi_support.h"
-#import "PyObjC/objc_support.h"
-#import "PyObjC/objc-runtime-compat.h"
#import <Foundation/Foundation.h>
#include <stdarg.h>
@@ -30,7 +28,6 @@
#include <objc/objc-class.h>
#endif
-
static NSAutoreleasePool *objcl_autorelease_pool = NULL;
/* Preallocate an exception to throw when memory is all used up. */
@@ -372,3 +369,70 @@ objcl_alignof_type (const char *typespec)
fprintf (stderr, "WARNING: objcl_align_typespec: Alignment might not fit into a long.\n");
return PyObjCRT_AlignOfType (typespec);
}
+
+
+void
+objcl_set_slot_value (id obj, const char *ivar_name, void *value)
+{
+ /* For the GNU runtime, this function is defined in objc-runtime-gnu.m. */
+ object_setInstanceVariable (obj, ivar_name, value);
+}
+
+
+void *
+objcl_slot_value (id obj, const char *ivar_name)
+{
+ void *value;
+ /* Caching Ivars may be useful here. Using those instead of strings
+ is claimed to be faster. */
+ /* For the GNU runtime, this function is defined in objc-runtime-gnu.m. */
+ object_getInstanceVariable (obj, ivar_name, &value);
+ return value;
+}
+
+
+IVAR_T *
+objcl_class_direct_slots (Class class, unsigned int *count, unsigned int *element_size)
+{
+ IVAR_T *ivars;
+
+#ifdef __NEXT_RUNTIME__
+#else
+ int i;
+#endif
+
+ *element_size = sizeof (IVAR_T);
+
+#ifdef __NEXT_RUNTIME__
+ ivars = class_copyIvarList (class, count);
+#else
+ *count = class->ivars->ivar_count;
+ ivars = malloc ((*count) * (*element_size));
+ for (i = 0; i < *count; i++)
+ ivars[i] = &class->ivars->ivar_list[i];
+#endif
+
+ return ivars;
+}
+
+
+const char *
+objcl_slot_name (IVAR_T ivar)
+{
+#ifdef __NEXT_RUNTIME__
+ return ivar_getName (ivar);
+#else
+ return ivar->ivar_name;
+#endif
+}
+
+
+const char *
+objcl_slot_type (IVAR_T ivar)
+{
+#ifdef __NEXT_RUNTIME__
+ return ivar_getTypeEncoding (ivar);
+#else
+ return ivar->ivar_type;
+#endif
+}