mirror of
https://github.com/python/cpython.git
synced 2025-10-19 16:03:42 +00:00
[3.14] gh-139525: Don't specialize functions which have a modified vectorcall (GH-139524) (#139709)
Don't specialize functions which have a modified vectorcall
This commit is contained in:
parent
1c1a0bdfdc
commit
81dc8b12f0
3 changed files with 37 additions and 0 deletions
|
@ -567,6 +567,14 @@ def test(default=None):
|
||||||
with self.assertRaises(RecursionError):
|
with self.assertRaises(RecursionError):
|
||||||
test()
|
test()
|
||||||
|
|
||||||
|
def test_dont_specialize_custom_vectorcall(self):
|
||||||
|
def f():
|
||||||
|
raise Exception("no way")
|
||||||
|
|
||||||
|
_testinternalcapi.set_vectorcall_nop(f)
|
||||||
|
for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
|
||||||
|
f()
|
||||||
|
|
||||||
|
|
||||||
def make_deferred_ref_count_obj():
|
def make_deferred_ref_count_obj():
|
||||||
"""Create an object that uses deferred reference counting.
|
"""Create an object that uses deferred reference counting.
|
||||||
|
|
|
@ -2389,6 +2389,25 @@ emscripten_set_up_async_input_device(PyObject *self, PyObject *Py_UNUSED(ignored
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
vectorcall_nop(PyObject *callable, PyObject *const *args,
|
||||||
|
size_t nargsf, PyObject *kwnames)
|
||||||
|
{
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
set_vectorcall_nop(PyObject *self, PyObject *func)
|
||||||
|
{
|
||||||
|
if (!PyFunction_Check(func)) {
|
||||||
|
PyErr_SetString(PyExc_TypeError, "expected function");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
((PyFunctionObject*)func)->vectorcall = vectorcall_nop;
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
static PyMethodDef module_functions[] = {
|
static PyMethodDef module_functions[] = {
|
||||||
{"get_configs", get_configs, METH_NOARGS},
|
{"get_configs", get_configs, METH_NOARGS},
|
||||||
{"get_recursion_depth", get_recursion_depth, METH_NOARGS},
|
{"get_recursion_depth", get_recursion_depth, METH_NOARGS},
|
||||||
|
@ -2496,6 +2515,7 @@ static PyMethodDef module_functions[] = {
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
{"emscripten_set_up_async_input_device", emscripten_set_up_async_input_device, METH_NOARGS},
|
{"emscripten_set_up_async_input_device", emscripten_set_up_async_input_device, METH_NOARGS},
|
||||||
#endif
|
#endif
|
||||||
|
{"set_vectorcall_nop", set_vectorcall_nop, METH_O},
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -630,6 +630,7 @@ _PyCode_Quicken(_Py_CODEUNIT *instructions, Py_ssize_t size, int enable_counters
|
||||||
#define SPEC_FAIL_CALL_INIT_NOT_PYTHON 21
|
#define SPEC_FAIL_CALL_INIT_NOT_PYTHON 21
|
||||||
#define SPEC_FAIL_CALL_PEP_523 22
|
#define SPEC_FAIL_CALL_PEP_523 22
|
||||||
#define SPEC_FAIL_CALL_BOUND_METHOD 23
|
#define SPEC_FAIL_CALL_BOUND_METHOD 23
|
||||||
|
#define SPEC_FAIL_CALL_VECTORCALL 24
|
||||||
#define SPEC_FAIL_CALL_CLASS_MUTABLE 26
|
#define SPEC_FAIL_CALL_CLASS_MUTABLE 26
|
||||||
#define SPEC_FAIL_CALL_METHOD_WRAPPER 28
|
#define SPEC_FAIL_CALL_METHOD_WRAPPER 28
|
||||||
#define SPEC_FAIL_CALL_OPERATOR_WRAPPER 29
|
#define SPEC_FAIL_CALL_OPERATOR_WRAPPER 29
|
||||||
|
@ -2071,6 +2072,10 @@ specialize_py_call(PyFunctionObject *func, _Py_CODEUNIT *instr, int nargs,
|
||||||
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CALL_PEP_523);
|
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CALL_PEP_523);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (func->vectorcall != _PyFunction_Vectorcall) {
|
||||||
|
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CALL_VECTORCALL);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
int argcount = -1;
|
int argcount = -1;
|
||||||
if (kind == SPEC_FAIL_CODE_NOT_OPTIMIZED) {
|
if (kind == SPEC_FAIL_CODE_NOT_OPTIMIZED) {
|
||||||
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CODE_NOT_OPTIMIZED);
|
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CODE_NOT_OPTIMIZED);
|
||||||
|
@ -2110,6 +2115,10 @@ specialize_py_call_kw(PyFunctionObject *func, _Py_CODEUNIT *instr, int nargs,
|
||||||
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CALL_PEP_523);
|
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CALL_PEP_523);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (func->vectorcall != _PyFunction_Vectorcall) {
|
||||||
|
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CALL_VECTORCALL);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
if (kind == SPEC_FAIL_CODE_NOT_OPTIMIZED) {
|
if (kind == SPEC_FAIL_CODE_NOT_OPTIMIZED) {
|
||||||
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CODE_NOT_OPTIMIZED);
|
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CODE_NOT_OPTIMIZED);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue