Skip to content

Commit

Permalink
Do not preload Python's .so library
Browse files Browse the repository at this point in the history
  • Loading branch information
iakov committed Nov 19, 2023
1 parent 66c1ebe commit 2f701d6
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/PythonQt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,20 +339,22 @@ PythonQt* PythonQt::self() { return _self; }

PythonQt::PythonQt(int flags, const QByteArray& pythonQtModuleName)
{
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 8 && defined(__linux__)
// #if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 8 && defined(__linux__)
/* Starting from python 3.8, python C extensions no longer link to libpython3.X.so
This is a problem, since libpython3.X.so is loaded through a reference in libtrikScriptRunner.so
This is a possible problem, since libpython3.X.so is loaded through a reference in libtrikScriptRunner.so
and (somehow) ld.so does not place it's symbols into global symbol table. This results into a failure to load any C module.
Loading libpython3.X.so with dlopen and RTLD_GLOBAL flag effectively solves this issue. */

// TODO: Someting like PyRun_String("sysconfig.get_config_var('LDLIBRARY')")
// should be used to extract shared object name for current interpreter
const auto &libName = QString("libpython3.%1.so.1.0").arg(PY_MINOR_VERSION).toStdString();
if (NULL == dlopen(libName.c_str(), RTLD_GLOBAL | RTLD_LAZY)) {
qFatal("Failed to load %s", libName.c_str());
abort();
}
#endif

// NOTE 2023-07-07: On Centos7 .so is a link named `libpython3.8.so` and points to `libpython3.8.so.rh-python38-1.0`
// const auto &libName = QString("libpython3.%1.so.1.0").arg(PY_MINOR_VERSION).toStdString();
// if (NULL == dlopen(libName.c_str(), RTLD_GLOBAL | RTLD_LAZY)) {
//qFatal("Failed to load %s", libName.c_str());
//abort();
// }
// #endif
_p = new PythonQtPrivate;
_p->_initFlags = flags;

Expand Down

0 comments on commit 2f701d6

Please sign in to comment.