MISSING_C_DOCSTRINGS,
)
from test.test_import import no_rerun
+from test.support.script_helper import assert_python_ok
+from test.support.import_helper import import_fresh_module
+
import collections.abc
from collections import namedtuple, UserDict
import copy
def test_capsule_type(self):
self.assertIsInstance(_datetime.datetime_CAPI, types.CapsuleType)
+ def test_call_unbound_crash(self):
+ # GH-131998: The specialized instruction would get tricked into dereferencing
+ # a bound "self" that didn't exist if subsequently called unbound.
+ code = """if True:
+
+ def call(part):
+ [] + ([] + [])
+ part.pop()
+
+ for _ in range(3):
+ call(['a'])
+ try:
+ call(list)
+ except TypeError:
+ pass
+ """
+ assert_python_ok("-c", code)
+
class UnionTests(unittest.TestCase):
--- /dev/null
+Fix a crash when using an unbound method :term:`descriptor` object in a
+function where a bound method descriptor was used.
args--;
total_args++;
}
+ DEOPT_IF(total_args == 0);
PyMethodDescrObject *method = (PyMethodDescrObject *)callable;
DEOPT_IF(!Py_IS_TYPE(method, &PyMethodDescr_Type));
PyMethodDef *meth = method->d_method;
DEOPT_IF(meth->ml_flags != (METH_FASTCALL|METH_KEYWORDS));
PyTypeObject *d_type = method->d_common.d_type;
PyObject *self = args[0];
+ assert(self != NULL);
DEOPT_IF(!Py_IS_TYPE(self, d_type));
STAT_INC(CALL, hit);
int nargs = total_args - 1;
total_args++;
}
PyMethodDescrObject *method = (PyMethodDescrObject *)callable;
+ DEOPT_IF(total_args == 0);
/* Builtin METH_FASTCALL methods, without keywords */
DEOPT_IF(!Py_IS_TYPE(method, &PyMethodDescr_Type));
PyMethodDef *meth = method->d_method;
DEOPT_IF(meth->ml_flags != METH_FASTCALL);
PyObject *self = args[0];
+ assert(self != NULL);
DEOPT_IF(!Py_IS_TYPE(self, method->d_common.d_type));
STAT_INC(CALL, hit);
PyCFunctionFast cfunc =
args--;
total_args++;
}
+ if (total_args == 0) {
+ UOP_STAT_INC(uopcode, miss);
+ JUMP_TO_JUMP_TARGET();
+ }
PyMethodDescrObject *method = (PyMethodDescrObject *)callable;
if (!Py_IS_TYPE(method, &PyMethodDescr_Type)) {
UOP_STAT_INC(uopcode, miss);
}
PyTypeObject *d_type = method->d_common.d_type;
PyObject *self = args[0];
+ assert(self != NULL);
if (!Py_IS_TYPE(self, d_type)) {
UOP_STAT_INC(uopcode, miss);
JUMP_TO_JUMP_TARGET();
total_args++;
}
PyMethodDescrObject *method = (PyMethodDescrObject *)callable;
+ if (total_args == 0) {
+ UOP_STAT_INC(uopcode, miss);
+ JUMP_TO_JUMP_TARGET();
+ }
/* Builtin METH_FASTCALL methods, without keywords */
if (!Py_IS_TYPE(method, &PyMethodDescr_Type)) {
UOP_STAT_INC(uopcode, miss);
JUMP_TO_JUMP_TARGET();
}
PyObject *self = args[0];
+ assert(self != NULL);
if (!Py_IS_TYPE(self, method->d_common.d_type)) {
UOP_STAT_INC(uopcode, miss);
JUMP_TO_JUMP_TARGET();
total_args++;
}
PyMethodDescrObject *method = (PyMethodDescrObject *)callable;
+ DEOPT_IF(total_args == 0, CALL);
/* Builtin METH_FASTCALL methods, without keywords */
DEOPT_IF(!Py_IS_TYPE(method, &PyMethodDescr_Type), CALL);
PyMethodDef *meth = method->d_method;
DEOPT_IF(meth->ml_flags != METH_FASTCALL, CALL);
PyObject *self = args[0];
+ assert(self != NULL);
DEOPT_IF(!Py_IS_TYPE(self, method->d_common.d_type), CALL);
STAT_INC(CALL, hit);
PyCFunctionFast cfunc =
args--;
total_args++;
}
+ DEOPT_IF(total_args == 0, CALL);
PyMethodDescrObject *method = (PyMethodDescrObject *)callable;
DEOPT_IF(!Py_IS_TYPE(method, &PyMethodDescr_Type), CALL);
PyMethodDef *meth = method->d_method;
DEOPT_IF(meth->ml_flags != (METH_FASTCALL|METH_KEYWORDS), CALL);
PyTypeObject *d_type = method->d_common.d_type;
PyObject *self = args[0];
+ assert(self != NULL);
DEOPT_IF(!Py_IS_TYPE(self, d_type), CALL);
STAT_INC(CALL, hit);
int nargs = total_args - 1;