Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Merge in the main branch
  • Loading branch information
encukou committed Jul 19, 2024
commit 085b93e1725fc8066aa67647f528434df4392225
15 changes: 11 additions & 4 deletions Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,17 @@ Initializing and finalizing the interpreter
Undo all initializations made by :c:func:`Py_Initialize` and subsequent use of
Python/C API functions, and destroy all sub-interpreters (see
:c:func:`Py_NewInterpreter` below) that were created and not yet destroyed since
the last call to :c:func:`Py_Initialize`. This is a no-op when called for a second
time (without calling :c:func:`Py_Initialize` again first). Normally the
return value is ``0``. If there were errors during finalization
(flushing buffered data), ``-1`` is returned.
the last call to :c:func:`Py_Initialize`. This is a no-op when called for a second
time (without calling :c:func:`Py_Initialize` again first).

Since this is the reverse of :c:func:`Py_Initialize`, it should be called
in the same thread with the same interpreter active. That means
the main thread and the main interpreter.
This should never be called while :c:func:`Py_RunMain` is running.

Normally the return value is ``0``.
If there were errors during finalization (flushing buffered data),
``-1`` is returned.

Note that Python will do a best effort at freeing all memory allocated by the Python
interpreter. Therefore, any C-Extension should make sure to correctly clean up all
Expand Down
118 changes: 108 additions & 10 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2119,16 +2119,114 @@ New Features
* Add :c:func:`Py_HashPointer` function to hash a pointer.
(Contributed by Victor Stinner in :gh:`111545`.)

* Modified the ``_PyUnicode_ClearInterned`` function to always delete all
interned strings during a call to :c:func:`Py_Finalize`. This makes all
is backwards incompatible to any C-Extension that holds onto an interned
string after a call to :c:func:`Py_Finalize` and is then reused after a
call to :c:func:`Py_Initialize`. Any issues arising from this behavior will
normally result in crashes during the exectuion of the subsequent call to
:c:func:`Py_Initialize` from accessing uninitialized memory. To fix, use
an address sanitizer (i.e. ASAN) to identify any use-after-free coming from
an interned string and deallocate it during module shutdown.
(Contribued by Eddie Elizondo in :gh:`113601`.)
* Add :c:func:`PyObject_GenericHash` function that implements the default
hashing function of a Python object.
(Contributed by Serhiy Storchaka in :gh:`113024`.)

* Add PyTime C API:

* :c:type:`PyTime_t` type.
* :c:var:`PyTime_MIN` and :c:var:`PyTime_MAX` constants.
* Add functions:

* :c:func:`PyTime_AsSecondsDouble`.
* :c:func:`PyTime_Monotonic`.
* :c:func:`PyTime_MonotonicRaw`.
* :c:func:`PyTime_PerfCounter`.
* :c:func:`PyTime_PerfCounterRaw`.
* :c:func:`PyTime_Time`.
* :c:func:`PyTime_TimeRaw`.

(Contributed by Victor Stinner and Petr Viktorin in :gh:`110850`.)

* Add :c:func:`PyLong_AsNativeBytes`, :c:func:`PyLong_FromNativeBytes` and
:c:func:`PyLong_FromUnsignedNativeBytes` functions to simplify converting
between native integer types and Python :class:`int` objects.
(Contributed by Steve Dower in :gh:`111140`.)

* Add :c:func:`PyType_GetFullyQualifiedName` function to get the type's fully
qualified name. Equivalent to ``f"{type.__module__}.{type.__qualname__}"``,
or ``type.__qualname__`` if ``type.__module__`` is not a string or is equal
to ``"builtins"``.
(Contributed by Victor Stinner in :gh:`111696`.)

* Add :c:func:`PyType_GetModuleName` function to get the type's module name.
Equivalent to getting the ``type.__module__`` attribute.
(Contributed by Eric Snow and Victor Stinner in :gh:`111696`.)

* Add support for ``%T``, ``%#T``, ``%N`` and ``%#N`` formats to
:c:func:`PyUnicode_FromFormat`: format the fully qualified name of an object
type and of a type: call :c:func:`PyType_GetModuleName`. See :pep:`737` for
more information.
(Contributed by Victor Stinner in :gh:`111696`.)

* Add :c:func:`Py_GetConstant` and :c:func:`Py_GetConstantBorrowed` functions
to get constants. For example, ``Py_GetConstant(Py_CONSTANT_ZERO)`` returns a
:term:`strong reference` to the constant zero.
(Contributed by Victor Stinner in :gh:`115754`.)

* Add :c:func:`PyType_GetModuleByDef` to the limited C API
(Contributed by Victor Stinner in :gh:`116936`.)

* Add two new functions to the C-API, :c:func:`PyRefTracer_SetTracer` and
:c:func:`PyRefTracer_GetTracer`, that allows to track object creation and
destruction the same way the :mod:`tracemalloc` module does. (Contributed
by Pablo Galindo in :gh:`93502`.)

* Add :c:func:`PyEval_GetFrameBuiltins`, :c:func:`PyEval_GetFrameGlobals`, and
:c:func:`PyEval_GetFrameLocals` to the C API. These replacements for
:c:func:`PyEval_GetBuiltins`, :c:func:`PyEval_GetGlobals`, and
:c:func:`PyEval_GetLocals` return :term:`strong references <strong reference>`
rather than borrowed references. (Added as part of :pep:`667`.)

* Add :c:type:`PyMutex` API, a lightweight mutex that occupies a single byte.
The :c:func:`PyMutex_Lock` function will release the GIL (if currently held)
if the operation needs to block.
(Contributed by Sam Gross in :gh:`108724`.)

Build Changes
=============

* The :file:`configure` option :option:`--with-system-libmpdec` now defaults
to ``yes``. The bundled copy of ``libmpdecimal`` will be removed in Python
3.15.

* Autoconf 2.71 and aclocal 1.16.4 are now required to regenerate
the :file:`configure` script.
(Contributed by Christian Heimes in :gh:`89886`.)

* SQLite 3.15.2 or newer is required to build the :mod:`sqlite3` extension module.
(Contributed by Erlend Aasland in :gh:`105875`.)

* Python built with :file:`configure` :option:`--with-trace-refs` (tracing
references) is now ABI compatible with the Python release build and
:ref:`debug build <debug-build>`.
(Contributed by Victor Stinner in :gh:`108634`.)

* Building CPython now requires a compiler with support for the C11 atomic
library, GCC built-in atomic functions, or MSVC interlocked intrinsics.

* The ``errno``, ``fcntl``, ``grp``, ``md5``, ``pwd``, ``resource``,
``termios``, ``winsound``,
``_ctypes_test``, ``_multiprocessing.posixshmem``, ``_scproxy``, ``_stat``,
``_statistics``, ``_testconsole``, ``_testimportmultiple`` and ``_uuid``
C extensions are now built with the :ref:`limited C API <limited-c-api>`.
(Contributed by Victor Stinner in :gh:`85283`.)

* ``wasm32-wasi`` is now a :pep:`11` tier 2 platform.
(Contributed by Brett Cannon in :gh:`115192`.)

* ``wasm32-emscripten`` is no longer a :pep:`11` supported platform.
(Contributed by Brett Cannon in :gh:`115192`.)

* Python now bundles the `mimalloc library <https://github.com/microsoft/mimalloc>`__.
It is licensed under the MIT license; see :ref:`mimalloc license <mimalloc-license>`.
The bundled mimalloc has custom changes, see :gh:`113141` for details.
(Contributed by Dino Viehland in :gh:`109914`.)

* On POSIX systems, the pkg-config (``.pc``) filenames now include the ABI
flags. For example, the free-threaded build generates ``python-3.13t.pc``
and the debug build generates ``python-3.13d.pc``.


Porting to Python 3.13
Expand Down
11 changes: 11 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,17 @@ New Features

(Contributed by Victor Stinner in :gh:`119182`.)

* Modified the ``_PyUnicode_ClearInterned`` function to always delete all
interned strings during a call to :c:func:`Py_Finalize`. This
Comment thread
eduardo-elizondo marked this conversation as resolved.
Outdated
is backwards incompatible to any C-Extension that holds onto an interned
string after a call to :c:func:`Py_Finalize` and is then reused after a
call to :c:func:`Py_Initialize`. Any issues arising from this behavior will
normally result in crashes during the exectuion of the subsequent call to
:c:func:`Py_Initialize` from accessing uninitialized memory. To fix, use
an address sanitizer (i.e. ASAN) to identify any use-after-free coming from
Comment thread
encukou marked this conversation as resolved.
Outdated
an interned string and deallocate it during module shutdown.
(Contribued by Eddie Elizondo in :gh:`113601`.)

Porting to Python 3.14
----------------------

Expand Down
5 changes: 0 additions & 5 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -15619,9 +15619,6 @@ _PyUnicode_ClearInterned(PyInterpreterState *interp)
}
assert(PyDict_CheckExact(interned));

/* For all non-singleton interned strings, restore the two valid references
to that instance from within the intern string dictionary and let the
normal reference counting process clean up these instances. */
#ifdef INTERNED_STATS
fprintf(stderr, "releasing %zd interned strings\n",
PyDict_GET_SIZE(interned));
Expand All @@ -15647,7 +15644,6 @@ _PyUnicode_ClearInterned(PyInterpreterState *interp)
* strict guarantee that no memory will be left after
* `Py_Finalize`.
*/
#ifdef Py_DEBUG
// Skip the Immortal Instance check and restore
// the two references (key and value) ignored
// by PyUnicode_InternInPlace().
Expand All @@ -15660,7 +15656,6 @@ _PyUnicode_ClearInterned(PyInterpreterState *interp)
#ifdef INTERNED_STATS
total_length += PyUnicode_GET_LENGTH(s);
#endif
#endif // Py_DEBUG
break;
case SSTATE_INTERNED_IMMORTAL_STATIC:
/* It is shared between interpreters, so we should unmark it
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.