summaryrefslogtreecommitdiffstats
path: root/Objects/classobject.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/classobject.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/classobject.c')
-rw-r--r--Objects/classobject.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c
index 4a9add1..d3fc726 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -2,6 +2,7 @@
#include "Python.h"
#include "pycore_object.h"
+#include "pycore_pyerrors.h"
#include "pycore_pymem.h"
#include "pycore_pystate.h"
#include "structmember.h"
@@ -37,25 +38,28 @@ method_vectorcall(PyObject *method, PyObject *const *args,
size_t nargsf, PyObject *kwnames)
{
assert(Py_TYPE(method) == &PyMethod_Type);
- PyObject *self, *func, *result;
- self = PyMethod_GET_SELF(method);
- func = PyMethod_GET_FUNCTION(method);
+
+ PyThreadState *tstate = _PyThreadState_GET();
+ PyObject *self = PyMethod_GET_SELF(method);
+ PyObject *func = PyMethod_GET_FUNCTION(method);
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ PyObject *result;
if (nargsf & PY_VECTORCALL_ARGUMENTS_OFFSET) {
/* PY_VECTORCALL_ARGUMENTS_OFFSET is set, so we are allowed to mutate the vector */
PyObject **newargs = (PyObject**)args - 1;
nargs += 1;
PyObject *tmp = newargs[0];
newargs[0] = self;
- result = _PyObject_Vectorcall(func, newargs, nargs, kwnames);
+ result = _PyObject_VectorcallTstate(tstate, func, newargs,
+ nargs, kwnames);
newargs[0] = tmp;
}
else {
Py_ssize_t nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames);
Py_ssize_t totalargs = nargs + nkwargs;
if (totalargs == 0) {
- return _PyObject_Vectorcall(func, &self, 1, NULL);
+ return _PyObject_VectorcallTstate(tstate, func, &self, 1, NULL);
}
PyObject *newargs_stack[_PY_FASTCALL_SMALL_STACK];
@@ -66,7 +70,7 @@ method_vectorcall(PyObject *method, PyObject *const *args,
else {
newargs = PyMem_Malloc((totalargs+1) * sizeof(PyObject *));
if (newargs == NULL) {
- PyErr_NoMemory();
+ _PyErr_NoMemory(tstate);
return NULL;
}
}
@@ -77,7 +81,8 @@ method_vectorcall(PyObject *method, PyObject *const *args,
* undefined behaviour. */
assert(args != NULL);
memcpy(newargs + 1, args, totalargs * sizeof(PyObject *));
- result = _PyObject_Vectorcall(func, newargs, nargs+1, kwnames);
+ result = _PyObject_VectorcallTstate(tstate, func,
+ newargs, nargs+1, kwnames);
if (newargs != newargs_stack) {
PyMem_Free(newargs);
}