[Lldb-commits] [lldb] 2a7b0f0 - [lldb] use the Py_REFCNT() macro instead of directly accessing member (#188161)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Mar 24 15:49:14 PDT 2026
Author: Charlie Li
Date: 2026-03-24T17:49:09-05:00
New Revision: 2a7b0f06d2060dbab8fa38fae7689f2d9048fa9d
URL: https://github.com/llvm/llvm-project/commit/2a7b0f06d2060dbab8fa38fae7689f2d9048fa9d
DIFF: https://github.com/llvm/llvm-project/commit/2a7b0f06d2060dbab8fa38fae7689f2d9048fa9d.diff
LOG: [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.
Added:
Modified:
lldb/bindings/python/python-wrapper.swig
Removed:
################################################################################
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 lldb-commits
mailing list