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 OC_TestFilePointer : NSObject 10{ 11} 12 13-(FILE*)openFile:(char*)path withMode:(char*)mode; 14-(NSString*)readline:(FILE*)fp; 15@end 16 17@implementation OC_TestFilePointer 18-(FILE*)openFile:(char*)path withMode:(char*)mode 19{ 20 return fopen(path, mode); 21} 22 23-(NSString*)readline:(FILE*)fp 24{ 25 char buf[1024]; 26 27 return [NSString stringWithCString: fgets(buf, sizeof(buf), fp) 28 encoding:NSASCIIStringEncoding]; 29} 30@end 31 32static PyMethodDef mod_methods[] = { 33 { 0, 0, 0, 0 } 34}; 35 36#if PY_VERSION_HEX >= 0x03000000 37 38static struct PyModuleDef mod_module = { 39 PyModuleDef_HEAD_INIT, 40 "filepointer", 41 NULL, 42 0, 43 mod_methods, 44 NULL, 45 NULL, 46 NULL, 47 NULL 48}; 49 50#define INITERROR() return NULL 51#define INITDONE() return m 52 53PyObject* PyInit_filepointer(void); 54 55PyObject* 56PyInit_filepointer(void) 57 58#else 59 60#define INITERROR() return 61#define INITDONE() return 62 63void initfilepointer(void); 64 65void 66initfilepointer(void) 67#endif 68{ 69 PyObject* m; 70 71#if PY_VERSION_HEX >= 0x03000000 72 m = PyModule_Create(&mod_module); 73#else 74 m = Py_InitModule4("filepointer", mod_methods, 75 NULL, NULL, PYTHON_API_VERSION); 76#endif 77 if (!m) { 78 INITERROR(); 79 } 80 81 if (PyObjC_ImportAPI(m) < 0) { 82 INITERROR(); 83 } 84 85 if (PyModule_AddObject(m, "OC_TestFilePointer", 86 PyObjCClass_New([OC_TestFilePointer class])) < 0) { 87 INITERROR(); 88 } 89 90 INITDONE(); 91} 92