Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into tail-call
Browse files Browse the repository at this point in the history
  • Loading branch information
Fidget-Spinner committed Jan 13, 2025
2 parents d26ef11 + b70a567 commit 70db5e9
Show file tree
Hide file tree
Showing 88 changed files with 2,237 additions and 909 deletions.
30 changes: 30 additions & 0 deletions Doc/library/ctypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,36 @@ invalid non-\ ``NULL`` pointers would crash Python)::
ValueError: NULL pointer access
>>>

.. _ctypes-thread-safety:

Thread safety without the GIL
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

In Python 3.13, the :term:`GIL` may be disabled on :term:`experimental free threaded <free threading>` builds.
In ctypes, reads and writes to a single object concurrently is safe, but not across multiple objects:

.. code-block:: pycon
>>> number = c_int(42)
>>> pointer_a = pointer(number)
>>> pointer_b = pointer(number)
In the above, it's only safe for one object to read and write to the address at once if the GIL is disabled.
So, ``pointer_a`` can be shared and written to across multiple threads, but only if ``pointer_b``
is not also attempting to do the same. If this is an issue, consider using a :class:`threading.Lock`
to synchronize access to memory:

.. code-block:: pycon
>>> import threading
>>> lock = threading.Lock()
>>> # Thread 1
>>> with lock:
... pointer_a.contents = 24
>>> # Thread 2
>>> with lock:
... pointer_b.contents = 42
.. _ctypes-type-conversions:

Expand Down
18 changes: 12 additions & 6 deletions Doc/library/fnmatch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ module. See module :mod:`glob` for pathname expansion (:mod:`glob` uses
a period are not special for this module, and are matched by the ``*`` and ``?``
patterns.

Also note that :func:`functools.lru_cache` with the *maxsize* of 32768 is used to
cache the compiled regex patterns in the following functions: :func:`fnmatch`,
:func:`fnmatchcase`, :func:`.filter`.
Unless stated otherwise, "filename string" and "pattern string" either refer to
:class:`str` or ``ISO-8859-1`` encoded :class:`bytes` objects. Note that the
functions documented below do not allow to mix a :class:`!bytes` pattern with
a :class:`!str` filename, and vice-versa.

Finally, note that :func:`functools.lru_cache` with a *maxsize* of 32768
is used to cache the (typed) compiled regex patterns in the following
functions: :func:`fnmatch`, :func:`fnmatchcase`, :func:`.filter`.


.. function:: fnmatch(name, pat)

Expand Down Expand Up @@ -78,16 +84,16 @@ cache the compiled regex patterns in the following functions: :func:`fnmatch`,

.. function:: filter(names, pat)

Construct a list from those elements of the :term:`iterable` *names*
that match pattern *pat*.
Construct a list from those elements of the :term:`iterable` of filename
strings *names* that match the pattern string *pat*.
It is the same as ``[n for n in names if fnmatch(n, pat)]``,
but implemented more efficiently.


.. function:: translate(pat)

Return the shell-style pattern *pat* converted to a regular expression for
using with :func:`re.match`.
using with :func:`re.match`. The pattern is expected to be a :class:`str`.

Example:

Expand Down
94 changes: 94 additions & 0 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,100 @@ objects that compare equal might have different :attr:`~range.start`,
single: str (built-in class); (see also string)
pair: object; string

.. _text-methods-summary:

Text and Binary Sequence Type Methods Summary
=============================================
The following table summarizes the text and binary sequence types methods by
category.


+--------------------------+-------------------------------------------+---------------------------------------------------+
| Category | :class:`str` methods | :class:`bytes` and :class:`bytearray` methods |
+==========================+===========================================+===================================================+
| Formatting | :meth:`str.format` | |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.format_map` | |
| +-------------------------------------------+---------------------------------------------------+
| | :ref:`f-strings` | |
| +-------------------------------------------+---------------------------------------------------+
| | :ref:`old-string-formatting` | :ref:`bytes-formatting` |
+--------------------------+------------------+------------------------+--------------------+------------------------------+
| Searching and Replacing | :meth:`str.find` | :meth:`str.rfind` | :meth:`bytes.find` | :meth:`bytes.rfind` |
| +------------------+------------------------+--------------------+------------------------------+
| | :meth:`str.index`| :meth:`str.rindex` | :meth:`bytes.index`| :meth:`bytes.rindex` |
| +------------------+------------------------+--------------------+------------------------------+
| | :meth:`str.startswith` | :meth:`bytes.startswith` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.endswith` | :meth:`bytes.endswith` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.count` | :meth:`bytes.count` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.replace` | :meth:`bytes.replace` |
+--------------------------+-------------------+-----------------------+---------------------+-----------------------------+
| Splitting and Joining | :meth:`str.split` | :meth:`str.rsplit` | :meth:`bytes.split` | :meth:`bytes.rsplit` |
| +-------------------+-----------------------+---------------------+-----------------------------+
| | :meth:`str.splitlines` | :meth:`bytes.splitlines` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.partition` | :meth:`bytes.partition` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.rpartition` | :meth:`bytes.rpartition` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.join` | :meth:`bytes.join` |
+--------------------------+-------------------------------------------+---------------------------------------------------+
| String Classification | :meth:`str.isalpha` | :meth:`bytes.isalpha` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isdecimal` | |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isdigit` | :meth:`bytes.isdigit` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isnumeric` | |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isalnum` | :meth:`bytes.isalnum` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isidentifier` | |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.islower` | :meth:`bytes.islower` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isupper` | :meth:`bytes.isupper` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.istitle` | :meth:`bytes.istitle` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isspace` | :meth:`bytes.isspace` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isprintable` | |
+--------------------------+-------------------------------------------+---------------------------------------------------+
| Case Manipulation | :meth:`str.lower` | :meth:`bytes.lower` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.upper` | :meth:`bytes.upper` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.casefold` | |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.capitalize` | :meth:`bytes.capitalize` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.title` | :meth:`bytes.title` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.swapcase` | :meth:`bytes.swapcase` |
+--------------------------+-------------------+-----------------------+---------------------+-----------------------------+
| Padding and Stripping | :meth:`str.ljust` | :meth:`str.rjust` | :meth:`bytes.ljust` | :meth:`bytes.rjust` |
| +-------------------+-----------------------+---------------------+-----------------------------+
| | :meth:`str.center` | :meth:`bytes.center` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.expandtabs` | :meth:`bytes.expandtabs` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.strip` | :meth:`bytes.strip` |
| +--------------------+----------------------+----------------------+----------------------------+
| | :meth:`str.lstrip` | :meth:`str.rstrip` | :meth:`bytes.lstrip` | :meth:`bytes.rstrip` |
+--------------------------+--------------------+----------------------+----------------------+----------------------------+
| Translation and Encoding | :meth:`str.translate` | :meth:`bytes.translate` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.maketrans` | :meth:`bytes.maketrans` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.encode` | |
| +-------------------------------------------+---------------------------------------------------+
| | | :meth:`bytes.decode` |
+--------------------------+-------------------------------------------+---------------------------------------------------+

.. _textseq:

Text Sequence Type --- :class:`str`
Expand Down
3 changes: 2 additions & 1 deletion Doc/library/sysconfig.rst
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ Other functions

Windows will return one of:

- win-amd64 (64bit Windows on AMD64, aka x86_64, Intel64, and EM64T)
- win-amd64 (64-bit Windows on AMD64, aka x86_64, Intel64, and EM64T)
- win-arm64 (64-bit Windows on ARM64, aka AArch64)
- win32 (all others - specifically, sys.platform is returned)

macOS can return:
Expand Down
16 changes: 16 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,22 @@ io
file's bytes in full. (Contributed by Cody Maloney and Victor Stinner in
:gh:`120754` and :gh:`90102`.)


uuid
----

* Improve generation of :class:`~uuid.UUID` objects via their dedicated
functions:

* :func:`~uuid.uuid3` and :func:`~uuid.uuid5` are both roughly 40% faster
for 16-byte names and 20% faster for 1024-byte names. Performance for
longer names remains unchanged.
* :func:`~uuid.uuid4` and :func:`~uuid.uuid8` are 30% and 40% faster
respectively.

(Contributed by Bénédikt Tran in :gh:`128150`.)


Deprecated
==========

Expand Down
12 changes: 11 additions & 1 deletion Include/cpython/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,27 @@ struct _typeobject {
PyObject *tp_weaklist; /* not used for static builtin types */
destructor tp_del;

/* Type attribute cache version tag. Added in version 2.6 */
/* Type attribute cache version tag. Added in version 2.6.
* If zero, the cache is invalid and must be initialized.
*/
unsigned int tp_version_tag;

destructor tp_finalize;
vectorcallfunc tp_vectorcall;

/* bitset of which type-watchers care about this type */
unsigned char tp_watched;

/* Number of tp_version_tag values used.
* Set to _Py_ATTR_CACHE_UNUSED if the attribute cache is
* disabled for this type (e.g. due to custom MRO entries).
* Otherwise, limited to MAX_VERSIONS_PER_CLASS (defined elsewhere).
*/
uint16_t tp_versions_used;
};

#define _Py_ATTR_CACHE_UNUSED (30000) // (see tp_versions_used)

/* This struct is used by the specializer
* It should be treated as an opaque blob
* by code other than the specializer and interpreter. */
Expand Down
24 changes: 6 additions & 18 deletions Include/internal/pycore_emscripten_trampoline.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,14 @@

#if defined(__EMSCRIPTEN__) && defined(PY_CALL_TRAMPOLINE)

void _Py_EmscriptenTrampoline_Init(_PyRuntimeState *runtime);
void
_Py_EmscriptenTrampoline_Init(_PyRuntimeState *runtime);

PyObject*
_PyEM_TrampolineCall_JavaScript(PyCFunctionWithKeywords func,
PyObject* self,
PyObject* args,
PyObject* kw);

PyObject*
_PyEM_TrampolineCall_Reflection(PyCFunctionWithKeywords func,
PyObject* self,
PyObject* args,
PyObject* kw);

#define _PyEM_TrampolineCall(meth, self, args, kw) \
((_PyRuntime.wasm_type_reflection_available) ? \
(_PyEM_TrampolineCall_Reflection((PyCFunctionWithKeywords)(meth), (self), (args), (kw))) : \
(_PyEM_TrampolineCall_JavaScript((PyCFunctionWithKeywords)(meth), (self), (args), (kw))))
_PyEM_TrampolineCall(PyCFunctionWithKeywords func,
PyObject* self,
PyObject* args,
PyObject* kw);

#define _PyCFunction_TrampolineCall(meth, self, args) \
_PyEM_TrampolineCall( \
Expand All @@ -62,8 +52,6 @@ _PyEM_TrampolineCall_Reflection(PyCFunctionWithKeywords func,

#else // defined(__EMSCRIPTEN__) && defined(PY_CALL_TRAMPOLINE)

#define _Py_EmscriptenTrampoline_Init(runtime)

#define _PyCFunction_TrampolineCall(meth, self, args) \
(meth)((self), (args))

Expand Down
2 changes: 2 additions & 0 deletions Include/internal/pycore_freelist_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern "C" {
# define Py_futureiters_MAXFREELIST 255
# define Py_object_stack_chunks_MAXFREELIST 4
# define Py_unicode_writers_MAXFREELIST 1
# define Py_pymethodobjects_MAXFREELIST 20

// A generic freelist of either PyObjects or other data structures.
struct _Py_freelist {
Expand All @@ -48,6 +49,7 @@ struct _Py_freelists {
struct _Py_freelist futureiters;
struct _Py_freelist object_stack_chunks;
struct _Py_freelist unicode_writers;
struct _Py_freelist pymethodobjects;
};

#ifdef __cplusplus
Expand Down
3 changes: 2 additions & 1 deletion Include/internal/pycore_magic_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ Known values:
Python 3.14a4 3610 (Add VALUE_WITH_FAKE_GLOBALS format to annotationlib)
Python 3.14a4 3611 (Add NOT_TAKEN instruction)
Python 3.14a4 3612 (Add POP_ITER and INSTRUMENTED_POP_ITER)
Python 3.14a4 3613 (Add LOAD_CONST_MORTAL instruction)
Python 3.15 will start with 3650
Expand All @@ -277,7 +278,7 @@ PC/launcher.c must also be updated.
*/

#define PYC_MAGIC_NUMBER 3612
#define PYC_MAGIC_NUMBER 3613
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
(little-endian) and then appending b'\r\n'. */
#define PYC_MAGIC_NUMBER_TOKEN \
Expand Down
Loading

0 comments on commit 70db5e9

Please sign in to comment.