summaryrefslogtreecommitdiff
path: root/Objects/methodobject.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2001-08-16 13:15:00 +0000
committerMartin v. Löwis <martin@v.loewis.de>2001-08-16 13:15:00 +0000
commite3eb1f2b2320bceb10a763ec8691200b85ec287a (patch)
treedf47f81391869945dc661a08c405b53753fba887 /Objects/methodobject.c
parentc35422109b36d20f409a3a72f60c0c7e2e0bc824 (diff)
downloadcpython-git-e3eb1f2b2320bceb10a763ec8691200b85ec287a.tar.gz
Patch #427190: Implement and use METH_NOARGS and METH_O.
Diffstat (limited to 'Objects/methodobject.c')
-rw-r--r--Objects/methodobject.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/Objects/methodobject.c b/Objects/methodobject.c
index 9d430445c8..cdba3505f9 100644
--- a/Objects/methodobject.c
+++ b/Objects/methodobject.c
@@ -63,6 +63,7 @@ PyCFunction_Call(PyObject *func, PyObject *arg, PyObject *kw)
PyCFunction meth = PyCFunction_GET_FUNCTION(func);
PyObject *self = PyCFunction_GET_SELF(func);
int flags = PyCFunction_GET_FLAGS(func);
+ int size = PyTuple_GET_SIZE(arg);
if (flags & METH_KEYWORDS) {
return (*(PyCFunctionWithKeywords)meth)(self, arg, kw);
@@ -73,21 +74,39 @@ PyCFunction_Call(PyObject *func, PyObject *arg, PyObject *kw)
f->m_ml->ml_name);
return NULL;
}
- if (flags & METH_VARARGS) {
+
+ switch (flags) {
+ case METH_VARARGS:
return (*meth)(self, arg);
- }
- if (!(flags & METH_VARARGS)) {
+ break;
+ case METH_NOARGS:
+ if (size == 0)
+ return (*meth)(self, NULL);
+ PyErr_Format(PyExc_TypeError,
+ "%.200s() takes no arguments (%d given)",
+ f->m_ml->ml_name, size);
+ return NULL;
+ break;
+ case METH_O:
+ if (size == 1)
+ return (*meth)(self, PyTuple_GET_ITEM(arg, 0));
+ PyErr_Format(PyExc_TypeError,
+ "%.200s() takes exactly one argument (%d given)",
+ f->m_ml->ml_name, size);
+ return NULL;
+ break;
+ case METH_OLDARGS:
/* the really old style */
- int size = PyTuple_GET_SIZE(arg);
if (size == 1)
arg = PyTuple_GET_ITEM(arg, 0);
else if (size == 0)
arg = NULL;
return (*meth)(self, arg);
+ default:
+ /* should never get here ??? */
+ PyErr_BadInternalCall();
+ return NULL;
}
- /* should never get here ??? */
- PyErr_BadInternalCall();
- return NULL;
}
/* Methods (the standard built-in methods, that is) */