Skip to content

Commit ac0c035

Browse files
Merge branch 'main' into fix-lsprof-uaf
2 parents ffc48d5 + 68a01f9 commit ac0c035

Some content is hidden

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

45 files changed

+551
-393
lines changed

Doc/library/importlib.resources.abc.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,14 @@
6363
If the resource does not concretely exist on the file system,
6464
raise :exc:`FileNotFoundError`.
6565

66-
.. method:: is_resource(name)
66+
.. method:: is_resource(path)
6767
:abstractmethod:
6868

69-
Returns ``True`` if the named *name* is considered a resource.
70-
:exc:`FileNotFoundError` is raised if *name* does not exist.
69+
Returns ``True`` if the named *path* is considered a resource.
70+
:exc:`FileNotFoundError` is raised if *path* does not exist.
71+
72+
.. versionchanged:: 3.10
73+
The argument *name* was renamed to *path*.
7174

7275
.. method:: contents()
7376
:abstractmethod:

Doc/library/importlib.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,6 @@ Functions
210210
:exc:`ModuleNotFoundError` is raised when the module being reloaded lacks
211211
a :class:`~importlib.machinery.ModuleSpec`.
212212

213-
.. versionchanged:: 3.15
214-
If *module* is a lazy module that has not yet been materialized (i.e.,
215-
loaded via :class:`importlib.util.LazyLoader` and not yet accessed),
216-
calling :func:`reload` is a no-op and returns the module unchanged.
217-
This prevents the reload from unintentionally triggering the lazy load.
218-
219213
.. warning::
220214
This function is not thread-safe. Calling it from multiple threads can result
221215
in unexpected behavior. It's recommended to use the :class:`threading.Lock`

Doc/library/test.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,12 @@ The :mod:`test.support` module defines the following functions:
492492
tests.
493493

494494

495+
.. function:: get_resource_value(resource)
496+
497+
Return the value specified for *resource* (as :samp:`-u {resource}={value}`).
498+
Return ``None`` if *resource* is disabled or no value is specified.
499+
500+
495501
.. function:: python_is_optimized()
496502

497503
Return ``True`` if Python was not built with ``-O0`` or ``-Og``.

Include/internal/pycore_genobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ PyGenObject *_PyGen_GetGeneratorFromFrame(_PyInterpreterFrame *frame)
2222
}
2323

2424
PyAPI_FUNC(PyObject *)_PyGen_yf(PyGenObject *);
25-
extern void _PyGen_Finalize(PyObject *self);
25+
extern int _PyGen_ClearFrame(PyGenObject *self);
2626

2727
// Export for '_asyncio' shared extension
2828
PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *);

Include/internal/pycore_optimizer.h

Lines changed: 2 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ extern "C" {
1212
#include "pycore_uop.h" // _PyUOpInstruction
1313
#include "pycore_uop_ids.h"
1414
#include "pycore_stackref.h" // _PyStackRef
15+
#include "pycore_optimizer_types.h"
1516
#include <stdbool.h>
1617

1718

@@ -84,7 +85,7 @@ PyAPI_FUNC(void) _Py_Executors_InvalidateCold(PyInterpreterState *interp);
8485
#define JIT_CLEANUP_THRESHOLD 1000
8586

8687
int _Py_uop_analyze_and_optimize(
87-
PyFunctionObject *func,
88+
_PyThreadStateImpl *tstate,
8889
_PyUOpInstruction *trace, int trace_len, int curr_stackentries,
8990
_PyBloomFilter *dependencies);
9091

@@ -112,86 +113,6 @@ static inline uint16_t uop_get_error_target(const _PyUOpInstruction *inst)
112113
return inst->error_target;
113114
}
114115

115-
// Holds locals, stack, locals, stack ... co_consts (in that order)
116-
#define MAX_ABSTRACT_INTERP_SIZE 4096
117-
118-
#define TY_ARENA_SIZE (UOP_MAX_TRACE_LENGTH * 5)
119-
120-
// Need extras for root frame and for overflow frame (see TRACE_STACK_PUSH())
121-
#define MAX_ABSTRACT_FRAME_DEPTH (16)
122-
123-
// The maximum number of side exits that we can take before requiring forward
124-
// progress (and inserting a new ENTER_EXECUTOR instruction). In practice, this
125-
// is the "maximum amount of polymorphism" that an isolated trace tree can
126-
// handle before rejoining the rest of the program.
127-
#define MAX_CHAIN_DEPTH 4
128-
129-
/* Symbols */
130-
/* See explanation in optimizer_symbols.c */
131-
132-
133-
typedef enum _JitSymType {
134-
JIT_SYM_UNKNOWN_TAG = 1,
135-
JIT_SYM_NULL_TAG = 2,
136-
JIT_SYM_NON_NULL_TAG = 3,
137-
JIT_SYM_BOTTOM_TAG = 4,
138-
JIT_SYM_TYPE_VERSION_TAG = 5,
139-
JIT_SYM_KNOWN_CLASS_TAG = 6,
140-
JIT_SYM_KNOWN_VALUE_TAG = 7,
141-
JIT_SYM_TUPLE_TAG = 8,
142-
JIT_SYM_TRUTHINESS_TAG = 9,
143-
JIT_SYM_COMPACT_INT = 10,
144-
} JitSymType;
145-
146-
typedef struct _jit_opt_known_class {
147-
uint8_t tag;
148-
uint32_t version;
149-
PyTypeObject *type;
150-
} JitOptKnownClass;
151-
152-
typedef struct _jit_opt_known_version {
153-
uint8_t tag;
154-
uint32_t version;
155-
} JitOptKnownVersion;
156-
157-
typedef struct _jit_opt_known_value {
158-
uint8_t tag;
159-
PyObject *value;
160-
} JitOptKnownValue;
161-
162-
#define MAX_SYMBOLIC_TUPLE_SIZE 7
163-
164-
typedef struct _jit_opt_tuple {
165-
uint8_t tag;
166-
uint8_t length;
167-
uint16_t items[MAX_SYMBOLIC_TUPLE_SIZE];
168-
} JitOptTuple;
169-
170-
typedef struct {
171-
uint8_t tag;
172-
bool invert;
173-
uint16_t value;
174-
} JitOptTruthiness;
175-
176-
typedef struct {
177-
uint8_t tag;
178-
} JitOptCompactInt;
179-
180-
typedef union _jit_opt_symbol {
181-
uint8_t tag;
182-
JitOptKnownClass cls;
183-
JitOptKnownValue value;
184-
JitOptKnownVersion version;
185-
JitOptTuple tuple;
186-
JitOptTruthiness truthiness;
187-
JitOptCompactInt compact;
188-
} JitOptSymbol;
189-
190-
191-
// This mimics the _PyStackRef API
192-
typedef union {
193-
uintptr_t bits;
194-
} JitOptRef;
195116

196117
#define REF_IS_BORROWED 1
197118

@@ -238,48 +159,6 @@ PyJitRef_IsBorrowed(JitOptRef ref)
238159
return (ref.bits & REF_IS_BORROWED) == REF_IS_BORROWED;
239160
}
240161

241-
struct _Py_UOpsAbstractFrame {
242-
bool globals_watched;
243-
// The version number of the globals dicts, once checked. 0 if unchecked.
244-
uint32_t globals_checked_version;
245-
// Max stacklen
246-
int stack_len;
247-
int locals_len;
248-
PyFunctionObject *func;
249-
PyCodeObject *code;
250-
251-
JitOptRef *stack_pointer;
252-
JitOptRef *stack;
253-
JitOptRef *locals;
254-
};
255-
256-
typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame;
257-
258-
typedef struct ty_arena {
259-
int ty_curr_number;
260-
int ty_max_number;
261-
JitOptSymbol arena[TY_ARENA_SIZE];
262-
} ty_arena;
263-
264-
typedef struct _JitOptContext {
265-
char done;
266-
char out_of_space;
267-
bool contradiction;
268-
// Has the builtins dict been watched?
269-
bool builtins_watched;
270-
// The current "executing" frame.
271-
_Py_UOpsAbstractFrame *frame;
272-
_Py_UOpsAbstractFrame frames[MAX_ABSTRACT_FRAME_DEPTH];
273-
int curr_frame_depth;
274-
275-
// Arena for the symbolic types.
276-
ty_arena t_arena;
277-
278-
JitOptRef *n_consumed;
279-
JitOptRef *limit;
280-
JitOptRef locals_and_stack[MAX_ABSTRACT_INTERP_SIZE];
281-
} JitOptContext;
282-
283162
extern bool _Py_uop_sym_is_null(JitOptRef sym);
284163
extern bool _Py_uop_sym_is_not_null(JitOptRef sym);
285164
extern bool _Py_uop_sym_is_const(JitOptContext *ctx, JitOptRef sym);
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#ifndef Py_INTERNAL_OPTIMIZER_TYPES_H
2+
#define Py_INTERNAL_OPTIMIZER_TYPES_H
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
#ifndef Py_BUILD_CORE
8+
# error "this header requires Py_BUILD_CORE define"
9+
#endif
10+
11+
#include "pycore_uop.h" // UOP_MAX_TRACE_LENGTH
12+
13+
// Holds locals, stack, locals, stack ... co_consts (in that order)
14+
#define MAX_ABSTRACT_INTERP_SIZE 4096
15+
16+
#define TY_ARENA_SIZE (UOP_MAX_TRACE_LENGTH * 5)
17+
18+
// Need extras for root frame and for overflow frame (see TRACE_STACK_PUSH())
19+
#define MAX_ABSTRACT_FRAME_DEPTH (16)
20+
21+
// The maximum number of side exits that we can take before requiring forward
22+
// progress (and inserting a new ENTER_EXECUTOR instruction). In practice, this
23+
// is the "maximum amount of polymorphism" that an isolated trace tree can
24+
// handle before rejoining the rest of the program.
25+
#define MAX_CHAIN_DEPTH 4
26+
27+
/* Symbols */
28+
/* See explanation in optimizer_symbols.c */
29+
30+
31+
typedef enum _JitSymType {
32+
JIT_SYM_UNKNOWN_TAG = 1,
33+
JIT_SYM_NULL_TAG = 2,
34+
JIT_SYM_NON_NULL_TAG = 3,
35+
JIT_SYM_BOTTOM_TAG = 4,
36+
JIT_SYM_TYPE_VERSION_TAG = 5,
37+
JIT_SYM_KNOWN_CLASS_TAG = 6,
38+
JIT_SYM_KNOWN_VALUE_TAG = 7,
39+
JIT_SYM_TUPLE_TAG = 8,
40+
JIT_SYM_TRUTHINESS_TAG = 9,
41+
JIT_SYM_COMPACT_INT = 10,
42+
} JitSymType;
43+
44+
typedef struct _jit_opt_known_class {
45+
uint8_t tag;
46+
uint32_t version;
47+
PyTypeObject *type;
48+
} JitOptKnownClass;
49+
50+
typedef struct _jit_opt_known_version {
51+
uint8_t tag;
52+
uint32_t version;
53+
} JitOptKnownVersion;
54+
55+
typedef struct _jit_opt_known_value {
56+
uint8_t tag;
57+
PyObject *value;
58+
} JitOptKnownValue;
59+
60+
#define MAX_SYMBOLIC_TUPLE_SIZE 7
61+
62+
typedef struct _jit_opt_tuple {
63+
uint8_t tag;
64+
uint8_t length;
65+
uint16_t items[MAX_SYMBOLIC_TUPLE_SIZE];
66+
} JitOptTuple;
67+
68+
typedef struct {
69+
uint8_t tag;
70+
bool invert;
71+
uint16_t value;
72+
} JitOptTruthiness;
73+
74+
typedef struct {
75+
uint8_t tag;
76+
} JitOptCompactInt;
77+
78+
typedef union _jit_opt_symbol {
79+
uint8_t tag;
80+
JitOptKnownClass cls;
81+
JitOptKnownValue value;
82+
JitOptKnownVersion version;
83+
JitOptTuple tuple;
84+
JitOptTruthiness truthiness;
85+
JitOptCompactInt compact;
86+
} JitOptSymbol;
87+
88+
// This mimics the _PyStackRef API
89+
typedef union {
90+
uintptr_t bits;
91+
} JitOptRef;
92+
93+
typedef struct _Py_UOpsAbstractFrame {
94+
bool globals_watched;
95+
// The version number of the globals dicts, once checked. 0 if unchecked.
96+
uint32_t globals_checked_version;
97+
// Max stacklen
98+
int stack_len;
99+
int locals_len;
100+
PyFunctionObject *func;
101+
PyCodeObject *code;
102+
103+
JitOptRef *stack_pointer;
104+
JitOptRef *stack;
105+
JitOptRef *locals;
106+
} _Py_UOpsAbstractFrame;
107+
108+
typedef struct ty_arena {
109+
int ty_curr_number;
110+
int ty_max_number;
111+
JitOptSymbol arena[TY_ARENA_SIZE];
112+
} ty_arena;
113+
114+
typedef struct _JitOptContext {
115+
char done;
116+
char out_of_space;
117+
bool contradiction;
118+
// Has the builtins dict been watched?
119+
bool builtins_watched;
120+
// The current "executing" frame.
121+
_Py_UOpsAbstractFrame *frame;
122+
_Py_UOpsAbstractFrame frames[MAX_ABSTRACT_FRAME_DEPTH];
123+
int curr_frame_depth;
124+
125+
// Arena for the symbolic types.
126+
ty_arena t_arena;
127+
128+
JitOptRef *n_consumed;
129+
JitOptRef *limit;
130+
JitOptRef locals_and_stack[MAX_ABSTRACT_INTERP_SIZE];
131+
} JitOptContext;
132+
133+
134+
#ifdef __cplusplus
135+
}
136+
#endif
137+
#endif /* !Py_INTERNAL_OPTIMIZER_TYPES_H */

Include/internal/pycore_tstate.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ extern "C" {
1212
#include "pycore_freelist_state.h" // struct _Py_freelists
1313
#include "pycore_interpframe_structs.h" // _PyInterpreterFrame
1414
#include "pycore_mimalloc.h" // struct _mimalloc_thread_state
15+
#include "pycore_optimizer_types.h" // JitOptContext
1516
#include "pycore_qsbr.h" // struct qsbr
1617
#include "pycore_uop.h" // struct _PyUOpInstruction
1718
#include "pycore_structs.h"
@@ -52,10 +53,11 @@ typedef struct _PyJitTracerTranslatorState {
5253
} _PyJitTracerTranslatorState;
5354

5455
typedef struct _PyJitTracerState {
55-
_PyUOpInstruction *code_buffer;
5656
_PyJitTracerInitialState initial_state;
5757
_PyJitTracerPreviousState prev_state;
5858
_PyJitTracerTranslatorState translator_state;
59+
JitOptContext opt_context;
60+
_PyUOpInstruction code_buffer[UOP_MAX_TRACE_LENGTH];
5961
} _PyJitTracerState;
6062

6163
#endif

Lib/copy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def _reconstruct(x, memo, func, args,
230230
*, deepcopy=deepcopy):
231231
deep = memo is not None
232232
if deep and args:
233-
args = (deepcopy(arg, memo) for arg in args)
233+
args = [deepcopy(arg, memo) for arg in args]
234234
y = func(*args)
235235
if deep:
236236
memo[id(x)] = y

Lib/importlib/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,6 @@ def reload(module):
9797
The module must have been successfully imported before.
9898
9999
"""
100-
# If a LazyModule has not yet been materialized, reload is a no-op.
101-
if importlib_util := sys.modules.get('importlib.util'):
102-
if lazy_module_type := getattr(importlib_util, '_LazyModule', None):
103-
if isinstance(module, lazy_module_type):
104-
return module
105100
try:
106101
name = module.__spec__.name
107102
except AttributeError:

0 commit comments

Comments
 (0)