1/* 2 * Helper methods opaque-pointer tests (objc.test.test_opaque) 3 */ 4#include "Python.h" 5#include "pyobjc-api.h" 6#include <stdarg.h> 7 8#import <Foundation/Foundation.h> 9 10static PyObject* 11make_opaque_capsule(PyObject* mod __attribute__((__unused__))) 12{ 13 return PyCapsule_New((void*)1234, "objc.__opaque__", NULL); 14} 15 16static PyObject* 17make_object_capsule(PyObject* mod __attribute__((__unused__))) 18{ 19 NSObject* object = [[[NSObject alloc] init] autorelease]; 20 return PyCapsule_New(object, "objc.__object__", NULL); 21} 22 23 24static PyMethodDef mod_methods[] = { 25 { 26 "opaque_capsule", 27 (PyCFunction)make_opaque_capsule, 28 METH_NOARGS, 29 0, 30 }, 31 { 32 "object_capsule", 33 (PyCFunction)make_object_capsule, 34 METH_NOARGS, 35 0, 36 }, 37 { 0, 0, 0, 0 } 38}; 39 40#if PY_VERSION_HEX >= 0x03000000 41 42static struct PyModuleDef mod_module = { 43 PyModuleDef_HEAD_INIT, 44 "pointersupport", 45 NULL, 46 0, 47 mod_methods, 48 NULL, 49 NULL, 50 NULL, 51 NULL 52}; 53 54#define INITERROR() return NULL 55#define INITDONE() return m 56 57PyObject* PyInit_pointersupport(void); 58 59PyObject* 60PyInit_pointersupport(void) 61 62#else 63 64#define INITERROR() return 65#define INITDONE() return 66 67void initpointersupport(void); 68 69void 70initpointersupport(void) 71#endif 72{ 73 PyObject* m; 74 75#if PY_VERSION_HEX >= 0x03000000 76 m = PyModule_Create(&mod_module); 77#else 78 m = Py_InitModule4("pointersupport", mod_methods, 79 NULL, NULL, PYTHON_API_VERSION); 80#endif 81 if (!m) { 82 INITERROR(); 83 } 84 85 if (PyObjC_ImportAPI(m) < 0) { 86 INITERROR(); 87 } 88 89 INITDONE(); 90} 91