1/* 2 */ 3#include "Python.h" 4#include "pyobjc-api.h" 5 6#import <Cocoa/Cocoa.h> 7 8@interface StructArgClass : NSObject 9{ 10} 11-(NSString*)compP:(NSPoint)aPoint aRect:(NSRect)aRect anOp:(int)op; 12-(size_t)stackPtr; 13-(NSRect)someRect; 14-(NSRect)someRectWithRect:(NSRect)rect; 15-(NSRect)someRectWithX:(int)x Y:(int)y H:(int)h W:(int)w; 16-(NSRect)someRectWithObject:(StructArgClass*)o X:(int)x Y:(int)y H:(int)h W:(int)w; 17@end 18 19@implementation StructArgClass 20-(NSRect)someRectWithRect:(NSRect)rect 21{ 22 return rect; 23} 24 25-(NSRect)someRectWithX:(int)x Y:(int)y H:(int)h W:(int)w 26{ 27 return NSMakeRect(x, y, h, w); 28} 29 30-(NSRect)someRectWithObject:(StructArgClass*)o X:(int)x Y:(int)y H:(int)h W:(int)w 31{ 32 return [o someRectWithRect:NSMakeRect(x, y, h, w)]; 33} 34 35-(NSRect)someRect 36{ 37 NSRect retval = NSMakeRect(1,2,3,4); 38 return retval; 39} 40 41 42-(NSString*)compP:(NSPoint)aPoint aRect:(NSRect)aRect anOp:(int)op 43{ 44 return [NSString stringWithFormat:@"aP:%@ aR:%@ anO:%d", 45 NSStringFromPoint(aPoint), 46 NSStringFromRect(aRect), 47 op]; 48} 49 50static size_t ident(size_t v) 51{ 52 return v; 53} 54-(size_t)stackPtr 55{ 56 char c; 57 58 return ident(((size_t)&c)+1); 59} 60@end 61 62static PyMethodDef mod_methods[] = { 63 { 0, 0, 0, 0 } 64}; 65 66#if PY_VERSION_HEX >= 0x03000000 67 68static struct PyModuleDef mod_module = { 69 PyModuleDef_HEAD_INIT, 70 "structargs", 71 NULL, 72 0, 73 mod_methods, 74 NULL, 75 NULL, 76 NULL, 77 NULL 78}; 79 80#define INITERROR() return NULL 81#define INITDONE() return m 82 83PyObject* PyInit_structargs(void); 84 85PyObject* 86PyInit_structargs(void) 87 88#else 89 90#define INITERROR() return 91#define INITDONE() return 92 93void initstructargs(void); 94 95void 96initstructargs(void) 97#endif 98{ 99 PyObject* m; 100 101#if PY_VERSION_HEX >= 0x03000000 102 m = PyModule_Create(&mod_module); 103#else 104 m = Py_InitModule4("structargs", mod_methods, 105 NULL, NULL, PYTHON_API_VERSION); 106#endif 107 if (!m) { 108 INITERROR(); 109 } 110 111 if (PyObjC_ImportAPI(m) < 0) { 112 INITERROR(); 113 } 114 115 if (PyModule_AddObject(m, "StructArgClass", 116 PyObjCClass_New([StructArgClass class])) < 0) { 117 INITERROR(); 118 } 119 120 INITDONE(); 121} 122 123 124 125