292 Commits

Author SHA1 Message Date
Anuj Nitin Bharambe f6d16a0d70 gh-149216: Notify type watchers on heap type deallocation (GH-149236)
Authored-by: Anuj Bharambe <anujnitinb@gmail.com>
2026-05-05 11:24:07 +01:00
Petr Viktorin 508b49845d gh-149044: Implement PEP 820 – PySlot: Unified slot system for the C API (GH-149055)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2026-05-05 09:18:04 +02:00
Jelle Zijlstra 29a92abb60 gh-148829: Implement PEP 661 (#148831)
Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2026-04-27 19:28:30 -07:00
Petr Viktorin 8923ca418c gh-145921: Add "_DuringGC" functions for tp_traverse (GH-145925)
There are newly documented restrictions on tp_traverse:

    The traversal function must not have any side effects.
    It must not modify the reference counts of any Python
    objects nor create or destroy any Python objects.

* Add several functions that are guaranteed side-effect-free,
  with a _DuringGC suffix.
* Use these in ctypes
* Consolidate tp_traverse docs in gcsupport.rst, moving unique
  content from typeobj.rst there

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-04-08 09:15:11 +02:00
Victor Stinner c1a4112c22 gh-147988: Initialize digits in long_alloc() in debug mode (#147989)
When Python is built in debug mode:

* long_alloc() now initializes digits with a pattern to detect usage of
  uninitialized digits.
* _PyLong_CompactValue() now makes sure that the digit is zero when the
  sign is zero.
* PyLongWriter_Finish() now raises SystemError if it detects uninitialized
  digits

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-04-02 11:55:34 +00:00
Petr Viktorin a86963b3e2 gh-146636: Py_mod_abi mandatory for modules created from slots array (GH-146855) 2026-04-02 13:54:21 +02:00
Sergey B Kirpichev db5936c5b8 gh-143050: Correct PyLong_FromString() to use _PyLong_Negate() (#145901)
The long_from_string_base() might return a small integer, when the
_pylong.py is used to do conversion.  Hence, we must be careful here to
not smash it "small int" bit by using the _PyLong_FlipSign().

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-31 13:17:49 +00:00
sunmy2019 b7055533ab gh-146615: Fix format specifiers in test cextensions (GH-146618) 2026-03-31 10:58:27 +03:00
Serhiy Storchaka ab47892c32 Improve tests for the PyUnicodeWriter C API (GH-146157)
Add tests for corner cases: NULL pointers and out of range values.
2026-03-19 19:15:30 +02:00
Serhiy Storchaka 0f2246b155 gh-146056: Fix list.__repr__() for lists containing NULLs (GH-146129)
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-19 09:59:48 +02:00
AN Long 6f8867a676 gh-129849: Add tests for Py_tp_bases (#143208) 2026-03-16 13:59:55 +05:30
Victor Stinner 9159287f58 gh-144175: Add PyArg_ParseArray() function (#144283)
Add PyArg_ParseArray() and PyArg_ParseArrayAndKeywords()
functions to parse arguments of functions using the METH_FASTCALL
calling convention.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-03-06 21:57:44 +00:00
Victor Stinner 9e083b57ee gh-141510: Test frozendict C API (#145081)
Add tests on functions:

* PyAnyDict_Check()
* PyAnyDict_CheckExact()
* PyFrozenDict_Check()
* PyFrozenDict_CheckExact()
* PyFrozenDict_New()
2026-02-21 17:00:23 +01:00
Pablo Galindo Salgado 46d5106cfa gh-142349: Implement PEP 810 - Explicit lazy imports (#142351)
Co-authored-by: T. Wouters <twouters@meta.com >
Co-authored-by: Brittany Reynoso <breynoso@meta.com>
Co-authored-by: Dino Viehland <dinoviehland@meta.com>
2026-02-12 00:15:33 +00:00
Kumar Aditya 347d3594d3 gh-143300: implement PyUnstable_SetImmortal for marking objects as immortal (#144543) 2026-02-11 20:59:31 +05:30
Nybblista cc81707e40 gh-144629: Add test for the PyFunction_GetAnnotations() function (#144630) 2026-02-10 14:38:24 +00:00
Petr Viktorin b22ff1e543 gh-140550: allow slots that repeat information from PyModuleDef (GH-144340)
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.
2026-02-09 11:35:43 +01:00
Jake Lishman 19de10d3d8 gh-140557: Force alignment of empty bytearray and array.array buffers (GH-140559)
This ensures the buffers used by the empty `bytearray` and `array.array`
are aligned the same as a pointer returned by the allocator.  This is a
more convenient default for interop with other languages that have
stricter requirements of type-safe buffers (e.g. Rust's `&[T]` type)
even when empty.
2026-01-26 16:45:17 +01:00
Shamil 7ca9e7ad05 Fix UBSan error in _testcapi: correct create_attr_from_spec signature (#143097)
Co-authored-by: sobolevn <mail@sobolevn.me>
2026-01-17 18:05:09 +00:00
Peter Bierma 19e64afddf gh-141070: Rename PyUnstable_Object_Dump to PyObject_Dump (GH-142848) 2026-01-16 09:19:43 -05:00
Henry Chen dcdb23f9db gh-143429: Use compile-time NaN encoding detection for test_struct (#143432) 2026-01-09 10:46:48 +00:00
Sam Gross a26c831bc4 gh-142589: Fix PyUnstable_Object_IsUniqueReferencedTemporary (gh-142593)
PyUnstable_Object_IsUniqueReferencedTemporary wasn't handling tagged
ints on the evaluation stack properly.
2025-12-11 14:41:03 -05:00
Petr Viktorin bf66bce4ee gh-141780: Make PyModule_FromSlotsAndSpec enable GIL if needed (GH-141785) 2025-11-24 13:26:35 +01:00
Victor Stinner 600f3feb23 gh-141070: Add PyUnstable_Object_Dump() function (#141072)
* Promote _PyObject_Dump() as a public function.
* Keep _PyObject_Dump() alias to PyUnstable_Object_Dump()
  for backward compatibility.
* Replace _PyObject_Dump() with PyUnstable_Object_Dump().

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2025-11-18 16:13:13 +00:00
Petr Viktorin 589a03a8ce gh-140550: Initial implementation of PEP 793 – PyModExport (GH-140556)
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-11-05 12:31:42 +01:00
Victor Stinner d0b18b19fa gh-129813: Fix PyBytesWriter tests (#139892) 2025-10-10 13:01:06 +02:00
Victor Stinner e31c22dbf9 gh-111489: Add PyTuple_FromArray() function (#139691) 2025-10-10 08:54:12 +02:00
Victor Stinner 5a77f02d72 gh-79315: Remove Include/pylock.h and Include/monitoring.h (#139731)
Keep Include/cpython/pylock.h and Include/cpython/monitoring.h.
2025-10-08 00:49:24 +02:00
dgpb 7ce25edb8f gh-133059: Increase the small positive integer cache to 1024 (GH-133160) 2025-09-24 17:05:30 -04:00
Peter Bierma 49f1c302df gh-139098: Use multiphase initialization in _testcapi (GH-139102)
Use multiphase initialization in the _testcapi module to allow loading in subinterpreters. The isolation here isn't perfect as there's still some use of globals, but _testcapi should generally work in other interpreters.
2025-09-18 11:00:50 +00:00
Victor Stinner c3fca5d478 gh-129813, PEP 782: Add PyBytesWriter_Format() (#138824)
Modify PyBytes_FromFormatV() to use the public PyBytesWriter API
rather than the _PyBytesWriter private API.
2025-09-12 14:21:57 +02:00
Victor Stinner adb414044f gh-129813, PEP 782: Add PyBytesWriter C API (#138822) 2025-09-12 13:41:59 +02:00
Petr Viktorin 0c74fc8af0 gh-137210: Add a struct, slot & function for checking an extension's ABI (GH-137212)
Co-authored-by: Steve Dower <steve.dower@microsoft.com>
2025-09-05 16:23:18 +02:00
Adam Turner 918e3ba6c0 GH-137623: Use an AC decorator for docstring line length enforcement (#137690) 2025-08-18 18:29:00 +01:00
William S Fulton 7de8ea7be6 gh-136300: Modify C tests to conform to PEP-737 (GH-136301)
- Use %T format specifier instead of %s and Py_TYPE(x)->tp_name.
- Remove legacy %.200s format specifier for truncating type names.

Co-authored-by: Victor Stinner <vstinner@python.org>
2025-07-11 15:18:35 +02:00
William S Fulton d1d5dce14f gh-136288: Fix error message in _testcapi/vectorcall.c (GH-136258)
Use the %N format specifier instead of %s and `PyType_GetName`.
2025-07-04 11:54:00 -04:00
Victor Stinner da79ac9d26 gh-135075: Make PyObject_SetAttr() fail with NULL value and exception (#136180)
Make PyObject_SetAttr() and PyObject_SetAttrString() fail if called
with NULL value and an exception set.
2025-07-03 14:51:44 +02:00
sobolevn 9c3c02019c gh-135709: Fix two compile warnings on WASM buildbot (#135712) 2025-06-19 18:46:40 +03:00
Petr Viktorin e413e26719 gh-134891: Add PyUnstable_Unicode_GET_CACHED_HASH (GH-134892) 2025-06-06 15:51:00 +02:00
Victor Stinner f49a07b531 gh-133968: Add PyUnicodeWriter_WriteASCII() function (#133973)
Replace most PyUnicodeWriter_WriteUTF8() calls with
PyUnicodeWriter_WriteASCII().

Unrelated change to please the linter: remove an unused
import in test_ctypes.

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-05-29 14:54:30 +00:00
Peter Bierma b275b8f342 gh-133140: Add PyUnstable_Object_IsUniquelyReferenced for free-threading (#133144) 2025-05-05 21:01:20 +02:00
Sam Gross f2379535fe gh-133164: Add PyUnstable_Object_IsUniqueReferencedTemporary C API (gh-133170)
After gh-130704, the interpreter replaces some uses of `LOAD_FAST` with
`LOAD_FAST_BORROW` which avoid incref/decrefs by "borrowing" references
on the interpreter stack when the bytecode compiler can determine that
it's safe.

This change broke some checks in C API extensions that relied on
`Py_REFCNT()` of `1` to determine if it's safe to modify an object
in-place. Objects may have a reference count of one, but still be
referenced further up the interpreter stack due to borrowing of
references.

This provides a replacement function for those checks.
`PyUnstable_Object_IsUniqueReferencedTemporary` is more conservative:
it checks that the object has a reference count of one and that it exists as a
unique strong reference in the interpreter's stack of temporary
variables in the top most frame.

See also:

* https://github.com/numpy/numpy/issues/28681

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: T. Wouters <thomas@python.org>
Co-authored-by: mpage <mpage@cs.stanford.edu>
Co-authored-by: Mark Shannon <mark@hotpy.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-05-02 13:24:57 +00:00
Sergey B Kirpichev ad2f0884b1 gh-130317: Fix test_pack_unpack_roundtrip() and add docs (#133204)
* Skip sNaN's testing in 32-bit mode.
* Drop float_set_snan() helper.
* Use memcpy() workaround for sNaN's in PyFloat_Unpack4().
* Document, that sNaN's may not be preserved by PyFloat_Pack/Unpack API.
2025-05-01 16:20:36 +02:00
neonene fa52f289a3 gh-133166: Fix missing error emission of PyType_GetModuleByDef (GH-133240) 2025-05-01 14:32:57 +02:00
Victor Stinner 02cd6d7097 gh-130317: Fix strict aliasing in PyFloat_Pack8() (#133150)
* Fix strict aliasing in PyFloat_Pack8() and PyFloat_Pack4().
* Fix _testcapi.float_set_snan() on x86 (32-bit).
2025-04-29 14:27:50 +00:00
Sergey B Kirpichev 6157135a8d gh-130317: Fix PyFloat_Pack/Unpack[24] for NaN's with payload (#130452)
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-04-28 15:23:26 +02:00
alexey semenyuk d7365e6050 gh-132162: Add tests for Py_UniversalNewlineFgets() (#132164) 2025-04-24 17:43:48 +02:00
Sergey B Kirpichev 79f7c67bf6 gh-128813: hide mixed-mode functions for complex arithmetic from C-API (#131703) 2025-04-22 14:18:18 +02:00
Bénédikt Tran edbf7fb129 gh-111178: remove redundant casts for functions with correct signatures (#131673) 2025-04-01 17:18:11 +02:00
Michael Droettboom 8614f86b71 gh-131525: Cache the result of tuple_hash (#131529)
* gh-131525: Cache the result of tuple_hash

* Fix debug builds

* Add blurb

* Fix formatting

* Pre-compute empty tuple singleton

* Mostly set the cache within tuple_alloc

* Fixes for TSAN

* Pre-compute empty tuple singleton

* Fix for 32-bit platforms

* Assert that op != NULL in _PyTuple_RESET_HASH_CACHE

* Use FT_ATOMIC_STORE_SSIZE_RELAXED macro

* Update Include/internal/pycore_tuple.h

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* Fix alignment

* atomic load

* Update Objects/tupleobject.c

Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>

---------

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
2025-03-27 09:57:06 -04:00