From d0dd29fcf87b51280dd5c2685063ea42cf4fc115 Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Sat, 15 Sep 2007 14:03:32 +0200 Subject: Make the code copied from PyObjC compilable stand-alone. darcs-hash:6a1f1865b6259fc5a7551ffb10494f914359ecc6 --- Objective-C/objc_support.m | 72 ++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 44 deletions(-) (limited to 'Objective-C/objc_support.m') 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 #include @@ -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) { -- cgit v1.2.3