From 036a0020a90077abdd504141a9d54f755673d40a Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Wed, 24 Sep 2014 11:34:13 -0500 Subject: Properly re-export loaded module symbols as global This relates to Bug 1995 --- src/pythonize.cpp | 2 +- src/pythonize.h | 4 ++-- src/tdedistutils.py | 17 +++++++++++------ 3 files changed, 14 insertions(+), 9 deletions(-) (limited to 'src') 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 #include +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif // _GNU_SOURCE +#include + #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) { -- cgit v1.2.1