[llvm-branch-commits] [lldb] release/22.x: [lldb] use the Py_REFCNT() macro instead of directly accessing member (#188161) (PR #188768)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Mar 26 08:27:52 PDT 2026
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/188768
Backport 2a7b0f06d2060dbab8fa38fae7689f2d9048fa9d
Requested by: @JDevlieghere
>From 03019fca56e040c65167762071a18bbaadf9678f Mon Sep 17 00:00:00 2001
From: Charlie Li <git at vishwin.info>
Date: Tue, 24 Mar 2026 18:49:09 -0400
Subject: [PATCH] [lldb] use the Py_REFCNT() macro instead of directly
accessing member (#188161)
[PyObject members are not to be accessed
directly](https://docs.python.org/3/c-api/structures.html#c.PyObject),
but rather through macros, in this case `Py_REFCNT()`.
In most, ie Global Interpreter Lock-enabled, CPython cases,
`Py_REFCNT()` expands to accessing `ob_refcnt` anyway. However, in a
free-threaded CPython, combined with disabling the limited API (since it
requires the GIL for now), the direct member does not exist, causing the
build to fail. The macro expands to the correct access method in the
free-threaded configuration.
(cherry picked from commit 2a7b0f06d2060dbab8fa38fae7689f2d9048fa9d)
---
lldb/bindings/python/python-wrapper.swig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lldb/bindings/python/python-wrapper.swig b/lldb/bindings/python/python-wrapper.swig
index bf59569920470..72f90f1b23c29 100644
--- a/lldb/bindings/python/python-wrapper.swig
+++ b/lldb/bindings/python/python-wrapper.swig
@@ -134,7 +134,7 @@ bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallTypeScript(
#endif
) {
pfunc_impl = (PyObject *)(*pyfunct_wrapper);
- if (pfunc_impl->ob_refcnt == 1) {
+ if (Py_REFCNT(pfunc_impl) == 1) {
Py_XDECREF(pfunc_impl);
pfunc_impl = NULL;
}
More information about the llvm-branch-commits
mailing list