From b7b5bd2d3ca7f3e339512582179e355d4df71293 Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Sun, 3 Feb 2008 22:35:36 +0100 Subject: Objective-C layer: Add slot handling functions. darcs-hash:b4ec2fb1229c4eb9f3201e378a2d3e6e5fc6b872 --- Objective-C/libobjcl.m | 70 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 3 deletions(-) (limited to 'Objective-C/libobjcl.m') 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 #include @@ -30,7 +28,6 @@ #include #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 +} -- cgit v1.2.3