Skip to content

Commit e163032

Browse files
committed
Update Python inlined files: 3.12.8 (4.8)
1 parent 7322d23 commit e163032

File tree

7 files changed

+76
-18
lines changed

7 files changed

+76
-18
lines changed

graalpython/com.oracle.graal.python.cext/include/internal/pycore_call.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ _PyObject_CallNoArgsTstate(PyThreadState *tstate, PyObject *func) {
103103
// Private static inline function variant of public PyObject_CallNoArgs()
104104
static inline PyObject *
105105
_PyObject_CallNoArgs(PyObject *func) {
106+
EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_API, func);
106107
PyThreadState *tstate = _PyThreadState_GET();
107108
return _PyObject_VectorcallTstate(tstate, func, NULL, 0, NULL);
108109
}
@@ -111,6 +112,7 @@ _PyObject_CallNoArgs(PyObject *func) {
111112
static inline PyObject *
112113
_PyObject_FastCallTstate(PyThreadState *tstate, PyObject *func, PyObject *const *args, Py_ssize_t nargs)
113114
{
115+
EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_API, func);
114116
return _PyObject_VectorcallTstate(tstate, func, args, (size_t)nargs, NULL);
115117
}
116118

graalpython/com.oracle.graal.python.cext/include/internal/pycore_ceval.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ extern _PyPerf_Callbacks _Py_perfmap_callbacks;
8484
static inline PyObject*
8585
_PyEval_EvalFrame(PyThreadState *tstate, struct _PyInterpreterFrame *frame, int throwflag)
8686
{
87+
EVAL_CALL_STAT_INC(EVAL_CALL_TOTAL);
8788
if (tstate->interp->eval_frame == NULL) {
8889
return _PyEval_EvalFrameDefault(tstate, frame, throwflag);
8990
}

graalpython/com.oracle.graal.python.cext/include/patchlevel.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
/* Version parsed out into numeric values */
1818
/*--start constants--*/
1919
#define PY_MAJOR_VERSION 3
20-
#define PY_MINOR_VERSION 11
21-
#define PY_MICRO_VERSION 7
20+
#define PY_MINOR_VERSION 12
21+
#define PY_MICRO_VERSION 8
2222
#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_FINAL
2323
#define PY_RELEASE_SERIAL 0
2424

2525
/* Version as a string */
26-
#define PY_VERSION "3.11.7"
26+
#define PY_VERSION "3.12.8"
2727
/*--end constants--*/
2828

2929
/* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2.

graalpython/com.oracle.graal.python.cext/src/call.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include "Python.h"
22
#include "pycore_call.h" // _PyObject_CallNoArgsTstate()
3-
#include "pycore_ceval.h" // _PyEval_EvalFrame()
4-
#include "pycore_object.h" // _PyObject_GC_TRACK()
3+
#include "pycore_ceval.h" // _Py_EnterRecursiveCallTstate()
4+
#include "pycore_dict.h" // _PyDict_FromItems()
5+
#include "pycore_object.h" // _PyCFunctionWithKeywords_TrampolineCall()
56
#include "pycore_pyerrors.h" // _PyErr_Occurred()
67
#include "pycore_pystate.h" // _PyThreadState_GET()
78
#include "pycore_tuple.h" // _PyTuple_ITEMS()
@@ -98,7 +99,9 @@ _Py_CheckSlotResult(PyObject *obj, const char *slot_name, int success)
9899
PyObject *
99100
PyObject_CallNoArgs(PyObject *func)
100101
{
101-
return _PyObject_CallNoArgs(func);
102+
EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_API, func);
103+
PyThreadState *tstate = _PyThreadState_GET();
104+
return _PyObject_VectorcallTstate(tstate, func, NULL, 0, NULL);
102105
}
103106

104107

@@ -345,7 +348,7 @@ _PyObject_Call(PyThreadState *tstate, PyObject *callable,
345348
assert(!_PyErr_Occurred(tstate));
346349
assert(PyTuple_Check(args));
347350
assert(kwargs == NULL || PyDict_Check(kwargs));
348-
351+
EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_API, callable);
349352
vectorcallfunc vector_func = _PyVectorcall_Function(callable);
350353
if (vector_func != NULL) {
351354
return _PyVectorcall_Call(tstate, vector_func, callable, args, kwargs);
@@ -388,6 +391,7 @@ PyCFunction_Call(PyObject *callable, PyObject *args, PyObject *kwargs)
388391
PyObject *
389392
PyObject_CallOneArg(PyObject *func, PyObject *arg)
390393
{
394+
EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_API, func);
391395
assert(arg != NULL);
392396
PyObject *_args[2];
393397
PyObject **args = _args + 1; // For PY_VECTORCALL_ARGUMENTS_OFFSET
@@ -410,6 +414,7 @@ _PyFunction_Vectorcall(PyObject *func, PyObject* const* stack,
410414
assert(nargs >= 0);
411415
PyThreadState *tstate = _PyThreadState_GET();
412416
assert(nargs == 0 || stack != NULL);
417+
EVAL_CALL_STAT_INC(EVAL_CALL_FUNCTION_VECTORCALL);
413418
if (((PyCodeObject *)f->func_code)->co_flags & CO_OPTIMIZED) {
414419
return _PyEval_Vector(tstate, f, NULL, stack, nargs, kwnames);
415420
}
@@ -541,7 +546,7 @@ _PyObject_CallFunctionVa(PyThreadState *tstate, PyObject *callable,
541546
if (stack == NULL) {
542547
return NULL;
543548
}
544-
549+
EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_API, callable);
545550
if (nargs == 1 && PyTuple_Check(stack[0])) {
546551
/* Special cases for backward compatibility:
547552
- PyObject_CallFunction(func, "O", tuple) calls func(*tuple)
@@ -836,6 +841,11 @@ object_vacall(PyThreadState *tstate, PyObject *base,
836841
stack[i] = va_arg(vargs, PyObject *);
837842
}
838843

844+
#ifdef Py_STATS
845+
if (PyFunction_Check(callable)) {
846+
EVAL_CALL_STAT_INC(EVAL_CALL_API);
847+
}
848+
#endif
839849
/* Call the function */
840850
result = _PyObject_VectorcallTstate(tstate, callable, stack, nargs, NULL);
841851

@@ -873,6 +883,7 @@ PyObject_VectorcallMethod(PyObject *name, PyObject *const *args,
873883
args++;
874884
nargsf--;
875885
}
886+
EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_METHOD, callable);
876887
PyObject *result = _PyObject_VectorcallTstate(tstate, callable,
877888
args, nargsf, kwnames);
878889
Py_DECREF(callable);

graalpython/com.oracle.graal.python.cext/src/getargs.c

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "Python.h"
55
#include "pycore_tuple.h" // _PyTuple_ITEMS()
66
#include "pycore_pylifecycle.h" // _PyArg_Fini
7+
#include "pycore_pystate.h" // _Py_IsMainInterpreter()
78

89
#include <ctype.h>
910
#include <float.h>
@@ -1846,9 +1847,6 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
18461847
}
18471848

18481849

1849-
/* List of static parsers. */
1850-
static struct _PyArg_Parser *static_arg_parsers = NULL;
1851-
18521850
static int
18531851
scan_keywords(const char * const *keywords, int *ptotal, int *pposonly)
18541852
{
@@ -2006,7 +2004,23 @@ _parser_init(struct _PyArg_Parser *parser)
20062004
int owned;
20072005
PyObject *kwtuple = parser->kwtuple;
20082006
if (kwtuple == NULL) {
2007+
/* We may temporarily switch to the main interpreter to avoid
2008+
* creating a tuple that could outlive its owning interpreter. */
2009+
PyThreadState *save_tstate = NULL;
2010+
PyThreadState *temp_tstate = NULL;
2011+
if (!_Py_IsMainInterpreter(PyInterpreterState_Get())) {
2012+
temp_tstate = PyThreadState_New(_PyInterpreterState_Main());
2013+
if (temp_tstate == NULL) {
2014+
return -1;
2015+
}
2016+
save_tstate = PyThreadState_Swap(temp_tstate);
2017+
}
20092018
kwtuple = new_kwtuple(keywords, len, pos);
2019+
if (temp_tstate != NULL) {
2020+
PyThreadState_Clear(temp_tstate);
2021+
(void)PyThreadState_Swap(save_tstate);
2022+
PyThreadState_Delete(temp_tstate);
2023+
}
20102024
if (kwtuple == NULL) {
20112025
return 0;
20122026
}
@@ -2033,7 +2047,22 @@ _parser_init(struct _PyArg_Parser *parser)
20332047
static int
20342048
parser_init(struct _PyArg_Parser *parser)
20352049
{
2050+
// volatile as it can be modified by other threads
2051+
// and should not be optimized or reordered by compiler
2052+
if (*((volatile int *)&parser->initialized)) {
2053+
assert(parser->kwtuple != NULL);
2054+
return 1;
2055+
}
2056+
PyThread_acquire_lock(_PyRuntime.getargs.mutex, WAIT_LOCK);
2057+
// Check again if another thread initialized the parser
2058+
// while we were waiting for the lock.
2059+
if (*((volatile int *)&parser->initialized)) {
2060+
assert(parser->kwtuple != NULL);
2061+
PyThread_release_lock(_PyRuntime.getargs.mutex);
2062+
return 1;
2063+
}
20362064
int ret = _parser_init(parser);
2065+
PyThread_release_lock(_PyRuntime.getargs.mutex);
20372066
return ret;
20382067
}
20392068

graalpython/com.oracle.graal.python.frozen/freeze_modules.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import os
99
import ntpath
1010
import posixpath
11-
import sys
1211
import argparse
1312
from update_file import updating_file_with_tmpfile
1413

@@ -33,6 +32,9 @@
3332
OS_PATH = 'ntpath' if os.name == 'nt' else 'posixpath'
3433

3534
# These are modules that get frozen.
35+
# If you're debugging new bytecode instructions,
36+
# you can delete all sections except 'import system'.
37+
# This also speeds up building somewhat.
3638
TESTS_SECTION = 'Test module'
3739
FROZEN = [
3840
# See parse_frozen_spec() for the format.
@@ -46,6 +48,7 @@
4648
# on a builtin zip file instead of a filesystem.
4749
'zipimport',
4850
]),
51+
# (You can delete entries from here down to the end of the list.)
4952
('stdlib - startup, without site (python -S)', [
5053
'abc',
5154
'codecs',
@@ -81,6 +84,7 @@
8184
'<__phello__.**.*>',
8285
f'frozen_only : __hello_only__ = {FROZEN_ONLY}',
8386
]),
87+
# (End of stuff you could delete.)
8488
]
8589
BOOTSTRAP = {
8690
'importlib._bootstrap',
@@ -463,6 +467,17 @@ def replace_block(lines, start_marker, end_marker, replacements, file):
463467
return lines[:start_pos + 1] + replacements + lines[end_pos:]
464468

465469

470+
class UniqueList(list):
471+
def __init__(self):
472+
self._seen = set()
473+
474+
def append(self, item):
475+
if item in self._seen:
476+
return
477+
super().append(item)
478+
self._seen.add(item)
479+
480+
466481
def regen_frozen(modules, frozen_modules: bool):
467482
headerlines = []
468483
parentdir = os.path.dirname(FROZEN_FILE)
@@ -473,7 +488,7 @@ def regen_frozen(modules, frozen_modules: bool):
473488
header = relpath_for_posix_display(src.frozenfile, parentdir)
474489
headerlines.append(f'#include "{header}"')
475490

476-
externlines = []
491+
externlines = UniqueList()
477492
bootstraplines = []
478493
stdliblines = []
479494
testlines = []
@@ -521,7 +536,7 @@ def regen_frozen(modules, frozen_modules: bool):
521536

522537
for lines in (bootstraplines, stdliblines, testlines):
523538
# TODO: Is this necessary any more?
524-
if not lines[0]:
539+
if lines and not lines[0]:
525540
del lines[0]
526541
for i, line in enumerate(lines):
527542
if line:
@@ -582,7 +597,7 @@ def regen_makefile(modules):
582597
frozenfiles = []
583598
rules = ['']
584599
deepfreezerules = ["$(DEEPFREEZE_C): $(DEEPFREEZE_DEPS)",
585-
"\t$(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py \\"]
600+
"\t$(PYTHON_FOR_FREEZE) $(srcdir)/Tools/build/deepfreeze.py \\"]
586601
for src in _iter_sources(modules):
587602
frozen_header = relpath_for_posix_display(src.frozenfile, ROOT_DIR)
588603
frozenfiles.append(f'\t\t{frozen_header} \\')
@@ -647,7 +662,7 @@ def regen_pcbuild(modules):
647662
projlines = []
648663
filterlines = []
649664
corelines = []
650-
deepfreezerules = ['\t<Exec Command=\'$(PythonForBuild) "$(PySourcePath)Tools\\scripts\\deepfreeze.py" ^']
665+
deepfreezerules = ['\t<Exec Command=\'$(PythonForBuild) "$(PySourcePath)Tools\\build\\deepfreeze.py" ^']
651666
for src in _iter_sources(modules):
652667
pyfile = relpath_for_windows_display(src.pyfile, ROOT_DIR)
653668
header = relpath_for_windows_display(src.frozenfile, ROOT_DIR)

graalpython/com.oracle.graal.python.pegparser.generator/pegen/sccutils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def strongly_connected_components(
1818
exactly once; vertices not part of a SCC are returned as
1919
singleton sets.
2020
21-
From http://code.activestate.com/recipes/578507/.
21+
From https://code.activestate.com/recipes/578507-strongly-connected-components-of-a-directed-graph/.
2222
"""
2323
identified: Set[str] = set()
2424
stack: List[str] = []
@@ -81,7 +81,7 @@ def topsort(
8181
{B, C}
8282
{A}
8383
84-
From http://code.activestate.com/recipes/577413/.
84+
From https://code.activestate.com/recipes/577413-topological-sort/history/1/.
8585
"""
8686
# TODO: Use a faster algorithm?
8787
for k, v in data.items():

0 commit comments

Comments
 (0)