diff options
Diffstat (limited to 'Objective-C')
-rw-r--r-- | Objective-C/GNUmakefile | 11 | ||||
-rw-r--r-- | Objective-C/libobjcl.m | 2 | ||||
-rw-r--r-- | Objective-C/objc-runtime-apple.h | 9 | ||||
-rw-r--r-- | Objective-C/objc-runtime-apple.m | 10 | ||||
-rw-r--r-- | Objective-C/objc-runtime-gnu.h | 4 | ||||
-rw-r--r-- | Objective-C/objc-runtime-gnu.m | 1 | ||||
-rw-r--r-- | Objective-C/objc_support.h | 55 | ||||
-rw-r--r-- | Objective-C/objc_support.m | 72 |
8 files changed, 59 insertions, 105 deletions
diff --git a/Objective-C/GNUmakefile b/Objective-C/GNUmakefile index 7cae671..33b91ac 100644 --- a/Objective-C/GNUmakefile +++ b/Objective-C/GNUmakefile @@ -5,8 +5,15 @@ include ../version.make LIBRARY_NAME = libobjcl RPM_DISABLE_RELOCATABLE = YES -ADDITIONAL_OBJCFLAGS = -Wall -g -DVERSION=\"$(VERSION)\" -#ADDITIONAL_LDFLAGS = -lavcall +ADDITIONAL_OBJCFLAGS = -Wall -g -DVERSION=\"$(VERSION)\" -I/usr/local/include + +ifdef USE_LIBFFI +ADDITIONAL_LDFLAGS = -lffi +ADDITIONAL_OBJCFLAGS += -DUSE_LIBFFI +else +ADDITIONAL_LDFLAGS = -lavcall +endif + libobjcl_OBJC_FILES = libobjcl.m objc_support.m objc-runtime-apple.m objc-runtime-gnu.m LIBRARIES_DEPEND_UPON = $(FND_LIBS) $(GUI_LIBS) $(OBJC_LIBS) $(SYSTEM_LIBS) $(CONFIG_SYSTEM_LIBS) diff --git a/Objective-C/libobjcl.m b/Objective-C/libobjcl.m index aff3c4c..bd1e410 100644 --- a/Objective-C/libobjcl.m +++ b/Objective-C/libobjcl.m @@ -274,7 +274,7 @@ objcl_invoke_with_types (void *receiver, *exception = NULL; #ifdef __NEXT_RUNTIME__ - method = class_getInstanceMethod ([obj class], method_selector)->method_imp; + method = class_getInstanceMethod ([((id) receiver) class], method_selector)->method_imp; #else method = objc_msg_lookup (receiver, method_selector); #endif diff --git a/Objective-C/objc-runtime-apple.h b/Objective-C/objc-runtime-apple.h index fb15b27..8d050a1 100644 --- a/Objective-C/objc-runtime-apple.h +++ b/Objective-C/objc-runtime-apple.h @@ -24,6 +24,11 @@ #include <objc/objc-runtime.h> #include <objc/Protocol.h> +#include <string.h> +#include <stdlib.h> +#include <assert.h> +#include <ctype.h> + static inline int PyObjCRT_SameSEL(SEL a, SEL b) { @@ -70,8 +75,8 @@ PyObjCRT_ClassAddMethodList(Class cls, struct objc_method_list* lst) } -extern struct objc_method_list* PyObjCRT_AllocMethodList(Py_ssize_t); -extern struct objc_protocol_list* PyObjCRT_AllocProtocolList(Py_ssize_t); +extern struct objc_method_list* PyObjCRT_AllocMethodList(ssize_t); +extern struct objc_protocol_list* PyObjCRT_AllocProtocolList(ssize_t); typedef Method PyObjCRT_Method_t; typedef Ivar PyObjCRT_Ivar_t; diff --git a/Objective-C/objc-runtime-apple.m b/Objective-C/objc-runtime-apple.m index a20713b..2af9b43 100644 --- a/Objective-C/objc-runtime-apple.m +++ b/Objective-C/objc-runtime-apple.m @@ -5,6 +5,7 @@ #include "pyobjc.h" #if defined(APPLE_RUNTIME) +#include "objc-runtime-apple.h" int PyObjCRT_SetupClass( Class cls, @@ -12,12 +13,15 @@ int PyObjCRT_SetupClass( const char*name, Class superCls, Class rootCls, - Py_ssize_t ivarSize, + ssize_t ivarSize, struct objc_ivar_list* ivarList, struct objc_protocol_list* protocolList ) { + /* Preallocate en exception to throw when memory is all used up. */ + static oom_exception = [NSException exceptionWithName: "MLKOutOfMemoryException"] + /* Initialize the structure */ memset(cls, 0, sizeof(*cls)); memset(metaCls, 0, sizeof(*cls)); @@ -117,7 +121,7 @@ void PyObjCRT_ClearClass(Class cls) } } -struct objc_method_list *PyObjCRT_AllocMethodList(Py_ssize_t numMethods) +struct objc_method_list *PyObjCRT_AllocMethodList(ssize_t numMethods) { struct objc_method_list *mlist; @@ -134,7 +138,7 @@ struct objc_method_list *PyObjCRT_AllocMethodList(Py_ssize_t numMethods) return mlist; } -struct objc_protocol_list* PyObjCRT_AllocProtocolList(Py_ssize_t numProtocols) +struct objc_protocol_list* PyObjCRT_AllocProtocolList(ssize_t numProtocols) { struct objc_protocol_list *plist; diff --git a/Objective-C/objc-runtime-gnu.h b/Objective-C/objc-runtime-gnu.h index 644dfde..5c87b6d 100644 --- a/Objective-C/objc-runtime-gnu.h +++ b/Objective-C/objc-runtime-gnu.h @@ -117,8 +117,8 @@ PyObjCRT_InitMethod(Method_t m, SEL name, const char* types, IMP imp) } -extern MethodList_t PyObjCRT_AllocMethodList(Py_ssize_t); -extern struct objc_protocol_list* PyObjCRT_AllocProtocolList(Py_ssize_t); +extern MethodList_t PyObjCRT_AllocMethodList(ssize_t); +extern struct objc_protocol_list* PyObjCRT_AllocProtocolList(ssize_t); typedef Method_t PyObjCRT_Method_t; diff --git a/Objective-C/objc-runtime-gnu.m b/Objective-C/objc-runtime-gnu.m index 0f585e1..df868e4 100644 --- a/Objective-C/objc-runtime-gnu.m +++ b/Objective-C/objc-runtime-gnu.m @@ -8,6 +8,7 @@ #include "pyobjc.h" #if defined(GNU_RUNTIME) +#include "objc-runtime-gnu.h" struct objc_protocol_list* PyObjCRT_AllocProtocolList(int numProtocols) { diff --git a/Objective-C/objc_support.h b/Objective-C/objc_support.h index 6c4028e..a9b4b28 100644 --- a/Objective-C/objc_support.h +++ b/Objective-C/objc_support.h @@ -32,61 +32,14 @@ #endif -/*#F Takes a C value pointed by @var{datum} with its type encoded in - @var{type}, that should be coming from an ObjC @encode directive, - and returns an equivalent Python object where C structures and - arrays are represented as tuples. */ -extern PyObject *pythonify_c_value (const char *type, - void *datum); -extern PyObject *pythonify_c_return_value (const char *type, - void *datum); - -/*#F Takes a Python object @var{arg} and translate it into a C value - pointed by @var{datum} accordingly with the type specification - encoded in @var{type}, that should be coming from an ObjC @encode - directive. - Returns NULL on success, or a static error string describing the - error. */ -extern int depythonify_c_value (const char *type, - PyObject *arg, - void *datum); -extern int depythonify_c_return_value (const char *type, - PyObject *arg, - void *datum); - -extern Py_ssize_t PyObjCRT_SizeOfReturnType(const char* type); -extern Py_ssize_t PyObjCRT_SizeOfType(const char *type); -extern Py_ssize_t PyObjCRT_AlignOfType(const char *type); +extern ssize_t PyObjCRT_SizeOfReturnType(const char* type); +extern ssize_t PyObjCRT_SizeOfType(const char *type); +extern ssize_t PyObjCRT_AlignOfType(const char *type); extern const char *PyObjCRT_SkipTypeSpec (const char *type); extern const char* PyObjCRT_SkipTypeQualifiers (const char* type); -/* - * Compatibility with pyobjc-api.h - */ -static inline id PyObjC_PythonToId(PyObject* value) -{ - id res; - int r; - - r = depythonify_c_value(@encode(id), value, &res); - if (r == -1) { - return NULL; - } else { - return res; - } -} - -static inline PyObject* PyObjC_IdToPython(id value) -{ - PyObject* res; - - res = pythonify_c_value(@encode(id), &value); - return res; -} - - extern int PyObjCRT_SetupClass( - Class, Class, const char*, Class, Class, Py_ssize_t, struct objc_ivar_list*, + Class, Class, const char*, Class, Class, ssize_t, struct objc_ivar_list*, struct objc_protocol_list*); extern void PyObjCRT_ClearClass(Class cls); diff --git a/Objective-C/objc_support.m b/Objective-C/objc_support.m index 5bbd338..862879c 100644 --- a/Objective-C/objc_support.m +++ b/Objective-C/objc_support.m @@ -15,6 +15,9 @@ * Created Tue Sep 10 14:16:02 1996. */ +#include "objc_support.h" +#include "pyobjc.h" + #include <objc/Protocol.h> #include <unistd.h> @@ -36,6 +39,10 @@ #endif /* MACOSX */ +/* Define in order to throw exceptions when a typespec cannot be parsed. */ +#undef STRICT_TYPE_PARSING + + #ifndef MAX static inline ssize_t MAX(ssize_t x, ssize_t y) @@ -169,8 +176,13 @@ PyObjCRT_SkipTypeSpec (const char *type) default: - PyErr_Format(PyObjCExc_InternalError, - "PyObjCRT_SkipTypeSpec: Unhandled type '%#x'", *type); +#ifdef STRICT_TYPE_PARSING + [[NSException exceptionWithName: @"PyObjCRT_SkipTypeSpec" + reason: [NSString stringWithFormat: @"Unhandled type: '%c'", *type] + userInfo: NULL] raise]; +#else + NSLog (@"PyObjCRT_SkipTypeSpec: Unhandled type: '%c'", *type); +#endif return NULL; } @@ -335,8 +347,13 @@ PyObjCRT_AlignOfType (const char *type) return PyObjCRT_AlignOfType(type+1); default: - PyErr_Format(PyObjCExc_InternalError, - "PyObjCRT_AlignOfType: Unhandled type '%#x'", *type); +#ifdef STRICT_TYPE_PARSING + [[NSException exceptionWithName: @"PyObjCRT_SkipTypeSpec" + reason: [NSString stringWithFormat: @"Unhandled type: '%c'", *type] + userInfo: NULL] raise]; +#else + NSLog (@"PyObjCRT_SkipTypeSpec: Unhandled type: '%c'", *type); +#endif return -1; } } @@ -461,51 +478,18 @@ PyObjCRT_SizeOfType (const char *type) return PyObjCRT_SizeOfType(type+1); default: - PyErr_Format(PyObjCExc_InternalError, - "PyObjCRT_SizeOfType: Unhandled type '%#x", *type); +#ifdef STRICT_TYPE_PARSING + [[NSException exceptionWithName: @"PyObjCRT_SkipTypeSpec" + reason: [NSString stringWithFormat: @"Unhandled type: '%c'", *type] + userInfo: NULL] raise]; +#else + NSLog (@"PyObjCRT_SkipTypeSpec: Unhandled type: '%c'", *type); +#endif return -1; } } -/*#F Returns a tuple of objects representing the content of a C array -of type @var{type} pointed by @var{datum}. */ -static PyObject * -pythonify_c_array (const char *type, void *datum) -{ - PyObject *ret; - ssize_t nitems, itemidx, sizeofitem; - unsigned char* curdatum; - - nitems = atoi (type+1); - while (isdigit (*++type)) - ; - sizeofitem = PyObjCRT_SizeOfType (type); - if (sizeofitem == -1) return NULL; - - ret = PyTuple_New (nitems); - if (!ret) return NULL; - - curdatum = datum; - for (itemidx=0; itemidx < nitems; itemidx++) { - PyObject *pyitem = NULL; - - pyitem = pythonify_c_value (type, curdatum); - - if (pyitem) { - PyTuple_SET_ITEM (ret, itemidx, pyitem); - } else { - Py_DECREF(ret); - return NULL; - } - - curdatum += sizeofitem; - } - - return ret; -} - - ssize_t PyObjCRT_SizeOfReturnType(const char* type) { |