Python.h now also includes <string.h> in the limited C API version 3.11
and newer to fix the Py_CLEAR() macro which uses memcpy().
Add a Py_CLEAR() test in test_cext.
Modify also _Py_TYPEOF to use C23 typeof() if available.
Don't test internal header files including mimalloc on macOS since
mimalloc emits compiler warnings:
In file included from extension.cpp:21:
In file included from Include/internal/pycore_backoff.h:15:
In file included from Include/internal/pycore_interp_structs.h:15:
In file included from Include/internal/pycore_tstate.h:14:
In file included from Include/internal/pycore_mimalloc.h:43:
Include/internal/mimalloc/mimalloc.h:464:85: error: defaulted
function definitions are a C++11 extension
[-Werror,-Wc++11-extensions]
mi_stl_allocator() mi_attr_noexcept = default;
^
Include/internal/mimalloc/mimalloc.h:465:85: error: defaulted
function definitions are a C++11 extension
[-Werror,-Wc++11-extensions]
mi_stl_allocator(const mi_stl_allocator&) mi_attr_noexcept = default;
Log also CXX and CXXFLAGS env vars in test_cppext. Log also CPPFLAGS
in test_cext.
Fix a race condition where a thread could receive a partially-initialized
module when another thread's import fails. The race occurs when:
1. Thread 1 starts importing, adds module to sys.modules
2. Thread 2 sees the module in sys.modules via the fast path
3. Thread 1's import fails, removes module from sys.modules
4. Thread 2 returns a stale module reference not in sys.modules
The fix adds verification after the "skip lock" optimization in both Python
and C code paths to check if the module is still in sys.modules. If the
module was removed (due to import failure), we retry the import so the
caller receives the actual exception from the import failure rather than
a stale module reference.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When _ctypes is imported, it may call dlopen on the libpython shared
library, causing the dynamic linker to load a second mapping of the
library into the process address space. The remote debugging code
iterates memory regions from low addresses upward and returns the first
mapping whose filename matches libpython. After _ctypes is imported, it
finds the dlopen'd copy first, but that copy's PyRuntime section was
never initialized, so reading debug offsets from it fails.
Fix this by validating each candidate PyRuntime address before accepting
it. The validation reads the first 8 bytes and checks for the "xdebugpy"
cookie that is only present in an initialized PyRuntime. Uninitialized
duplicate mappings will fail this check and be skipped, allowing the
search to continue to the real, initialized PyRuntime.
Changing the values requires forking and patching, which is intentional. Simply rebuilding from source does not change the implementation enough to justify changing these values - they would still be `cpython` and compatible with existing `.pyc` files. But people who maintain forks are better served by being able to easily override these values in a place that can be forward-ported reliably.
When integrating slots-based module creation is with the inittab,
which currently requires PyModuleDef, it would be convenient to
reuse the the same slots array for the MethodDef.
Allow slots that match what's already present in the PyModuleDef.
Fix thread-safety issues when accessing frame attributes while another
thread is executing the frame:
- Add critical section to frame_repr() to prevent races when accessing
the frame's code object and line number
- Add _Py_NO_SANITIZE_THREAD to PyUnstable_InterpreterFrame_GetLasti()
to allow intentional racy reads of instr_ptr.
- Fix take_ownership() to not write to the original frame's f_executable
Add Ascii85, Base85, and Z85 encoders and decoders to binascii,
replacing the existing pure Python implementations in base64.
This makes the codecs two orders of magnitude faster and consume
two orders of magnitude less memory.
Note that attempting to decode Ascii85 or Base85 data of length 1 mod 5
(after accounting for Ascii85 quirks) now produces an error, as no
encoder would emit such data. This should be the only significant
externally visible difference compared to the old implementation.
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Move classmethod and staticmethod initialization from __init__() to
__new__().
PyClassMethod_New() and PyStaticMethod_New() now copy attributes of
the wrapped functions: __module__, __name__, __qualname__ and
__doc__.
Change static type initialization: initialize PyStaticMethod_Type and
PyCFunction_Type earlier.
Remove test_refleaks_in_classmethod___init__() and
test_refleaks_in_staticmethod___init__() tests from test_descr since
classmethod and staticmethod have no __init__() method anymore.
__enter__(), __exit__(), __aenter__(), and __aexit__() can now be
arbitrary descriptors, not only normal methods, for consistency with the
"with" and "async with" statements.