Skip to content

[lldb] Use PyThread_get_thread_ident instead of accessing PyThreadState #153460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2025

Conversation

JDevlieghere
Copy link
Member

Use PyThread_get_thread_ident, which is part of the Stable API, instead of accessing a member of the PyThreadState, which is opaque when using the Stable API.

Use `PyThread_get_thread_ident`, which is part of the Stable API,
instead of accessing a member of the PyThreadState, which is opaque when
using the Stable API.
@llvmbot
Copy link
Member

llvmbot commented Aug 13, 2025

@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)

Changes

Use PyThread_get_thread_ident, which is part of the Stable API, instead of accessing a member of the PyThreadState, which is opaque when using the Stable API.


Full diff: https://github.com/llvm/llvm-project/pull/153460.diff

1 Files Affected:

  • (modified) lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp (+2-2)
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 5b97fcb5acf58..15ea5e995af5c 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -909,11 +909,11 @@ bool ScriptInterpreterPythonImpl::Interrupt() {
   Log *log = GetLog(LLDBLog::Script);
 
   if (IsExecutingPython()) {
-    PyThreadState *state = PyThreadState_GET();
+    PyThreadState *state = PyThreadState_Get();
     if (!state)
       state = GetThreadState();
     if (state) {
-      long tid = state->thread_id;
+      long tid = PyThread_get_thread_ident();
       PyThreadState_Swap(state);
       int num_threads = PyThreadState_SetAsyncExc(tid, PyExc_KeyboardInterrupt);
       LLDB_LOGF(log,

@JDevlieghere
Copy link
Member Author

Part of #151617. This only applies to Windows where we don't use LLDB_USE_PYTHON_SET_INTERRUPT.

@JDevlieghere JDevlieghere merged commit ac0ad50 into llvm:main Aug 14, 2025
11 checks passed
@JDevlieghere JDevlieghere deleted the PyThread_get_thread_ident branch August 14, 2025 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants