summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/scripts/lldb.swig10
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp3
2 files changed, 8 insertions, 5 deletions
diff --git a/lldb/scripts/lldb.swig b/lldb/scripts/lldb.swig
index dc987040e76..e920718d3e8 100644
--- a/lldb/scripts/lldb.swig
+++ b/lldb/scripts/lldb.swig
@@ -41,12 +41,12 @@ Older swig versions will simply ignore this setting.
*/
%define MODULEIMPORT
"try:
- # Try a relative import first
- from . import $module
+ # Try an absolute import first. If we're being loaded from lldb,
+ # _lldb should be a built-in module.
+ import $module
except ImportError:
- # Maybe absolute import will work (if we're being loaded from lldb, it
- # should).
- import $module"
+ # Relative import should work if we are being loaded by Python.
+ from . import $module"
%enddef
// These versions will not generate working python modules, so error out early.
#if SWIG_VERSION >= 0x030009 && SWIG_VERSION < 0x030011
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index bc6ed6cbdf9..0db28294ebd 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -132,6 +132,9 @@ public:
InitializePythonHome();
+ // Register _lldb as a built-in module.
+ PyImport_AppendInittab("_lldb", g_swig_init_callback);
+
// Python < 3.2 and Python >= 3.2 reversed the ordering requirements for
// calling `Py_Initialize` and `PyEval_InitThreads`. < 3.2 requires that you
// call `PyEval_InitThreads` first, and >= 3.2 requires that you call it last.
OpenPOWER on IntegriCloud