bpo-43688: Support the limited C API in debug mode (GH-25131)
The limited C API is now supported if Python is built in debug mode
(if the Py_DEBUG macro is defined). In the limited C API, the
Py_INCREF() and Py_DECREF() functions are now implemented as opaque
function calls, rather than accessing directly the PyObject.ob_refcnt
member, if Python is built in debug mode and the Py_LIMITED_API macro
targets Python 3.10 or newer. It became possible to support the
limited C API in debug mode because the PyObject structure is the
same in release and debug mode since Python 3.8 (see bpo-36465).
The limited C API is still not supported in the --with-trace-refs
special build (Py_TRACE_REFS macro).
diff --git a/setup.py b/setup.py
index 75bd163..3b4e7ae 100644
--- a/setup.py
+++ b/setup.py
@@ -1864,17 +1864,11 @@ def detect_modules(self):
## # Uncomment these lines if you want to play with xxmodule.c
## self.add(Extension('xx', ['xxmodule.c']))
- if 'd' not in sysconfig.get_config_var('ABIFLAGS'):
- # Non-debug mode: Build xxlimited with limited API
- self.add(Extension('xxlimited', ['xxlimited.c'],
- define_macros=[('Py_LIMITED_API', '0x030a0000')]))
- self.add(Extension('xxlimited_35', ['xxlimited_35.c'],
- define_macros=[('Py_LIMITED_API', '0x03050000')]))
- else:
- # Debug mode: Build xxlimited with the full API
- # (which is compatible with the limited one)
- self.add(Extension('xxlimited', ['xxlimited.c']))
- self.add(Extension('xxlimited_35', ['xxlimited_35.c']))
+ # Limited C API
+ self.add(Extension('xxlimited', ['xxlimited.c'],
+ define_macros=[('Py_LIMITED_API', '0x030a0000')]))
+ self.add(Extension('xxlimited_35', ['xxlimited_35.c'],
+ define_macros=[('Py_LIMITED_API', '0x03050000')]))
def detect_tkinter_fromenv(self):
# Build _tkinter using the Tcl/Tk locations specified by