Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into gh-112069-init
Browse files Browse the repository at this point in the history
  • Loading branch information
corona10 committed Apr 20, 2024
2 parents 9cca889 + d8f3503 commit abecdf0
Show file tree
Hide file tree
Showing 61 changed files with 786 additions and 166 deletions.
2 changes: 1 addition & 1 deletion Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ Process-wide parameters
It is recommended that applications embedding the Python interpreter
for purposes other than executing a single script pass ``0`` as *updatepath*,
and update :data:`sys.path` themselves if desired.
See `CVE-2008-5983 <https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-5983>`_.
See :cve:`2008-5983`.
On versions before 3.1.3, you can achieve the same effect by manually
popping the first :data:`sys.path` element after having called
Expand Down
6 changes: 6 additions & 0 deletions Doc/c-api/tuple.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ Tuple Objects
Return the object at position *pos* in the tuple pointed to by *p*. If *pos* is
negative or out of bounds, return ``NULL`` and set an :exc:`IndexError` exception.
The returned reference is borrowed from the tuple *p*
(that is: it is only valid as long as you hold a reference to *p*).
To get a :term:`strong reference`, use
:c:func:`Py_NewRef(PyTuple_GetItem(...)) <Py_NewRef>`
or :c:func:`PySequence_GetItem`.
.. c:function:: PyObject* PyTuple_GET_ITEM(PyObject *p, Py_ssize_t pos)
Expand Down
3 changes: 2 additions & 1 deletion Doc/c-api/typeobj.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,8 @@ and :c:data:`PyType_Type` effectively act as defaults.)
the type, and the type object is INCREF'ed when a new instance is created, and
DECREF'ed when an instance is destroyed (this does not apply to instances of
subtypes; only the type referenced by the instance's ob_type gets INCREF'ed or
DECREF'ed).
DECREF'ed). Heap types should also :ref:`support garbage collection <supporting-cycle-detection>`
as they can form a reference cycle with their own module object.

**Inheritance:**

Expand Down
5 changes: 3 additions & 2 deletions Doc/library/ast.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2536,7 +2536,8 @@ to stdout. Otherwise, the content is read from stdin.
code that generated them. This is helpful for tools that make source code
transformations.

`leoAst.py <https://leoeditor.com/appendices.html#leoast-py>`_ unifies the
`leoAst.py <https://leo-editor.github.io/leo-editor/appendices.html#leoast-py>`_
unifies the
token-based and parse-tree-based views of python programs by inserting
two-way links between tokens and ast nodes.

Expand All @@ -2548,4 +2549,4 @@ to stdout. Otherwise, the content is read from stdin.
`Parso <https://parso.readthedocs.io>`_ is a Python parser that supports
error recovery and round-trip parsing for different Python versions (in
multiple Python versions). Parso is also able to list multiple syntax errors
in your python file.
in your Python file.
14 changes: 7 additions & 7 deletions Doc/library/statistics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,9 @@ However, for reading convenience, most of the examples show sorted sequences.
variance indicates that the data is spread out; a small variance indicates
it is clustered closely around the mean.

If the optional second argument *mu* is given, it is typically the mean of
the *data*. It can also be used to compute the second moment around a
point that is not the mean. If it is missing or ``None`` (the default),
If the optional second argument *mu* is given, it should be the *population*
mean of the *data*. It can also be used to compute the second moment around
a point that is not the mean. If it is missing or ``None`` (the default),
the arithmetic mean is automatically calculated.

Use this function to calculate the variance from the entire population. To
Expand Down Expand Up @@ -573,8 +573,8 @@ However, for reading convenience, most of the examples show sorted sequences.
the data is spread out; a small variance indicates it is clustered closely
around the mean.

If the optional second argument *xbar* is given, it should be the mean of
*data*. If it is missing or ``None`` (the default), the mean is
If the optional second argument *xbar* is given, it should be the *sample*
mean of *data*. If it is missing or ``None`` (the default), the mean is
automatically calculated.

Use this function when your data is a sample from a population. To calculate
Expand All @@ -590,8 +590,8 @@ However, for reading convenience, most of the examples show sorted sequences.
>>> variance(data)
1.3720238095238095

If you have already calculated the mean of your data, you can pass it as the
optional second argument *xbar* to avoid recalculation:
If you have already calculated the sample mean of your data, you can pass it
as the optional second argument *xbar* to avoid recalculation:

.. doctest::

Expand Down
7 changes: 7 additions & 0 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5542,6 +5542,13 @@ types, where they are relevant. Some of these are not reported by the
[<class 'bool'>, <enum 'IntEnum'>, <flag 'IntFlag'>, <class 're._constants._NamedIntConstant'>]


.. attribute:: class.__static_attributes__

A tuple containing names of attributes of this class which are accessed
through ``self.X`` from any function in its body.

.. versionadded:: 3.13

.. _int_max_str_digits:

Integer string conversion length limitation
Expand Down
10 changes: 7 additions & 3 deletions Doc/library/tarfile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -637,11 +637,15 @@ be finalized; only the internally used file object will be closed. See the

.. method:: TarFile.addfile(tarinfo, fileobj=None)

Add the :class:`TarInfo` object *tarinfo* to the archive. If *fileobj* is given,
it should be a :term:`binary file`, and
``tarinfo.size`` bytes are read from it and added to the archive. You can
Add the :class:`TarInfo` object *tarinfo* to the archive. If *tarinfo* represents
a non zero-size regular file, the *fileobj* argument should be a :term:`binary file`,
and ``tarinfo.size`` bytes are read from it and added to the archive. You can
create :class:`TarInfo` objects directly, or by using :meth:`gettarinfo`.

.. versionchanged:: 3.13

*fileobj* must be given for non-zero-sized regular files.


.. method:: TarFile.gettarinfo(name=None, arcname=None, fileobj=None)

Expand Down
4 changes: 3 additions & 1 deletion Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3024,7 +3024,9 @@ Introspection helpers

This is often the same as ``obj.__annotations__``. In addition,
forward references encoded as string literals are handled by evaluating
them in ``globals`` and ``locals`` namespaces. For a class ``C``, return
them in ``globals``, ``locals`` and (where applicable)
:ref:`type parameter <type-params>` namespaces.
For a class ``C``, return
a dictionary constructed by merging all the ``__annotations__`` along
``C.__mro__`` in reverse order.

Expand Down
5 changes: 5 additions & 0 deletions Doc/reference/datamodel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,7 @@ A class object can be called (see above) to yield a class instance (see below).
single: __doc__ (class attribute)
single: __annotations__ (class attribute)
single: __type_params__ (class attribute)
single: __static_attributes__ (class attribute)

Special attributes:

Expand Down Expand Up @@ -1000,6 +1001,10 @@ Special attributes:
A tuple containing the :ref:`type parameters <type-params>` of
a :ref:`generic class <generic-classes>`.

:attr:`~class.__static_attributes__`
A tuple containing names of attributes of this class which are accessed
through ``self.X`` from any function in its body.


Class instances
---------------
Expand Down
6 changes: 3 additions & 3 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ inspect

* Add :func:`inspect.markcoroutinefunction` to mark sync functions that return
a :term:`coroutine` for use with :func:`inspect.iscoroutinefunction`.
(Contributed Carlton Gibson in :gh:`99247`.)
(Contributed by Carlton Gibson in :gh:`99247`.)

* Add :func:`inspect.getasyncgenstate` and :func:`inspect.getasyncgenlocals`
for determining the current state of asynchronous generators.
Expand All @@ -751,8 +751,8 @@ math
(Contributed by Raymond Hettinger in :gh:`100485`.)

* Extend :func:`math.nextafter` to include a *steps* argument
for moving up or down multiple steps at a time.
(By Matthias Goergens, Mark Dickinson, and Raymond Hettinger in :gh:`94906`.)
for moving up or down multiple steps at a time. (Contributed by
Matthias Goergens, Mark Dickinson, and Raymond Hettinger in :gh:`94906`.)

os
--
Expand Down
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ Improved Error Messages
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
TypeError: split() got an unexpected keyword argument 'max_split'. Did you mean 'maxsplit'?

* Classes have a new :attr:`~class.__static_attributes__` attribute, populated by the compiler,
with a tuple of names of attributes of this class which are accessed
through ``self.X`` from any function in its body. (Contributed by Irit Katriel
in :gh:`115775`.)

Incremental Garbage Collection
------------------------------

Expand Down
8 changes: 8 additions & 0 deletions Include/cpython/pyatomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,16 @@ _Py_atomic_store_ullong_relaxed(unsigned long long *obj,
static inline void *
_Py_atomic_load_ptr_acquire(const void *obj);

static inline uintptr_t
_Py_atomic_load_uintptr_acquire(const uintptr_t *obj);

// Stores `*obj = value` (release operation)
static inline void
_Py_atomic_store_ptr_release(void *obj, void *value);

static inline void
_Py_atomic_store_uintptr_release(uintptr_t *obj, uintptr_t value);

static inline void
_Py_atomic_store_ssize_release(Py_ssize_t *obj, Py_ssize_t value);

Expand All @@ -491,6 +497,8 @@ static inline Py_ssize_t
_Py_atomic_load_ssize_acquire(const Py_ssize_t *obj);




// --- _Py_atomic_fence ------------------------------------------------------

// Sequential consistency fence. C11 fences have complex semantics. When
Expand Down
8 changes: 8 additions & 0 deletions Include/cpython/pyatomic_gcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,18 @@ static inline void *
_Py_atomic_load_ptr_acquire(const void *obj)
{ return (void *)__atomic_load_n((void **)obj, __ATOMIC_ACQUIRE); }

static inline uintptr_t
_Py_atomic_load_uintptr_acquire(const uintptr_t *obj)
{ return (uintptr_t)__atomic_load_n((uintptr_t *)obj, __ATOMIC_ACQUIRE); }

static inline void
_Py_atomic_store_ptr_release(void *obj, void *value)
{ __atomic_store_n((void **)obj, value, __ATOMIC_RELEASE); }

static inline void
_Py_atomic_store_uintptr_release(uintptr_t *obj, uintptr_t value)
{ __atomic_store_n(obj, value, __ATOMIC_RELEASE); }

static inline void
_Py_atomic_store_int_release(int *obj, int value)
{ __atomic_store_n(obj, value, __ATOMIC_RELEASE); }
Expand Down
25 changes: 25 additions & 0 deletions Include/cpython/pyatomic_msc.h
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,18 @@ _Py_atomic_load_ptr_acquire(const void *obj)
#endif
}

static inline uintptr_t
_Py_atomic_load_uintptr_acquire(const uintptr_t *obj)
{
#if defined(_M_X64) || defined(_M_IX86)
return *(uintptr_t volatile *)obj;
#elif defined(_M_ARM64)
return (uintptr_t)__ldar64((unsigned __int64 volatile *)obj);
#else
# error "no implementation of _Py_atomic_load_uintptr_acquire"
#endif
}

static inline void
_Py_atomic_store_ptr_release(void *obj, void *value)
{
Expand All @@ -926,6 +938,19 @@ _Py_atomic_store_ptr_release(void *obj, void *value)
#endif
}

static inline void
_Py_atomic_store_uintptr_release(uintptr_t *obj, uintptr_t value)
{
#if defined(_M_X64) || defined(_M_IX86)
*(uintptr_t volatile *)obj = value;
#elif defined(_M_ARM64)
_Py_atomic_ASSERT_ARG_TYPE(unsigned __int64);
__stlr64((unsigned __int64 volatile *)obj, (unsigned __int64)value);
#else
# error "no implementation of _Py_atomic_store_uintptr_release"
#endif
}

static inline void
_Py_atomic_store_int_release(int *obj, int value)
{
Expand Down
16 changes: 16 additions & 0 deletions Include/cpython/pyatomic_std.h
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,14 @@ _Py_atomic_load_ptr_acquire(const void *obj)
memory_order_acquire);
}

static inline uintptr_t
_Py_atomic_load_uintptr_acquire(const uintptr_t *obj)
{
_Py_USING_STD;
return atomic_load_explicit((const _Atomic(uintptr_t)*)obj,
memory_order_acquire);
}

static inline void
_Py_atomic_store_ptr_release(void *obj, void *value)
{
Expand All @@ -871,6 +879,14 @@ _Py_atomic_store_ptr_release(void *obj, void *value)
memory_order_release);
}

static inline void
_Py_atomic_store_uintptr_release(uintptr_t *obj, uintptr_t value)
{
_Py_USING_STD;
atomic_store_explicit((_Atomic(uintptr_t)*)obj, value,
memory_order_release);
}

static inline void
_Py_atomic_store_int_release(int *obj, int value)
{
Expand Down
4 changes: 4 additions & 0 deletions Include/cpython/setobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ typedef struct {
(assert(PyAnySet_Check(so)), _Py_CAST(PySetObject*, so))

static inline Py_ssize_t PySet_GET_SIZE(PyObject *so) {
#ifdef Py_GIL_DISABLED
return _Py_atomic_load_ssize_relaxed(&(_PySet_CAST(so)->used));
#else
return _PySet_CAST(so)->used;
#endif
}
#define PySet_GET_SIZE(so) PySet_GET_SIZE(_PyObject_CAST(so))
1 change: 1 addition & 0 deletions Include/internal/pycore_ceval_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct _ceval_runtime_state {
} perf;
/* Pending calls to be made only on the main thread. */
struct _pending_calls pending_mainthread;
PyMutex sys_trace_profile_mutex;
};

#ifdef PY_HAVE_PERF_TRAMPOLINE
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static inline void _PyObject_GC_SET_SHARED(PyObject *op) {
* threads and needs special purpose when freeing due to
* the possibility of in-flight lock-free reads occurring.
* Objects with this bit that are GC objects will automatically
* delay-freed by PyObject_GC_Del. */
* delay-freed by PyObject_GC_Del. */
static inline int _PyObject_GC_IS_SHARED_INLINE(PyObject *op) {
return (op->ob_gc_bits & _PyGC_BITS_SHARED_INLINE) != 0;
}
Expand Down
Loading

0 comments on commit abecdf0

Please sign in to comment.