Skip to content

Commit a047009

Browse files
authored
Merge pull request swiftlang#7756 from medismailben/swift/release/5.10
[lldb] Update python deprecated APIs.
2 parents 286ccd3 + 713a629 commit a047009

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

lldb/scripts/use_lldb_suite.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ def find_lldb_root():
1616
return lldb_root
1717

1818
lldb_root = find_lldb_root()
19-
import imp
20-
fp, pathname, desc = imp.find_module("use_lldb_suite_root", [lldb_root])
21-
try:
22-
imp.load_module("use_lldb_suite_root", fp, pathname, desc)
23-
finally:
24-
if fp:
25-
fp.close()
19+
20+
import importlib.machinery
21+
import importlib.util
22+
23+
path = os.path.join(lldb_root, "use_lldb_suite_root.py")
24+
loader = importlib.machinery.SourceFileLoader("use_lldb_suite_root", path)
25+
spec = importlib.util.spec_from_loader("use_lldb_suite_root", loader=loader)
26+
module = importlib.util.module_from_spec(spec)
27+
loader.exec_module(module)

lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ Expected<std::string> python::As<std::string>(Expected<PythonObject> &&obj) {
7272
}
7373

7474
static bool python_is_finalizing() {
75-
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 7
75+
#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 13) || (PY_MAJOR_VERSION > 3)
76+
return Py_IsFinalizing();
77+
#elif PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 7
7678
return _Py_Finalizing != nullptr;
7779
#else
7880
return _Py_IsFinalizing();

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,31 @@ struct InitializePythonRAII {
176176
return;
177177
#endif
178178

179+
// `PyEval_ThreadsInitialized` was deprecated in Python 3.9 and removed in
180+
// Python 3.13. It has been returning `true` always since Python 3.7.
181+
#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 9) || (PY_MAJOR_VERSION < 3)
179182
if (PyEval_ThreadsInitialized()) {
183+
#else
184+
if (true) {
185+
#endif
180186
Log *log = GetLog(LLDBLog::Script);
181187

182188
m_was_already_initialized = true;
183189
m_gil_state = PyGILState_Ensure();
184190
LLDB_LOGV(log, "Ensured PyGILState. Previous state = {0}locked\n",
185191
m_gil_state == PyGILState_UNLOCKED ? "un" : "");
192+
193+
// `PyEval_InitThreads` was deprecated in Python 3.9 and removed in
194+
// Python 3.13.
195+
#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 9) || (PY_MAJOR_VERSION < 3)
186196
return;
187197
}
188198

189199
// InitThreads acquires the GIL if it hasn't been called before.
190200
PyEval_InitThreads();
201+
#else
202+
}
203+
#endif
191204
}
192205

193206
PyGILState_STATE m_gil_state = PyGILState_UNLOCKED;

lldb/test/API/use_lldb_suite.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ def find_lldb_root():
2020

2121
lldb_root = find_lldb_root()
2222

23-
import imp
23+
import importlib.machinery
24+
import importlib.util
2425

25-
fp, pathname, desc = imp.find_module("use_lldb_suite_root", [lldb_root])
26-
try:
27-
imp.load_module("use_lldb_suite_root", fp, pathname, desc)
28-
finally:
29-
if fp:
30-
fp.close()
26+
path = os.path.join(lldb_root, "use_lldb_suite_root.py")
27+
loader = importlib.machinery.SourceFileLoader("use_lldb_suite_root", path)
28+
spec = importlib.util.spec_from_loader("use_lldb_suite_root", loader=loader)
29+
module = importlib.util.module_from_spec(spec)
30+
loader.exec_module(module)

0 commit comments

Comments
 (0)