summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimothy Pearson <[email protected]>2014-09-24 11:34:13 -0500
committerTimothy Pearson <[email protected]>2014-09-24 11:34:13 -0500
commit036a0020a90077abdd504141a9d54f755673d40a (patch)
tree15e81db620cd2c358f8ff381ca0b62904ae32006
parentaa5db0802c4472ad9ffeeb7c0101abed1b415c73 (diff)
downloadpytdeextensions-036a0020a90077abdd504141a9d54f755673d40a.tar.gz
pytdeextensions-036a0020a90077abdd504141a9d54f755673d40a.zip
Properly re-export loaded module symbols as global
This relates to Bug 1995
-rw-r--r--src/pythonize.cpp2
-rw-r--r--src/pythonize.h4
-rw-r--r--src/tdedistutils.py17
3 files changed, 14 insertions, 9 deletions
diff --git a/src/pythonize.cpp b/src/pythonize.cpp
index e83f965..d8fb038 100644
--- a/src/pythonize.cpp
+++ b/src/pythonize.cpp
@@ -202,7 +202,7 @@ PyObject *importModule (char *moduleName)
// returns an object from a loaded module
// you must decref the object returned when done with it (new reference returned)
-PyObject *getNewObjectRef (PyObject *module, char *object)
+PyObject *getNewObjectRef (PyObject *module, const char *object)
{
return _pythonize ? _pythonize->getNewObjectRef (module, object) : NULL;
}
diff --git a/src/pythonize.h b/src/pythonize.h
index 6db64d2..23114ef 100644
--- a/src/pythonize.h
+++ b/src/pythonize.h
@@ -49,7 +49,7 @@ public:
// returns an object from a loaded module
// you must decref the object returned when done with it (new reference returned)
- PyObject *getNewObjectRef (PyObject *module, char *object) { return PyObject_GetAttrString (module, object); }
+ PyObject *getNewObjectRef (PyObject *module, const char *object) { return PyObject_GetAttrString (module, object); }
int getPythonInit () { return pythonInit; }
@@ -84,7 +84,7 @@ extern "C" {
// returns an object from a loaded module
// you must decref the object returned when done with it (new reference returned)
- PyObject *getNewObjectRef (PyObject *module, char *object);
+ PyObject *getNewObjectRef (PyObject *module, const char *object);
bool getPythonInit();
diff --git a/src/tdedistutils.py b/src/tdedistutils.py
index 45bdce2..a0f7971 100644
--- a/src/tdedistutils.py
+++ b/src/tdedistutils.py
@@ -896,15 +896,19 @@ class BuildKControlModule(Command):
#include <tqstring.h>
#include <sip.h>
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif // _GNU_SOURCE
+#include <dlfcn.h>
+
#define MODULE_DIR "%(moduledir)s"
#define EXTRA_MODULE_DIR "%(extramodule)s"
#define MODULE_NAME "%(modulename)s"
#define FACTORY "%(factoryfunction)s"
#define CPP_FACTORY %(factoryfunction)s
-#define LIB_PYTHON "libpython%(python_version)s.so"
#define debug 1
-static TDECModule *report_error(char *msg) {
+static TDECModule *report_error(const char *msg) {
if (debug) printf ("error: %%s\n", msg);
return NULL;
}
@@ -914,15 +918,17 @@ static TDECModule* return_instance( TQWidget *parent, const char *name ) {
PyObject *pyTDECModuleTuple;
PyObject *pyTDECModule;
Pythonize *pyize; // Pythonize object to manage the Python interpreter.
- int isErr;
// Try to determine what py script we're loading. Note that "name"
// typically appears to be NULL.
TQString script(MODULE_NAME);
- // Reload libpython, but this time tell the runtime linker to make the
+ // Reload this module, but this time tell the runtime linker to make the
// symbols global and available for later loaded libraries/module.
- KLibLoader::self()->globalLibrary(LIB_PYTHON);
+ Dl_info info;
+ if (!dladdr((const void *)(&return_instance), &info) || !info.dli_fname || !dlopen(info.dli_fname, RTLD_GLOBAL|RTLD_NOW)) {
+ return report_error ("***Unable to export symbols\n");
+ }
// Start the interpreter.
pyize = initialize();
@@ -997,7 +1003,6 @@ static TDECModule* return_instance( TQWidget *parent, const char *name ) {
Py_INCREF(PyTuple_GET_ITEM(pyTDECModuleTuple,0));
// convert the TDECModule PyObject to a real C++ TDECModule *.
- isErr = 0;
pyTDECModule = PyTuple_GET_ITEM(pyTDECModuleTuple,1);
tdecmodule = (TDECModule *)PyLong_AsVoidPtr(pyTDECModule);
if(!tdecmodule) {