Properly re-export loaded module symbols as global

This relates to Bug 1995
pull/1/head
Timothy Pearson 10 years ago
parent aa5db0802c
commit 036a0020a9

@ -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;
}

@ -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();

@ -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) {

Loading…
Cancel
Save