Skip to content

Commit 7466c8d

Browse files
Merge branch '3.13' into backport-b1558b6-3.13
2 parents d1f3676 + 9756d8c commit 7466c8d

27 files changed

Lines changed: 511 additions & 159 deletions

Doc/c-api/conversion.rst

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,33 @@ The following functions provide locale-independent string to number conversions.
162162
.. versionadded:: 3.1
163163
164164
165-
.. c:function:: int PyOS_stricmp(const char *s1, const char *s2)
165+
.. c:function:: int PyOS_mystricmp(const char *str1, const char *str2)
166+
int PyOS_mystrnicmp(const char *str1, const char *str2, Py_ssize_t size)
166167
167-
Case insensitive comparison of strings. The function works almost
168-
identically to :c:func:`!strcmp` except that it ignores the case.
168+
Case insensitive comparison of strings. These functions work almost
169+
identically to :c:func:`!strcmp` and :c:func:`!strncmp` (respectively),
170+
except that they ignore the case of ASCII characters.
169171
172+
Return ``0`` if the strings are equal, a negative value if *str1* sorts
173+
lexicographically before *str2*, or a positive value if it sorts after.
170174
171-
.. c:function:: int PyOS_strnicmp(const char *s1, const char *s2, Py_ssize_t size)
175+
In the *str1* or *str2* arguments, a NUL byte marks the end of the string.
176+
For :c:func:`!PyOS_mystrnicmp`, the *size* argument gives the maximum size
177+
of the string, as if NUL was present at the index given by *size*.
172178
173-
Case insensitive comparison of strings. The function works almost
174-
identically to :c:func:`!strncmp` except that it ignores the case.
179+
These functions do not use the locale.
180+
181+
182+
.. c:function:: int PyOS_stricmp(const char *str1, const char *str2)
183+
int PyOS_strnicmp(const char *str1, const char *str2, Py_ssize_t size)
184+
185+
Case insensitive comparison of strings.
186+
187+
On Windows, these are aliases of :c:func:`!stricmp` and :c:func:`!strnicmp`,
188+
respectively.
189+
190+
On other platforms, they are aliases of :c:func:`PyOS_mystricmp` and
191+
:c:func:`PyOS_mystrnicmp`, respectively.
175192
176193
177194
Character classification and conversion

Doc/c-api/init.rst

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2544,3 +2544,218 @@ code triggered by the finalizer blocks and calls :c:func:`PyEval_SaveThread`.
25442544
In the default build, this macro expands to ``}``.
25452545
25462546
.. versionadded:: 3.13
2547+
2548+
2549+
Legacy Locking APIs
2550+
-------------------
2551+
2552+
These APIs are obsolete since Python 3.13 with the introduction of
2553+
:c:type:`PyMutex`.
2554+
2555+
.. versionchanged:: 3.15
2556+
These APIs are now a simple wrapper around ``PyMutex``.
2557+
2558+
2559+
.. c:type:: PyThread_type_lock
2560+
2561+
A pointer to a mutual exclusion lock.
2562+
2563+
2564+
.. c:type:: PyLockStatus
2565+
2566+
The result of acquiring a lock with a timeout.
2567+
2568+
.. c:namespace:: NULL
2569+
2570+
.. c:enumerator:: PY_LOCK_FAILURE
2571+
2572+
Failed to acquire the lock.
2573+
2574+
.. c:enumerator:: PY_LOCK_ACQUIRED
2575+
2576+
The lock was successfully acquired.
2577+
2578+
.. c:enumerator:: PY_LOCK_INTR
2579+
2580+
The lock was interrupted by a signal.
2581+
2582+
2583+
.. c:function:: PyThread_type_lock PyThread_allocate_lock(void)
2584+
2585+
Allocate a new lock.
2586+
2587+
On success, this function returns a lock; on failure, this
2588+
function returns ``0`` without an exception set.
2589+
2590+
The caller does not need to hold the :term:`GIL`.
2591+
2592+
.. versionchanged:: 3.15
2593+
This function now always uses :c:type:`PyMutex`. In prior versions, this
2594+
would use a lock provided by the operating system.
2595+
2596+
2597+
.. c:function:: void PyThread_free_lock(PyThread_type_lock lock)
2598+
2599+
Destroy *lock*. The lock should not be held by any thread when calling
2600+
this.
2601+
2602+
The caller does not need to hold the :term:`GIL`.
2603+
2604+
2605+
.. c:function:: PyLockStatus PyThread_acquire_lock_timed(PyThread_type_lock lock, long long microseconds, int intr_flag)
2606+
2607+
Acquire *lock* with a timeout.
2608+
2609+
This will wait for *microseconds* microseconds to acquire the lock. If the
2610+
timeout expires, this function returns :c:enumerator:`PY_LOCK_FAILURE`.
2611+
If *microseconds* is ``-1``, this will wait indefinitely until the lock has
2612+
been released.
2613+
2614+
If *intr_flag* is ``1``, acquiring the lock may be interrupted by a signal,
2615+
in which case this function returns :c:enumerator:`PY_LOCK_INTR`. Upon
2616+
interruption, it's generally expected that the caller makes a call to
2617+
:c:func:`Py_MakePendingCalls` to propagate an exception to Python code.
2618+
2619+
If the lock is successfully acquired, this function returns
2620+
:c:enumerator:`PY_LOCK_ACQUIRED`.
2621+
2622+
The caller does not need to hold the :term:`GIL`.
2623+
2624+
2625+
.. c:function:: int PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)
2626+
2627+
Acquire *lock*.
2628+
2629+
If *waitflag* is ``1`` and another thread currently holds the lock, this
2630+
function will wait until the lock can be acquired and will always return
2631+
``1``.
2632+
2633+
If *waitflag* is ``0`` and another thread holds the lock, this function will
2634+
not wait and instead return ``0``. If the lock is not held by any other
2635+
thread, then this function will acquire it and return ``1``.
2636+
2637+
Unlike :c:func:`PyThread_acquire_lock_timed`, acquiring the lock cannot be
2638+
interrupted by a signal.
2639+
2640+
The caller does not need to hold the :term:`GIL`.
2641+
2642+
2643+
.. c:function:: int PyThread_release_lock(PyThread_type_lock lock)
2644+
2645+
Release *lock*. If *lock* is not held, then this function issues a
2646+
fatal error.
2647+
2648+
The caller does not need to hold the :term:`GIL`.
2649+
2650+
2651+
Operating System Thread APIs
2652+
============================
2653+
2654+
.. c:macro:: PYTHREAD_INVALID_THREAD_ID
2655+
2656+
Sentinel value for an invalid thread ID.
2657+
2658+
This is currently equivalent to ``(unsigned long)-1``.
2659+
2660+
2661+
.. c:function:: unsigned long PyThread_start_new_thread(void (*func)(void *), void *arg)
2662+
2663+
Start function *func* in a new thread with argument *arg*.
2664+
The resulting thread is not intended to be joined.
2665+
2666+
*func* must not be ``NULL``, but *arg* may be ``NULL``.
2667+
2668+
On success, this function returns the identifier of the new thread; on failure,
2669+
this returns :c:macro:`PYTHREAD_INVALID_THREAD_ID`.
2670+
2671+
The caller does not need to hold the :term:`GIL`.
2672+
2673+
2674+
.. c:function:: unsigned long PyThread_get_thread_ident(void)
2675+
2676+
Return the identifier of the current thread, which will never be zero.
2677+
2678+
This function cannot fail, and the caller does not need to hold the
2679+
:term:`GIL`.
2680+
2681+
.. seealso::
2682+
:py:func:`threading.get_ident`
2683+
2684+
2685+
.. c:function:: PyObject *PyThread_GetInfo(void)
2686+
2687+
Get general information about the current thread in the form of a
2688+
:ref:`struct sequence <struct-sequence-objects>` object. This information is
2689+
accessible as :py:attr:`sys.thread_info` in Python.
2690+
2691+
On success, this returns a new :term:`strong reference` to the thread
2692+
information; on failure, this returns ``NULL`` with an exception set.
2693+
2694+
The caller must hold the :term:`GIL`.
2695+
2696+
2697+
.. c:macro:: PY_HAVE_THREAD_NATIVE_ID
2698+
2699+
This macro is defined when the system supports native thread IDs.
2700+
2701+
2702+
.. c:function:: unsigned long PyThread_get_thread_native_id(void)
2703+
2704+
Get the native identifier of the current thread as it was assigned by the operating
2705+
system's kernel, which will never be less than zero.
2706+
2707+
This function is only available when :c:macro:`PY_HAVE_THREAD_NATIVE_ID` is
2708+
defined.
2709+
2710+
This function cannot fail, and the caller does not need to hold the
2711+
:term:`GIL`.
2712+
2713+
.. seealso::
2714+
:py:func:`threading.get_native_id`
2715+
2716+
2717+
.. c:function:: void PyThread_exit_thread(void)
2718+
2719+
Terminate the current thread. This function is generally considered unsafe
2720+
and should be avoided. It is kept solely for backwards compatibility.
2721+
2722+
This function is only safe to call if all functions in the full call
2723+
stack are written to safely allow it.
2724+
2725+
.. warning::
2726+
2727+
If the current system uses POSIX threads (also known as "pthreads"),
2728+
this calls :manpage:`pthread_exit(3)`, which attempts to unwind the stack
2729+
and call C++ destructors on some libc implementations. However, if a
2730+
``noexcept`` function is reached, it may terminate the process.
2731+
Other systems, such as macOS, do unwinding.
2732+
2733+
On Windows, this function calls ``_endthreadex()``, which kills the thread
2734+
without calling C++ destructors.
2735+
2736+
In any case, there is a risk of corruption on the thread's stack.
2737+
2738+
2739+
.. c:function:: void PyThread_init_thread(void)
2740+
2741+
Initialize ``PyThread*`` APIs. Python executes this function automatically,
2742+
so there's little need to call it from an extension module.
2743+
2744+
2745+
.. c:function:: int PyThread_set_stacksize(size_t size)
2746+
2747+
Set the stack size of the current thread to *size* bytes.
2748+
2749+
This function returns ``0`` on success, ``-1`` if *size* is invalid, or
2750+
``-2`` if the system does not support changing the stack size. This function
2751+
does not set exceptions.
2752+
2753+
The caller does not need to hold the :term:`GIL`.
2754+
2755+
2756+
.. c:function:: size_t PyThread_get_stacksize(void)
2757+
2758+
Return the stack size of the current thread in bytes, or ``0`` if the system's
2759+
default stack size is in use.
2760+
2761+
The caller does not need to hold the :term:`GIL`.

Doc/c-api/intro.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,19 @@ complete listing.
326326
PyDoc_VAR(python_doc) = PyDoc_STR("A genus of constricting snakes in the Pythonidae family native "
327327
"to the tropics and subtropics of the Eastern Hemisphere.");
328328

329+
.. c:macro:: Py_ARRAY_LENGTH(array)
330+
331+
Compute the length of a statically allocated C array at compile time.
332+
333+
The *array* argument must be a C array with a size known at compile time.
334+
Passing an array with an unknown size, such as a heap-allocated array,
335+
will result in a compilation error on some compilers, or otherwise produce
336+
incorrect results.
337+
338+
This is roughly equivalent to::
339+
340+
sizeof(array) / sizeof((array)[0])
341+
329342

330343
.. _api-objects:
331344

Doc/c-api/module.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ The available slot types are:
404404
``PyModuleDef`` has non-``NULL`` ``m_traverse``, ``m_clear``,
405405
``m_free``; non-zero ``m_size``; or slots other than ``Py_mod_create``.
406406
407+
.. versionadded:: 3.5
408+
407409
.. c:macro:: Py_mod_exec
408410
409411
Specifies a function that is called to *execute* the module.
@@ -418,6 +420,8 @@ The available slot types are:
418420
If multiple ``Py_mod_exec`` slots are specified, they are processed in the
419421
order they appear in the *m_slots* array.
420422
423+
.. versionadded:: 3.5
424+
421425
.. c:macro:: Py_mod_multiple_interpreters
422426
423427
Specifies one of the following values:

Doc/c-api/veryhigh.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,43 @@ Available start symbols
396396
* :pep:`484`
397397
398398
.. versionadded:: 3.8
399+
400+
401+
Stack Effects
402+
^^^^^^^^^^^^^
403+
404+
.. seealso::
405+
:py:func:`dis.stack_effect`
406+
407+
408+
.. c:macro:: PY_INVALID_STACK_EFFECT
409+
410+
Sentinel value representing an invalid stack effect.
411+
412+
This is currently equivalent to ``INT_MAX``.
413+
414+
.. versionadded:: 3.8
415+
416+
417+
.. c:function:: int PyCompile_OpcodeStackEffect(int opcode, int oparg)
418+
419+
Compute the stack effect of *opcode* with argument *oparg*.
420+
421+
On success, this function returns the stack effect; on failure, this
422+
returns :c:macro:`PY_INVALID_STACK_EFFECT`.
423+
424+
.. versionadded:: 3.4
425+
426+
427+
.. c:function:: int PyCompile_OpcodeStackEffectWithJump(int opcode, int oparg, int jump)
428+
429+
Similar to :c:func:`PyCompile_OpcodeStackEffect`, but don't include the
430+
stack effect of jumping if *jump* is zero.
431+
432+
If *jump* is ``0``, this will not include the stack effect of jumping, but
433+
if *jump* is ``1`` or ``-1``, this will include it.
434+
435+
On success, this function returns the stack effect; on failure, this
436+
returns :c:macro:`PY_INVALID_STACK_EFFECT`.
437+
438+
.. versionadded:: 3.8

Doc/data/stable_abi.dat

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

Doc/howto/a-conceptual-overview-of-asyncio.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,12 @@ The recommended way to create tasks is via :func:`asyncio.create_task`.
175175
Creating a task automatically schedules it for execution (by adding a
176176
callback to run it in the event loop's to-do list, that is, collection of jobs).
177177

178-
Since there's only one event loop (in each thread), :mod:`!asyncio` takes care of
179-
associating the task with the event loop for you. As such, there's no need
180-
to specify the event loop.
178+
:mod:`!asyncio` automatically associates tasks with the event loop for you.
179+
This automatic association was purposely designed into :mod:`!asyncio` for
180+
the sake of simplicity.
181+
Without it, you'd have to keep track of the event loop object and pass it to
182+
any coroutine function that wants to create tasks, adding redundant clutter
183+
to your code.
181184

182185
::
183186

Doc/howto/unicode.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ If you don't include such a comment, the default encoding used will be UTF-8 as
352352
already mentioned. See also :pep:`263` for more information.
353353

354354

355+
.. _unicode-properties:
356+
355357
Unicode Properties
356358
------------------
357359

0 commit comments

Comments
 (0)