1/* 2 * This module is used in the unittests for object identity. 3 */ 4#include "Python.h" 5#include "pyobjc-api.h" 6 7#import <Foundation/Foundation.h> 8 9@interface ClassWithVariables : NSObject 10{ 11 int intValue; 12 double floatValue; 13 char charValue; 14 char* strValue; 15 NSRect rectValue; 16 NSObject* nilValue; 17 PyObject* pyValue; 18 NSString* objValue; 19} 20-init; 21-(void)dealloc; 22@end 23 24@implementation ClassWithVariables 25-init 26{ 27 self = [super init]; 28 if (self == nil) return nil; 29 30 intValue = 42; 31 floatValue = -10.055; 32 charValue = 'a'; 33 strValue = "hello world"; 34 rectValue = NSMakeRect(1,2,3,4); 35 nilValue = nil; 36 pyValue = PySlice_New( 37 PyLong_FromLong(1), 38 PyLong_FromLong(10), 39 PyLong_FromLong(4)); 40 objValue = [[NSObject alloc] init]; 41 return self; 42} 43 44-(void)dealloc 45{ 46 Py_XDECREF(pyValue); 47 [objValue release]; 48 [nilValue release]; 49 [super dealloc]; 50} 51 52@end 53 54 55static PyMethodDef mod_methods[] = { 56 { 0, 0, 0, 0 } 57}; 58 59#if PY_VERSION_HEX >= 0x03000000 60 61static struct PyModuleDef mod_module = { 62 PyModuleDef_HEAD_INIT, 63 "instanceVariables", 64 NULL, 65 0, 66 mod_methods, 67 NULL, 68 NULL, 69 NULL, 70 NULL 71}; 72 73#define INITERROR() return NULL 74#define INITDONE() return m 75 76PyObject* PyInit_instanceVariables(void); 77 78PyObject* 79PyInit_instanceVariables(void) 80 81#else 82 83#define INITERROR() return 84#define INITDONE() return 85 86void initinstanceVariables(void); 87 88void 89initinstanceVariables(void) 90#endif 91{ 92 PyObject* m; 93 94#if PY_VERSION_HEX >= 0x03000000 95 m = PyModule_Create(&mod_module); 96#else 97 m = Py_InitModule4("instanceVariables", mod_methods, 98 NULL, NULL, PYTHON_API_VERSION); 99#endif 100 if (!m) { 101 INITERROR(); 102 } 103 104 if (PyObjC_ImportAPI(m) < 0) { 105 INITERROR(); 106 } 107 if (PyModule_AddObject(m, "ClassWithVariables", 108 PyObjCClass_New([ClassWithVariables class])) < 0) { 109 INITERROR(); 110 } 111 INITDONE(); 112} 113