summaryrefslogtreecommitdiff
path: root/Objects/typeobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/typeobject.c')
-rw-r--r--Objects/typeobject.c312
1 files changed, 160 insertions, 152 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 329261b037..0193192102 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -121,6 +121,22 @@ skip_signature(const char *doc)
return NULL;
}
+#ifdef Py_DEBUG
+static int
+_PyType_CheckConsistency(PyTypeObject *type)
+{
+ if (!(type->tp_flags & Py_TPFLAGS_READY)) {
+ /* don't check types before PyType_Ready() */
+ return 1;
+ }
+
+ assert(!(type->tp_flags & Py_TPFLAGS_READYING));
+ assert(type->tp_mro != NULL && PyTuple_Check(type->tp_mro));
+ assert(type->tp_dict != NULL);
+ return 1;
+}
+#endif
+
static const char *
_PyType_DocWithoutSignature(const char *name, const char *internal_doc)
{
@@ -140,8 +156,7 @@ _PyType_GetDocFromInternalDoc(const char *name, const char *internal_doc)
const char *doc = _PyType_DocWithoutSignature(name, internal_doc);
if (!doc || *doc == '\0') {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
return PyUnicode_FromString(doc);
@@ -158,8 +173,7 @@ _PyType_GetTextSignatureFromInternalDoc(const char *name, const char *internal_d
else
end = NULL;
if (!end) {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/* back "end" up until it points just past the final ')' */
@@ -721,6 +735,7 @@ type_set_bases(PyTypeObject *type, PyObject *new_bases, void *context)
Py_DECREF(old_bases);
Py_DECREF(old_base);
+ assert(_PyType_CheckConsistency(type));
return res;
undo:
@@ -754,6 +769,7 @@ type_set_bases(PyTypeObject *type, PyObject *new_bases, void *context)
Py_DECREF(old_base);
}
+ assert(_PyType_CheckConsistency(type));
return -1;
}
@@ -761,8 +777,7 @@ static PyObject *
type_dict(PyTypeObject *type, void *context)
{
if (type->tp_dict == NULL) {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
return PyDictProxy_New(type->tp_dict);
}
@@ -887,7 +902,7 @@ type_call(PyTypeObject *type, PyObject *args, PyObject *kwds)
#ifdef Py_DEBUG
/* type_call() must not be called with an exception set,
- because it may clear it (directly or indirectly) and so the
+ because it can clear it (directly or indirectly) and so the
caller loses its exception */
assert(!PyErr_Occurred());
#endif
@@ -902,7 +917,7 @@ type_call(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (type == &PyType_Type &&
PyTuple_Check(args) && PyTuple_GET_SIZE(args) == 1 &&
(kwds == NULL ||
- (PyDict_Check(kwds) && PyDict_Size(kwds) == 0)))
+ (PyDict_Check(kwds) && PyDict_GET_SIZE(kwds) == 0)))
return obj;
/* If the returned object is not an instance of type,
@@ -1420,43 +1435,24 @@ _PyObject_LookupSpecial(PyObject *self, _Py_Identifier *attrid)
return lookup_maybe(self, attrid);
}
-/* A variation of PyObject_CallMethod that uses lookup_method()
+/* A variation of PyObject_CallMethodObjArgs that uses lookup_method()
instead of PyObject_GetAttrString(). This uses the same convention
as lookup_method to cache the interned name string object. */
static PyObject *
-call_method(PyObject *o, _Py_Identifier *nameid, const char *format, ...)
+call_method(PyObject *obj, _Py_Identifier *name,
+ PyObject **args, Py_ssize_t nargs)
{
- va_list va;
- PyObject *func = NULL, *retval;
+ PyObject *func, *retval;
- func = lookup_maybe(o, nameid);
+ func = lookup_maybe(obj, name);
if (func == NULL) {
if (!PyErr_Occurred())
- PyErr_SetObject(PyExc_AttributeError, nameid->object);
+ PyErr_SetObject(PyExc_AttributeError, name->object);
return NULL;
}
- if (format && *format) {
- PyObject *args;
-
- va_start(va, format);
- args = Py_VaBuildValue(format, va);
- va_end(va);
-
- if (args == NULL) {
- Py_DECREF(func);
- return NULL;
- }
- assert(PyTuple_Check(args));
-
- retval = PyObject_Call(func, args, NULL);
- Py_DECREF(args);
- }
- else {
- retval = _PyObject_CallNoArg(func);
- }
-
+ retval = _PyObject_FastCall(func, args, nargs);
Py_DECREF(func);
return retval;
@@ -1465,38 +1461,19 @@ call_method(PyObject *o, _Py_Identifier *nameid, const char *format, ...)
/* Clone of call_method() that returns NotImplemented when the lookup fails. */
static PyObject *
-call_maybe(PyObject *o, _Py_Identifier *nameid, const char *format, ...)
+call_maybe(PyObject *obj, _Py_Identifier *name,
+ PyObject **args, Py_ssize_t nargs)
{
- va_list va;
- PyObject *func = NULL, *retval;
+ PyObject *func, *retval;
- func = lookup_maybe(o, nameid);
+ func = lookup_maybe(obj, name);
if (func == NULL) {
if (!PyErr_Occurred())
Py_RETURN_NOTIMPLEMENTED;
return NULL;
}
- if (format && *format) {
- PyObject *args;
-
- va_start(va, format);
- args = Py_VaBuildValue(format, va);
- va_end(va);
-
- if (args == NULL) {
- Py_DECREF(func);
- return NULL;
- }
- assert(PyTuple_Check(args));
-
- retval = PyObject_Call(func, args, NULL);
- Py_DECREF(args);
- }
- else {
- retval = _PyObject_CallNoArg(func);
- }
-
+ retval = _PyObject_FastCall(func, args, nargs);
Py_DECREF(func);
return retval;
@@ -1617,14 +1594,14 @@ set_mro_error(PyObject *to_merge, int *remain)
}
}
}
- n = PyDict_Size(set);
+ n = PyDict_GET_SIZE(set);
off = PyOS_snprintf(buf, sizeof(buf), "Cannot create a \
consistent method resolution\norder (MRO) for bases");
i = 0;
while (PyDict_Next(set, &i, &k, &v) && (size_t)off < sizeof(buf)) {
PyObject *name = class_name(k);
- char *name_str;
+ const char *name_str;
if (name != NULL) {
name_str = PyUnicode_AsUTF8(name);
if (name_str == NULL)
@@ -1856,7 +1833,7 @@ mro_invoke(PyTypeObject *type)
PyObject *mro_meth = lookup_method((PyObject *)type, &PyId_mro);
if (mro_meth == NULL)
return NULL;
- mro_result = PyObject_CallObject(mro_meth, NULL);
+ mro_result = _PyObject_CallNoArg(mro_meth);
Py_DECREF(mro_meth);
}
else {
@@ -2219,7 +2196,7 @@ type_init(PyObject *cls, PyObject *args, PyObject *kwds)
assert(kwds == NULL || PyDict_Check(kwds));
if (kwds != NULL && PyTuple_Check(args) && PyTuple_GET_SIZE(args) == 1 &&
- PyDict_Check(kwds) && PyDict_Size(kwds) != 0) {
+ PyDict_Check(kwds) && PyDict_GET_SIZE(kwds) != 0) {
PyErr_SetString(PyExc_TypeError,
"type.__init__() takes no keyword arguments");
return -1;
@@ -2304,7 +2281,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
Note: We don't call PyType_CheckExact as that also allows subclasses */
if (metatype == &PyType_Type) {
const Py_ssize_t nargs = PyTuple_GET_SIZE(args);
- const Py_ssize_t nkwds = kwds == NULL ? 0 : PyDict_Size(kwds);
+ const Py_ssize_t nkwds = kwds == NULL ? 0 : PyDict_GET_SIZE(kwds);
if (nargs == 1 && nkwds == 0) {
PyObject *x = PyTuple_GET_ITEM(args, 0);
@@ -2572,7 +2549,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
PyObject *doc = _PyDict_GetItemId(dict, &PyId___doc__);
if (doc != NULL && PyUnicode_Check(doc)) {
Py_ssize_t len;
- char *doc_str;
+ const char *doc_str;
char *tp_doc;
doc_str = PyUnicode_AsUTF8(doc);
@@ -3075,6 +3052,7 @@ type_getattro(PyTypeObject *type, PyObject *name)
static int
type_setattro(PyTypeObject *type, PyObject *name, PyObject *value)
{
+ int res;
if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
PyErr_Format(
PyExc_TypeError,
@@ -3082,9 +3060,11 @@ type_setattro(PyTypeObject *type, PyObject *name, PyObject *value)
type->tp_name);
return -1;
}
- if (PyObject_GenericSetAttr((PyObject *)type, name, value) < 0)
+ if (_PyObject_GenericSetAttrWithDict((PyObject *)type, name, value, NULL) < 0)
return -1;
- return update_slot(type, name);
+ res = update_slot(type, name);
+ assert(_PyType_CheckConsistency(type));
+ return res;
}
extern void
@@ -3150,7 +3130,8 @@ type_subclasses(PyTypeObject *type, PyObject *args_ignored)
}
static PyObject *
-type_prepare(PyObject *self, PyObject *args, PyObject *kwds)
+type_prepare(PyObject *self, PyObject **args, Py_ssize_t nargs,
+ PyObject *kwnames)
{
return PyDict_New();
}
@@ -3254,7 +3235,7 @@ static PyMethodDef type_methods[] = {
{"__subclasses__", (PyCFunction)type_subclasses, METH_NOARGS,
PyDoc_STR("__subclasses__() -> list of immediate subclasses")},
{"__prepare__", (PyCFunction)type_prepare,
- METH_VARARGS | METH_KEYWORDS | METH_CLASS,
+ METH_FASTCALL | METH_CLASS,
PyDoc_STR("__prepare__() -> dict\n"
"used to create the namespace for the class statement")},
{"__instancecheck__", type___instancecheck__, METH_O,
@@ -3448,7 +3429,7 @@ static int
excess_args(PyObject *args, PyObject *kwds)
{
return PyTuple_GET_SIZE(args) ||
- (kwds && PyDict_Check(kwds) && PyDict_Size(kwds));
+ (kwds && PyDict_Check(kwds) && PyDict_GET_SIZE(kwds));
}
static int
@@ -3926,7 +3907,7 @@ _PyObject_GetState(PyObject *obj, int required)
We also return None if the dict is empty to make the behavior
consistent regardless whether the dict was initialized or not.
This make unit testing easier. */
- if (dict != NULL && *dict != NULL && PyDict_Size(*dict) > 0) {
+ if (dict != NULL && *dict != NULL && PyDict_GET_SIZE(*dict)) {
state = *dict;
}
else {
@@ -4015,7 +3996,7 @@ _PyObject_GetState(PyObject *obj, int required)
/* If we found some slot attributes, pack them in a tuple along
the original attribute dictionary. */
- if (PyDict_Size(slots) > 0) {
+ if (PyDict_GET_SIZE(slots) > 0) {
PyObject *state2;
state2 = PyTuple_Pack(2, state, slots);
@@ -4032,7 +4013,7 @@ _PyObject_GetState(PyObject *obj, int required)
Py_DECREF(slotnames);
}
else { /* getstate != NULL */
- state = PyObject_CallObject(getstate, NULL);
+ state = _PyObject_CallNoArg(getstate);
Py_DECREF(getstate);
if (state == NULL)
return NULL;
@@ -4057,7 +4038,7 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs)
__getnewargs_ex__ on the object. */
getnewargs_ex = _PyObject_LookupSpecial(obj, &PyId___getnewargs_ex__);
if (getnewargs_ex != NULL) {
- PyObject *newargs = PyObject_CallObject(getnewargs_ex, NULL);
+ PyObject *newargs = _PyObject_CallNoArg(getnewargs_ex);
Py_DECREF(getnewargs_ex);
if (newargs == NULL) {
return -1;
@@ -4110,7 +4091,7 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs)
__getnewargs__ instead. */
getnewargs = _PyObject_LookupSpecial(obj, &PyId___getnewargs__);
if (getnewargs != NULL) {
- *args = PyObject_CallObject(getnewargs, NULL);
+ *args = _PyObject_CallNoArg(getnewargs);
Py_DECREF(getnewargs);
if (*args == NULL) {
return -1;
@@ -4207,7 +4188,7 @@ reduce_newobj(PyObject *obj)
return NULL;
}
hasargs = (args != NULL);
- if (kwargs == NULL || PyDict_Size(kwargs) == 0) {
+ if (kwargs == NULL || PyDict_GET_SIZE(kwargs) == 0) {
_Py_IDENTIFIER(__newobj__);
PyObject *cls;
Py_ssize_t i, n;
@@ -4362,7 +4343,7 @@ object_reduce_ex(PyObject *self, PyObject *args)
override = (clsreduce != objreduce);
Py_DECREF(clsreduce);
if (override) {
- res = PyObject_CallObject(reduce, NULL);
+ res = _PyObject_CallNoArg(reduce);
Py_DECREF(reduce);
return res;
}
@@ -4558,6 +4539,7 @@ add_methods(PyTypeObject *type, PyMethodDef *meth)
for (; meth->ml_name != NULL; meth++) {
PyObject *descr;
int err;
+ int isdescr = 1;
if (PyDict_GetItemString(dict, meth->ml_name) &&
!(meth->ml_flags & METH_COEXIST))
continue;
@@ -4574,6 +4556,7 @@ add_methods(PyTypeObject *type, PyMethodDef *meth)
if (cfunc == NULL)
return -1;
descr = PyStaticMethod_New(cfunc);
+ isdescr = 0; // PyStaticMethod is not PyDescrObject
Py_DECREF(cfunc);
}
else {
@@ -4581,7 +4564,12 @@ add_methods(PyTypeObject *type, PyMethodDef *meth)
}
if (descr == NULL)
return -1;
- err = PyDict_SetItemString(dict, meth->ml_name, descr);
+ if (isdescr) {
+ err = PyDict_SetItem(dict, PyDescr_NAME(descr), descr);
+ }
+ else {
+ err = PyDict_SetItemString(dict, meth->ml_name, descr);
+ }
Py_DECREF(descr);
if (err < 0)
return -1;
@@ -4601,7 +4589,7 @@ add_members(PyTypeObject *type, PyMemberDef *memb)
descr = PyDescr_NewMember(type, memb);
if (descr == NULL)
return -1;
- if (PyDict_SetItemString(dict, memb->name, descr) < 0) {
+ if (PyDict_SetItem(dict, PyDescr_NAME(descr), descr) < 0) {
Py_DECREF(descr);
return -1;
}
@@ -4623,7 +4611,7 @@ add_getset(PyTypeObject *type, PyGetSetDef *gsp)
if (descr == NULL)
return -1;
- if (PyDict_SetItemString(dict, gsp->name, descr) < 0) {
+ if (PyDict_SetItem(dict, PyDescr_NAME(descr), descr) < 0) {
Py_DECREF(descr);
return -1;
}
@@ -4891,7 +4879,7 @@ PyType_Ready(PyTypeObject *type)
Py_ssize_t i, n;
if (type->tp_flags & Py_TPFLAGS_READY) {
- assert(type->tp_dict != NULL);
+ assert(_PyType_CheckConsistency(type));
return 0;
}
assert((type->tp_flags & Py_TPFLAGS_READYING) == 0);
@@ -5085,9 +5073,9 @@ PyType_Ready(PyTypeObject *type)
}
/* All done -- set the ready flag */
- assert(type->tp_dict != NULL);
type->tp_flags =
(type->tp_flags & ~Py_TPFLAGS_READYING) | Py_TPFLAGS_READY;
+ assert(_PyType_CheckConsistency(type));
return 0;
error:
@@ -5367,8 +5355,7 @@ wrap_sq_setitem(PyObject *self, PyObject *args, void *wrapped)
res = (*func)(self, i, value);
if (res == -1 && PyErr_Occurred())
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
@@ -5388,8 +5375,7 @@ wrap_sq_delitem(PyObject *self, PyObject *args, void *wrapped)
res = (*func)(self, i, NULL);
if (res == -1 && PyErr_Occurred())
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/* XXX objobjproc is a misnomer; should be objargpred */
@@ -5422,8 +5408,7 @@ wrap_objobjargproc(PyObject *self, PyObject *args, void *wrapped)
res = (*func)(self, key, value);
if (res == -1 && PyErr_Occurred())
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
@@ -5439,8 +5424,7 @@ wrap_delitem(PyObject *self, PyObject *args, void *wrapped)
res = (*func)(self, key, NULL);
if (res == -1 && PyErr_Occurred())
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/* Helper to check for object.__setattr__ or __delattr__ applied to a type.
@@ -5477,8 +5461,7 @@ wrap_setattr(PyObject *self, PyObject *args, void *wrapped)
res = (*func)(self, name, value);
if (res < 0)
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
@@ -5496,8 +5479,7 @@ wrap_delattr(PyObject *self, PyObject *args, void *wrapped)
res = (*func)(self, name, NULL);
if (res < 0)
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
@@ -5608,8 +5590,7 @@ wrap_descr_set(PyObject *self, PyObject *args, void *wrapped)
ret = (*func)(self, obj, value);
if (ret < 0)
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
@@ -5625,8 +5606,7 @@ wrap_descr_delete(PyObject *self, PyObject *args, void *wrapped)
ret = (*func)(self, obj, NULL);
if (ret < 0)
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
@@ -5636,8 +5616,7 @@ wrap_init(PyObject *self, PyObject *args, void *wrapped, PyObject *kwds)
if (func(self, args, kwds) < 0)
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
@@ -5733,15 +5712,16 @@ static PyObject * \
FUNCNAME(PyObject *self) \
{ \
_Py_static_string(id, OPSTR); \
- return call_method(self, &id, NULL); \
+ return call_method(self, &id, NULL, 0); \
}
-#define SLOT1(FUNCNAME, OPSTR, ARG1TYPE, ARGCODES) \
+#define SLOT1(FUNCNAME, OPSTR, ARG1TYPE) \
static PyObject * \
FUNCNAME(PyObject *self, ARG1TYPE arg1) \
{ \
+ PyObject* stack[1] = {arg1}; \
_Py_static_string(id, OPSTR); \
- return call_method(self, &id, "(" ARGCODES ")", arg1); \
+ return call_method(self, &id, stack, 1); \
}
/* Boolean helper for SLOT1BINFULL().
@@ -5783,6 +5763,7 @@ method_is_overloaded(PyObject *left, PyObject *right, struct _Py_Identifier *nam
static PyObject * \
FUNCNAME(PyObject *self, PyObject *other) \
{ \
+ PyObject* stack[1]; \
_Py_static_string(op_id, OPSTR); \
_Py_static_string(rop_id, ROPSTR); \
int do_other = Py_TYPE(self) != Py_TYPE(other) && \
@@ -5794,20 +5775,23 @@ FUNCNAME(PyObject *self, PyObject *other) \
if (do_other && \
PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self)) && \
method_is_overloaded(self, other, &rop_id)) { \
- r = call_maybe(other, &rop_id, "(O)", self); \
+ stack[0] = self; \
+ r = call_maybe(other, &rop_id, stack, 1); \
if (r != Py_NotImplemented) \
return r; \
Py_DECREF(r); \
do_other = 0; \
} \
- r = call_maybe(self, &op_id, "(O)", other); \
+ stack[0] = other; \
+ r = call_maybe(self, &op_id, stack, 1); \
if (r != Py_NotImplemented || \
Py_TYPE(other) == Py_TYPE(self)) \
return r; \
Py_DECREF(r); \
} \
if (do_other) { \
- return call_maybe(other, &rop_id, "(O)", self); \
+ stack[0] = self; \
+ return call_maybe(other, &rop_id, stack, 1); \
} \
Py_RETURN_NOTIMPLEMENTED; \
}
@@ -5815,18 +5799,10 @@ FUNCNAME(PyObject *self, PyObject *other) \
#define SLOT1BIN(FUNCNAME, SLOTNAME, OPSTR, ROPSTR) \
SLOT1BINFULL(FUNCNAME, FUNCNAME, SLOTNAME, OPSTR, ROPSTR)
-#define SLOT2(FUNCNAME, OPSTR, ARG1TYPE, ARG2TYPE, ARGCODES) \
-static PyObject * \
-FUNCNAME(PyObject *self, ARG1TYPE arg1, ARG2TYPE arg2) \
-{ \
- _Py_static_string(id, #OPSTR); \
- return call_method(self, &id, "(" ARGCODES ")", arg1, arg2); \
-}
-
static Py_ssize_t
slot_sq_length(PyObject *self)
{
- PyObject *res = call_method(self, &PyId___len__, NULL);
+ PyObject *res = call_method(self, &PyId___len__, NULL, 0);
Py_ssize_t len;
if (res == NULL)
@@ -5873,7 +5849,7 @@ slot_sq_item(PyObject *self, Py_ssize_t i)
goto error;
}
- retval = _PyObject_CallArg1(func, ival);
+ retval = PyObject_CallFunctionObjArgs(func, ival, NULL);
Py_DECREF(func);
Py_DECREF(ival);
return retval;
@@ -5886,14 +5862,28 @@ error:
static int
slot_sq_ass_item(PyObject *self, Py_ssize_t index, PyObject *value)
{
+ PyObject *stack[2];
PyObject *res;
+ PyObject *index_obj;
- if (value == NULL)
- res = call_method(self, &PyId___delitem__, "(n)", index);
- else
- res = call_method(self, &PyId___setitem__, "(nO)", index, value);
- if (res == NULL)
+ index_obj = PyLong_FromSsize_t(index);
+ if (index_obj == NULL) {
+ return -1;
+ }
+
+ stack[0] = index_obj;
+ if (value == NULL) {
+ res = call_method(self, &PyId___delitem__, stack, 1);
+ }
+ else {
+ stack[1] = value;
+ res = call_method(self, &PyId___setitem__, stack, 2);
+ }
+ Py_DECREF(index_obj);
+
+ if (res == NULL) {
return -1;
+ }
Py_DECREF(res);
return 0;
}
@@ -5914,7 +5904,7 @@ slot_sq_contains(PyObject *self, PyObject *value)
return -1;
}
if (func != NULL) {
- res = _PyObject_CallArg1(func, value);
+ res = PyObject_CallFunctionObjArgs(func, value, NULL);
Py_DECREF(func);
if (res != NULL) {
result = PyObject_IsTrue(res);
@@ -5931,17 +5921,22 @@ slot_sq_contains(PyObject *self, PyObject *value)
#define slot_mp_length slot_sq_length
-SLOT1(slot_mp_subscript, "__getitem__", PyObject *, "O")
+SLOT1(slot_mp_subscript, "__getitem__", PyObject *)
static int
slot_mp_ass_subscript(PyObject *self, PyObject *key, PyObject *value)
{
+ PyObject *stack[2];
PyObject *res;
- if (value == NULL)
- res = call_method(self, &PyId___delitem__, "(O)", key);
- else
- res = call_method(self, &PyId___setitem__, "(OO)", key, value);
+ stack[0] = key;
+ if (value == NULL) {
+ res = call_method(self, &PyId___delitem__, stack, 1);
+ }
+ else {
+ stack[1] = value;
+ res = call_method(self, &PyId___setitem__, stack, 2);
+ }
if (res == NULL)
return -1;
@@ -5973,7 +5968,8 @@ slot_nb_power(PyObject *self, PyObject *other, PyObject *modulus)
slot_nb_power, so check before calling self.__pow__. */
if (Py_TYPE(self)->tp_as_number != NULL &&
Py_TYPE(self)->tp_as_number->nb_power == slot_nb_power) {
- return call_method(self, &PyId___pow__, "(OO)", other, modulus);
+ PyObject* stack[2] = {other, modulus};
+ return call_method(self, &PyId___pow__, stack, 2);
}
Py_RETURN_NOTIMPLEMENTED;
}
@@ -6040,7 +6036,7 @@ static PyObject *
slot_nb_index(PyObject *self)
{
_Py_IDENTIFIER(__index__);
- return call_method(self, &PyId___index__, NULL);
+ return call_method(self, &PyId___index__, NULL, 0);
}
@@ -6053,28 +6049,29 @@ SLOT1BIN(slot_nb_or, nb_or, "__or__", "__ror__")
SLOT0(slot_nb_int, "__int__")
SLOT0(slot_nb_float, "__float__")
-SLOT1(slot_nb_inplace_add, "__iadd__", PyObject *, "O")
-SLOT1(slot_nb_inplace_subtract, "__isub__", PyObject *, "O")
-SLOT1(slot_nb_inplace_multiply, "__imul__", PyObject *, "O")
-SLOT1(slot_nb_inplace_matrix_multiply, "__imatmul__", PyObject *, "O")
-SLOT1(slot_nb_inplace_remainder, "__imod__", PyObject *, "O")
+SLOT1(slot_nb_inplace_add, "__iadd__", PyObject *)
+SLOT1(slot_nb_inplace_subtract, "__isub__", PyObject *)
+SLOT1(slot_nb_inplace_multiply, "__imul__", PyObject *)
+SLOT1(slot_nb_inplace_matrix_multiply, "__imatmul__", PyObject *)
+SLOT1(slot_nb_inplace_remainder, "__imod__", PyObject *)
/* Can't use SLOT1 here, because nb_inplace_power is ternary */
static PyObject *
slot_nb_inplace_power(PyObject *self, PyObject * arg1, PyObject *arg2)
{
+ PyObject *stack[1] = {arg1};
_Py_IDENTIFIER(__ipow__);
- return call_method(self, &PyId___ipow__, "(" "O" ")", arg1);
+ return call_method(self, &PyId___ipow__, stack, 1);
}
-SLOT1(slot_nb_inplace_lshift, "__ilshift__", PyObject *, "O")
-SLOT1(slot_nb_inplace_rshift, "__irshift__", PyObject *, "O")
-SLOT1(slot_nb_inplace_and, "__iand__", PyObject *, "O")
-SLOT1(slot_nb_inplace_xor, "__ixor__", PyObject *, "O")
-SLOT1(slot_nb_inplace_or, "__ior__", PyObject *, "O")
+SLOT1(slot_nb_inplace_lshift, "__ilshift__", PyObject *)
+SLOT1(slot_nb_inplace_rshift, "__irshift__", PyObject *)
+SLOT1(slot_nb_inplace_and, "__iand__", PyObject *)
+SLOT1(slot_nb_inplace_xor, "__ixor__", PyObject *)
+SLOT1(slot_nb_inplace_or, "__ior__", PyObject *)
SLOT1BIN(slot_nb_floor_divide, nb_floor_divide,
"__floordiv__", "__rfloordiv__")
SLOT1BIN(slot_nb_true_divide, nb_true_divide, "__truediv__", "__rtruediv__")
-SLOT1(slot_nb_inplace_floor_divide, "__ifloordiv__", PyObject *, "O")
-SLOT1(slot_nb_inplace_true_divide, "__itruediv__", PyObject *, "O")
+SLOT1(slot_nb_inplace_floor_divide, "__ifloordiv__", PyObject *)
+SLOT1(slot_nb_inplace_true_divide, "__itruediv__", PyObject *)
static PyObject *
slot_tp_repr(PyObject *self)
@@ -6184,7 +6181,8 @@ slot_tp_call(PyObject *self, PyObject *args, PyObject *kwds)
static PyObject *
slot_tp_getattro(PyObject *self, PyObject *name)
{
- return call_method(self, &PyId___getattribute__, "(O)", name);
+ PyObject *stack[1] = {name};
+ return call_method(self, &PyId___getattribute__, stack, 1);
}
static PyObject *
@@ -6251,14 +6249,19 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name)
static int
slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value)
{
+ PyObject *stack[2];
PyObject *res;
_Py_IDENTIFIER(__delattr__);
_Py_IDENTIFIER(__setattr__);
- if (value == NULL)
- res = call_method(self, &PyId___delattr__, "(O)", name);
- else
- res = call_method(self, &PyId___setattr__, "(OO)", name, value);
+ stack[0] = name;
+ if (value == NULL) {
+ res = call_method(self, &PyId___delattr__, stack, 1);
+ }
+ else {
+ stack[1] = value;
+ res = call_method(self, &PyId___setattr__, stack, 2);
+ }
if (res == NULL)
return -1;
Py_DECREF(res);
@@ -6284,7 +6287,7 @@ slot_tp_richcompare(PyObject *self, PyObject *other, int op)
PyErr_Clear();
Py_RETURN_NOTIMPLEMENTED;
}
- res = _PyObject_CallArg1(func, other);
+ res = PyObject_CallFunctionObjArgs(func, other, NULL);
Py_DECREF(func);
return res;
}
@@ -6326,7 +6329,7 @@ static PyObject *
slot_tp_iternext(PyObject *self)
{
_Py_IDENTIFIER(__next__);
- return call_method(self, &PyId___next__, NULL);
+ return call_method(self, &PyId___next__, NULL, 0);
}
static PyObject *
@@ -6354,14 +6357,19 @@ slot_tp_descr_get(PyObject *self, PyObject *obj, PyObject *type)
static int
slot_tp_descr_set(PyObject *self, PyObject *target, PyObject *value)
{
+ PyObject* stack[2];
PyObject *res;
_Py_IDENTIFIER(__delete__);
_Py_IDENTIFIER(__set__);
- if (value == NULL)
- res = call_method(self, &PyId___delete__, "(O)", target);
- else
- res = call_method(self, &PyId___set__, "(OO)", target, value);
+ stack[0] = target;
+ if (value == NULL) {
+ res = call_method(self, &PyId___delete__, stack, 1);
+ }
+ else {
+ stack[1] = value;
+ res = call_method(self, &PyId___set__, stack, 2);
+ }
if (res == NULL)
return -1;
Py_DECREF(res);