|
From: Andre R. <and...@us...> - 2004-11-24 03:34:24
|
Update of /cvsroot/frontierkernel/Frontier/Common/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20768/Common/source Modified Files: Tag: sidewinder-branch langpython.c Log Message: Added support for dynamic loading of Python.framework at runtime on Mac OS X. Index: langpython.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/langpython.c,v retrieving revision 1.2.4.11 retrieving revision 1.2.4.12 diff -C2 -d -r1.2.4.11 -r1.2.4.12 *** langpython.c 24 Nov 2004 02:05:06 -0000 1.2.4.11 --- langpython.c 24 Nov 2004 03:34:01 -0000 1.2.4.12 *************** *** 61,64 **** --- 61,68 ---- //#endif + #ifdef MACVERSION + #include "CallMachOFrameWork.h" + #endif + #ifdef FRONTIER_PYTHON *************** *** 82,86 **** ! #ifdef WIN95VERSION /* --- 86,90 ---- ! #if defined(WIN95VERSION) /* || (defined(MACVERSION) && defined(TARGET_RT_MAC_MACHO)) */ /* *************** *** 98,106 **** */ static struct { ! HMODULE hmodule; /*handle to DLL if it was loaded and all symbols were found*/ PyObject * (*ptr_PyObject_CallMethod) (PyObject *, char *, char *, ...); /*abstract.h*/ --- 102,119 ---- */ + #if defined(WIN95VERSION) + + typedef HMODULE typythonlib; + + #elif defined(MACVERSION) + + typedef CFBundleRef typythonlib; + + #endif static struct { ! typythonlib hmodule; /*handle to python library if it was loaded and all symbols were found*/ PyObject * (*ptr_PyObject_CallMethod) (PyObject *, char *, char *, ...); /*abstract.h*/ *************** *** 121,124 **** --- 134,139 ---- int (*ptr_PyDict_SetItemString) (PyObject *, const char *, PyObject *); + PyTypeObject * ptr_PyFile_Type; /*fileobject.h*/ + PyTypeObject * ptr_PyFloat_Type; /*floatobject.h*/ double (*ptr_PyFloat_AsDouble) (PyObject *); *************** *** 127,131 **** long (*ptr_PyInt_AsLong) (PyObject *); ! int (*ptr_PyList_Append) (PyObject *, PyObject *); /*listobject.h*/ PyObject * (*ptr_PyList_GetItem) (PyObject *, int); int (*ptr_PyList_SetItem) (PyObject *, int, PyObject *); --- 142,149 ---- long (*ptr_PyInt_AsLong) (PyObject *); ! PyTypeObject * ptr_PySeqIter_Type; /*iterobject.h*/ ! ! PyTypeObject * ptr_PyList_Type; /*listobject.h*/ ! int (*ptr_PyList_Append) (PyObject *, PyObject *); PyObject * (*ptr_PyList_GetItem) (PyObject *, int); int (*ptr_PyList_SetItem) (PyObject *, int, PyObject *); *************** *** 135,140 **** PyTypeObject * ptr_PyLong_Type; /*longobject.h*/ ! PyObject * (*ptr_Py_FindMethod) (PyMethodDef[], PyObject *, char *); /*methodobject.h*/ PyObject * (*ptr_Py_BuildValue) (char *, ...); /*modsupport.h*/ PyObject * (*ptr_Py_InitModule4) (char *, PyMethodDef *, char *, PyObject *, int); --- 153,161 ---- PyTypeObject * ptr_PyLong_Type; /*longobject.h*/ ! PyTypeObject * ptr_PyMethod_Type; /*methodobject.h*/ ! PyObject * (*ptr_Py_FindMethod) (PyMethodDef[], PyObject *, char *); + PyTypeObject * ptr_PyModule_Type; /*moduleobject.h*/ + PyObject * (*ptr_Py_BuildValue) (char *, ...); /*modsupport.h*/ PyObject * (*ptr_Py_InitModule4) (char *, PyMethodDef *, char *, PyObject *, int); *************** *** 143,146 **** --- 164,168 ---- PyObject * ptr__Py_NoneStruct; /*object.h*/ + PyTypeObject * ptr_PyType_Type; PyObject * (*ptr_PyObject_GetAttrString) (PyObject *, char *); PyObject * (*ptr_PyObject_Str) (PyObject *); *************** *** 174,180 **** --- 196,206 ---- PyObject * (*ptr_PyRun_String) (const char *, int, PyObject *, PyObject *); + PyTypeObject * ptr_PySlice_Type; /*sliceobject.h*/ + PyTypeObject * ptr_PyString_Type; /*stringobject.h*/ char * (*ptr_PyString_AsString) (PyObject *); PyObject * (*ptr_PyString_FromString) (const char *); + + PyTypeObject * ptr_PyTuple_Type; /*tupleobject.h*/ } py; *************** *** 197,200 **** --- 223,228 ---- #define PyDict_SetItemString (*py.ptr_PyDict_SetItemString) + #define PyFile_Type (*py.ptr_PyFile_Type) + #define PyFloat_Type (*py.ptr_PyFloat_Type) #define PyFloat_AsDouble (*py.ptr_PyFloat_AsDouble) *************** *** 203,206 **** --- 231,237 ---- #define PyInt_AsLong (*py.ptr_PyInt_AsLong) + #define PySeqIter_Type (*py.ptr_PySeqIter_Type) + + #define PyList_Type (*py.ptr_PyList_Type) #define PyList_Append (*py.ptr_PyList_Append) #define PyList_GetItem (*py.ptr_PyList_GetItem) *************** *** 211,216 **** --- 242,250 ---- #define PyLong_Type (*py.ptr_PyLong_Type) + #define PyMethod_Type (*py.ptr_PyMethod_Type) #define Py_FindMethod (*py.ptr_Py_FindMethod) + #define PyModule_Type (*py.ptr_PyModule_Type) + #define Py_BuildValue (*py.ptr_Py_BuildValue) #define Py_InitModule4 (*py.ptr_Py_InitModule4) *************** *** 219,222 **** --- 253,257 ---- #define _Py_NoneStruct (*py.ptr__Py_NoneStruct) + #define PyType_Type (*py.ptr_PyType_Type) #define PyObject_GetAttrString (*py.ptr_PyObject_GetAttrString) #define PyObject_Str (*py.ptr_PyObject_Str) *************** *** 250,258 **** --- 285,297 ---- #define PyRun_String (*py.ptr_PyRun_String) + #define PySlice_Type (*py.ptr_PySlice_Type) #define PyString_Type (*py.ptr_PyString_Type) #define PyString_AsString (*py.ptr_PyString_AsString) #define PyString_FromString (*py.ptr_PyString_FromString) + #define PyTuple_Type (*py.ptr_PyTuple_Type) + #if defined(WIN95VERSION) + static boolean importsymbol (HMODULE hm, LPCSTR symbol, void **ptraddress) { *************** *** 262,272 **** } /*importsymbol*/ static boolean loadpythonlib (void) { ! HMODULE hm; boolean fl = true; hm = LoadLibraryEx("python23.dll", NULL, 0); if (hm == NULL) --- 301,331 ---- } /*importsymbol*/ + #elif defined(MACVERSION) + + static boolean importsymbol (CFBundleRef hm, char *symbol, void **ptraddress) { + + CFStringRef symbolref; + + symbolref = CFStringCreateWithCString (kCFAllocatorSystemDefault, symbol, kCFStringEncodingMacRoman); + + *ptraddress = (void*) CFBundleGetFunctionPointerForName (hm, symbolref); + + CFRelease (symbolref); + + return (*ptraddress != NULL); + } /*importsymbol*/ + + #endif static boolean loadpythonlib (void) { ! typythonlib hm = NULL; boolean fl = true; + #if defined(WIN95VERSION) hm = LoadLibraryEx("python23.dll", NULL, 0); + #elif defined(MACVERSION) + LoadFrameworkBundle (CFSTR ("Python.framework"), &hm); + #endif if (hm == NULL) *************** *** 347,354 **** fl = fl && importsymbol (hm, "PyString_FromString", (void**) &py.ptr_PyString_FromString); ! if (fl) py.hmodule = hm; /*success!*/ ! else FreeLibrary (hm); return (fl); --- 406,421 ---- fl = fl && importsymbol (hm, "PyString_FromString", (void**) &py.ptr_PyString_FromString); ! if (fl) { ! py.hmodule = hm; /*success!*/ ! } ! else { ! ! #if defined(WIN95VERSION) FreeLibrary (hm); + #elif defined(MACVERSION) + CFRelease (hm); + #endif + } return (fl); *************** *** 356,365 **** ! static void freepythonlib () { if (py.hmodule != NULL) { FreeLibrary (py.hmodule); ! py.hmodule = NULL; } --- 423,437 ---- ! #if 0 ! ! static void freepythonlib (void) { if (py.hmodule != NULL) { + #if defined(WIN95VERSION) FreeLibrary (py.hmodule); ! #elif defined(MACVERSION) ! CFRelease (py.hmodule); ! #endif py.hmodule = NULL; } *************** *** 367,372 **** } /*freepythonlib*/ ! #endif /*WIN95VERSION*/ --- 439,458 ---- } /*freepythonlib*/ + #endif ! ! #else ! ! /*linking at build time*/ ! ! static boolean loadpythonlib (void) { ! return (true); ! } /*loadpythonlib*/ ! ! //static void freepythonlib (void) { ! // return; ! // } /*freepythonlib*/ ! ! #endif *************** *** 1518,1526 **** boolean pythoninitverbs (void) { ! #ifdef WIN95VERSION ! loadpythonlib (); ! #endif ! ! return (loadfunctionprocessor (idpythonverbs, &pythonfunctionvalue)); } --- 1604,1611 ---- boolean pythoninitverbs (void) { ! if (loadpythonlib ()) ! return (loadfunctionprocessor (idpythonverbs, &pythonfunctionvalue)); ! ! return (true); } |