diff options
author | Matthias Benkard <code@mail.matthias.benkard.de> | 2008-02-03 22:35:36 +0100 |
---|---|---|
committer | Matthias Benkard <code@mail.matthias.benkard.de> | 2008-02-03 22:35:36 +0100 |
commit | b7b5bd2d3ca7f3e339512582179e355d4df71293 (patch) | |
tree | 690aae451d4b2b1b967a72d88578e7b7a39bc3ff | |
parent | eda523e8135febb9005ade74c9bf2c135b2da4db (diff) |
Objective-C layer: Add slot handling functions.
darcs-hash:b4ec2fb1229c4eb9f3201e378a2d3e6e5fc6b872
-rw-r--r-- | Objective-C/PyObjC/pyobjc.h | 2 | ||||
-rw-r--r-- | Objective-C/libobjcl.h | 27 | ||||
-rw-r--r-- | Objective-C/libobjcl.m | 70 |
3 files changed, 95 insertions, 4 deletions
diff --git a/Objective-C/PyObjC/pyobjc.h b/Objective-C/PyObjC/pyobjc.h index 3a159c8..f762f70 100644 --- a/Objective-C/PyObjC/pyobjc.h +++ b/Objective-C/PyObjC/pyobjc.h @@ -5,7 +5,6 @@ #include <stdlib.h> #include <stdio.h> -#include "libobjcl.h" #ifdef __NEXT_RUNTIME__ #include "pyobjc-compat.h" @@ -51,5 +50,6 @@ #include "objc_support.h" #include "libffi_support.h" +#import "libobjcl.h" #endif /* __pyobjc_H */ diff --git a/Objective-C/libobjcl.h b/Objective-C/libobjcl.h index 968cf14..09b08ab 100644 --- a/Objective-C/libobjcl.h +++ b/Objective-C/libobjcl.h @@ -22,6 +22,10 @@ #include "../config.h" +#import "PyObjC/pyobjc.h" +#import "PyObjC/objc_support.h" +#import "PyObjC/objc-runtime-compat.h" + #ifdef USE_LIBFFI #ifdef HAVE_FFI_H #include <ffi.h> @@ -33,6 +37,12 @@ #endif #endif +#ifdef __NEXT_RUNTIME__ +typedef Ivar IVAR_T; +#else +typedef struct objc_ivar *IVAR_T; +#endif + extern NSException *objcl_oom_exception; @@ -118,3 +128,20 @@ objcl_sizeof_return_type (const char *typespec); long objcl_alignof_type (const char *typespec); + +void +objcl_set_slot_value (id obj, const char *ivar_name, void *value); + +void * +objcl_slot_value (id obj, const char *ivar_name); + +/* The following function returns a freshly consed array that the caller + must deallocate. */ +IVAR_T * +objcl_class_direct_slots (Class class, unsigned int *count, unsigned int *element_size); + +const char * +objcl_slot_name (IVAR_T ivar); + +const char * +objcl_slot_type (IVAR_T ivar); 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 +} |