summaryrefslogtreecommitdiffstats
path: root/Objects/abstract.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/abstract.c')
-rw-r--r--Objects/abstract.c111
1 files changed, 75 insertions, 36 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 9105769..57424a6 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -2082,10 +2082,11 @@ PyMapping_Keys(PyObject *o)
{
PyObject *keys;
PyObject *fast;
+ _Py_identifier(keys);
if (PyDict_CheckExact(o))
return PyDict_Keys(o);
- keys = PyObject_CallMethod(o, "keys", NULL);
+ keys = _PyObject_CallMethodId(o, &PyId_keys, NULL);
if (keys == NULL)
return NULL;
fast = PySequence_Fast(keys, "o.keys() are not iterable");
@@ -2098,10 +2099,11 @@ PyMapping_Items(PyObject *o)
{
PyObject *items;
PyObject *fast;
+ _Py_identifier(items);
if (PyDict_CheckExact(o))
return PyDict_Items(o);
- items = PyObject_CallMethod(o, "items", NULL);
+ items = _PyObject_CallMethodId(o, &PyId_items, NULL);
if (items == NULL)
return NULL;
fast = PySequence_Fast(items, "o.items() are not iterable");
@@ -2114,10 +2116,11 @@ PyMapping_Values(PyObject *o)
{
PyObject *values;
PyObject *fast;
+ _Py_identifier(values);
if (PyDict_CheckExact(o))
return PyDict_Values(o);
- values = PyObject_CallMethod(o, "values", NULL);
+ values = _PyObject_CallMethodId(o, &PyId_values, NULL);
if (values == NULL)
return NULL;
fast = PySequence_Fast(values, "o.values() are not iterable");
@@ -2223,22 +2226,11 @@ _PyObject_CallFunction_SizeT(PyObject *callable, char *format, ...)
return call_function_tail(callable, args);
}
-PyObject *
-PyObject_CallMethod(PyObject *o, char *name, char *format, ...)
+static PyObject*
+callmethod(PyObject* func, char *format, va_list va, int is_size_t)
{
- va_list va;
- PyObject *args;
- PyObject *func = NULL;
PyObject *retval = NULL;
-
- if (o == NULL || name == NULL)
- return null_error();
-
- func = PyObject_GetAttrString(o, name);
- if (func == NULL) {
- PyErr_SetString(PyExc_AttributeError, name);
- return 0;
- }
+ PyObject *args;
if (!PyCallable_Check(func)) {
type_error("attribute of type '%.200s' is not callable", func);
@@ -2246,9 +2238,10 @@ PyObject_CallMethod(PyObject *o, char *name, char *format, ...)
}
if (format && *format) {
- va_start(va, format);
- args = Py_VaBuildValue(format, va);
- va_end(va);
+ if (is_size_t)
+ args = _Py_VaBuildValue_SizeT(format, va);
+ else
+ args = Py_VaBuildValue(format, va);
}
else
args = PyTuple_New(0);
@@ -2263,10 +2256,9 @@ PyObject_CallMethod(PyObject *o, char *name, char *format, ...)
}
PyObject *
-_PyObject_CallMethod_SizeT(PyObject *o, char *name, char *format, ...)
+PyObject_CallMethod(PyObject *o, char *name, char *format, ...)
{
va_list va;
- PyObject *args;
PyObject *func = NULL;
PyObject *retval = NULL;
@@ -2279,28 +2271,75 @@ _PyObject_CallMethod_SizeT(PyObject *o, char *name, char *format, ...)
return 0;
}
- if (!PyCallable_Check(func)) {
- type_error("attribute of type '%.200s' is not callable", func);
- goto exit;
- }
+ va_start(va, format);
+ retval = callmethod(func, format, va, 0);
+ va_end(va);
+ return retval;
+}
- if (format && *format) {
- va_start(va, format);
- args = _Py_VaBuildValue_SizeT(format, va);
- va_end(va);
+PyObject *
+_PyObject_CallMethodId(PyObject *o, _Py_Identifier *name, char *format, ...)
+{
+ va_list va;
+ PyObject *func = NULL;
+ PyObject *retval = NULL;
+
+ if (o == NULL || name == NULL)
+ return null_error();
+
+ func = _PyObject_GetAttrId(o, name);
+ if (func == NULL) {
+ PyErr_SetString(PyExc_AttributeError, name->string);
+ return 0;
}
- else
- args = PyTuple_New(0);
- retval = call_function_tail(func, args);
+ va_start(va, format);
+ retval = callmethod(func, format, va, 0);
+ va_end(va);
+ return retval;
+}
- exit:
- /* args gets consumed in call_function_tail */
- Py_XDECREF(func);
+PyObject *
+_PyObject_CallMethod_SizeT(PyObject *o, char *name, char *format, ...)
+{
+ va_list va;
+ PyObject *func = NULL;
+ PyObject *retval;
+
+ if (o == NULL || name == NULL)
+ return null_error();
+ func = PyObject_GetAttrString(o, name);
+ if (func == NULL) {
+ PyErr_SetString(PyExc_AttributeError, name);
+ return 0;
+ }
+ va_start(va, format);
+ retval = callmethod(func, format, va, 1);
+ va_end(va);
return retval;
}
+PyObject *
+_PyObject_CallMethodId_SizeT(PyObject *o, _Py_Identifier *name, char *format, ...)
+{
+ va_list va;
+ PyObject *func = NULL;
+ PyObject *retval;
+
+ if (o == NULL || name == NULL)
+ return null_error();
+
+ func = _PyObject_GetAttrId(o, name);
+ if (func == NULL) {
+ PyErr_SetString(PyExc_AttributeError, name->string);
+ return NULL;
+ }
+ va_start(va, format);
+ retval = callmethod(func, format, va, 1);
+ va_end(va);
+ return retval;
+}
static PyObject *
objargs_mktuple(va_list va)