Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 197dace

Browse files
author
Anselm Kruis
committed
Merge branch master into master-slp
2 parents 52a131d + 99bb14b commit 197dace

File tree

1 file changed

+40
-32
lines changed

1 file changed

+40
-32
lines changed

Objects/typeobject.c

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -911,42 +911,50 @@ type_call(PyTypeObject *type, PyObject *args, PyObject *kwds)
911911
#endif
912912

913913
obj = type->tp_new(type, args, kwds);
914-
if (obj != NULL) {
915-
/* Ugly exception: when the call was type(something),
916-
don't call tp_init on the result. */
917-
if (type == &PyType_Type &&
918-
PyTuple_Check(args) && PyTuple_GET_SIZE(args) == 1 &&
919-
(kwds == NULL ||
920-
(PyDict_Check(kwds) && PyDict_Size(kwds) == 0)))
921-
return obj;
922-
/* If the returned object is not an instance of type,
923-
it won't be initialized. */
924-
if (!PyType_IsSubtype(Py_TYPE(obj), type))
925-
return obj;
926-
type = Py_TYPE(obj);
927-
if (type->tp_init != NULL) {
928-
initproc tp_init = type->tp_init;
929-
int res;
914+
obj = _Py_CheckFunctionResult((PyObject*)type, obj, NULL);
915+
if (obj == NULL)
916+
return NULL;
917+
918+
/* Ugly exception: when the call was type(something),
919+
don't call tp_init on the result. */
920+
if (type == &PyType_Type &&
921+
PyTuple_Check(args) && PyTuple_GET_SIZE(args) == 1 &&
922+
(kwds == NULL ||
923+
(PyDict_Check(kwds) && PyDict_Size(kwds) == 0)))
924+
return obj;
925+
926+
/* If the returned object is not an instance of type,
927+
it won't be initialized. */
928+
if (!PyType_IsSubtype(Py_TYPE(obj), type))
929+
return obj;
930+
931+
type = Py_TYPE(obj);
932+
if (type->tp_init != NULL) {
933+
initproc tp_init = type->tp_init;
934+
int res;
930935
#ifdef STACKLESS
931-
int is_stackless;
932-
if (tp_init == slot_tp_init)
933-
STACKLESS_PROMOTE_ALL();
934-
is_stackless = slp_try_stackless;
936+
int is_stackless;
937+
if (tp_init == slot_tp_init)
938+
STACKLESS_PROMOTE_ALL();
939+
is_stackless = slp_try_stackless;
935940
#endif
936-
res = tp_init(obj, args, kwds);
941+
res = tp_init(obj, args, kwds);
937942
#ifdef STACKLESS
938-
STACKLESS_ASSERT();
939-
if (is_stackless && res == STACKLESS_UNWINDING_MAGIC) {
940-
/* It is a stackless call and it is unwinding.
941-
* the real result is in Py_UnwindToken */
942-
Py_DECREF(obj);
943-
return (PyObject *)Py_UnwindToken;
944-
}
943+
STACKLESS_ASSERT();
944+
if (is_stackless && res == STACKLESS_UNWINDING_MAGIC) {
945+
/* It is a stackless call and it is unwinding.
946+
* the real result is in Py_UnwindToken */
947+
Py_DECREF(obj);
948+
return (PyObject *)Py_UnwindToken;
949+
}
945950
#endif
946-
if (res < 0) {
947-
Py_DECREF(obj);
948-
obj = NULL;
949-
}
951+
if (res < 0) {
952+
assert(PyErr_Occurred());
953+
Py_DECREF(obj);
954+
obj = NULL;
955+
}
956+
else {
957+
assert(!PyErr_Occurred());
950958
}
951959
}
952960
return obj;

0 commit comments

Comments
 (0)