Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions Doc/c-api/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
38 changes: 38 additions & 0 deletions Doc/c-api/gen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 19 additions & 0 deletions Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed the sqlite3_shutdown call that could cause closing connections for sqlite when used with multiple sub interpreters.
21 changes: 12 additions & 9 deletions Modules/_remote_debugging_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@
* HEADERS AND INCLUDES
* ============================================================================ */

#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif
Expand All @@ -32,6 +23,18 @@
#include <internal/pycore_stackref.h> // 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 <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifndef HAVE_PROCESS_VM_READV
# define HAVE_PROCESS_VM_READV 0
#endif
Expand Down
1 change: 0 additions & 1 deletion Modules/_sqlite/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,6 @@ module_exec(PyObject *module)
return 0;

error:
sqlite3_shutdown();
return -1;
}

Expand Down
Loading