1#include <Python.h> 2#include "pyobjc-api.h" 3 4#import <Foundation/Foundation.h> 5 6@interface OCTestNULL : NSObject {} 7-(int)callList:(NSMutableArray*)list andInOut:(int*)pval; 8-(int)callList:(NSMutableArray*)list andInOut2:(int*)pval; 9-(int)callList:(NSMutableArray*)list andIn:(int*)pval; 10-(int)callList:(NSMutableArray*)list andOut:(int*)pval; 11-(void)callOut:(int*)pval; 12@end 13 14@implementation OCTestNULL 15 16-(int)callList:(NSMutableArray*)list andInOut:(int*)pval 17{ 18 if (pval == NULL) { 19 [list addObject: @"NULL"]; 20 } else { 21 [list addObject: [NSString stringWithFormat:@"%d", *pval]]; 22 *pval = *pval / 2; 23 } 24 return 12; 25} 26 27/* This is the same implementation as callList:andInOut:, the python code 28 * uses a different type string for this one. 29 */ 30-(int)callList:(NSMutableArray*)list andInOut2:(int*)pval 31{ 32 if (pval == NULL) { 33 [list addObject: @"NULL"]; 34 } else { 35 [list addObject: [NSString stringWithFormat:@"%d", *pval]]; 36 *pval = *pval / 2; 37 } 38 return 12; 39} 40 41-(int)callList:(NSMutableArray*)list andIn:(int*)pval 42{ 43 if (pval == NULL) { 44 [list addObject: @"NULL"]; 45 } else { 46 [list addObject: [NSString stringWithFormat:@"%d", *pval]]; 47 } 48 return 24; 49} 50 51-(int)callList:(NSMutableArray*)list andOut:(int*)pval 52{ 53 if (pval == NULL) { 54 [list addObject: @"NULL"]; 55 } else { 56 [list addObject: @"POINTER"]; 57 *pval = 99; 58 } 59 60 return 24; 61} 62 63-(int)on:(OCTestNULL*)object callList:(NSMutableArray*)list andInOut:(int*)pval 64{ 65 return [object callList:list andInOut:pval]; 66} 67 68-(int)on:(OCTestNULL*)object callList:(NSMutableArray*)list andIn:(int*)pval 69{ 70 return [object callList:list andIn:pval]; 71} 72 73-(int)on:(OCTestNULL*)object callList:(NSMutableArray*)list andOut:(int*)pval 74{ 75 return [object callList:list andOut:pval]; 76} 77 78-(void)callOut:(int*)pval 79{ 80 *pval = 144; 81} 82 83-(void)on:(OCTestNULL*)object callOut:(int*)pval 84{ 85 [object callOut:pval]; 86} 87 88@end 89 90 91static PyMethodDef mod_methods[] = { 92 { 0, 0, 0, 0 } 93}; 94 95#if PY_VERSION_HEX >= 0x03000000 96 97static struct PyModuleDef mod_module = { 98 PyModuleDef_HEAD_INIT, 99 "NULL", 100 NULL, 101 0, 102 mod_methods, 103 NULL, 104 NULL, 105 NULL, 106 NULL 107}; 108 109#define INITERROR() return NULL 110#define INITDONE() return m 111 112PyObject* PyInit_NULL(void); 113 114PyObject* 115PyInit_NULL(void) 116 117#else 118 119#define INITERROR() return 120#define INITDONE() return 121 122void initNULL(void); 123 124void 125initNULL(void) 126#endif 127{ 128 PyObject* m; 129 130#if PY_VERSION_HEX >= 0x03000000 131 m = PyModule_Create(&mod_module); 132#else 133 m = Py_InitModule4("NULL", mod_methods, 134 NULL, NULL, PYTHON_API_VERSION); 135#endif 136 if (!m) { 137 INITERROR(); 138 } 139 140 if (PyObjC_ImportAPI(m) < 0) { 141 INITERROR(); 142 } 143 144 if (PyModule_AddObject(m, "OCTestNULL", 145 PyObjCClass_New([OCTestNULL class])) < 0) { 146 INITERROR(); 147 } 148 149 INITDONE(); 150} 151