8000 Merge branch 'main' into small_int_immortal_v2 · python/cpython@d91b6e3 · GitHub
[go: up one dir, main page]

Skip to content

Commit d91b6e3

Browse files
authored
Merge branch 'main' into small_int_immortal_v2
2 parents 7834406 + 39e69a7 commit d91b6e3

File tree

85 files changed

+2292
-1064
lines changed

Some content is hidden

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

85 files changed

+2292
-1064
lines changed

.github/workflows/reusable-macos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
run: |
4343
brew install pkg-config openssl@3.0 xz gdbm tcl-tk@8 make
4444
# Because alternate versions are not symlinked into place by default:
45-
brew link tcl-tk@8
45+
brew link --overwrite tcl-tk@8
4646
- name: Configure CPython
4747
run: |
4848
GDBM_CFLAGS="-I$(brew --prefix gdbm)/include" \

Doc/c-api/monitoring.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,14 @@ See :mod:`sys.monitoring` for descriptions of the events.
7575
Fire a ``JUMP`` event.
7676
7777
78-
.. c:function:: int PyMonitoring_FireBranchEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, PyObject *target_offset)
78+
.. c:function:: int PyMonitoring_FireBranchLeftEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, PyObject *target_offset)
7979
80-
Fire a ``BRANCH`` event.
80+
Fire a ``BRANCH_LEFT`` event.
81+
82+
83+
.. c:function:: int PyMonitoring_FireBranchRightEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, PyObject *target_offset)
84+
85+
Fire a ``BRANCH_RIGHT`` event.
8186
8287
8388
.. c:function:: int PyMonitoring_FireCReturnEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, PyObject *retval)
@@ -168,7 +173,8 @@ would typically correspond to a python function.
168173
================================================== =====================================
169174
Macro Event
170175
================================================== =====================================
171-
.. c:macro:: PY_MONITORING_EVENT_BRANCH :monitoring-event:`BRANCH`
176+
.. c:macro:: PY_MONITORING_EVENT_BRANCH_LEFT :monitoring-event:`BRANCH_LEFT`
177+
.. c:macro:: PY_MONITORING_EVENT_BRANCH_RIGHT :monitoring-event:`BRANCH_RIGHT`
172178
.. c:macro:: PY_MONITORING_EVENT_CALL :monitoring-event:`CALL`
173179
.. c:macro:: PY_MONITORING_EVENT_C_RAISE :monitoring-event:`C_RAISE`
174180
.. c:macro:: PY_MONITORING_EVENT_C_RETURN :monitoring-event:`C_RETURN`

Doc/c-api/weakref.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ as much as it can.
8888
Use :c:func:`PyWeakref_GetRef` instead.
8989
9090
91+
.. c:function:: int PyWeakref_IsDead(PyObject *ref)
92+
93+
Test if the weak reference *ref* is dead. Returns 1 if the reference is
94+
dead, 0 if it is alive, and -1 with an error set if *ref* is not a weak
95+
reference object.
96+
97+
.. versionadded:: 3.14
98+
99+
91100
.. c:function:: void PyObject_ClearWeakRefs(PyObject *object)
92101
93102
This function is called by the :c:member:`~PyTypeObject.tp_dealloc` handler

Doc/library/asyncio-policy.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ for the current process:
4040

4141
Return the current process-wide policy.
4242

43+
.. deprecated:: next
44+
The :func:`get_event_loop_policy` function is deprecated and
45+
will be removed in Python 3.16.
46+
4347
.. function:: set_event_loop_policy(policy)
4448

4549
Set the current process-wide policy to *policy*.

Doc/library/enum.rst

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,14 @@ Module Contents
149149

150150
Return a list of all power-of-two integers contained in a flag.
151151

152+
:class:`EnumDict`
153+
154+
A subclass of :class:`dict` for use when subclassing :class:`EnumType`.
155+
152156

153157
.. versionadded:: 3.6 ``Flag``, ``IntFlag``, ``auto``
154158
.. versionadded:: 3.11 ``StrEnum``, ``EnumCheck``, ``ReprEnum``, ``FlagBoundary``, ``property``, ``member``, ``nonmember``, ``global_enum``, ``show_flag_values``
159+
.. versionadded:: 3.14 ``EnumDict``
155160

156161
---------------
157162

@@ -821,7 +826,17 @@ Data Types
821826
>>> KeepFlag(2**2 + 2**4)
822827
<KeepFlag.BLUE|16: 20>
823828

824-
.. versionadded:: 3.11
829+
.. versionadded:: 3.11
830+
831+
.. class:: EnumDict
832+
833+
*EnumDict* is a subclass of :class:`dict` for use when subclassing :class:`EnumType`.
834+
835+
.. attribute:: EnumDict.member_names
836+
837+
Return list of member names.
838+
839+
.. versionadded:: 3.14
825840

826841
---------------
827842

Doc/library/inspect.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,13 @@ which is a bitmap of the following flags:
17081708

17091709
.. versionadded:: 3.14
17101710

1711+
.. data:: CO_METHOD
1712+
1713+
The flag is set when the code object is a function defined in class
1714+
scope.
1715+
1716+
.. versionadded:: 3.14
1717+
17111718
.. note::
17121719
The flags are specific to CPython, and may not be defined in other
17131720
Python implementations. Furthermore, the flags are an implementation

Doc/library/os.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5420,10 +5420,22 @@ operating system.
54205420
Scheduling policy for CPU-intensive processes that tries to preserve
54215421
interactivity on the rest of the computer.
54225422

5423+
.. data:: SCHED_DEADLINE
5424+
5425+
Scheduling policy for tasks with deadline constraints.
5426+
5427+
.. versionadded:: next
5428+
54235429
.. data:: SCHED_IDLE
54245430

54255431
Scheduling policy for extremely low priority background tasks.
54265432

5433+
.. data:: SCHED_NORMAL
5434+
5435+
Alias for :data:`SCHED_OTHER`.
5436+
5437+
.. versionadded:: next
5438+
54275439
.. data:: SCHED_SPORADIC
54285440

54295441
Scheduling policy for sporadic server programs.

Doc/library/ssl.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,8 +2508,8 @@ thus several things you need to be aware of:
25082508
.. seealso::
25092509

25102510
The :mod:`asyncio` module supports :ref:`non-blocking SSL sockets
2511-
<ssl-nonblocking>` and provides a
2512-
higher level API. It polls for events using the :mod:`selectors` module and
2511+
<ssl-nonblocking>` and provides a higher level :ref:`Streams API <asyncio-streams>`.
2512+
It polls for events using the :mod:`selectors` module and
25132513
handles :exc:`SSLWantWriteError`, :exc:`SSLWantReadError` and
25142514
:exc:`BlockingIOError` exceptions. It runs the SSL handshake asynchronously
25152515
as well.

Doc/library/sys.monitoring.rst

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,17 @@ Events
7979

8080
The following events are supported:
8181

82-
.. monitoring-event:: BRANCH
82+
.. monitoring-event:: BRANCH_LEFT
8383

84-
A conditional branch is taken (or not).
84+
A conditional branch goes left.
85+
86+
It is up to the tool to determine how to present "left" and "right" branches.
87+
There is no guarantee which branch is "left" and which is "right", except
88+
that it will be consistent for the duration of the program.
89+
90+
.. monitoring-event:: BRANCH_RIGHT
91+
92+
A conditional branch goes right.
8593

8694
.. monitoring-event:: CALL
8795

@@ -180,9 +188,20 @@ The local events are:
180188
* :monitoring-event:`LINE`
181189
* :monitoring-event:`INSTRUCTION`
182190
* :monitoring-event:`JUMP`
183-
* :monitoring-event:`BRANCH`
191+
* :monitoring-event:`BRANCH_LEFT`
192+
* :monitoring-event:`BRANCH_RIGHT`
184193
* :monitoring-event:`STOP_ITERATION`
185194

195+
Deprecated event
196+
''''''''''''''''
197+
198+
* ``BRANCH``
199+
200+
The ``BRANCH`` event is deprecated in 3.14.
201+
Using :monitoring-event:`BRANCH_LEFT` and :monitoring-event:`BRANCH_RIGHT`
202+
events will give much better performance as they can be disabled
203+
independently.
204+
186205
Ancillary events
187206
''''''''''''''''
188207

@@ -357,13 +376,11 @@ Different events will provide the callback function with different arguments, as
357376

358377
func(code: CodeType, line_number: int) -> DISABLE | Any
359378

360-
* :monitoring-event:`BRANCH` and :monitoring-event:`JUMP`::
379+
* :monitoring-event:`BRANCH_LEFT`, :monitoring-event:`BRANCH_RIGHT` and :monitoring-event:`JUMP`::
361380

362381
func(code: CodeType, instruction_offset: int, destination_offset: int) -> DISABLE | Any
363382

364383
Note that the *destination_offset* is where the code will next execute.
365-
For an untaken branch this will be the offset of the instruction following
366-
the branch.
367384

368385
* :monitoring-event:`INSTRUCTION`::
369386

Doc/whatsnew/3.13.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,11 @@ email
879879
(Contributed by Thomas Dwyer and Victor Stinner for :gh:`102988` to improve
880880
the :cve:`2023-27043` fix.)
881881

882+
enum
883+
----
884+
885+
* :class:`~enum.EnumDict` has been made public in :mod:`enum` to better support
886+
subclassing :class:`~enum.EnumType`.
882887

883888
fractions
884889
---------
@@ -1971,7 +1976,7 @@ New Features
19711976
* :c:func:`PyMonitoring_FireCallEvent`
19721977
* :c:func:`PyMonitoring_FireLineEvent`
19731978
* :c:func:`PyMonitoring_FireJumpEvent`
1974-
* :c:func:`PyMonitoring_FireBranchEvent`
1979+
* ``PyMonitoring_FireBranchEvent``
19751980
* :c:func:`PyMonitoring_FireCReturnEvent`
19761981
* :c:func:`PyMonitoring_FirePyThrowEvent`
19771982
* :c:func:`PyMonitoring_FireRaiseEvent`

Doc/whatsnew/3.14.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,10 @@ os
525525
same process.
526526
(Contributed by Victor Stinner in :gh:`120057`.)
527527

528+
* Add the :data:`~os.SCHED_DEADLINE` and :data:`~os.SCHED_NORMAL` constants
529+
to the :mod:`os` module.
530+
(Contributed by James Roy in :gh:`127688`.)
531+
528532

529533
pathlib
530534
-------
@@ -599,6 +603,11 @@ sys
599603
which only exists in specialized builds of Python, may now return objects
600604
from other interpreters than the one it's called in.
601605

606+
sys.monitoring
607+
--------------
608+
609+
Two new events are added: :monitoring-event:`BRANCH_LEFT` and
610+
:monitoring-event:`BRANCH_RIGHT`. The ``BRANCH`` event is deprecated.
602611

603612
tkinter
604613
-------
@@ -1140,6 +1149,11 @@ New features
11401149
a :exc:`UnicodeError` object.
11411150
(Contributed by Bénédikt Tran in :gh:`127691`.)
11421151

1152+
* Add :c:func:`PyMonitoring_FireBranchLeftEvent` and
1153+
:c:func:`PyMonitoring_FireBranchRightEvent` for generating
1154+
:monitoring-event:`BRANCH_LEFT` and :monitoring-event:`BRANCH_RIGHT`
1155+
events, respectively.
1156+
11431157

11441158
Porting to Python 3.14
11451159
----------------------
@@ -1173,6 +1187,10 @@ Deprecated
11731187

11741188
.. include:: ../deprecations/c-api-pending-removal-in-future.rst
11751189

1190+
* The ``PyMonitoring_FireBranchEvent`` function is deprecated and should
1191+
be replaced with calls to :c:func:`PyMonitoring_FireBranchLeftEvent`
1192+
and :c:func:`PyMonitoring_FireBranchRightEvent`.
1193+
11761194
Removed
11771195
-------
11781196

Include/cpython/code.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ extern "C" {
1111
/* Total tool ids available */
1212
#define _PY_MONITORING_TOOL_IDS 8
1313
/* Count of all local monitoring events */
14-
#define _PY_MONITORING_LOCAL_EVENTS 10
14+
#define _PY_MONITORING_LOCAL_EVENTS 11
1515
/* Count of all "real" monitoring events (not derived from other events) */
16-
#define _PY_MONITORING_UNGROUPED_EVENTS 15
16+
#define _PY_MONITORING_UNGROUPED_EVENTS 16
1717
/* Count of all monitoring events */
18-
#define _PY_MONITORING_EVENTS 17
18+
#define _PY_MONITORING_EVENTS 19
1919

2020
/* Tables of which tools are active for each monitored event. */
2121
typedef struct _Py_LocalMonitors {
@@ -199,6 +199,9 @@ struct PyCodeObject _PyCode_DEF(1);
199199
*/
200200
#define CO_HAS_DOCSTRING 0x4000000
201201

202+
/* A function defined in class scope */
203+
#define CO_METHOD 0x8000000
204+
202205
/* This should be defined if a future statement modifies the syntax.
203206
For example, when a keyword is added.
204207
*/

Include/cpython/monitoring.h

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,27 @@
1313
#define PY_MONITORING_EVENT_LINE 5
1414
#define PY_MONITORING_EVENT_INSTRUCTION 6
1515
#define PY_MONITORING_EVENT_JUMP 7
16-
#define PY_MONITORING_EVENT_BRANCH 8
17-
#define PY_MONITORING_EVENT_STOP_ITERATION 9
16+
#define PY_MONITORING_EVENT_BRANCH_LEFT 8
17+
#define PY_MONITORING_EVENT_BRANCH_RIGHT 9
18+
#define PY_MONITORING_EVENT_STOP_ITERATION 10
1819

1920
#define PY_MONITORING_IS_INSTRUMENTED_EVENT(ev) \
2021
((ev) < _PY_MONITORING_LOCAL_EVENTS)
2122

2223
/* Other events, mainly exceptions */
2324

24-
#define PY_MONITORING_EVENT_RAISE 10
25-
#define PY_MONITORING_EVENT_EXCEPTION_HANDLED 11
26-
#define PY_MONITORING_EVENT_PY_UNWIND 12
27-
#define PY_MONITORING_EVENT_PY_THROW 13
28-
#define PY_MONITORING_EVENT_RERAISE 14
25+
#define PY_MONITORING_EVENT_RAISE 11
26+
#define PY_MONITORING_EVENT_EXCEPTION_HANDLED 12
27+
#define PY_MONITORING_EVENT_PY_UNWIND 13
28+
#define PY_MONITORING_EVENT_PY_THROW 14
29+
#define PY_MONITORING_EVENT_RERAISE 15
2930

3031

3132
/* Ancillary events */
3233

33-
#define PY_MONITORING_EVENT_C_RETURN 15
34-
#define PY_MONITORING_EVENT_C_RAISE 16
34+
#define PY_MONITORING_EVENT_C_RETURN 16
35+
#define PY_MONITORING_EVENT_C_RAISE 17
36+
#define PY_MONITORING_EVENT_BRANCH 18
3537

3638

3739
typedef struct _PyMonitoringState {
@@ -74,10 +76,18 @@ PyAPI_FUNC(int)
7476
_PyMonitoring_FireJumpEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
7577
PyObject *target_offset);
7678

77-
PyAPI_FUNC(int)
79+
Py_DEPRECATED(3.14) PyAPI_FUNC(int)
7880
_PyMonitoring_FireBranchEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
7981
PyObject *target_offset);
8082

83+
PyAPI_FUNC(int)
84+
_PyMonitoring_FireBranchRightEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
85+
PyObject *target_offset);
86+
87+
PyAPI_FUNC(int)
88+
_PyMonitoring_FireBranchLeftEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
89+
PyObject *target_offset);
90+
8191
PyAPI_FUNC(int)
8292
_PyMonitoring_FireCReturnEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
8393
PyObject *retval);
@@ -174,12 +184,21 @@ PyMonitoring_FireJumpEvent(PyMonitoringState *state, PyObject *codelike, int32_t
174184
}
175185

176186
static inline int
177-
PyMonitoring_FireBranchEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
187+
PyMonitoring_FireBranchRightEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
188+
PyObject *target_offset)
189+
{
190+
_PYMONITORING_IF_ACTIVE(
191+
state,
192+
_PyMonitoring_FireBranchRightEvent(state, codelike, offset, target_offset));
193+
}
194+
195+
static inline int
196+
PyMonitoring_FireBranchLeftEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset,
178197
PyObject *target_offset)
179198
{
180199
_PYMONITORING_IF_ACTIVE(
181200
state,
182-
_PyMonitoring_FireBranchEvent(state, codelike, offset, target_offset));
201+
_PyMonitoring_FireBranchLeftEvent(state, codelike, offset, target_offset));
183202
}
184203

185204
static inline int

Include/cpython/weakrefobject.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self);
4545
#define _PyWeakref_CAST(op) \
4646
(assert(PyWeakref_Check(op)), _Py_CAST(PyWeakReference*, (op)))
4747

48+
// Test if a weak reference is dead.
49+
PyAPI_FUNC(int) PyWeakref_IsDead(PyObject *ref);
50+
4851
Py_DEPRECATED(3.13) static inline PyObject* PyWeakref_GET_OBJECT(PyObject *ref_obj)
4952
{
5053
PyWeakReference *ref = _PyWeakref_CAST(ref_obj);

Include/internal/pycore_code.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,8 @@ extern _Py_CODEUNIT _Py_GetBaseCodeUnit(PyCodeObject *code, int offset);
603603

604604
extern int _PyInstruction_GetLength(PyCodeObject *code, int offset);
605605

606+
extern PyObject *_PyInstrumentation_BranchesIterator(PyCodeObject *code);
607+
606608
struct _PyCode8 _PyCode_DEF(8);
607609

608610
PyAPI_DATA(const struct _PyCode8) _Py_InitCleanup;

0 commit comments

Comments
 (0)
0