From ce701032a3d5d3597466d5836ebe989db6eda2aa Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Thu, 20 Nov 2025 08:42:01 -0500 Subject: [PATCH 1/5] gh-141004: Document `Py_MakePendingCalls` (GH-141137) Co-authored-by: Victor Stinner --- Doc/c-api/init.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst index 3cac2c8b213c80..4a841c9e3c8f9a 100644 --- a/Doc/c-api/init.rst +++ b/Doc/c-api/init.rst @@ -1891,6 +1891,25 @@ pointer and a void pointer argument. This function now always schedules *func* to be run in the main interpreter. + +.. c:function:: int Py_MakePendingCalls(void) + + Execute all pending calls. This is usually executed automatically by the + interpreter. + + This function returns ``0`` on success, and returns ``-1`` with an exception + set on failure. + + If this is not called in the main thread of the main + interpreter, this function does nothing and returns ``0``. + The caller must hold an :term:`attached thread state`. + + .. versionadded:: 3.1 + + .. versionchanged:: 3.12 + This function only runs pending calls in the main interpreter. + + .. _profiling: Profiling and Tracing From 2da7ecc680548804ea99d62ba4d228cfa5011671 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Thu, 20 Nov 2025 08:46:27 -0500 Subject: [PATCH 2/5] gh-141004: Document missing generator APIs (GH-141409) Co-authored-by: Victor Stinner --- Doc/c-api/gen.rst | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Doc/c-api/gen.rst b/Doc/c-api/gen.rst index 0eb5922f6da75f..44f3bdbf959b9c 100644 --- a/Doc/c-api/gen.rst +++ b/Doc/c-api/gen.rst @@ -44,3 +44,41 @@ than explicitly calling :c:func:`PyGen_New` or :c:func:`PyGen_NewWithQualName`. with ``__name__`` and ``__qualname__`` set to *name* and *qualname*. A reference to *frame* is stolen by this function. The *frame* argument must not be ``NULL``. + +.. c:function:: PyCodeObject* PyGen_GetCode(PyGenObject *gen) + + Return a new :term:`strong reference` to the code object wrapped by *gen*. + This function always succeeds. + + +Asynchronous Generator Objects +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. seealso:: + :pep:`525` + +.. c:var:: PyTypeObject PyAsyncGen_Type + + The type object corresponding to asynchronous generator objects. This is + available as :class:`types.AsyncGeneratorType` in the Python layer. + + .. versionadded:: 3.6 + +.. c:function:: PyObject *PyAsyncGen_New(PyFrameObject *frame, PyObject *name, PyObject *qualname) + + Create a new asynchronous generator wrapping *frame*, with ``__name__`` and + ``__qualname__`` set to *name* and *qualname*. *frame* is stolen by this + function and must not be ``NULL``. + + On success, this function returns a :term:`strong reference` to the + new asynchronous generator. On failure, this function returns ``NULL`` + with an exception set. + + .. versionadded:: 3.6 + +.. c:function:: int PyAsyncGen_CheckExact(PyObject *op) + + Return true if *op* is an asynchronous generator object, false otherwise. + This function always succeeds. + + .. versionadded:: 3.6 From 4273616ebfbfe2a7cfd93460a08364f5a40f89e2 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Thu, 20 Nov 2025 08:48:10 -0500 Subject: [PATCH 3/5] gh-141004: Document missing `PyDateTime*` APIs (GH-141543) Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Co-authored-by: Victor Stinner --- Doc/c-api/datetime.rst | 48 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/Doc/c-api/datetime.rst b/Doc/c-api/datetime.rst index f311aad5f15499..127d7c9c91a3d5 100644 --- a/Doc/c-api/datetime.rst +++ b/Doc/c-api/datetime.rst @@ -8,11 +8,42 @@ DateTime Objects Various date and time objects are supplied by the :mod:`datetime` module. Before using any of these functions, the header file :file:`datetime.h` must be included in your source (note that this is not included by :file:`Python.h`), -and the macro :c:macro:`!PyDateTime_IMPORT` must be invoked, usually as part of +and the macro :c:macro:`PyDateTime_IMPORT` must be invoked, usually as part of the module initialisation function. The macro puts a pointer to a C structure -into a static variable, :c:data:`!PyDateTimeAPI`, that is used by the following +into a static variable, :c:data:`PyDateTimeAPI`, that is used by the following macros. +.. c:macro:: PyDateTime_IMPORT() + + Import the datetime C API. + + On success, populate the :c:var:`PyDateTimeAPI` pointer. + On failure, set :c:var:`PyDateTimeAPI` to ``NULL`` and set an exception. + The caller must check if an error occurred via :c:func:`PyErr_Occurred`: + + .. code-block:: + + PyDateTime_IMPORT; + if (PyErr_Occurred()) { /* cleanup */ } + + .. warning:: + + This is not compatible with subinterpreters. + +.. c:type:: PyDateTime_CAPI + + Structure containing the fields for the datetime C API. + + The fields of this structure are private and subject to change. + + Do not use this directly; prefer ``PyDateTime_*`` APIs instead. + +.. c:var:: PyDateTime_CAPI *PyDateTimeAPI + + Dynamically allocated object containing the datetime C API. + + This variable is only available once :c:macro:`PyDateTime_IMPORT` succeeds. + .. c:type:: PyDateTime_Date This subtype of :c:type:`PyObject` represents a Python date object. @@ -325,3 +356,16 @@ Macros for the convenience of modules implementing the DB API: Create and return a new :class:`datetime.date` object given an argument tuple suitable for passing to :meth:`datetime.date.fromtimestamp`. + + +Internal data +------------- + +The following symbols are exposed by the C API but should be considered +internal-only. + +.. c:macro:: PyDateTime_CAPSULE_NAME + + Name of the datetime capsule to pass to :c:func:`PyCapsule_Import`. + + Internal usage only. Use :c:macro:`PyDateTime_IMPORT` instead. From b1558b6d3e2af8964840a5c00356533107368f22 Mon Sep 17 00:00:00 2001 From: Prithviraj Chaudhuri Date: Thu, 20 Nov 2025 09:35:22 -0500 Subject: [PATCH 4/5] gh-140042: Removing unsafe call to sqlite3_shutdown (GH-141690) --- .../next/C_API/2025-11-18-04-16-09.gh-issue-140042.S1C7id.rst | 1 + Modules/_sqlite/module.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/C_API/2025-11-18-04-16-09.gh-issue-140042.S1C7id.rst diff --git a/Misc/NEWS.d/next/C_API/2025-11-18-04-16-09.gh-issue-140042.S1C7id.rst b/Misc/NEWS.d/next/C_API/2025-11-18-04-16-09.gh-issue-140042.S1C7id.rst new file mode 100644 index 00000000000000..608e806b431372 --- /dev/null +++ b/Misc/NEWS.d/next/C_API/2025-11-18-04-16-09.gh-issue-140042.S1C7id.rst @@ -0,0 +1 @@ +Removed the sqlite3_shutdown call that could cause closing connections for sqlite when used with multiple sub interpreters. diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c index 5464fd1227ad20..831dd9219f77ab 100644 --- a/Modules/_sqlite/module.c +++ b/Modules/_sqlite/module.c @@ -774,7 +774,6 @@ module_exec(PyObject *module) return 0; error: - sqlite3_shutdown(); return -1; } From 722f4bb8c9c6b32a7221e4813058cbb5c3989c10 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 20 Nov 2025 17:30:35 +0100 Subject: [PATCH 5/5] gh-141784: Fix _remote_debugging_module.c compilation on 32-bit Linux (#141796) Include Python.h before system headers to make sure that _remote_debugging_module.c uses the same types (ABI) than Python. --- ...-11-20-17-01-05.gh-issue-141784.LkYI2n.rst | 4 ++++ Modules/_remote_debugging_module.c | 21 +++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 Misc/NEWS.d/next/Build/2025-11-20-17-01-05.gh-issue-141784.LkYI2n.rst diff --git a/Misc/NEWS.d/next/Build/2025-11-20-17-01-05.gh-issue-141784.LkYI2n.rst b/Misc/NEWS.d/next/Build/2025-11-20-17-01-05.gh-issue-141784.LkYI2n.rst new file mode 100644 index 00000000000000..f20d84094162ac --- /dev/null +++ b/Misc/NEWS.d/next/Build/2025-11-20-17-01-05.gh-issue-141784.LkYI2n.rst @@ -0,0 +1,4 @@ +Fix ``_remote_debugging_module.c`` compilation on 32-bit Linux. Include +Python.h before system headers to make sure that +``_remote_debugging_module.c`` uses the same types (ABI) than Python. Patch +by Victor Stinner. diff --git a/Modules/_remote_debugging_module.c b/Modules/_remote_debugging_module.c index 6544e3a0ce6876..928bc9ff47a378 100644 --- a/Modules/_remote_debugging_module.c +++ b/Modules/_remote_debugging_module.c @@ -11,15 +11,6 @@ * HEADERS AND INCLUDES * ============================================================================ */ -#include -#include -#include -#include -#include -#include -#include -#include - #ifndef Py_BUILD_CORE_BUILTIN # define Py_BUILD_CORE_MODULE 1 #endif @@ -32,6 +23,18 @@ #include // Py_TAG_BITS #include "../Python/remote_debug.h" +// gh-141784: Python.h header must be included first, before system headers. +// Otherwise, some types such as ino_t can be defined differently, causing ABI +// issues. +#include +#include +#include +#include +#include +#include +#include +#include + #ifndef HAVE_PROCESS_VM_READV # define HAVE_PROCESS_VM_READV 0 #endif