Skip to content

Commit 5cea41f

Browse files
committed
Allow inexact arguments for CALL_ALLOC_AND_ENTER_INIT.
1 parent 2b94491 commit 5cea41f

File tree

4 files changed

+12
-31
lines changed

4 files changed

+12
-31
lines changed

Python/bytecodes.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3691,15 +3691,14 @@ dummy_func(
36913691
PyHeapTypeObject *cls = (PyHeapTypeObject *)callable_o;
36923692
PyFunctionObject *init_func = (PyFunctionObject *)cls->_spec_cache.init;
36933693
PyCodeObject *code = (PyCodeObject *)init_func->func_code;
3694-
DEOPT_IF(code->co_argcount != oparg+1);
36953694
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize + _Py_InitCleanup.co_framesize));
36963695
STAT_INC(CALL, hit);
36973696
self = PyStackRef_FromPyObjectSteal(_PyType_NewManagedObject(tp));
36983697
if (PyStackRef_IsNull(self)) {
36993698
ERROR_NO_POP();
37003699
}
3701-
init = PyStackRef_FromPyObjectNew(init_func);
37023700
PyStackRef_CLOSE(callable);
3701+
init = PyStackRef_FromPyObjectNew(init_func);
37033702
}
37043703

37053704
op(_CREATE_INIT_FRAME, (self, init, args[oparg] -- init_frame: _PyInterpreterFrame *)) {
@@ -3709,12 +3708,9 @@ dummy_func(
37093708
/* Push self onto stack of shim */
37103709
shim->localsplus[0] = PyStackRef_DUP(self);
37113710
PyFunctionObject *init_func = (PyFunctionObject *)PyStackRef_AsPyObjectSteal(init);
3712-
init_frame = _PyFrame_PushUnchecked(tstate, init_func, oparg+1, shim);
3713-
/* Copy self followed by args to __init__ frame */
3714-
init_frame->localsplus[0] = self;
3715-
for (int i = 0; i < oparg; i++) {
3716-
init_frame->localsplus[i+1] = args[i];
3717-
}
3711+
args[-1] = self;
3712+
init_frame = _PyEvalFramePushAndInit(
3713+
tstate, init_func, NULL, args-1, oparg+1, NULL, shim);
37183714
frame->return_offset = 1 + INLINE_CACHE_ENTRIES_CALL;
37193715
SYNC_SP();
37203716
/* Account for pushing the extra frame.

Python/executor_cases.c.h

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

Python/generated_cases.c.h

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

Python/specialize.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,10 +1814,6 @@ specialize_class_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs)
18141814
return -1;
18151815
}
18161816
if (init != NULL) {
1817-
if (((PyCodeObject *)init->func_code)->co_argcount != nargs+1) {
1818-
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_WRONG_NUMBER_ARGUMENTS);
1819-
return -1;
1820-
}
18211817
_PyCallCache *cache = (_PyCallCache *)(instr + 1);
18221818
write_u32(cache->func_version, tp->tp_version_tag);
18231819
_Py_SET_OPCODE(*instr, CALL_ALLOC_AND_ENTER_INIT);

0 commit comments

Comments
 (0)