Skip to content

Commit 2859437

Browse files
authored
Merge branch 'main' into queue-shutdown-multiprocessing
2 parents 54d1ae9 + acfa776 commit 2859437

47 files changed

Lines changed: 917 additions & 382 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Doc/data/stable_abi.dat‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Doc/howto/abi3t-migration.rst‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,22 @@ or :c:member:`PyTypeObject.tp_itemsize`), it cannot be ported to
169169
``abi3t`` 3.15.
170170

171171

172+
.. _abi3t-migration-build:
173+
172174
Setting up the build
173175
====================
174176

175-
If you use a build tool (such as setuptools, meson-python, scikit-build-core),
176-
search its documentation for a way to select ``abi3t``.
177-
At the time of writing, not all of them have this; but if your tool does,
178-
use it.
179-
You may want to verify that it set the right flag by temporarily adding the
177+
If you use a build tool, search its documentation for "``abi3t``", and follow
178+
any instructions to select the ABI.
179+
For reference, here are direct links for several popular build tools:
180+
181+
- `meson-python
182+
<https://mesonbuild.com/meson-python/how-to-guides/limited-api.html#the-abi3t-stable-abi>`__
183+
- `scikit-build-core
184+
<https://scikit-build-core.readthedocs.io/en/stable/configuration/#customizing-the-output-wheel>`__
185+
- `Maturin <https://www.maturin.rs/bindings#py_limited_apiabi3>`__
186+
187+
You may want to verify that the tool set the right flag by temporarily adding the
180188
following just after ``#include <Python.h>``::
181189

182190
#if Py_TARGET_ABI3T+0 <= 0x30f0000
@@ -185,6 +193,13 @@ following just after ``#include <Python.h>``::
185193

186194
This should result in a different error than "``abi3t`` define is not set".
187195

196+
.. seealso::
197+
198+
`Building and distributing abi3t extensions
199+
<https://py-free-threading.github.io/abi3t/>`__:
200+
Build configuration and wheel testing examples in the community-maintained
201+
Python Free-Threading Guide.
202+
188203
.. note::
189204

190205
If your build tool doesn't support ``abi3t`` yet, set the following macro

‎Doc/library/sys.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2113,7 +2113,7 @@ always available. Unless explicitly noted otherwise, all variables are read-only
21132113
See :ref:`remote-debugging` for more information about the remote debugging
21142114
mechanism.
21152115

2116-
.. audit-event:: sys.remote_exec pid script_path
2116+
.. audit-event:: sys.remote_exec pid,script_path
21172117

21182118
When the code is executed in the remote process, an
21192119
:ref:`auditing event <auditing>` ``sys.remote_exec`` is raised with

‎Doc/using/configure.rst‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,19 @@ Debug options
10221022

10231023
.. versionadded:: 3.6
10241024

1025+
.. option:: --with-hwaddress-sanitizer
1026+
1027+
Enable HWAddressSanitizer memory error detector, ``hwasan`` (default is no).
1028+
Note that on x86-64 this uses `page aliasing
1029+
<https://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html#supported-architectures>`_,
1030+
which only tags heap allocations and is unsafe for programs that ``fork()``,
1031+
including much of the test suite.
1032+
See the `LLVM HWASan design documentation
1033+
<https://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html>`_
1034+
for more information.
1035+
1036+
.. versionadded:: next
1037+
10251038
.. option:: --with-memory-sanitizer
10261039

10271040
Enable MemorySanitizer allocation error detector, ``msan`` (default is no).

‎Doc/whatsnew/3.15.rst‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,16 +572,19 @@ the existing Stable ABI (``abi3``) and the version-specific ABI for
572572
free-threading (``cp315t``) separately.
573573

574574
Stable ABI for Free-Threaded Builds should typically
575-
be selected in a build tool (such as, for example, Setuptools, meson-python,
576-
scikit-build-core, or Maturin).
577-
At the time of writing, these tools do **not** support ``abi3t``.
578-
If this is the case for your tool, compile for ``cp315t`` separately.
575+
be selected in a build tool. Tools with ``abi3t`` support include
576+
meson-python, scikit-build-core, and Maturin; see
577+
:ref:`abi3t-migration-build` for links to their documentation on ``abi3t`` builds.
578+
If your build tool does not support ``abi3t``, compile for ``cp315t`` separately.
579579
If not using a build tool -- or when writing such a tool -- you can select
580580
``abi3t`` by setting the macro :c:macro:`!Py_TARGET_ABI3T` as discussed
581581
in :ref:`abi3-compiling`.
582582

583583
A practical :ref:`migration guide <abi3t-migration-howto>` for switching to
584584
``abi3t`` is available.
585+
The community-maintained `Python Free-Threading Guide
586+
<https://py-free-threading.github.io/abi3t/>`__ provides examples of building
587+
and testing ``abi3t`` wheels.
585588

586589
.. seealso:: :pep:`803` for further details.
587590

‎Doc/whatsnew/3.16.rst‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,11 @@ Build changes
11711171

11721172
(Contributed by Stan Ulbrych in :gh:`139314`.)
11731173

1174+
* Add the :option:`--with-hwaddress-sanitizer` :program:`configure` option to
1175+
build with `HWAddressSanitizer <https://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html>`_.
1176+
1177+
(Contributed by Stan Ulbrych, Florian Mayer and AnnaAr321 in :gh:`156049`.)
1178+
11741179

11751180
C API changes
11761181
=============
@@ -1181,6 +1186,10 @@ New features
11811186
* Add :c:func:`Py_HashBuffer` to the limited C API.
11821187
(Contributed by Victor Stinner in :gh:`148233`.)
11831188

1189+
* Add :c:macro:`Py_SETREF` and :c:macro:`Py_XSETREF` macros to the limited C
1190+
API.
1191+
(Contributed by Nathan Goldbaum and Victor Stinner in :gh:`158842`.)
1192+
11841193
Porting to Python 3.16
11851194
----------------------
11861195

‎Include/cpython/object.h‎

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -326,87 +326,6 @@ _PyObject_GenericSetAttrWithDict(PyObject *, PyObject *,
326326

327327
PyAPI_FUNC(PyObject *) _PyObject_FunctionStr(PyObject *);
328328

329-
/* Safely decref `dst` and set `dst` to `src`.
330-
*
331-
* As in case of Py_CLEAR "the obvious" code can be deadly:
332-
*
333-
* Py_DECREF(dst);
334-
* dst = src;
335-
*
336-
* The safe way is:
337-
*
338-
* Py_SETREF(dst, src);
339-
*
340-
* That arranges to set `dst` to `src` _before_ decref'ing, so that any code
341-
* triggered as a side-effect of `dst` getting torn down no longer believes
342-
* `dst` points to a valid object.
343-
*
344-
* Temporary variables are used to only evaluate macro arguments once and so
345-
* avoid the duplication of side effects. _Py_TYPEOF(), C++ auto, or memcpy()
346-
* is used to avoid a miscompilation caused by type punning. See Py_CLEAR()
347-
* comment for implementation details about type punning.
348-
*
349-
* The memcpy() implementation does not emit a compiler warning if 'src' has
350-
* not the same type than 'src': any pointer type is accepted for 'src'.
351-
*/
352-
#ifdef _Py_TYPEOF
353-
#define Py_SETREF(dst, src) \
354-
do { \
355-
_Py_TYPEOF(&(dst)) _tmp_dst_ptr = &(dst); \
356-
_Py_TYPEOF(dst) _tmp_old_dst = (*_tmp_dst_ptr); \
357-
*_tmp_dst_ptr = (src); \
358-
Py_DECREF(_tmp_old_dst); \
359-
} while (0)
360-
#elif defined(__cplusplus) && (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
361-
#define Py_SETREF(dst, src) \
362-
do { \
363-
auto _tmp_dst_ptr = &(dst); \
364-
auto _tmp_old_dst = (*_tmp_dst_ptr); \
365-
*_tmp_dst_ptr = (src); \
366-
Py_DECREF(_tmp_old_dst); \
367-
} while (0)
368-
#else
369-
#define Py_SETREF(dst, src) \
370-
do { \
371-
PyObject **_tmp_dst_ptr = _Py_CAST(PyObject**, &(dst)); \
372-
PyObject *_tmp_old_dst = (*_tmp_dst_ptr); \
373-
PyObject *_tmp_src = _PyObject_CAST(src); \
374-
memcpy(_tmp_dst_ptr, &_tmp_src, sizeof(PyObject*)); \
375-
Py_DECREF(_tmp_old_dst); \
376-
} while (0)
377-
#endif
378-
379-
/* Py_XSETREF() is a variant of Py_SETREF() that uses Py_XDECREF() instead of
380-
* Py_DECREF().
381-
*/
382-
#ifdef _Py_TYPEOF
383-
#define Py_XSETREF(dst, src) \
384-
do { \
385-
_Py_TYPEOF(&(dst)) _tmp_dst_ptr = &(dst); \
386-
_Py_TYPEOF(dst) _tmp_old_dst = (*_tmp_dst_ptr); \
387-
*_tmp_dst_ptr = (src); \
388-
Py_XDECREF(_tmp_old_dst); \
389-
} while (0)
390-
#elif defined(__cplusplus) && (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
391-
#define Py_XSETREF(dst, src) \
392-
do { \
393-
auto _tmp_dst_ptr = &(dst); \
394-
auto _tmp_old_dst = (*_tmp_dst_ptr); \
395-
*_tmp_dst_ptr = (src); \
396-
Py_XDECREF(_tmp_old_dst); \
397-
} while (0)
398-
#else
399-
#define Py_XSETREF(dst, src) \
400-
do { \
401-
PyObject **_tmp_dst_ptr = _Py_CAST(PyObject**, &(dst)); \
402-
PyObject *_tmp_old_dst = (*_tmp_dst_ptr); \
403-
PyObject *_tmp_src = _PyObject_CAST(src); \
404-
memcpy(_tmp_dst_ptr, &_tmp_src, sizeof(PyObject*)); \
405-
Py_XDECREF(_tmp_old_dst); \
406-
} while (0)
407-
#endif
408-
409-
410329
/* Define a pair of assertion macros:
411330
_PyObject_ASSERT_FROM(), _PyObject_ASSERT_WITH_MSG() and _PyObject_ASSERT().
412331

‎Include/pyport.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,12 @@ extern "C" {
567567
# define _Py_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
568568
# endif
569569
# endif
570+
# if __has_feature(hwaddress_sanitizer)
571+
# if !defined(_Py_ADDRESS_SANITIZER)
572+
# define _Py_ADDRESS_SANITIZER
573+
# define _Py_NO_SANITIZE_ADDRESS __attribute__((no_sanitize("hwaddress")))
574+
# endif
575+
# endif
570576
# if __has_feature(thread_sanitizer)
571577
# if !defined(_Py_THREAD_SANITIZER)
572578
# define _Py_THREAD_SANITIZER
@@ -577,6 +583,9 @@ extern "C" {
577583
# if defined(__SANITIZE_ADDRESS__)
578584
# define _Py_ADDRESS_SANITIZER
579585
# define _Py_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
586+
# elif defined(__SANITIZE_HWADDRESS__)
587+
# define _Py_ADDRESS_SANITIZER
588+
# define _Py_NO_SANITIZE_ADDRESS __attribute__((no_sanitize("hwaddress")))
580589
# endif
581590
# if defined(__SANITIZE_THREAD__)
582591
# define _Py_THREAD_SANITIZER

‎Include/refcount.h‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,87 @@ static inline Py_ALWAYS_INLINE void Py_DECREF(PyObject *op)
516516
#endif
517517

518518

519+
/* Safely decref `dst` and set `dst` to `src`.
520+
*
521+
* As in case of Py_CLEAR "the obvious" code can be deadly:
522+
*
523+
* Py_DECREF(dst);
524+
* dst = src;
525+
*
526+
* The safe way is:
527+
*
528+
* Py_SETREF(dst, src);
529+
*
530+
* That arranges to set `dst` to `src` _before_ decref'ing, so that any code
531+
* triggered as a side-effect of `dst` getting torn down no longer believes
532+
* `dst` points to a valid object.
533+
*
534+
* Temporary variables are used to only evaluate macro arguments once and so
535+
* avoid the duplication of side effects. _Py_TYPEOF(), C++ auto, or memcpy()
536+
* is used to avoid a miscompilation caused by type punning. See Py_CLEAR()
537+
* comment for implementation details about type punning.
538+
*
539+
* The memcpy() implementation does not emit a compiler warning if 'src' has
540+
* not the same type than 'src': any pointer type is accepted for 'src'.
541+
*/
542+
#ifdef _Py_TYPEOF
543+
#define Py_SETREF(dst, src) \
544+
do { \
545+
_Py_TYPEOF(&(dst)) _tmp_dst_ptr = &(dst); \
546+
_Py_TYPEOF(dst) _tmp_old_dst = (*_tmp_dst_ptr); \
547+
*_tmp_dst_ptr = (src); \
548+
Py_DECREF(_tmp_old_dst); \
549+
} while (0)
550+
#elif defined(__cplusplus) && (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
551+
#define Py_SETREF(dst, src) \
552+
do { \
553+
auto _tmp_dst_ptr = &(dst); \
554+
auto _tmp_old_dst = (*_tmp_dst_ptr); \
555+
*_tmp_dst_ptr = (src); \
556+
Py_DECREF(_tmp_old_dst); \
557+
} while (0)
558+
#else
559+
#define Py_SETREF(dst, src) \
560+
do { \
561+
PyObject **_tmp_dst_ptr = _Py_CAST(PyObject**, &(dst)); \
562+
PyObject *_tmp_old_dst = (*_tmp_dst_ptr); \
563+
PyObject *_tmp_src = _PyObject_CAST(src); \
564+
memcpy(_tmp_dst_ptr, &_tmp_src, sizeof(PyObject*)); \
565+
Py_DECREF(_tmp_old_dst); \
566+
} while (0)
567+
#endif
568+
569+
/* Py_XSETREF() is a variant of Py_SETREF() that uses Py_XDECREF() instead of
570+
* Py_DECREF().
571+
*/
572+
#ifdef _Py_TYPEOF
573+
#define Py_XSETREF(dst, src) \
574+
do { \
575+
_Py_TYPEOF(&(dst)) _tmp_dst_ptr = &(dst); \
576+
_Py_TYPEOF(dst) _tmp_old_dst = (*_tmp_dst_ptr); \
577+
*_tmp_dst_ptr = (src); \
578+
Py_XDECREF(_tmp_old_dst); \
579+
} while (0)
580+
#elif defined(__cplusplus) && (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
581+
#define Py_XSETREF(dst, src) \
582+
do { \
583+
auto _tmp_dst_ptr = &(dst); \
584+
auto _tmp_old_dst = (*_tmp_dst_ptr); \
585+
*_tmp_dst_ptr = (src); \
586+
Py_XDECREF(_tmp_old_dst); \
587+
} while (0)
588+
#else
589+
#define Py_XSETREF(dst, src) \
590+
do { \
591+
PyObject **_tmp_dst_ptr = _Py_CAST(PyObject**, &(dst)); \
592+
PyObject *_tmp_old_dst = (*_tmp_dst_ptr); \
593+
PyObject *_tmp_src = _PyObject_CAST(src); \
594+
memcpy(_tmp_dst_ptr, &_tmp_src, sizeof(PyObject*)); \
595+
Py_XDECREF(_tmp_old_dst); \
596+
} while (0)
597+
#endif
598+
599+
519600
/* Function to use in case the object pointer can be NULL: */
520601
static inline void Py_XINCREF(PyObject *op)
521602
{

‎Include/slots.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct PySlot {
4242
#define PySlot_STATIC_DATA(NAME, VALUE) \
4343
{.sl_id=(NAME), .sl_flags=PySlot_STATIC, .sl_ptr=(VALUE)}
4444

45-
#define PySlot_END {0}
45+
#define PySlot_END {0, 0, {0}, {_Py_NULL}}
4646

4747

4848
// Macros without designated initializers (for C++11 and below):

0 commit comments

Comments
 (0)