Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e98e19e

Browse filesBrowse files
Merge branch 'main' into use-extra-assertions
2 parents ac23640 + e792f4b commit e98e19e
Copy full SHA for e98e19e

File tree

Expand file treeCollapse file tree

138 files changed

+4218
-4177
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

138 files changed

+4218
-4177
lines changed

‎Doc/c-api/init_config.rst

Copy file name to clipboardExpand all lines: Doc/c-api/init_config.rst
+1,555-1,301Lines changed: 1555 additions & 1301 deletions
Large diffs are not rendered by default.

‎Doc/c-api/unicode.rst

Copy file name to clipboardExpand all lines: Doc/c-api/unicode.rst
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,15 @@ These are the UTF-8 codec APIs:
10541054
10551055
As :c:func:`PyUnicode_AsUTF8AndSize`, but does not store the size.
10561056
1057+
.. warning::
1058+
1059+
This function does not have any special behavior for
1060+
`null characters <https://en.wikipedia.org/wiki/Null_character>`_ embedded within
1061+
*unicode*. As a result, strings containing null characters will remain in the returned
1062+
string, which some C functions might interpret as the end of the string, leading to
1063+
truncation. If truncation is an issue, it is recommended to use :c:func:`PyUnicode_AsUTF8AndSize`
1064+
instead.
1065+
10571066
.. versionadded:: 3.3
10581067
10591068
.. versionchanged:: 3.7

‎Doc/glossary.rst

Copy file name to clipboardExpand all lines: Doc/glossary.rst
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -811,9 +811,11 @@ Glossary
811811
processed.
812812

813813
loader
814-
An object that loads a module. It must define a method named
815-
:meth:`load_module`. A loader is typically returned by a
816-
:term:`finder`. See also:
814+
An object that loads a module.
815+
It must define the :meth:`!exec_module` and :meth:`!create_module` methods
816+
to implement the :class:`~importlib.abc.Loader` interface.
817+
A loader is typically returned by a :term:`finder`.
818+
See also:
817819

818820
* :ref:`finders-and-loaders`
819821
* :class:`importlib.abc.Loader`

‎Doc/tools/.nitignore

Copy file name to clipboardExpand all lines: Doc/tools/.nitignore
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Doc/c-api/stable.rst
1212
Doc/c-api/type.rst
1313
Doc/c-api/typeobj.rst
1414
Doc/extending/extending.rst
15-
Doc/glossary.rst
1615
Doc/library/ast.rst
1716
Doc/library/asyncio-extending.rst
1817
Doc/library/asyncio-subprocess.rst

‎Doc/whatsnew/3.14.rst

Copy file name to clipboardExpand all lines: Doc/whatsnew/3.14.rst
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,3 +1375,7 @@ Removed
13751375

13761376
* Creating :c:data:`immutable types <Py_TPFLAGS_IMMUTABLETYPE>` with mutable
13771377
bases was deprecated since 3.12 and now raises a :exc:`TypeError`.
1378+
1379+
* Remove the private ``_Py_InitializeMain()`` function. It was a
1380+
:term:`provisional API` added to Python 3.8 by :pep:`587`.
1381+
(Contributed by Victor Stinner in :gh:`129033`.)

‎Include/cpython/pylifecycle.h

Copy file name to clipboardExpand all lines: Include/cpython/pylifecycle.h
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ PyAPI_FUNC(PyStatus) Py_PreInitializeFromArgs(
2525
PyAPI_FUNC(PyStatus) Py_InitializeFromConfig(
2626
const PyConfig *config);
2727

28-
// Python 3.8 provisional API (PEP 587)
29-
PyAPI_FUNC(PyStatus) _Py_InitializeMain(void);
30-
3128
PyAPI_FUNC(int) Py_RunMain(void);
3229

3330

‎Include/internal/pycore_interp.h

Copy file name to clipboardExpand all lines: Include/internal/pycore_interp.h
-37Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -341,43 +341,6 @@ extern void _PyInterpreterState_SetWhence(
341341

342342
extern const PyConfig* _PyInterpreterState_GetConfig(PyInterpreterState *interp);
343343

344-
// Get a copy of the current interpreter configuration.
345-
//
346-
// Return 0 on success. Raise an exception and return -1 on error.
347-
//
348-
// The caller must initialize 'config', using PyConfig_InitPythonConfig()
349-
// for example.
350-
//
351-
// Python must be preinitialized to call this method.
352-
// The caller must hold the GIL.
353-
//
354-
// Once done with the configuration, PyConfig_Clear() must be called to clear
355-
// it.
356-
//
357-
// Export for '_testinternalcapi' shared extension.
358-
PyAPI_FUNC(int) _PyInterpreterState_GetConfigCopy(
359-
struct PyConfig *config);
360-
361-
// Set the configuration of the current interpreter.
362-
//
363-
// This function should be called during or just after the Python
364-
// initialization.
365-
//
366-
// Update the sys module with the new configuration. If the sys module was
367-
// modified directly after the Python initialization, these changes are lost.
368-
//
369-
// Some configuration like faulthandler or warnoptions can be updated in the
370-
// configuration, but don't reconfigure Python (don't enable/disable
371-
// faulthandler and don't reconfigure warnings filters).
372-
//
373-
// Return 0 on success. Raise an exception and return -1 on error.
374-
//
375-
// The configuration should come from _PyInterpreterState_GetConfigCopy().
376-
//
377-
// Export for '_testinternalcapi' shared extension.
378-
PyAPI_FUNC(int) _PyInterpreterState_SetConfig(
379-
const struct PyConfig *config);
380-
381344

382345
/*
383346
Runtime Feature Flags

‎Include/internal/pycore_optimizer.h

Copy file name to clipboardExpand all lines: Include/internal/pycore_optimizer.h
+89-50Lines changed: 89 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,6 @@ extern PyTypeObject _PyDefaultOptimizer_Type;
148148
extern PyTypeObject _PyUOpExecutor_Type;
149149
extern PyTypeObject _PyUOpOptimizer_Type;
150150

151-
/* Symbols */
152-
/* See explanation in optimizer_symbols.c */
153-
154-
struct _Py_UopsSymbol {
155-
int flags; // 0 bits: Top; 2 or more bits: Bottom
156-
PyTypeObject *typ; // Borrowed reference
157-
PyObject *const_val; // Owned reference (!)
158-
unsigned int type_version; // currently stores type version
159-
};
160151

161152
#define UOP_FORMAT_TARGET 0
162153
#define UOP_FORMAT_JUMP 1
@@ -193,27 +184,74 @@ static inline uint16_t uop_get_error_target(const _PyUOpInstruction *inst)
193184
// handle before rejoining the rest of the program.
194185
#define MAX_CHAIN_DEPTH 4
195186

196-
typedef struct _Py_UopsSymbol _Py_UopsSymbol;
187+
/* Symbols */
188+
/* See explanation in optimizer_symbols.c */
189+
190+
191+
typedef enum _JitSymType {
192+
JIT_SYM_UNKNOWN_TAG = 1,
193+
JIT_SYM_NULL_TAG = 2,
194+
JIT_SYM_NON_NULL_TAG = 3,
195+
JIT_SYM_BOTTOM_TAG = 4,
196+
JIT_SYM_TYPE_VERSION_TAG = 5,
197+
JIT_SYM_KNOWN_CLASS_TAG = 6,
198+
JIT_SYM_KNOWN_VALUE_TAG = 7,
199+
JIT_SYM_TUPLE_TAG = 8,
200+
} JitSymType;
201+
202+
typedef struct _jit_opt_known_class {
203+
uint8_t tag;
204+
uint32_t version;
205+
PyTypeObject *type;
206+
} JitOptKnownClass;
207+
208+
typedef struct _jit_opt_known_version {
209+
uint8_t tag;
210+
uint32_t version;
211+
} JitOptKnownVersion;
212+
213+
typedef struct _jit_opt_known_value {
214+
uint8_t tag;
215+
PyObject *value;
216+
} JitOptKnownValue;
217+
218+
#define MAX_SYMBOLIC_TUPLE_SIZE 7
219+
220+
typedef struct _jit_opt_tuple {
221+
uint8_t tag;
222+
uint8_t length;
223+
uint16_t items[MAX_SYMBOLIC_TUPLE_SIZE];
224+
} JitOptTuple;
225+
226+
typedef union _jit_opt_symbol {
227+
uint8_t tag;
228+
JitOptKnownClass cls;
229+
JitOptKnownValue value;
230+
JitOptKnownVersion version;
231+
JitOptTuple tuple;
232+
} JitOptSymbol;
233+
234+
197235

198236
struct _Py_UOpsAbstractFrame {
199237
// Max stacklen
200238
int stack_len;
201239
int locals_len;
202240

203-
_Py_UopsSymbol **stack_pointer;
204-
_Py_UopsSymbol **stack;
205-
_Py_UopsSymbol **locals;
241+
JitOptSymbol **stack_pointer;
242+
JitOptSymbol **stack;
243+
JitOptSymbol **locals;
206244
};
207245

208246
typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame;
209247

210248
typedef struct ty_arena {
211249
int ty_curr_number;
212250
int ty_max_number;
213-
_Py_UopsSymbol arena[TY_ARENA_SIZE];
251+
JitOptSymbol arena[TY_ARENA_SIZE];
214252
} ty_arena;
215253

216-
struct _Py_UOpsContext {
254+
typedef struct _JitOptContext {
217255
char done;
218256
char out_of_space;
219257
bool contradiction;
@@ -225,46 +263,47 @@ struct _Py_UOpsContext {
225263
// Arena for the symbolic types.
226264
ty_arena t_arena;
227265

228-
_Py_UopsSymbol **n_consumed;
229-
_Py_UopsSymbol **limit;
230-
_Py_UopsSymbol *locals_and_stack[MAX_ABSTRACT_INTERP_SIZE];
231-
};
232-
233-
typedef struct _Py_UOpsContext _Py_UOpsContext;
234-
235-
extern bool _Py_uop_sym_is_null(_Py_UopsSymbol *sym);
236-
extern bool _Py_uop_sym_is_not_null(_Py_UopsSymbol *sym);
237-
extern bool _Py_uop_sym_is_const(_Py_UopsSymbol *sym);
238-
extern PyObject *_Py_uop_sym_get_const(_Py_UopsSymbol *sym);
239-
extern _Py_UopsSymbol *_Py_uop_sym_new_unknown(_Py_UOpsContext *ctx);
240-
extern _Py_UopsSymbol *_Py_uop_sym_new_not_null(_Py_UOpsContext *ctx);
241-
extern _Py_UopsSymbol *_Py_uop_sym_new_type(
242-
_Py_UOpsContext *ctx, PyTypeObject *typ);
243-
extern _Py_UopsSymbol *_Py_uop_sym_new_const(_Py_UOpsContext *ctx, PyObject *const_val);
244-
extern _Py_UopsSymbol *_Py_uop_sym_new_null(_Py_UOpsContext *ctx);
245-
extern bool _Py_uop_sym_has_type(_Py_UopsSymbol *sym);
246-
extern bool _Py_uop_sym_matches_type(_Py_UopsSymbol *sym, PyTypeObject *typ);
247-
extern bool _Py_uop_sym_matches_type_version(_Py_UopsSymbol *sym, unsigned int version);
248-
extern void _Py_uop_sym_set_null(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym);
249-
extern void _Py_uop_sym_set_non_null(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym);
250-
extern void _Py_uop_sym_set_type(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, PyTypeObject *typ);
251-
extern bool _Py_uop_sym_set_type_version(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, unsigned int version);
252-
extern void _Py_uop_sym_set_const(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, PyObject *const_val);
253-
extern bool _Py_uop_sym_is_bottom(_Py_UopsSymbol *sym);
254-
extern int _Py_uop_sym_truthiness(_Py_UopsSymbol *sym);
255-
extern PyTypeObject *_Py_uop_sym_get_type(_Py_UopsSymbol *sym);
256-
257-
258-
extern void _Py_uop_abstractcontext_init(_Py_UOpsContext *ctx);
259-
extern void _Py_uop_abstractcontext_fini(_Py_UOpsContext *ctx);
266+
JitOptSymbol **n_consumed;
267+
JitOptSymbol **limit;
268+
JitOptSymbol *locals_and_stack[MAX_ABSTRACT_INTERP_SIZE];
269+
} JitOptContext;
270+
271+
extern bool _Py_uop_sym_is_null(JitOptSymbol *sym);
272+
extern bool _Py_uop_sym_is_not_null(JitOptSymbol *sym);
273+
extern bool _Py_uop_sym_is_const(JitOptSymbol *sym);
274+
extern PyObject *_Py_uop_sym_get_const(JitOptSymbol *sym);
275+
extern JitOptSymbol *_Py_uop_sym_new_unknown(JitOptContext *ctx);
276+
extern JitOptSymbol *_Py_uop_sym_new_not_null(JitOptContext *ctx);
277+
extern JitOptSymbol *_Py_uop_sym_new_type(
278+
JitOptContext *ctx, PyTypeObject *typ);
279+
extern JitOptSymbol *_Py_uop_sym_new_const(JitOptContext *ctx, PyObject *const_val);
280+
extern JitOptSymbol *_Py_uop_sym_new_null(JitOptContext *ctx);
281+
extern bool _Py_uop_sym_has_type(JitOptSymbol *sym);
282+
extern bool _Py_uop_sym_matches_type(JitOptSymbol *sym, PyTypeObject *typ);
283+
extern bool _Py_uop_sym_matches_type_version(JitOptSymbol *sym, unsigned int version);
284+
extern void _Py_uop_sym_set_null(JitOptContext *ctx, JitOptSymbol *sym);
285+
extern void _Py_uop_sym_set_non_null(JitOptContext *ctx, JitOptSymbol *sym);
286+
extern void _Py_uop_sym_set_type(JitOptContext *ctx, JitOptSymbol *sym, PyTypeObject *typ);
287+
extern bool _Py_uop_sym_set_type_version(JitOptContext *ctx, JitOptSymbol *sym, unsigned int version);
288+
extern void _Py_uop_sym_set_const(JitOptContext *ctx, JitOptSymbol *sym, PyObject *const_val);
289+
extern bool _Py_uop_sym_is_bottom(JitOptSymbol *sym);
290+
extern int _Py_uop_sym_truthiness(JitOptSymbol *sym);
291+
extern PyTypeObject *_Py_uop_sym_get_type(JitOptSymbol *sym);
292+
extern bool _Py_uop_sym_is_immortal(JitOptSymbol *sym);
293+
extern JitOptSymbol *_Py_uop_sym_new_tuple(JitOptContext *ctx, int size, JitOptSymbol **args);
294+
extern JitOptSymbol *_Py_uop_sym_tuple_getitem(JitOptContext *ctx, JitOptSymbol *sym, int item);
295+
extern int _Py_uop_sym_tuple_length(JitOptSymbol *sym);
296+
297+
extern void _Py_uop_abstractcontext_init(JitOptContext *ctx);
298+
extern void _Py_uop_abstractcontext_fini(JitOptContext *ctx);
260299

261300
extern _Py_UOpsAbstractFrame *_Py_uop_frame_new(
262-
_Py_UOpsContext *ctx,
301+
JitOptContext *ctx,
263302
PyCodeObject *co,
264303
int curr_stackentries,
265-
_Py_UopsSymbol **args,
304+
JitOptSymbol **args,
266305
int arg_len);
267-
extern int _Py_uop_frame_pop(_Py_UOpsContext *ctx);
306+
extern int _Py_uop_frame_pop(JitOptContext *ctx);
268307

269308
PyAPI_FUNC(PyObject *) _Py_uop_symbols_test(PyObject *self, PyObject *ignored);
270309

‎Include/internal/pycore_pystate.h

Copy file name to clipboardExpand all lines: Include/internal/pycore_pystate.h
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,19 @@ PyAPI_FUNC(const PyConfig*) _Py_GetConfig(void);
300300
// See also PyInterpreterState_Get() and _PyInterpreterState_GET().
301301
extern PyInterpreterState* _PyGILState_GetInterpreterStateUnsafe(void);
302302

303+
#ifndef NDEBUG
304+
/* Modern equivalent of assert(PyGILState_Check()) */
305+
static inline void
306+
_Py_AssertHoldsTstateFunc(const char *func)
307+
{
308+
PyThreadState *tstate = _PyThreadState_GET();
309+
_Py_EnsureFuncTstateNotNULL(func, tstate);
310+
}
311+
#define _Py_AssertHoldsTstate() _Py_AssertHoldsTstateFunc(__func__)
312+
#else
313+
#define _Py_AssertHoldsTstate()
314+
#endif
315+
303316
#ifdef __cplusplus
304317
}
305318
#endif

‎Lib/_colorize.py

Copy file name to clipboardExpand all lines: Lib/_colorize.py
+9-6Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ class ANSIColors:
2626
setattr(NoColors, attr, "")
2727

2828

29-
def get_colors(colorize: bool = False) -> ANSIColors:
30-
if colorize or can_colorize():
29+
def get_colors(colorize: bool = False, *, file=None) -> ANSIColors:
30+
if colorize or can_colorize(file=file):
3131
return ANSIColors()
3232
else:
3333
return NoColors
3434

3535

36-
def can_colorize() -> bool:
36+
def can_colorize(*, file=None) -> bool:
37+
if file is None:
38+
file = sys.stdout
39+
3740
if not sys.flags.ignore_environment:
3841
if os.environ.get("PYTHON_COLORS") == "0":
3942
return False
@@ -49,7 +52,7 @@ def can_colorize() -> bool:
4952
if os.environ.get("TERM") == "dumb":
5053
return False
5154

52-
if not hasattr(sys.stderr, "fileno"):
55+
if not hasattr(file, "fileno"):
5356
return False
5457

5558
if sys.platform == "win32":
@@ -62,6 +65,6 @@ def can_colorize() -> bool:
6265
return False
6366

6467
try:
65-
return os.isatty(sys.stderr.fileno())
68+
return os.isatty(file.fileno())
6669
except io.UnsupportedOperation:
67-
return sys.stderr.isatty()
70+
return file.isatty()

‎Lib/doctest.py

Copy file name to clipboardExpand all lines: Lib/doctest.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,7 @@ def out(s):
15581558
save_displayhook = sys.displayhook
15591559
sys.displayhook = sys.__displayhook__
15601560
saved_can_colorize = _colorize.can_colorize
1561-
_colorize.can_colorize = lambda: False
1561+
_colorize.can_colorize = lambda *args, **kwargs: False
15621562
color_variables = {"PYTHON_COLORS": None, "FORCE_COLOR": None}
15631563
for key in color_variables:
15641564
color_variables[key] = os.environ.pop(key, None)

‎Lib/sysconfig/__init__.py

Copy file name to clipboardExpand all lines: Lib/sysconfig/__init__.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,9 @@ def expand_makefile_vars(s, vars):
718718
"""
719719
import re
720720

721+
_findvar1_rx = r"\$\(([A-Za-z][A-Za-z0-9_]*)\)"
722+
_findvar2_rx = r"\${([A-Za-z][A-Za-z0-9_]*)}"
723+
721724
# This algorithm does multiple expansion, so if vars['foo'] contains
722725
# "${bar}", it will expand ${foo} to ${bar}, and then expand
723726
# ${bar}... and so forth. This is fine as long as 'vars' comes from

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.