Skip to content

Commit 06ddc00

Browse files
Apply Mark's and Brandt's suggestion
1 parent b933f6e commit 06ddc00

File tree

7 files changed

+58
-60
lines changed

7 files changed

+58
-60
lines changed

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ struct _Py_global_strings {
704704
STRUCT_FOR_ID(x)
705705
STRUCT_FOR_ID(year)
706706
STRUCT_FOR_ID(zdict)
707+
STRUCT_FOR_ID(zipimporter)
707708
} identifiers;
708709
struct {
709710
PyASCIIObject _ascii;

Include/internal/pycore_runtime_init_generated.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3483,40 +3483,14 @@ dummy_func(
34833483
int code_flags = ((PyCodeObject *)PyFunction_GET_CODE(func))->co_flags;
34843484
PyObject *locals = code_flags & CO_OPTIMIZED ? NULL : Py_NewRef(PyFunction_GET_GLOBALS(func));
34853485

3486-
bool has_dict = (kwargs != NULL && PyDict_GET_SIZE(kwargs) > 0);
3487-
PyObject *kwnames = NULL;
3488-
PyObject *const *newargs = has_dict
3489-
? _PyStack_UnpackDict(tstate, _PyTuple_ITEMS(callargs),
3490-
nargs, kwargs, &kwnames)
3491-
: &PyTuple_GET_ITEM(callargs, 0);
3492-
if (newargs == NULL) {
3493-
goto error;
3494-
}
3495-
if (!has_dict) {
3496-
/* We need to incref all our args since the new frame steals the references. */
3497-
for (Py_ssize_t i = 0; i < nargs; ++i) {
3498-
Py_INCREF(PyTuple_GET_ITEM(callargs, i));
3499-
}
3500-
}
3501-
_PyInterpreterFrame *new_frame = _PyEvalFramePushAndInit(
3502-
tstate, (PyFunctionObject *)func, locals,
3503-
newargs, nargs, kwnames
3504-
);
3486+
_PyInterpreterFrame *new_frame = _PyEvalFramePushAndInit_Ex(tstate,
3487+
(PyFunctionObject *)func, locals,
3488+
nargs, callargs, kwargs);
35053489
STACK_SHRINK(2); /* get rid of func and NULL */
3506-
Py_DECREF(callargs);
3507-
Py_XDECREF(kwargs);
3508-
if (has_dict) {
3509-
_PyStack_UnpackDict_FreeNoDecRef(newargs, kwnames);
3510-
}
35113490
if (new_frame == NULL) {
35123491
goto error;
35133492
}
3514-
_PyFrame_SetStackPointer(frame, stack_pointer);
3515-
frame->prev_instr = next_instr - 1;
3516-
new_frame->previous = frame;
3517-
cframe.current_frame = frame = new_frame;
3518-
CALL_STAT_INC(inlined_py_calls);
3519-
goto start_frame;
3493+
DISPATCH_INLINED(new_frame);
35203494
}
35213495
else {
35223496
result = do_call_core(tstate, func, callargs, kwargs, cframe.use_tracing);

Python/ceval.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ static _PyInterpreterFrame *
217217
_PyEvalFramePushAndInit(PyThreadState *tstate, PyFunctionObject *func,
218218
PyObject *locals, PyObject* const* args,
219219
size_t argcount, PyObject *kwnames);
220+
static _PyInterpreterFrame *
221+
_PyEvalFramePushAndInit_Ex(PyThreadState *tstate, PyFunctionObject *func,
222+
PyObject *locals, Py_ssize_t nargs, PyObject *callargs, PyObject *kwargs);
220223
static void
221224
_PyEvalFrameClearAndPop(PyThreadState *tstate, _PyInterpreterFrame *frame);
222225

@@ -2005,6 +2008,48 @@ _PyEvalFramePushAndInit(PyThreadState *tstate, PyFunctionObject *func,
20052008
return NULL;
20062009
}
20072010

2011+
/* Same as _PyEvalFramePushAndInit but takes an args tuple and kwargs dict.
2012+
Steals references to func, callargs and kwargs.
2013+
*/
2014+
static _PyInterpreterFrame *
2015+
_PyEvalFramePushAndInit_Ex(PyThreadState *tstate, PyFunctionObject *func,
2016+
PyObject *locals, Py_ssize_t nargs, PyObject *callargs, PyObject *kwargs)
2017+
{
2018+
bool has_dict = (kwargs != NULL && PyDict_GET_SIZE(kwargs) > 0);
2019+
PyObject *kwnames = NULL;
2020+
PyObject *const *newargs = has_dict
2021+
? _PyStack_UnpackDict(tstate, _PyTuple_ITEMS(callargs),
2022+
nargs, kwargs, &kwnames)
2023+
: &PyTuple_GET_ITEM(callargs, 0);
2024+
if (newargs == NULL) {
2025+
Py_DECREF(func);
2026+
goto error;
2027+
}
2028+
if (!has_dict) {
2029+
/* We need to incref all our args since the new frame steals the references. */
2030+
for (Py_ssize_t i = 0; i < nargs; ++i) {
2031+
Py_INCREF(PyTuple_GET_ITEM(callargs, i));
2032+
}
2033+
}
2034+
_PyInterpreterFrame *new_frame = _PyEvalFramePushAndInit(
2035+
tstate, (PyFunctionObject *)func, locals,
2036+
newargs, nargs, kwnames
2037+
);
2038+
if (has_dict) {
2039+
_PyStack_UnpackDict_FreeNoDecRef(newargs, kwnames);
2040+
}
2041+
/* No need to decref func here because the reference has been stolen by
2042+
_PyEvalFramePushAndInit.
2043+
*/
2044+
Py_DECREF(callargs);
2045+
Py_XDECREF(kwargs);
2046+
return new_frame;
2047+
error:
2048+
Py_DECREF(callargs);
2049+
Py_XDECREF(kwargs);
2050+
return NULL;
2051+
}
2052+
20082053
static void
20092054
clear_thread_frame(PyThreadState *tstate, _PyInterpreterFrame * frame)
20102055
{

Python/generated_cases.c.h

Lines changed: 4 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)