[osx/ios] remove unused function
[vuplus_xbmc] / xbmc / interfaces / python / XBPythonDll.cpp
1 /*
2  *      Copyright (C) 2005-2008 Team XBMC
3  *      http://www.xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, write to
17  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18  *  http://www.gnu.org/copyleft/gpl.html
19  *
20  */
21
22 #if (defined HAVE_CONFIG_H) && (!defined WIN32)
23   #include "config.h"
24 #endif
25 #if (defined USE_EXTERNAL_PYTHON)
26   #if (defined HAVE_LIBPYTHON2_6)
27     #include <python2.6/pyconfig.h>
28   #elif (defined HAVE_LIBPYTHON2_5)
29     #include <python2.5/pyconfig.h>
30   #elif (defined HAVE_LIBPYTHON2_4)
31     #include <python2.4/pyconfig.h>
32   #else
33     #error "Could not determine version of Python to use."
34   #endif
35 #else
36   #include "python/Include/pyconfig.h"
37 #endif
38
39 #include "XBPythonDll.h"
40 #include "cores/DllLoader/DllLoader.h"
41
42 // macro to make life a bit simpler
43
44 #define DLL_FUNCTION(function) #function, (void**)&p_##function
45
46 // use these if the dll exports data structs
47 #define DLL_OBJECT_DATA(data) #data, (void**)&pointer_##data
48
49 #define FUNCTION(function) void* (__cdecl* p_##function)();
50
51 extern "C"
52 {
53   /*****************************************
54    * python24.dll
55    */
56
57   FUNCTION(PyEval_ReleaseLock)
58   FUNCTION(PyEval_AcquireLock)
59   FUNCTION(PyThreadState_Get)
60   FUNCTION(PyRun_SimpleString)
61   FUNCTION(PyRun_SimpleStringFlags)
62   FUNCTION(PyRun_SimpleFileExFlags)
63   FUNCTION(PyEval_InitThreads)
64   FUNCTION(PyEval_ThreadsInitialized)
65   FUNCTION(Py_Initialize)
66   FUNCTION(Py_IsInitialized)
67   FUNCTION(Py_Finalize)
68   FUNCTION(Py_NewInterpreter)
69   FUNCTION(Py_EndInterpreter)
70   FUNCTION(PyThreadState_Swap)
71   FUNCTION(PyErr_SetString)
72   FUNCTION(PyRun_File)
73   FUNCTION(PyThreadState_New)
74   FUNCTION(PyErr_Print)
75   FUNCTION(PyErr_Occurred)
76   FUNCTION(PyRun_SimpleFile)
77   FUNCTION(PySys_SetPath)
78   FUNCTION(PyRun_String)
79   FUNCTION(PyImport_AddModule)
80   FUNCTION(PyObject_Str)
81   FUNCTION(PyErr_Fetch)
82   FUNCTION(PyImport_ImportModule)
83 #ifdef _LINUX
84   FUNCTION(Py_GetPath)
85 #endif
86   FUNCTION(PyThreadState_Delete)
87   FUNCTION(PyThreadState_Clear)
88   FUNCTION(Py_BuildValue)
89   FUNCTION(PyArg_Parse)
90   FUNCTION(PyArg_ParseTuple)
91   FUNCTION(PyType_IsSubtype)
92   FUNCTION(PyArg_ParseTupleAndKeywords)
93   FUNCTION(PyString_AsString)
94   FUNCTION(Py_AddPendingCall)
95   FUNCTION(PyList_GetItem)
96   FUNCTION(PyList_Size)
97   FUNCTION(_PyObject_New)
98   FUNCTION(PyLong_AsLong)
99   FUNCTION(PyLong_AsLongLong)
100   FUNCTION(PyErr_Format)
101   FUNCTION(PyList_New)
102   FUNCTION(PyList_Append)
103 #if Py_UNICODE_SIZE == 2
104   FUNCTION(PyUnicodeUCS2_AsUTF8String)
105   FUNCTION(PyUnicodeUCS2_DecodeUTF8)
106 #else
107   FUNCTION(PyUnicodeUCS4_AsUTF8String)
108   FUNCTION(PyUnicodeUCS4_DecodeUTF8)
109 #endif
110   FUNCTION(Py_MakePendingCalls)
111   FUNCTION(PyEval_SaveThread)
112   FUNCTION(PyEval_RestoreThread)
113   FUNCTION(PyLong_FromLong)
114   FUNCTION(PyModule_AddStringConstant)
115   FUNCTION(PyModule_AddObject)
116 #if (defined USE_EXTERNAL_PYTHON) && (!defined HAVE_LIBPYTHON2_4)
117   /* Upstream Python rename Py_InitModule4 for 64-bit systems, for Python
118    versions higher than 2.4 */
119   #if SIZEOF_SIZE_T != SIZEOF_INT
120   FUNCTION(Py_InitModule4_64)
121   #else
122   FUNCTION(Py_InitModule4)
123   #endif
124 #else
125   FUNCTION(Py_InitModule4)
126 #endif
127   FUNCTION(PyInt_AsLong)
128   FUNCTION(PyFloat_AsDouble)
129   FUNCTION(PyString_FromString)
130   FUNCTION(PyBool_FromLong)
131   FUNCTION(PyModule_AddIntConstant)
132   FUNCTION(PyObject_CallFunction) // va arg
133   FUNCTION(PyObject_CallMethod)
134   FUNCTION(PyDict_SetItemString)
135   FUNCTION(PyDict_New)
136   FUNCTION(PyModule_GetDict)
137   FUNCTION(PyImport_Import)
138   FUNCTION(PyInt_FromLong)
139   FUNCTION(PyDict_GetItemString)
140   FUNCTION(PyDict_Next)
141   FUNCTION(PyDict_Size)
142   FUNCTION(PyTuple_New)
143   FUNCTION(PyTuple_SetItem)
144   FUNCTION(PyType_Ready)
145   FUNCTION(PyType_GenericNew)
146   FUNCTION(PySys_SetArgv)
147   FUNCTION(PyObject_RichCompare)
148   FUNCTION(PyFloat_FromDouble)
149   FUNCTION(PyRun_FileExFlags)
150   FUNCTION(PyRun_StringFlags)
151   FUNCTION(PyErr_Clear)
152   FUNCTION(PyErr_ExceptionMatches)
153   FUNCTION(PyObject_SetAttrString)
154
155   DATA_OBJECT(PyExc_SystemExit)
156   DATA_OBJECT(PyExc_SystemError)
157   DATA_OBJECT(PyExc_ValueError)
158   DATA_OBJECT(PyExc_Exception)
159   DATA_OBJECT(PyExc_TypeError)
160   DATA_OBJECT(PyExc_KeyboardInterrupt)
161   DATA_OBJECT(PyExc_RuntimeError)
162   DATA_OBJECT(PyExc_ReferenceError)
163
164   DATA_OBJECT(_Py_NoneStruct)
165   DATA_OBJECT(_Py_NotImplementedStruct)
166   DATA_OBJECT(_Py_TrueStruct)
167   DATA_OBJECT(_Py_ZeroStruct)
168   DATA_OBJECT(PyString_Type)
169   DATA_OBJECT(PyList_Type)
170   DATA_OBJECT(PyLong_Type)
171   DATA_OBJECT(PyInt_Type)
172   DATA_OBJECT(PyUnicode_Type)
173   DATA_OBJECT(PyTuple_Type)
174   DATA_OBJECT(PyDict_Type)
175
176   bool python_load_dll(LibraryLoader& dll)
177   {
178     bool bResult;
179
180     bResult = (
181       dll.ResolveExport(DLL_FUNCTION(PyEval_ReleaseLock)) &&
182       dll.ResolveExport(DLL_FUNCTION(PyEval_AcquireLock)) &&
183       dll.ResolveExport(DLL_FUNCTION(PyThreadState_Get)) &&
184       dll.ResolveExport(DLL_FUNCTION(PyRun_SimpleString)) &&
185       dll.ResolveExport(DLL_FUNCTION(PyRun_SimpleStringFlags)) &&
186       dll.ResolveExport(DLL_FUNCTION(PyRun_SimpleFileExFlags)) &&
187       dll.ResolveExport(DLL_FUNCTION(PyEval_InitThreads)) &&
188       dll.ResolveExport(DLL_FUNCTION(PyEval_ThreadsInitialized)) &&
189       dll.ResolveExport(DLL_FUNCTION(Py_Initialize)) &&
190       dll.ResolveExport(DLL_FUNCTION(Py_IsInitialized)) &&
191       dll.ResolveExport(DLL_FUNCTION(Py_Finalize)) &&
192       dll.ResolveExport(DLL_FUNCTION(Py_NewInterpreter)) &&
193       dll.ResolveExport(DLL_FUNCTION(Py_EndInterpreter)) &&
194       dll.ResolveExport(DLL_FUNCTION(PyThreadState_Swap)) &&
195       dll.ResolveExport(DLL_FUNCTION(PyErr_SetString)) &&
196       dll.ResolveExport(DLL_FUNCTION(PyThreadState_New)) &&
197       dll.ResolveExport(DLL_FUNCTION(PyErr_Print)) &&
198       dll.ResolveExport(DLL_FUNCTION(PyErr_Occurred)) &&
199       dll.ResolveExport(DLL_FUNCTION(PyRun_SimpleFile)) &&
200       dll.ResolveExport(DLL_FUNCTION(PySys_SetPath)) &&
201       dll.ResolveExport(DLL_FUNCTION(PyRun_String)) &&
202       dll.ResolveExport(DLL_FUNCTION(PyImport_AddModule)) &&
203       dll.ResolveExport(DLL_FUNCTION(PyRun_File)) &&
204       dll.ResolveExport(DLL_FUNCTION(PyObject_Str)) &&
205       dll.ResolveExport(DLL_FUNCTION(PyErr_Fetch)) &&
206       dll.ResolveExport(DLL_FUNCTION(PyImport_ImportModule)) &&
207       dll.ResolveExport(DLL_FUNCTION(PyList_New)) &&
208       dll.ResolveExport(DLL_FUNCTION(PyList_Append)) &&         
209 #ifdef _LINUX
210       dll.ResolveExport(DLL_FUNCTION(Py_GetPath)) &&
211 #endif
212       dll.ResolveExport(DLL_FUNCTION(PyThreadState_Delete)) &&
213       dll.ResolveExport(DLL_FUNCTION(PyThreadState_Clear)) &&
214       dll.ResolveExport(DLL_FUNCTION(Py_BuildValue)) &&
215       dll.ResolveExport(DLL_FUNCTION(PyType_IsSubtype)) &&
216       dll.ResolveExport(DLL_FUNCTION(PyArg_ParseTupleAndKeywords)) &&
217       dll.ResolveExport(DLL_FUNCTION(PyString_AsString)) &&
218       dll.ResolveExport(DLL_FUNCTION(Py_AddPendingCall)) &&
219       dll.ResolveExport(DLL_FUNCTION(PyObject_CallMethod)) &&
220       dll.ResolveExport(DLL_FUNCTION(PyList_GetItem)) &&
221       dll.ResolveExport(DLL_FUNCTION(PyList_Size)) &&
222       dll.ResolveExport(DLL_FUNCTION(_PyObject_New)) &&
223       dll.ResolveExport(DLL_FUNCTION(PyLong_AsLong)) &&
224       dll.ResolveExport(DLL_FUNCTION(PyLong_AsLongLong)) &&
225       dll.ResolveExport(DLL_FUNCTION(PyErr_Format)) &&
226 #if Py_UNICODE_SIZE == 2
227       dll.ResolveExport(DLL_FUNCTION(PyUnicodeUCS2_AsUTF8String)) &&
228       dll.ResolveExport(DLL_FUNCTION(PyUnicodeUCS2_DecodeUTF8)) &&
229 #else
230       dll.ResolveExport(DLL_FUNCTION(PyUnicodeUCS4_AsUTF8String)) &&
231       dll.ResolveExport(DLL_FUNCTION(PyUnicodeUCS4_DecodeUTF8)) &&
232 #endif
233       dll.ResolveExport(DLL_FUNCTION(Py_MakePendingCalls)) &&
234       dll.ResolveExport(DLL_FUNCTION(PyEval_SaveThread)) &&
235       dll.ResolveExport(DLL_FUNCTION(PyEval_RestoreThread)) &&
236       dll.ResolveExport(DLL_FUNCTION(PyLong_FromLong)) &&
237       dll.ResolveExport(DLL_FUNCTION(PyModule_AddStringConstant)) &&
238       dll.ResolveExport(DLL_FUNCTION(PyModule_AddObject)) &&
239 #if (defined USE_EXTERNAL_PYTHON) && (!defined HAVE_LIBPYTHON2_4)
240 /* Upstream Python rename Py_InitModule4 for 64-bit systems, for Python versions
241  higher than 2.4 */
242 #if SIZEOF_SIZE_T != SIZEOF_INT
243       dll.ResolveExport(DLL_FUNCTION(Py_InitModule4_64)) &&
244 #else
245       dll.ResolveExport(DLL_FUNCTION(Py_InitModule4)) &&
246 #endif
247 #else
248       dll.ResolveExport(DLL_FUNCTION(Py_InitModule4)) &&
249 #endif
250       dll.ResolveExport(DLL_FUNCTION(PyInt_AsLong)) &&
251       dll.ResolveExport(DLL_FUNCTION(PyFloat_AsDouble)) &&
252       dll.ResolveExport(DLL_FUNCTION(PyString_FromString)) &&
253       dll.ResolveExport(DLL_FUNCTION(PyBool_FromLong)) &&
254       dll.ResolveExport(DLL_FUNCTION(PyModule_AddIntConstant)) &&
255       dll.ResolveExport(DLL_FUNCTION(PyObject_CallFunction)) &&
256       dll.ResolveExport(DLL_FUNCTION(PyDict_SetItemString)) &&
257       dll.ResolveExport(DLL_FUNCTION(PyDict_New)) &&
258       dll.ResolveExport(DLL_FUNCTION(PyModule_GetDict)) &&
259       dll.ResolveExport(DLL_FUNCTION(PyImport_Import)) &&
260       dll.ResolveExport(DLL_FUNCTION(PyFloat_FromDouble)) &&
261       dll.ResolveExport(DLL_FUNCTION(PyInt_FromLong)) &&
262       dll.ResolveExport(DLL_FUNCTION(PyDict_GetItemString)) &&
263       //dll.ResolveExport(DLL_FUNCTION(PyDict_GetItem)) &&
264       //dll.ResolveExport(DLL_FUNCTION(PyDict_Keys)) &&
265       dll.ResolveExport(DLL_FUNCTION(PyDict_Next)) &&
266       dll.ResolveExport(DLL_FUNCTION(PyDict_Size)) &&
267       dll.ResolveExport(DLL_FUNCTION(PyTuple_New)) &&
268       dll.ResolveExport(DLL_FUNCTION(PyTuple_SetItem)) &&
269       dll.ResolveExport(DLL_FUNCTION(PyType_Ready)) &&
270       dll.ResolveExport(DLL_FUNCTION(PyType_GenericNew)) &&
271       dll.ResolveExport(DLL_FUNCTION(PyArg_Parse)) &&
272       dll.ResolveExport(DLL_FUNCTION(PyArg_ParseTuple)) &&
273       dll.ResolveExport(DLL_FUNCTION(PySys_SetArgv)) &&
274       dll.ResolveExport(DLL_FUNCTION(PyObject_RichCompare)) &&
275       dll.ResolveExport(DLL_FUNCTION(PyRun_FileExFlags)) &&
276       dll.ResolveExport(DLL_FUNCTION(PyRun_StringFlags)) &&
277       dll.ResolveExport(DLL_FUNCTION(PyErr_Clear)) &&
278       dll.ResolveExport(DLL_FUNCTION(PyObject_SetAttrString)) &&
279       dll.ResolveExport(DLL_FUNCTION(PyErr_ExceptionMatches)) &&
280
281       dll.ResolveExport(DLL_OBJECT_DATA(PyExc_SystemExit)) &&
282       dll.ResolveExport(DLL_OBJECT_DATA(PyExc_SystemError)) &&
283       dll.ResolveExport(DLL_OBJECT_DATA(PyExc_ValueError)) &&
284       dll.ResolveExport(DLL_OBJECT_DATA(PyExc_Exception)) &&
285       dll.ResolveExport(DLL_OBJECT_DATA(PyExc_TypeError)) &&
286       dll.ResolveExport(DLL_OBJECT_DATA(PyExc_KeyboardInterrupt)) &&
287       dll.ResolveExport(DLL_OBJECT_DATA(PyExc_RuntimeError)) &&
288       dll.ResolveExport(DLL_OBJECT_DATA(PyExc_ReferenceError)) &&
289
290       dll.ResolveExport(DLL_OBJECT_DATA(_Py_NoneStruct)) &&
291       dll.ResolveExport(DLL_OBJECT_DATA(_Py_NotImplementedStruct)) &&
292       dll.ResolveExport(DLL_OBJECT_DATA(_Py_TrueStruct)) &&
293       dll.ResolveExport(DLL_OBJECT_DATA(_Py_ZeroStruct)) &&
294       dll.ResolveExport(DLL_OBJECT_DATA(PyString_Type)) &&
295       dll.ResolveExport(DLL_OBJECT_DATA(PyList_Type)) &&
296       dll.ResolveExport(DLL_OBJECT_DATA(PyLong_Type)) &&
297       dll.ResolveExport(DLL_OBJECT_DATA(PyInt_Type)) &&
298       dll.ResolveExport(DLL_OBJECT_DATA(PyUnicode_Type)) &&
299       dll.ResolveExport(DLL_OBJECT_DATA(PyTuple_Type)) &&
300       dll.ResolveExport(DLL_OBJECT_DATA(PyDict_Type)));
301
302     return bResult;
303   }
304 }