8000 Catch up with main · python/cpython@c33c78f · GitHub
[go: up one dir, main page]

Skip to content

Commit c33c78f

Browse files
committed
Catch up with main
2 parents 46bee49 + 841eacd commit c33c78f

Some content is hidden

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

48 files changed

+2772
-110
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ Lib/test/test_type_*.py @JelleZijlstra
4242
Lib/test/test_capi/test_misc.py @markshannon @gvanrossum
4343
Tools/c-analyzer/ @ericsnowcurrently
4444

45+
# dbm
46+
**/*dbm* @corona10 @erlend-aasland @serhiy-storchaka
47+
4548
# Exceptions
4649
Lib/traceback.py @iritkatriel
4750
Lib/test/test_except*.py @iritkatriel

Doc/library/sys.monitoring.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ following IDs are pre-defined to make co-operation of tools easier::
7575
sys.monitoring.PROFILER_ID = 2
7676
sys.monitoring.OPTIMIZER_ID = 5
7777

78-
There is no obligation to set an ID, nor is there anything preventing a tool
79-
from using an ID even it is already in use.
80-
However, tools are encouraged to use a unique ID and respect other tools.
8178

8279
Events
8380
------

Doc/library/threading.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,10 @@ All methods are executed atomically.
534534
lock, subsequent attempts to acquire it block, until it is released; any
535535
thread may release it.
536536

537-
Note that ``Lock`` is actually a factory function which returns an instance
538-
of the most efficient version of the concrete Lock class that is supported
539-
by the platform.
537+
.. versionchanged:: 3.13
538+
``Lock`` is now a class. In earlier Pythons, ``Lock`` was a factory
539+
function which returned an instance of the underlying private lock
540+
type.
540541

541542

542543
.. method:: acquire(blocking=True, timeout=-1)

Include/cpython/pystats.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,25 @@ typedef struct _optimization_stats {
122122
uint64_t optimized_trace_length_hist[_Py_UOP_HIST_SIZE];
123123
} OptimizationStats;
124124

125+
typedef struct _rare_event_stats {
126+
/* Setting an object's class, obj.__class__ = ... */
127+
uint64_t set_class;
128+
/* Setting the bases of a class, cls.__bases__ = ... */
129+
uint64_t set_bases;
130+
/* Setting the PEP 523 frame eval function, _PyInterpreterState_SetFrameEvalFunc() */
131+
uint64_t set_eval_frame_func;
132+
/* Modifying the builtins, __builtins__.__dict__[var] = ... */
133+
uint64_t builtin_dict;
134+
/* Modifying a function, e.g. func.__defaults__ = ..., etc. */
135+
uint64_t func_modification;
136+
} RareEventStats;
137+
125138
typedef struct _stats {
126139
OpcodeStats opcode_stats[256];
127140
CallStats call_stats;
128141
ObjectStats object_stats;
129142
OptimizationStats optimization_stats;
143+
RareEventStats rare_event_stats;
130144
GCStats *gc_stats;
131145
} PyStats;
132146

Include/internal/pycore_code.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ extern int _PyStaticCode_Init(PyCodeObject *co);
295295
_Py_stats->optimization_stats.name[bucket]++; \
296296
} \
297297
} while (0)
298+
#define RARE_EVENT_STAT_INC(name) do { if (_Py_stats) _Py_stats->rare_event_stats.name++; } while (0)
298299

299300
// Export for '_opcode' shared extension
300301
PyAPI_FUNC(PyObject*) _Py_GetSpecializationStats(void);
@@ -313,6 +314,7 @@ PyAPI_FUNC(PyObject*) _Py_GetSpecializationStats(void);
313314
#define UOP_STAT_INC(opname, name) ((void)0)
314315
#define OPT_UNSUPPORTED_OPCODE(opname) ((void)0)
315316
#define OPT_HIST(length, name) ((void)0)
317+
#define RARE_EVENT_STAT_INC(name) ((void)0)
316318
#endif // !Py_STATS
317319

318320
// Utility functions for reading/writing 32/64-bit values in the inline caches.

Include/internal/pycore_freelist.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ extern "C" {
2020
# define PyFloat_MAXFREELIST 100
2121
# define PyContext_MAXFREELIST 255
2222
# define _PyAsyncGen_MAXFREELIST 80
23+
# define _PyObjectStackChunk_MAXFREELIST 4
2324
#else
2425
# define PyTuple_NFREELISTS 0
2526
# define PyTuple_MAXFREELIST 0
2627
# define PyList_MAXFREELIST 0
2728
# define PyFloat_MAXFREELIST 0
2829
# define PyContext_MAXFREELIST 0
2930
# define _PyAsyncGen_MAXFREELIST 0
31+
# define _PyObjectStackChunk_MAXFREELIST 0
3032
#endif
3133

3234
struct _Py_list_state {
@@ -93,13 +95,21 @@ struct _Py_async_gen_state {
9395
#endif
9496
};
9597

98+
struct _PyObjectStackChunk;
99+
100+
struct _Py_object_stack_state {
101+
struct _PyObjectStackChunk *free_list;
102+
Py_ssize_t numfree;
103+
};
104+
96105
typedef struct _Py_freelist_state {
97106
struct _Py_float_state float_state;
98107
struct _Py_tuple_state tuple_state;
99108
struct _Py_list_state list_state;
100109
struct _Py_slice_state slice_state;
101110
struct _Py_context_state context_state;
102111
struct _Py_async_gen_state async_gen_state;
112+
struct _Py_object_stack_state object_stack_state;
103113
} _PyFreeListState;
104114

105115
#ifdef __cplusplus

Include/internal/pycore_gc.h

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,22 @@ static inline PyObject* _Py_FROM_GC(PyGC_Head *gc) {
3737
}
3838

3939

40+
/* Bit flags for ob_gc_bits (in Py_GIL_DISABLED builds) */
41+
#ifdef Py_GIL_DISABLED
42+
# define _PyGC_BITS_TRACKED (1)
43+
# define _PyGC_BITS_FINALIZED (2)
44+
# define _PyGC_BITS_UNREACHABLE (4)
45+
# define _PyGC_BITS_FROZEN (8)
46+
#endif
47+
4048
/* True if the object is currently tracked by the GC. */
4149
static inline int _PyObject_GC_IS_TRACKED(PyObject *op) {
50+
#ifdef Py_GIL_DISABLED
51+
return (op->ob_gc_bits & _PyGC_BITS_TRACKED) != 0;
52+
#else
4253
PyGC_Head *gc = _Py_AS_GC(op);
4354
return (gc->_gc_next != 0);
55+
#endif
4456
}
4557
#define _PyObject_GC_IS_TRACKED(op) _PyObject_GC_IS_TRACKED(_Py_CAST(PyObject*, op))
4658

@@ -107,24 +119,29 @@ static inline void _PyGCHead_SET_PREV(PyGC_Head *gc, PyGC_Head *prev) {
107119
gc->_gc_prev = ((gc->_gc_prev & ~_PyGC_PREV_MASK) | uprev);
108120
}
109121

110-
static inline int _PyGCHead_FINALIZED(PyGC_Head *gc) {
111-
return ((gc->_gc_prev & _PyGC_PREV_MASK_FINALIZED) != 0);
112-
}
113-
static inline void _PyGCHead_SET_FINALIZED(PyGC_Head *gc) {
114-
gc->_gc_prev |= _PyGC_PREV_MASK_FINALIZED;
115-
}
116-
117122
static inline int _PyGC_FINALIZED(PyObject *op) {
123+
#ifdef Py_GIL_DISABLED
124+
return (op->ob_gc_bits & _PyGC_BITS_FINALIZED) != 0;
125+
#else
118126
PyGC_Head *gc = _Py_AS_GC(op);
119-
return _PyGCHead_FINALIZED(gc);
127+
return ((gc->_gc_prev & _PyGC_PREV_MASK_FINALIZED) != 0);
128+
#endif
120129
}
121130
static inline void _PyGC_SET_FINALIZED(PyObject *op) {
131+
#ifdef Py_GIL_DISABLED
132+
op->ob_gc_bits |= _PyGC_BITS_FINALIZED;
133+
#else
122134
PyGC_Head *gc = _Py_AS_GC(op);
123-
_PyGCHead_SET_FINALIZED(gc);
135+
gc->_gc_prev |= _PyGC_PREV_MASK_FINALIZED;
136+
#endif
124137
}
125138
static inline void _PyGC_CLEAR_FINALIZED(PyObject *op) {
139+
#ifdef Py_GIL_DISABLED
140+
op->ob_gc_bits &= ~_PyGC_BITS_FINALIZED;
141+
#else
126142
PyGC_Head *gc = _Py_AS_GC(op);
127143
gc->_gc_prev &= ~_PyGC_PREV_MASK_FINALIZED;
144+
#endif
128145
}
129146

130147

Include/internal/pycore_interp.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ struct _stoptheworld_state {
6060

6161
/* cross-interpreter data registry */
6262

63+
/* Tracks some rare events per-interpreter, used by the optimizer to turn on/off
64+
specific optimizations. */
65+
typedef struct _rare_events {
66+
/* Setting an object's class, obj.__class__ = ... */
67+
uint8_t set_class;
68+
/* Setting the bases of a class, cls.__bases__ = ... */
69+
uint8_t set_bases;
70+
/* Setting the PEP 523 frame eval function, _PyInterpreterState_SetFrameEvalFunc() */
71+
uint8_t set_eval_frame_func;
72+
/* Modifying the builtins, __builtins__.__dict__[var] = ... */
73+
uint8_t builtin_dict;
74+
int builtins_dict_watcher_id;
75+
/* Modifying a function, e.g. func.__defaults__ = ..., etc. */
76+
uint8_t func_modification;
77+
} _rare_events;
6378

6479
/* interpreter state */
6580

@@ -217,6 +232,7 @@ struct _is {
217232
uint16_t optimizer_resume_threshold;
218233
uint16_t optimizer_backedge_threshold;
219234
uint32_t next_func_version;
235+
_rare_events rare_events;
220236

221237
_Py_GlobalMonitors monitors;
222238
bool sys_profile_initialized;
@@ -347,6 +363,19 @@ PyAPI_FUNC(PyStatus) _PyInterpreterState_New(
347363
PyInterpreterState **pinterp);
348364

349365

366+
#define RARE_EVENT_INTERP_INC(interp, name) \
367+
do { \
368+
/* saturating add */ \
369+
if (interp->rare_events.name < UINT8_MAX) interp->rare_events.name++; \
370+
RARE_EVENT_STAT_INC(name); \
371+
} while (0); \
372+
373+
#define RARE_EVENT_INC(name) \
374+
do { \
375+
PyInterpreterState *interp = PyInterpreterState_Get(); \
376+
RARE_EVENT_INTERP_INC(interp, name); \
377+
} while (0); \
378+
350379
#ifdef __cplusplus
351380
}
352381
#endif

0 commit comments

Comments
 (0)
0