- Add upstream patches to fix build with python 3.7: * get-rid-of-private-function-_PyImport_FixupBuiltin-for-__FreeCADBase__-module.patch * get-rid-of-private-function-_PyImport_FixupBuiltin-for-FreeCAD-and-FreeCADGui-modules.patch I haven't actually tested it with python 3.7 (it builds fine though), but it still works with 3.6.5 on my Leap 15.0 system. OBS-URL: https://build.opensuse.org/request/show/670582 OBS-URL: https://build.opensuse.org/package/show/science/FreeCAD?expand=0&rev=55
122 lines
4.5 KiB
Diff
122 lines
4.5 KiB
Diff
From b79e1bfee45d003e5ba646d828faca5d673f3e9b Mon Sep 17 00:00:00 2001
|
|
From: wmayer <wmayer@users.sourceforge.net>
|
|
Date: Sat, 1 Sep 2018 19:57:15 +0200
|
|
Subject: [PATCH] get rid of private function _PyImport_FixupBuiltin for
|
|
FreeCAD and FreeCADGui modules
|
|
|
|
---
|
|
src/App/Application.cpp | 38 ++++++++++++++++++++++++++++++--------
|
|
src/Gui/Application.cpp | 6 ++++--
|
|
src/Main/MainPy.cpp | 4 +++-
|
|
3 files changed, 37 insertions(+), 11 deletions(-)
|
|
|
|
diff --git a/src/App/Application.cpp b/src/App/Application.cpp
|
|
index 82270e3eea0..0895a8c83ac 100644
|
|
--- a/src/App/Application.cpp
|
|
+++ b/src/App/Application.cpp
|
|
@@ -226,6 +226,21 @@ init_freecad_base_module(void)
|
|
};
|
|
return PyModule_Create(&BaseModuleDef);
|
|
}
|
|
+
|
|
+// Set in inside Application
|
|
+static PyMethodDef* __AppMethods = nullptr;
|
|
+
|
|
+PyMODINIT_FUNC
|
|
+init_freecad_module(void)
|
|
+{
|
|
+ static struct PyModuleDef FreeCADModuleDef = {
|
|
+ PyModuleDef_HEAD_INIT,
|
|
+ "FreeCAD", FreeCAD_doc, -1,
|
|
+ __AppMethods,
|
|
+ NULL, NULL, NULL, NULL
|
|
+ };
|
|
+ return PyModule_Create(&FreeCADModuleDef);
|
|
+}
|
|
#endif
|
|
|
|
Application::Application(std::map<std::string,std::string> &mConfig)
|
|
@@ -239,14 +254,15 @@ Application::Application(std::map<std::string,std::string> &mConfig)
|
|
// setting up Python binding
|
|
Base::PyGILStateLocker lock;
|
|
#if PY_MAJOR_VERSION >= 3
|
|
- static struct PyModuleDef FreeCADModuleDef = {
|
|
- PyModuleDef_HEAD_INIT,
|
|
- "FreeCAD", FreeCAD_doc, -1,
|
|
- Application::Methods,
|
|
- NULL, NULL, NULL, NULL
|
|
- };
|
|
- PyObject* pAppModule = PyModule_Create(&FreeCADModuleDef);
|
|
- _PyImport_FixupBuiltin(pAppModule, "FreeCAD");
|
|
+ PyObject* modules = PyImport_GetModuleDict();
|
|
+
|
|
+ __AppMethods = Application::Methods;
|
|
+ PyObject* pAppModule = PyImport_ImportModule ("FreeCAD");
|
|
+ if (!pAppModule) {
|
|
+ PyErr_Clear();
|
|
+ pAppModule = init_freecad_module();
|
|
+ PyDict_SetItemString(modules, "FreeCAD", pAppModule);
|
|
+ }
|
|
#else
|
|
PyObject* pAppModule = Py_InitModule3("FreeCAD", Application::Methods, FreeCAD_doc);
|
|
#endif
|
|
@@ -282,6 +298,11 @@ Application::Application(std::map<std::string,std::string> &mConfig)
|
|
|
|
#if PY_MAJOR_VERSION >= 3
|
|
PyObject* pBaseModule = PyImport_ImportModule ("__FreeCADBase__");
|
|
+ if (!pBaseModule) {
|
|
+ PyErr_Clear();
|
|
+ pBaseModule = init_freecad_base_module();
|
|
+ PyDict_SetItemString(modules, "__FreeCADBase__", pBaseModule);
|
|
+ }
|
|
#else
|
|
PyObject* pBaseModule = Py_InitModule3("__FreeCADBase__", NULL, Base_doc);
|
|
#endif
|
|
@@ -1427,6 +1448,7 @@ void Application::initConfig(int argc, char ** argv)
|
|
|
|
// init python
|
|
#if PY_MAJOR_VERSION >= 3
|
|
+ PyImport_AppendInittab ("FreeCAD", init_freecad_module);
|
|
PyImport_AppendInittab ("__FreeCADBase__", init_freecad_base_module);
|
|
#endif
|
|
mConfig["PythonSearchPath"] = Interpreter().init(argc,argv);
|
|
diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp
|
|
index 33ddde2b4c6..8715c8d6e52 100644
|
|
--- a/src/Gui/Application.cpp
|
|
+++ b/src/Gui/Application.cpp
|
|
@@ -345,7 +345,8 @@ Application::Application(bool GUIenabled)
|
|
#if PY_MAJOR_VERSION >= 3
|
|
// if this returns a valid pointer then the 'FreeCADGui' Python module was loaded,
|
|
// otherwise the executable was launched
|
|
- PyObject *module = PyImport_AddModule("FreeCADGui");
|
|
+ PyObject* modules = PyImport_GetModuleDict();
|
|
+ PyObject* module = PyDict_GetItemString(modules, "FreeCADGui");
|
|
if (!module) {
|
|
static struct PyModuleDef FreeCADGuiModuleDef = {
|
|
PyModuleDef_HEAD_INIT,
|
|
@@ -354,7 +355,8 @@ Application::Application(bool GUIenabled)
|
|
NULL, NULL, NULL, NULL
|
|
};
|
|
module = PyModule_Create(&FreeCADGuiModuleDef);
|
|
- _PyImport_FixupBuiltin(module, "FreeCADGui");
|
|
+
|
|
+ PyDict_SetItemString(modules, "FreeCADGui", module);
|
|
}
|
|
else {
|
|
// extend the method list
|
|
diff --git a/src/Main/MainPy.cpp b/src/Main/MainPy.cpp
|
|
index 061740903c0..58b86fa7991 100644
|
|
--- a/src/Main/MainPy.cpp
|
|
+++ b/src/Main/MainPy.cpp
|
|
@@ -225,7 +225,9 @@ PyMOD_INIT_FUNC(FreeCAD)
|
|
free(argv);
|
|
|
|
#if PY_MAJOR_VERSION >= 3
|
|
- PyObject* module = _PyImport_FindBuiltin("FreeCAD");
|
|
+ //PyObject* module = _PyImport_FindBuiltin("FreeCAD");
|
|
+ PyObject* modules = PyImport_GetModuleDict();
|
|
+ PyObject* module = PyDict_GetItemString(modules, "FreeCAD");
|
|
if (!module) {
|
|
PyErr_SetString(PyExc_ImportError, "Failed to load FreeCAD module!");
|
|
}
|