summaryrefslogtreecommitdiffstats
path: root/Objects/typeobject.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2019-11-08 09:05:17 (GMT)
committerGitHub <noreply@github.com>2019-11-08 09:05:17 (GMT)
commit7e433733175e76627d46ed9bdab543860cd1452d (patch)
treeab96312f08fbd190262d5cdc628be5958948ad81 /Objects/typeobject.c
parentbefa032d8869e0fab4732d910f3887642879d644 (diff)
downloadcpython-7e433733175e76627d46ed9bdab543860cd1452d.zip
cpython-7e433733175e76627d46ed9bdab543860cd1452d.tar.gz
cpython-7e433733175e76627d46ed9bdab543860cd1452d.tar.bz2
bpo-38644: Add _PyObject_VectorcallTstate() (GH-17052)
* Add _PyObject_VectorcallTstate() function: similar to _PyObject_Vectorcall(), but with tstate parameter * Add tstate parameter to _PyObject_MakeTpCall()
Diffstat (limited to 'Objects/typeobject.c')
-rw-r--r--Objects/typeobject.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 0e1cb7b..50a3c15 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1445,7 +1445,7 @@ lookup_method(PyObject *self, _Py_Identifier *attrid, int *unbound)
static inline PyObject*
-vectorcall_unbound(int unbound, PyObject *func,
+vectorcall_unbound(PyThreadState *tstate, int unbound, PyObject *func,
PyObject *const *args, Py_ssize_t nargs)
{
size_t nargsf = nargs;
@@ -1455,7 +1455,7 @@ vectorcall_unbound(int unbound, PyObject *func,
args++;
nargsf = nargsf - 1 + PY_VECTORCALL_ARGUMENTS_OFFSET;
}
- return _PyObject_Vectorcall(func, args, nargsf, NULL);
+ return _PyObject_VectorcallTstate(tstate, func, args, nargsf, NULL);
}
static PyObject*
@@ -1479,13 +1479,15 @@ vectorcall_method(_Py_Identifier *name,
PyObject *const *args, Py_ssize_t nargs)
{
assert(nargs >= 1);
+
+ PyThreadState *tstate = _PyThreadState_GET();
int unbound;
PyObject *self = args[0];
PyObject *func = lookup_method(self, name, &unbound);
if (func == NULL) {
return NULL;
}
- PyObject *retval = vectorcall_unbound(unbound, func, args, nargs);
+ PyObject *retval = vectorcall_unbound(tstate, unbound, func, args, nargs);
Py_DECREF(func);
return retval;
}
@@ -1493,10 +1495,11 @@ vectorcall_method(_Py_Identifier *name,
/* Clone of vectorcall_method() that returns NotImplemented
* when the lookup fails. */
static PyObject *
-vectorcall_maybe(_Py_Identifier *name,
+vectorcall_maybe(PyThreadState *tstate, _Py_Identifier *name,
PyObject *const *args, Py_ssize_t nargs)
{
assert(nargs >= 1);
+
int unbound;
PyObject *self = args[0];
PyObject *func = lookup_maybe_method(self, name, &unbound);
@@ -1505,7 +1508,7 @@ vectorcall_maybe(_Py_Identifier *name,
Py_RETURN_NOTIMPLEMENTED;
return NULL;
}
- PyObject *retval = vectorcall_unbound(unbound, func, args, nargs);
+ PyObject *retval = vectorcall_unbound(tstate, unbound, func, args, nargs);
Py_DECREF(func);
return retval;
}
@@ -6177,6 +6180,7 @@ static PyObject * \
FUNCNAME(PyObject *self, PyObject *other) \
{ \
PyObject* stack[2]; \
+ PyThreadState *tstate = _PyThreadState_GET(); \
_Py_static_string(op_id, OPSTR); \
_Py_static_string(rop_id, ROPSTR); \
int do_other = Py_TYPE(self) != Py_TYPE(other) && \
@@ -6193,7 +6197,7 @@ FUNCNAME(PyObject *self, PyObject *other) \
if (ok) { \
stack[0] = other; \
stack[1] = self; \
- r = vectorcall_maybe(&rop_id, stack, 2); \
+ r = vectorcall_maybe(tstate, &rop_id, stack, 2); \
if (r != Py_NotImplemented) \
return r; \
Py_DECREF(r); \
@@ -6202,7 +6206,7 @@ FUNCNAME(PyObject *self, PyObject *other) \
} \
stack[0] = self; \
stack[1] = other; \
- r = vectorcall_maybe(&op_id, stack, 2); \
+ r = vectorcall_maybe(tstate, &op_id, stack, 2); \
if (r != Py_NotImplemented || \
Py_TYPE(other) == Py_TYPE(self)) \
return r; \
@@ -6211,7 +6215,7 @@ FUNCNAME(PyObject *self, PyObject *other) \
if (do_other) { \
stack[0] = other; \
stack[1] = self; \
- return vectorcall_maybe(&rop_id, stack, 2); \
+ return vectorcall_maybe(tstate, &rop_id, stack, 2); \
} \
Py_RETURN_NOTIMPLEMENTED; \
}
@@ -6293,6 +6297,7 @@ slot_sq_ass_item(PyObject *self, Py_ssize_t index, PyObject *value)
static int
slot_sq_contains(PyObject *self, PyObject *value)
{
+ PyThreadState *tstate = _PyThreadState_GET();
PyObject *func, *res;
int result = -1, unbound;
_Py_IDENTIFIER(__contains__);
@@ -6307,7 +6312,7 @@ slot_sq_contains(PyObject *self, PyObject *value)
}
if (func != NULL) {
PyObject *args[2] = {self, value};
- res = vectorcall_unbound(unbound, func, args, 2);
+ res = vectorcall_unbound(tstate, unbound, func, args, 2);
Py_DECREF(func);
if (res != NULL) {
result = PyObject_IsTrue(res);
@@ -6682,6 +6687,7 @@ static _Py_Identifier name_op[] = {
static PyObject *
slot_tp_richcompare(PyObject *self, PyObject *other, int op)
{
+ PyThreadState *tstate = _PyThreadState_GET();
int unbound;
PyObject *func, *res;
@@ -6692,7 +6698,7 @@ slot_tp_richcompare(PyObject *self, PyObject *other, int op)
}
PyObject *stack[2] = {self, other};
- res = vectorcall_unbound(unbound, func, stack, 2);
+ res = vectorcall_unbound(tstate, unbound, func, stack, 2);
Py_DECREF(func);
return res;
}