]> granicus.if.org Git - python/commitdiff
Patch #427190: Implement and use METH_NOARGS and METH_O.
authorMartin v. Löwis <martin@v.loewis.de>
Thu, 16 Aug 2001 13:15:00 +0000 (13:15 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Thu, 16 Aug 2001 13:15:00 +0000 (13:15 +0000)
17 files changed:
Doc/api/api.tex
Misc/NEWS
Objects/complexobject.c
Objects/descrobject.c
Objects/dictobject.c
Objects/fileobject.c
Objects/iterobject.c
Objects/listobject.c
Objects/methodobject.c
Objects/rangeobject.c
Objects/stringobject.c
Objects/typeobject.c
Objects/unicodeobject.c
Python/bltinmodule.c
Python/ceval.c
Python/sysmodule.c
configure

index adcb2802584fae6e1fe9a26801bdab84edc594ac..894e5b627826f463039352ebd8e6d7a869c4f217 100644 (file)
@@ -5257,6 +5257,68 @@ structure has four fields:
 \end{tableiii}
 \end{ctypedesc}
 
+The \var{ml_meth} is a C function pointer. The functions may be of
+different types, but they always return \ctype{PyObject*}. If the
+function is not of the \ctype{PyCFunction}, the compiler will require
+a cast in the method table. Even though \ctype{PyCFunction} defines
+the first parameter as \ctype{PyObject*}, it is common that the method
+implementation uses a the specific C type of the \var{self} object.
+
+The flags can have the following values. Only METH_VARARGS and
+METH_KEYWORDS can be combined; the others can't.
+
+\begin{datadesc}{METH_VARARGS}
+
+This is the typical calling convention, where the methods have the
+type \ctype{PyMethodDef}. The function expects two \ctype{PyObject*}.
+The first one is the \var{self} object for methods; for module
+functions, it has the value given to \cfunction{PyInitModule4} (or
+\NULL{} if \cfunction{PyInitModule} was used). The second parameter
+(often called \var{args}) is a tuple object representing all
+arguments. This parameter is typically processed using
+\cfunction{PyArg_ParseTuple}.
+
+\end{datadesc}
+
+\begin{datadesc}{METH_KEYWORDS}
+
+Methods with these flags must be of type
+\ctype{PyCFunctionWithKeywords}.  The function expects three
+parameters: \var{self}, \var{args}, and a dictionary of all the keyword
+arguments. The flag is typically combined with METH_VARARGS, and the
+parameters are typically processed using
+\cfunction{PyArg_ParseTupleAndKeywords}.
+
+\end{datadesc}
+
+\begin{datadesc}{METH_NOARGS}
+
+Methods without parameters don't need to check whether arguments are
+given if they are listed with the \code{METH_NOARGS} flag. They need
+to be of type \ctype{PyNoArgsFunction}, i.e. they expect a single
+\var{self} parameter.
+
+\end{datadesc}
+
+\begin{datadesc}{METH_O}
+
+Methods with a single object argument can be listed with the
+\code{METH_O} flag, instead of invoking \cfunction{PyArg_ParseTuple}
+with a \code{``O''} argument. They have the type \ctype{PyCFunction},
+with the \var{self} parameter, and a \ctype{PyObject*} parameter
+representing the single argument.
+
+\end{datadesc}
+
+\begin{datadesc}{METH_OLDARGS}
+
+This calling convention is deprecated. The method must be of type
+\ctype{PyCFunction}. The second argument is \NULL{} if no arguments
+are given, a single object if exactly one argument is given, and a
+tuple of objects if more than one argument is given.
+
+\end{datadesc}
+
 \begin{cfuncdesc}{PyObject*}{Py_FindMethod}{PyMethodDef[] table,
                                             PyObject *ob, char *name}
 Return a bound method object for an extension type implemented in C.
index 7648e3fbdc4493ef086b16ae145fd8e3fe07d766..6bcf2e4779c519fecfe558456cd6dd4d5e254eea 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -90,6 +90,12 @@ Core
   (These warnings currently don't conform to the warnings framework of
   PEP 230; we intend to fix this in 2.2a2.)
 
+- Two new flags METH_NOARGS and METH_O are available in method definition
+  tables to simplify implementation of methods with no arguments and a
+  single untyped argument. Calling such methods is more efficient than
+  calling corresponding METH_VARARGS methods. METH_OLDARGS is now
+  deprecated.
+
 - The UTF-16 codec was modified to be more RFC compliant. It will now
   only remove BOM characters at the start of the string and then
   only if running in native mode (UTF-16-LE and -BE won't remove a
index 5cfb3ca5c852519181a1d6d811bcf01a485bfbb6..84eee110f42a512459f46fc89170fe0a8324205b 100644 (file)
@@ -580,18 +580,16 @@ complex_float(PyObject *v)
 }
 
 static PyObject *
-complex_conjugate(PyObject *self, PyObject *args)
+complex_conjugate(PyObject *self)
 {
        Py_complex c;
-       if (!PyArg_ParseTuple(args, ":conjugate"))
-               return NULL;
        c = ((PyComplexObject *)self)->cval;
        c.imag = -c.imag;
        return PyComplex_FromCComplex(c);
 }
 
 static PyMethodDef complex_methods[] = {
-       {"conjugate",   complex_conjugate,      1},
+       {"conjugate",   (PyCFunction)complex_conjugate, METH_NOARGS},
        {NULL,          NULL}           /* sentinel */
 };
 
index a2ecde5b7e527738c0cf9478880edab29b42e634..facd1c4ff58831319eea04cd2a413df94f56c08f 100644 (file)
@@ -601,12 +601,8 @@ static PySequenceMethods proxy_as_sequence = {
 };
 
 static PyObject *
-proxy_has_key(proxyobject *pp, PyObject *args)
+proxy_has_key(proxyobject *pp, PyObject *key)
 {
-       PyObject *key;
-
-       if (!PyArg_ParseTuple(args, "O:has_key", &key))
-               return NULL;
        return PyInt_FromLong(PySequence_Contains(pp->dict, key));
 }
 
@@ -621,44 +617,36 @@ proxy_get(proxyobject *pp, PyObject *args)
 }
 
 static PyObject *
-proxy_keys(proxyobject *pp, PyObject *args)
+proxy_keys(proxyobject *pp)
 {
-       if (!PyArg_ParseTuple(args, ":keys"))
-               return NULL;
        return PyMapping_Keys(pp->dict);
 }
 
 static PyObject *
-proxy_values(proxyobject *pp, PyObject *args)
+proxy_values(proxyobject *pp)
 {
-       if (!PyArg_ParseTuple(args, ":values"))
-               return NULL;
        return PyMapping_Values(pp->dict);
 }
 
 static PyObject *
-proxy_items(proxyobject *pp, PyObject *args)
+proxy_items(proxyobject *pp)
 {
-       if (!PyArg_ParseTuple(args, ":items"))
-               return NULL;
        return PyMapping_Items(pp->dict);
 }
 
 static PyObject *
-proxy_copy(proxyobject *pp, PyObject *args)
+proxy_copy(proxyobject *pp)
 {
-       if (!PyArg_ParseTuple(args, ":copy"))
-               return NULL;
        return PyObject_CallMethod(pp->dict, "copy", NULL);
 }
 
 static PyMethodDef proxy_methods[] = {
-       {"has_key", (PyCFunction)proxy_has_key, METH_VARARGS, "XXX"},
+       {"has_key", (PyCFunction)proxy_has_key, METH_O, "XXX"},
        {"get",     (PyCFunction)proxy_get,     METH_VARARGS, "XXX"},
-       {"keys",    (PyCFunction)proxy_keys,    METH_VARARGS, "XXX"},
-       {"values",  (PyCFunction)proxy_values,  METH_VARARGS, "XXX"},
-       {"items",   (PyCFunction)proxy_items,   METH_VARARGS, "XXX"},
-       {"copy",    (PyCFunction)proxy_copy,    METH_VARARGS, "XXX"},
+       {"keys",    (PyCFunction)proxy_keys,    METH_NOARGS, "XXX"},
+       {"values",  (PyCFunction)proxy_values,  METH_NOARGS, "XXX"},
+       {"items",   (PyCFunction)proxy_items,   METH_NOARGS, "XXX"},
+       {"copy",    (PyCFunction)proxy_copy,    METH_NOARGS, "XXX"},
        {0}
 };
 
index 73c459fb41ce359cbed2a8248b7794d9151b28ea..ab5f4b54f5e1a2cfb481df5358c83ad2daf8fed4 100644 (file)
@@ -875,13 +875,11 @@ static PyMappingMethods dict_as_mapping = {
 };
 
 static PyObject *
-dict_keys(register dictobject *mp, PyObject *args)
+dict_keys(register dictobject *mp)
 {
        register PyObject *v;
        register int i, j, n;
 
-       if (!PyArg_NoArgs(args))
-               return NULL;
   again:
        n = mp->ma_used;
        v = PyList_New(n);
@@ -906,13 +904,11 @@ dict_keys(register dictobject *mp, PyObject *args)
 }
 
 static PyObject *
-dict_values(register dictobject *mp, PyObject *args)
+dict_values(register dictobject *mp)
 {
        register PyObject *v;
        register int i, j, n;
 
-       if (!PyArg_NoArgs(args))
-               return NULL;
   again:
        n = mp->ma_used;
        v = PyList_New(n);
@@ -937,14 +933,12 @@ dict_values(register dictobject *mp, PyObject *args)
 }
 
 static PyObject *
-dict_items(register dictobject *mp, PyObject *args)
+dict_items(register dictobject *mp)
 {
        register PyObject *v;
        register int i, j, n;
        PyObject *item, *key, *value;
 
-       if (!PyArg_NoArgs(args))
-               return NULL;
        /* Preallocate the list of tuples, to avoid allocations during
         * the loop over the items, which could trigger GC, which
         * could resize the dict. :-(
@@ -987,12 +981,8 @@ dict_items(register dictobject *mp, PyObject *args)
 }
 
 static PyObject *
-dict_update(PyObject *mp, PyObject *args)
+dict_update(PyObject *mp, PyObject *other)
 {
-       PyObject *other;
-
-       if (!PyArg_ParseTuple(args, "O:update", &other))
-               return NULL;
        if (PyDict_Update(mp, other) < 0)
                return NULL;
        Py_INCREF(Py_None);
@@ -1099,10 +1089,8 @@ PyDict_Merge(PyObject *a, PyObject *b, int override)
 }
 
 static PyObject *
-dict_copy(register dictobject *mp, PyObject *args)
+dict_copy(register dictobject *mp)
 {
-       if (!PyArg_Parse(args, ""))
-               return NULL;
        return PyDict_Copy((PyObject*)mp);
 }
 
@@ -1155,7 +1143,7 @@ PyDict_Keys(PyObject *mp)
                PyErr_BadInternalCall();
                return NULL;
        }
-       return dict_keys((dictobject *)mp, (PyObject *)NULL);
+       return dict_keys((dictobject *)mp);
 }
 
 PyObject *
@@ -1165,7 +1153,7 @@ PyDict_Values(PyObject *mp)
                PyErr_BadInternalCall();
                return NULL;
        }
-       return dict_values((dictobject *)mp, (PyObject *)NULL);
+       return dict_values((dictobject *)mp);
 }
 
 PyObject *
@@ -1175,7 +1163,7 @@ PyDict_Items(PyObject *mp)
                PyErr_BadInternalCall();
                return NULL;
        }
-       return dict_items((dictobject *)mp, (PyObject *)NULL);
+       return dict_items((dictobject *)mp);
 }
 
 /* Subroutine which returns the smallest key in a for which b's value
@@ -1366,13 +1354,10 @@ dict_richcompare(PyObject *v, PyObject *w, int op)
  }
 
 static PyObject *
-dict_has_key(register dictobject *mp, PyObject *args)
+dict_has_key(register dictobject *mp, PyObject *key)
 {
-       PyObject *key;
        long hash;
        register long ok;
-       if (!PyArg_ParseTuple(args, "O:has_key", &key))
-               return NULL;
 #ifdef CACHE_HASH
        if (!PyString_Check(key) ||
            (hash = ((PyStringObject *) key)->ob_shash) == -1)
@@ -1447,24 +1432,20 @@ dict_setdefault(register dictobject *mp, PyObject *args)
 
 
 static PyObject *
-dict_clear(register dictobject *mp, PyObject *args)
+dict_clear(register dictobject *mp)
 {
-       if (!PyArg_NoArgs(args))
-               return NULL;
        PyDict_Clear((PyObject *)mp);
        Py_INCREF(Py_None);
        return Py_None;
 }
 
 static PyObject *
-dict_popitem(dictobject *mp, PyObject *args)
+dict_popitem(dictobject *mp)
 {
        int i = 0;
        dictentry *ep;
        PyObject *res;
 
-       if (!PyArg_NoArgs(args))
-               return NULL;
        /* Allocate the result tuple before checking the size.  Believe it
         * or not, this allocation could trigger a garbage collection which
         * could empty the dict, so if we checked the size first and that
@@ -1573,26 +1554,20 @@ select_item(PyObject *key, PyObject *value)
 }
 
 static PyObject *
-dict_iterkeys(dictobject *dict, PyObject *args)
+dict_iterkeys(dictobject *dict)
 {
-       if (!PyArg_ParseTuple(args, ""))
-               return NULL;
        return dictiter_new(dict, select_key);
 }
 
 static PyObject *
-dict_itervalues(dictobject *dict, PyObject *args)
+dict_itervalues(dictobject *dict)
 {
-       if (!PyArg_ParseTuple(args, ""))
-               return NULL;
        return dictiter_new(dict, select_value);
 }
 
 static PyObject *
-dict_iteritems(dictobject *dict, PyObject *args)
+dict_iteritems(dictobject *dict)
 {
-       if (!PyArg_ParseTuple(args, ""))
-               return NULL;
        return dictiter_new(dict, select_item);
 }
 
@@ -1638,31 +1613,31 @@ static char iteritems__doc__[] =
 "D.iteritems() -> an iterator over the (key, value) items of D";
 
 static PyMethodDef mapp_methods[] = {
-       {"has_key",     (PyCFunction)dict_has_key,      METH_VARARGS,
+       {"has_key",     (PyCFunction)dict_has_key,      METH_O,
         has_key__doc__},
        {"get",         (PyCFunction)dict_get,          METH_VARARGS,
         get__doc__},
        {"setdefault",  (PyCFunction)dict_setdefault,   METH_VARARGS,
         setdefault_doc__},
-       {"popitem",     (PyCFunction)dict_popitem,      METH_OLDARGS,
+       {"popitem",     (PyCFunction)dict_popitem,      METH_NOARGS,
         popitem__doc__},
-       {"keys",        (PyCFunction)dict_keys,         METH_OLDARGS,
+       {"keys",        (PyCFunction)dict_keys,         METH_NOARGS,
        keys__doc__},
-       {"items",       (PyCFunction)dict_items,        METH_OLDARGS,
+       {"items",       (PyCFunction)dict_items,        METH_NOARGS,
         items__doc__},
-       {"values",      (PyCFunction)dict_values,       METH_OLDARGS,
+       {"values",      (PyCFunction)dict_values,       METH_NOARGS,
         values__doc__},
-       {"update",      (PyCFunction)dict_update,       METH_VARARGS,
+       {"update",      (PyCFunction)dict_update,       METH_O,
         update__doc__},
-       {"clear",       (PyCFunction)dict_clear,        METH_OLDARGS,
+       {"clear",       (PyCFunction)dict_clear,        METH_NOARGS,
         clear__doc__},
-       {"copy",        (PyCFunction)dict_copy,         METH_OLDARGS,
+       {"copy",        (PyCFunction)dict_copy,         METH_NOARGS,
         copy__doc__},
-       {"iterkeys",    (PyCFunction)dict_iterkeys,     METH_VARARGS,
+       {"iterkeys",    (PyCFunction)dict_iterkeys,     METH_NOARGS,
         iterkeys__doc__},
-       {"itervalues",  (PyCFunction)dict_itervalues,   METH_VARARGS,
+       {"itervalues",  (PyCFunction)dict_itervalues,   METH_NOARGS,
         itervalues__doc__},
-       {"iteritems",   (PyCFunction)dict_iteritems,    METH_VARARGS,
+       {"iteritems",   (PyCFunction)dict_iteritems,    METH_NOARGS,
         iteritems__doc__},
        {NULL,          NULL}   /* sentinel */
 };
index 946d41c22a5a96a53b48bacc23c2c3282c6a6329..0bb2f252b2ce72e6deb714126ea32c4520b5fff7 100644 (file)
@@ -189,11 +189,9 @@ file_repr(PyFileObject *f)
 }
 
 static PyObject *
-file_close(PyFileObject *f, PyObject *args)
+file_close(PyFileObject *f)
 {
        int sts = 0;
-       if (!PyArg_NoArgs(args))
-               return NULL;
        if (f->f_fp != NULL) {
                if (f->f_close != NULL) {
                        Py_BEGIN_ALLOW_THREADS
@@ -386,14 +384,12 @@ onioerror:
 #endif /* HAVE_FTRUNCATE */
 
 static PyObject *
-file_tell(PyFileObject *f, PyObject *args)
+file_tell(PyFileObject *f)
 {
        Py_off_t pos;
 
        if (f->f_fp == NULL)
                return err_closed();
-       if (!PyArg_NoArgs(args))
-               return NULL;
        Py_BEGIN_ALLOW_THREADS
        errno = 0;
        pos = _portable_ftell(f->f_fp);
@@ -411,24 +407,20 @@ file_tell(PyFileObject *f, PyObject *args)
 }
 
 static PyObject *
-file_fileno(PyFileObject *f, PyObject *args)
+file_fileno(PyFileObject *f)
 {
        if (f->f_fp == NULL)
                return err_closed();
-       if (!PyArg_NoArgs(args))
-               return NULL;
        return PyInt_FromLong((long) fileno(f->f_fp));
 }
 
 static PyObject *
-file_flush(PyFileObject *f, PyObject *args)
+file_flush(PyFileObject *f)
 {
        int res;
 
        if (f->f_fp == NULL)
                return err_closed();
-       if (!PyArg_NoArgs(args))
-               return NULL;
        Py_BEGIN_ALLOW_THREADS
        errno = 0;
        res = fflush(f->f_fp);
@@ -443,13 +435,11 @@ file_flush(PyFileObject *f, PyObject *args)
 }
 
 static PyObject *
-file_isatty(PyFileObject *f, PyObject *args)
+file_isatty(PyFileObject *f)
 {
        long res;
        if (f->f_fp == NULL)
                return err_closed();
-       if (!PyArg_NoArgs(args))
-               return NULL;
        Py_BEGIN_ALLOW_THREADS
        res = isatty((int)fileno(f->f_fp));
        Py_END_ALLOW_THREADS
@@ -968,13 +958,10 @@ file_readline(PyFileObject *f, PyObject *args)
 }
 
 static PyObject *
-file_xreadlines(PyFileObject *f, PyObject *args)
+file_xreadlines(PyFileObject *f)
 {
        static PyObject* xreadlines_function = NULL;
 
-       if (!PyArg_ParseTuple(args, ":xreadlines"))
-               return NULL;
-
        if (!xreadlines_function) {
                PyObject *xreadlines_module =
                        PyImport_ImportModule("xreadlines");
@@ -1248,22 +1235,22 @@ file_writelines(PyFileObject *f, PyObject *args)
 }
 
 static PyMethodDef file_methods[] = {
-       {"readline",    (PyCFunction)file_readline, 1},
-       {"read",        (PyCFunction)file_read, 1},
-       {"write",       (PyCFunction)file_write, 0},
-       {"fileno",      (PyCFunction)file_fileno, 0},
-       {"seek",        (PyCFunction)file_seek, 1},
+       {"readline",    (PyCFunction)file_readline,   METH_VARARGS},
+       {"read",        (PyCFunction)file_read,       METH_VARARGS},
+       {"write",       (PyCFunction)file_write,      METH_OLDARGS},
+       {"fileno",      (PyCFunction)file_fileno,     METH_NOARGS},
+       {"seek",        (PyCFunction)file_seek,       METH_VARARGS},
 #ifdef HAVE_FTRUNCATE
-       {"truncate",    (PyCFunction)file_truncate, 1},
+       {"truncate",    (PyCFunction)file_truncate,   METH_VARARGS},
 #endif
-       {"tell",        (PyCFunction)file_tell, 0},
-       {"readinto",    (PyCFunction)file_readinto, 0},
-       {"readlines",   (PyCFunction)file_readlines, 1},
-       {"xreadlines",  (PyCFunction)file_xreadlines, 1},
-       {"writelines",  (PyCFunction)file_writelines, 0},
-       {"flush",       (PyCFunction)file_flush, 0},
-       {"close",       (PyCFunction)file_close, 0},
-       {"isatty",      (PyCFunction)file_isatty, 0},
+       {"tell",        (PyCFunction)file_tell,       METH_NOARGS},
+       {"readinto",    (PyCFunction)file_readinto,   METH_OLDARGS},
+       {"readlines",   (PyCFunction)file_readlines,  METH_VARARGS},
+       {"xreadlines",  (PyCFunction)file_xreadlines, METH_NOARGS},
+       {"writelines",  (PyCFunction)file_writelines, METH_O},
+       {"flush",       (PyCFunction)file_flush,      METH_NOARGS},
+       {"close",       (PyCFunction)file_close,      METH_NOARGS},
+       {"isatty",      (PyCFunction)file_isatty,     METH_NOARGS},
        {NULL,          NULL}           /* sentinel */
 };
 
index e062c8ab71d1dfa88c514ce3beb8534aada232d8..5783d2085bc07d038d6e28f1b685a275a3e9d330 100644 (file)
@@ -37,7 +37,7 @@ iter_traverse(seqiterobject *it, visitproc visit, void *arg)
 }
 
 static PyObject *
-iter_next(seqiterobject *it, PyObject *args)
+iter_next(seqiterobject *it)
 {
        PyObject *seq = it->it_seq;
        PyObject *result = PySequence_GetItem(seq, it->it_index++);
@@ -91,7 +91,7 @@ iter_iternext(PyObject *iterator)
 }
 
 static PyMethodDef iter_methods[] = {
-       {"next",        (PyCFunction)iter_next, METH_VARARGS,
+       {"next",        (PyCFunction)iter_next, METH_NOARGS,
         "it.next() -- get the next value, or raise StopIteration"},
        {NULL,          NULL}           /* sentinel */
 };
index b77cc0af0270b4238d82c0c95523aa036b4fc07f..c45cf758bd464c9c8fafe9d68138dab86e4534bd 100644 (file)
@@ -623,11 +623,8 @@ listinsert(PyListObject *self, PyObject *args)
 }
 
 static PyObject *
-listappend(PyListObject *self, PyObject *args)
+listappend(PyListObject *self, PyObject *v)
 {
-       PyObject *v;
-       if (!PyArg_ParseTuple(args, "O:append", &v))
-               return NULL;
        return ins(self, (int) self->ob_size, v);
 }
 
@@ -702,14 +699,9 @@ list_inplace_concat(PyListObject *self, PyObject *other)
 }
 
 static PyObject *
-listextend(PyListObject *self, PyObject *args)
+listextend(PyListObject *self, PyObject *b)
 {
 
-       PyObject *b;
-       
-       if (!PyArg_ParseTuple(args, "O:extend", &b))
-               return NULL;
-
        b = PySequence_Fast(b, "list.extend() argument must be iterable");
        if (!b)
                return NULL;
@@ -1344,10 +1336,8 @@ _listreverse(PyListObject *self)
 }
 
 static PyObject *
-listreverse(PyListObject *self, PyObject *args)
+listreverse(PyListObject *self)
 {
-       if (!PyArg_ParseTuple(args, ":reverse"))
-               return NULL;
        _listreverse(self);
        Py_INCREF(Py_None);
        return Py_None;
@@ -1390,13 +1380,10 @@ PyList_AsTuple(PyObject *v)
 }
 
 static PyObject *
-listindex(PyListObject *self, PyObject *args)
+listindex(PyListObject *self, PyObject *v)
 {
        int i;
-       PyObject *v;
 
-       if (!PyArg_ParseTuple(args, "O:index", &v))
-               return NULL;
        for (i = 0; i < self->ob_size; i++) {
                int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
                if (cmp > 0)
@@ -1409,14 +1396,11 @@ listindex(PyListObject *self, PyObject *args)
 }
 
 static PyObject *
-listcount(PyListObject *self, PyObject *args)
+listcount(PyListObject *self, PyObject *v)
 {
        int count = 0;
        int i;
-       PyObject *v;
 
-       if (!PyArg_ParseTuple(args, "O:count", &v))
-               return NULL;
        for (i = 0; i < self->ob_size; i++) {
                int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
                if (cmp > 0)
@@ -1428,13 +1412,10 @@ listcount(PyListObject *self, PyObject *args)
 }
 
 static PyObject *
-listremove(PyListObject *self, PyObject *args)
+listremove(PyListObject *self, PyObject *v)
 {
        int i;
-       PyObject *v;
 
-       if (!PyArg_ParseTuple(args, "O:remove", &v))
-               return NULL;
        for (i = 0; i < self->ob_size; i++) {
                int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
                if (cmp > 0) {
@@ -1661,14 +1642,14 @@ static char sort_doc[] =
 "L.sort([cmpfunc]) -- sort *IN PLACE*; if given, cmpfunc(x, y) -> -1, 0, 1";
 
 static PyMethodDef list_methods[] = {
-       {"append",      (PyCFunction)listappend,  METH_VARARGS, append_doc},
+       {"append",      (PyCFunction)listappend,  METH_O, append_doc},
        {"insert",      (PyCFunction)listinsert,  METH_VARARGS, insert_doc},
-       {"extend",      (PyCFunction)listextend,  METH_VARARGS, extend_doc},
+       {"extend",      (PyCFunction)listextend,  METH_O, extend_doc},
        {"pop",         (PyCFunction)listpop,     METH_VARARGS, pop_doc},
-       {"remove",      (PyCFunction)listremove,  METH_VARARGS, remove_doc},
-       {"index",       (PyCFunction)listindex,   METH_VARARGS, index_doc},
-       {"count",       (PyCFunction)listcount,   METH_VARARGS, count_doc},
-       {"reverse",     (PyCFunction)listreverse, METH_VARARGS, reverse_doc},
+       {"remove",      (PyCFunction)listremove,  METH_O, remove_doc},
+       {"index",       (PyCFunction)listindex,   METH_O, index_doc},
+       {"count",       (PyCFunction)listcount,   METH_O, count_doc},
+       {"reverse",     (PyCFunction)listreverse, METH_NOARGS, reverse_doc},
        {"sort",        (PyCFunction)listsort,    METH_VARARGS, sort_doc},
        {NULL,          NULL}           /* sentinel */
 };
@@ -1749,13 +1730,13 @@ immutable_list_op(void)
 }
 
 static PyMethodDef immutable_list_methods[] = {
-       {"append",      (PyCFunction)immutable_list_op},
-       {"insert",      (PyCFunction)immutable_list_op},
-       {"remove",      (PyCFunction)immutable_list_op},
-       {"index",       (PyCFunction)listindex},
-       {"count",       (PyCFunction)listcount},
-       {"reverse",     (PyCFunction)immutable_list_op},
-       {"sort",        (PyCFunction)immutable_list_op},
+       {"append",      (PyCFunction)immutable_list_op, METH_VARARGS},
+       {"insert",      (PyCFunction)immutable_list_op, METH_VARARGS},
+       {"remove",      (PyCFunction)immutable_list_op, METH_VARARGS},
+       {"index",       (PyCFunction)listindex,         METH_O},
+       {"count",       (PyCFunction)listcount,         METH_O},
+       {"reverse",     (PyCFunction)immutable_list_op, METH_VARARGS},
+       {"sort",        (PyCFunction)immutable_list_op, METH_VARARGS},
        {NULL,          NULL}           /* sentinel */
 };
 
index 9d430445c8e9132f2839b88716fcedd76220eb1e..cdba3505f9b0426e4accf85ca7c083b537595e7e 100644 (file)
@@ -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) */
index 9f155cf5998c9d892607a182cf69faaddcb0433b..5ad86eddc1d6384046d0322587c2795c8882ab3f 100644 (file)
@@ -243,9 +243,6 @@ range_tolist(rangeobject *self, PyObject *args)
 
        WARN("xrange.tolist() is deprecated; use list(xrange) instead");
 
-       if (! PyArg_ParseTuple(args, ":tolist"))
-               return NULL;
-
        if (self->totlen == -1)
                return PyErr_NoMemory();
 
@@ -266,7 +263,7 @@ range_getattr(rangeobject *r, char *name)
        PyObject *result;
 
        static PyMethodDef range_methods[] = {
-               {"tolist",      (PyCFunction)range_tolist, METH_VARARGS,
+               {"tolist",      (PyCFunction)range_tolist, METH_NOARGS,
                  "tolist() -> list\n"
                  "Return a list object with the same values.\n"
                  "(This method is deprecated; use list() instead.)"},
index 3d12588d2c6de2cde40b18f30979e0b450137225..e2682a04aaa6292c0dda72262770173de77020bc 100644 (file)
@@ -921,7 +921,7 @@ Return a string which is the concatenation of the strings in the\n\
 sequence.  The separator between elements is S.";
 
 static PyObject *
-string_join(PyStringObject *self, PyObject *args)
+string_join(PyStringObject *self, PyObject *orig)
 {
        char *sep = PyString_AS_STRING(self);
        const int seplen = PyString_GET_SIZE(self);
@@ -930,10 +930,7 @@ string_join(PyStringObject *self, PyObject *args)
        int seqlen = 0;
        size_t sz = 0;
        int i;
-       PyObject *orig, *seq, *item;
-
-       if (!PyArg_ParseTuple(args, "O:join", &orig))
-               return NULL;
+       PyObject *seq, *item;
 
        seq = PySequence_Fast(orig, "");
        if (seq == NULL) {
@@ -1029,19 +1026,9 @@ string_join(PyStringObject *self, PyObject *args)
 PyObject *
 _PyString_Join(PyObject *sep, PyObject *x)
 {
-       PyObject* args;
-       PyObject* result = NULL;
-
        assert(sep != NULL && PyString_Check(sep));
        assert(x != NULL);
-       args = PyTuple_New(1);
-       if (args != NULL) {
-               Py_INCREF(x);
-               PyTuple_SET_ITEM(args, 0, x);
-               result = string_join((PyStringObject *)sep, args);
-               Py_DECREF(args);
-       }
-       return result;
+       return string_join((PyStringObject *)sep, x);
 }
 
 static long
@@ -1176,14 +1163,11 @@ string_rindex(PyStringObject *self, PyObject *args)
 
 
 static PyObject *
-do_strip(PyStringObject *self, PyObject *args, int striptype)
+do_strip(PyStringObject *self, int striptype)
 {
        char *s = PyString_AS_STRING(self);
        int len = PyString_GET_SIZE(self), i, j;
 
-       if (!PyArg_ParseTuple(args, ":strip"))
-               return NULL;
-
        i = 0;
        if (striptype != RIGHTSTRIP) {
                while (i < len && isspace(Py_CHARMASK(s[i]))) {
@@ -1215,9 +1199,9 @@ Return a copy of the string S with leading and trailing\n\
 whitespace removed.";
 
 static PyObject *
-string_strip(PyStringObject *self, PyObject *args)
+string_strip(PyStringObject *self)
 {
-       return do_strip(self, args, BOTHSTRIP);
+       return do_strip(self, BOTHSTRIP);
 }
 
 
@@ -1227,9 +1211,9 @@ static char lstrip__doc__[] =
 Return a copy of the string S with leading whitespace removed.";
 
 static PyObject *
-string_lstrip(PyStringObject *self, PyObject *args)
+string_lstrip(PyStringObject *self)
 {
-       return do_strip(self, args, LEFTSTRIP);
+       return do_strip(self, LEFTSTRIP);
 }
 
 
@@ -1239,9 +1223,9 @@ static char rstrip__doc__[] =
 Return a copy of the string S with trailing whitespace removed.";
 
 static PyObject *
-string_rstrip(PyStringObject *self, PyObject *args)
+string_rstrip(PyStringObject *self)
 {
-       return do_strip(self, args, RIGHTSTRIP);
+       return do_strip(self, RIGHTSTRIP);
 }
 
 
@@ -1251,14 +1235,12 @@ static char lower__doc__[] =
 Return a copy of the string S converted to lowercase.";
 
 static PyObject *
-string_lower(PyStringObject *self, PyObject *args)
+string_lower(PyStringObject *self)
 {
        char *s = PyString_AS_STRING(self), *s_new;
        int i, n = PyString_GET_SIZE(self);
        PyObject *new;
 
-       if (!PyArg_ParseTuple(args, ":lower"))
-               return NULL;
        new = PyString_FromStringAndSize(NULL, n);
        if (new == NULL)
                return NULL;
@@ -1281,14 +1263,12 @@ static char upper__doc__[] =
 Return a copy of the string S converted to uppercase.";
 
 static PyObject *
-string_upper(PyStringObject *self, PyObject *args)
+string_upper(PyStringObject *self)
 {
        char *s = PyString_AS_STRING(self), *s_new;
        int i, n = PyString_GET_SIZE(self);
        PyObject *new;
 
-       if (!PyArg_ParseTuple(args, ":upper"))
-               return NULL;
        new = PyString_FromStringAndSize(NULL, n);
        if (new == NULL)
                return NULL;
@@ -1312,15 +1292,13 @@ Return a titlecased version of S, i.e. words start with uppercase\n\
 characters, all remaining cased characters have lowercase.";
 
 static PyObject*
-string_title(PyStringObject *self, PyObject *args)
+string_title(PyStringObject *self)
 {
        char *s = PyString_AS_STRING(self), *s_new;
        int i, n = PyString_GET_SIZE(self);
        int previous_is_cased = 0;
        PyObject *new;
 
-       if (!PyArg_ParseTuple(args, ":title"))
-               return NULL;
        new = PyString_FromStringAndSize(NULL, n);
        if (new == NULL)
                return NULL;
@@ -1349,14 +1327,12 @@ Return a copy of the string S with only its first character\n\
 capitalized.";
 
 static PyObject *
-string_capitalize(PyStringObject *self, PyObject *args)
+string_capitalize(PyStringObject *self)
 {
        char *s = PyString_AS_STRING(self), *s_new;
        int i, n = PyString_GET_SIZE(self);
        PyObject *new;
 
-       if (!PyArg_ParseTuple(args, ":capitalize"))
-               return NULL;
        new = PyString_FromStringAndSize(NULL, n);
        if (new == NULL)
                return NULL;
@@ -1450,14 +1426,12 @@ Return a copy of the string S with uppercase characters\n\
 converted to lowercase and vice versa.";
 
 static PyObject *
-string_swapcase(PyStringObject *self, PyObject *args)
+string_swapcase(PyStringObject *self)
 {
        char *s = PyString_AS_STRING(self), *s_new;
        int i, n = PyString_GET_SIZE(self);
        PyObject *new;
 
-       if (!PyArg_ParseTuple(args, ":swapcase"))
-               return NULL;
        new = PyString_FromStringAndSize(NULL, n);
        if (new == NULL)
                return NULL;
@@ -2150,15 +2124,12 @@ Return 1 if there are only whitespace characters in S,\n\
 0 otherwise.";
 
 static PyObject*
-string_isspace(PyStringObject *self, PyObject *args)
+string_isspace(PyStringObject *self)
 {
     register const unsigned char *p
         = (unsigned char *) PyString_AS_STRING(self);
     register const unsigned char *e;
 
-    if (!PyArg_NoArgs(args))
-        return NULL;
-
     /* Shortcut for single character strings */
     if (PyString_GET_SIZE(self) == 1 &&
        isspace(*p))
@@ -2184,15 +2155,12 @@ Return 1 if  all characters in S are alphabetic\n\
 and there is at least one character in S, 0 otherwise.";
 
 static PyObject*
-string_isalpha(PyStringObject *self, PyObject *args)
+string_isalpha(PyStringObject *self)
 {
     register const unsigned char *p
         = (unsigned char *) PyString_AS_STRING(self);
     register const unsigned char *e;
 
-    if (!PyArg_NoArgs(args))
-        return NULL;
-
     /* Shortcut for single character strings */
     if (PyString_GET_SIZE(self) == 1 &&
        isalpha(*p))
@@ -2218,15 +2186,12 @@ Return 1 if  all characters in S are alphanumeric\n\
 and there is at least one character in S, 0 otherwise.";
 
 static PyObject*
-string_isalnum(PyStringObject *self, PyObject *args)
+string_isalnum(PyStringObject *self)
 {
     register const unsigned char *p
         = (unsigned char *) PyString_AS_STRING(self);
     register const unsigned char *e;
 
-    if (!PyArg_NoArgs(args))
-        return NULL;
-
     /* Shortcut for single character strings */
     if (PyString_GET_SIZE(self) == 1 &&
        isalnum(*p))
@@ -2252,15 +2217,12 @@ Return 1 if there are only digit characters in S,\n\
 0 otherwise.";
 
 static PyObject*
-string_isdigit(PyStringObject *self, PyObject *args)
+string_isdigit(PyStringObject *self)
 {
     register const unsigned char *p
         = (unsigned char *) PyString_AS_STRING(self);
     register const unsigned char *e;
 
-    if (!PyArg_NoArgs(args))
-        return NULL;
-
     /* Shortcut for single character strings */
     if (PyString_GET_SIZE(self) == 1 &&
        isdigit(*p))
@@ -2286,16 +2248,13 @@ Return 1 if  all cased characters in S are lowercase and there is\n\
 at least one cased character in S, 0 otherwise.";
 
 static PyObject*
-string_islower(PyStringObject *self, PyObject *args)
+string_islower(PyStringObject *self)
 {
     register const unsigned char *p
         = (unsigned char *) PyString_AS_STRING(self);
     register const unsigned char *e;
     int cased;
 
-    if (!PyArg_NoArgs(args))
-        return NULL;
-
     /* Shortcut for single character strings */
     if (PyString_GET_SIZE(self) == 1)
        return PyInt_FromLong(islower(*p) != 0);
@@ -2323,16 +2282,13 @@ Return 1 if  all cased characters in S are uppercase and there is\n\
 at least one cased character in S, 0 otherwise.";
 
 static PyObject*
-string_isupper(PyStringObject *self, PyObject *args)
+string_isupper(PyStringObject *self)
 {
     register const unsigned char *p
         = (unsigned char *) PyString_AS_STRING(self);
     register const unsigned char *e;
     int cased;
 
-    if (!PyArg_NoArgs(args))
-        return NULL;
-
     /* Shortcut for single character strings */
     if (PyString_GET_SIZE(self) == 1)
        return PyInt_FromLong(isupper(*p) != 0);
@@ -2361,16 +2317,13 @@ may only follow uncased characters and lowercase characters only cased\n\
 ones. Return 0 otherwise.";
 
 static PyObject*
-string_istitle(PyStringObject *self, PyObject *args)
+string_istitle(PyStringObject *self, PyObject *uncased)
 {
     register const unsigned char *p
         = (unsigned char *) PyString_AS_STRING(self);
     register const unsigned char *e;
     int cased, previous_is_cased;
 
-    if (!PyArg_NoArgs(args))
-        return NULL;
-
     /* Shortcut for single character strings */
     if (PyString_GET_SIZE(self) == 1)
        return PyInt_FromLong(isupper(*p) != 0);
@@ -2482,41 +2435,41 @@ static PyMethodDef
 string_methods[] = {
        /* Counterparts of the obsolete stropmodule functions; except
           string.maketrans(). */
-       {"join",       (PyCFunction)string_join,       1, join__doc__},
-       {"split",       (PyCFunction)string_split,       1, split__doc__},
-       {"lower",      (PyCFunction)string_lower,      1, lower__doc__},
-       {"upper",       (PyCFunction)string_upper,       1, upper__doc__},
-       {"islower", (PyCFunction)string_islower, 0, islower__doc__},
-       {"isupper", (PyCFunction)string_isupper, 0, isupper__doc__},
-       {"isspace", (PyCFunction)string_isspace, 0, isspace__doc__},
-       {"isdigit", (PyCFunction)string_isdigit, 0, isdigit__doc__},
-       {"istitle", (PyCFunction)string_istitle, 0, istitle__doc__},
-       {"isalpha", (PyCFunction)string_isalpha, 0, isalpha__doc__},
-       {"isalnum", (PyCFunction)string_isalnum, 0, isalnum__doc__},
-       {"capitalize", (PyCFunction)string_capitalize, 1, capitalize__doc__},
-       {"count",      (PyCFunction)string_count,      1, count__doc__},
-       {"endswith",   (PyCFunction)string_endswith,   1, endswith__doc__},
-       {"find",       (PyCFunction)string_find,       1, find__doc__},
-       {"index",      (PyCFunction)string_index,      1, index__doc__},
-       {"lstrip",     (PyCFunction)string_lstrip,     1, lstrip__doc__},
-       {"replace",     (PyCFunction)string_replace,     1, replace__doc__},
-       {"rfind",       (PyCFunction)string_rfind,       1, rfind__doc__},
-       {"rindex",      (PyCFunction)string_rindex,      1, rindex__doc__},
-       {"rstrip",      (PyCFunction)string_rstrip,      1, rstrip__doc__},
-       {"startswith",  (PyCFunction)string_startswith,  1, startswith__doc__},
-       {"strip",       (PyCFunction)string_strip,       1, strip__doc__},
-       {"swapcase",    (PyCFunction)string_swapcase,    1, swapcase__doc__},
-       {"translate",   (PyCFunction)string_translate,   1, translate__doc__},
-       {"title",       (PyCFunction)string_title,       1, title__doc__},
-       {"ljust",       (PyCFunction)string_ljust,       1, ljust__doc__},
-       {"rjust",       (PyCFunction)string_rjust,       1, rjust__doc__},
-       {"center",      (PyCFunction)string_center,      1, center__doc__},
-       {"encode",      (PyCFunction)string_encode,      1, encode__doc__},
-       {"decode",      (PyCFunction)string_decode,      1, decode__doc__},
-       {"expandtabs",  (PyCFunction)string_expandtabs,  1, expandtabs__doc__},
-       {"splitlines",  (PyCFunction)string_splitlines,  1, splitlines__doc__},
+       {"join",       (PyCFunction)string_join,   METH_O, join__doc__},
+       {"split",       (PyCFunction)string_split, METH_VARARGS, split__doc__},
+       {"lower",      (PyCFunction)string_lower,  METH_NOARGS, lower__doc__},
+       {"upper",       (PyCFunction)string_upper, METH_NOARGS, upper__doc__},
+       {"islower", (PyCFunction)string_islower, METH_NOARGS, islower__doc__},
+       {"isupper", (PyCFunction)string_isupper, METH_NOARGS, isupper__doc__},
+       {"isspace", (PyCFunction)string_isspace, METH_NOARGS, isspace__doc__},
+       {"isdigit", (PyCFunction)string_isdigit, METH_NOARGS, isdigit__doc__},
+       {"istitle", (PyCFunction)string_istitle, METH_NOARGS, istitle__doc__},
+       {"isalpha", (PyCFunction)string_isalpha, METH_NOARGS, isalpha__doc__},
+       {"isalnum", (PyCFunction)string_isalnum, METH_NOARGS, isalnum__doc__},
+       {"capitalize", (PyCFunction)string_capitalize,  METH_NOARGS, capitalize__doc__},
+       {"count",      (PyCFunction)string_count,       METH_VARARGS, count__doc__},
+       {"endswith",   (PyCFunction)string_endswith,    METH_VARARGS, endswith__doc__},
+       {"find",       (PyCFunction)string_find,        METH_VARARGS, find__doc__},
+       {"index",      (PyCFunction)string_index,       METH_VARARGS, index__doc__},
+       {"lstrip",     (PyCFunction)string_lstrip,      METH_NOARGS, lstrip__doc__},
+       {"replace",     (PyCFunction)string_replace,    METH_VARARGS, replace__doc__},
+       {"rfind",       (PyCFunction)string_rfind,      METH_VARARGS, rfind__doc__},
+       {"rindex",      (PyCFunction)string_rindex,     METH_VARARGS, rindex__doc__},
+       {"rstrip",      (PyCFunction)string_rstrip,     METH_NOARGS, rstrip__doc__},
+       {"startswith",  (PyCFunction)string_startswith, METH_VARARGS, startswith__doc__},
+       {"strip",       (PyCFunction)string_strip,      METH_NOARGS, strip__doc__},
+       {"swapcase",    (PyCFunction)string_swapcase,   METH_NOARGS, swapcase__doc__},
+       {"translate",   (PyCFunction)string_translate,  METH_VARARGS, translate__doc__},
+       {"title",       (PyCFunction)string_title,      METH_NOARGS, title__doc__},
+       {"ljust",       (PyCFunction)string_ljust,      METH_VARARGS, ljust__doc__},
+       {"rjust",       (PyCFunction)string_rjust,      METH_VARARGS, rjust__doc__},
+       {"center",      (PyCFunction)string_center,     METH_VARARGS, center__doc__},
+       {"encode",      (PyCFunction)string_encode,     METH_VARARGS, encode__doc__},
+       {"decode",      (PyCFunction)string_decode,     METH_VARARGS, decode__doc__},
+       {"expandtabs",  (PyCFunction)string_expandtabs, METH_VARARGS, expandtabs__doc__},
+       {"splitlines",  (PyCFunction)string_splitlines, METH_VARARGS, splitlines__doc__},
 #if 0
-       {"zfill",       (PyCFunction)string_zfill,       1, zfill__doc__},
+       {"zfill",       (PyCFunction)string_zfill,      METH_VARARGS, zfill__doc__},
 #endif
        {NULL,     NULL}                     /* sentinel */
 };
index c4dc3640e768054c2f3cd67490e508af403675b0..f7f2c9713bfdfbc733350be00c3029fb1f23886a 100644 (file)
@@ -376,12 +376,10 @@ mro_implementation(PyTypeObject *type)
 }
 
 static PyObject *
-mro_external(PyObject *self, PyObject *args)
+mro_external(PyObject *self)
 {
        PyTypeObject *type = (PyTypeObject *)self;
 
-       if (!PyArg_ParseTuple(args, ""))
-               return NULL;
        return mro_implementation(type);
 }
 
@@ -845,7 +843,7 @@ type_dealloc(PyTypeObject *type)
 }
 
 static PyMethodDef type_methods[] = {
-       {"mro", mro_external, METH_VARARGS,
+       {"mro", (PyCFunction)mro_external, METH_NOARGS,
         "mro() -> list\nreturn a type's method resolution order"},
        {0}
 };
index 8bd1287124c9b99b9cada71f02548f0c2b338245..c25c5ac9cb3e104886a65f0c39371cbd386e74fd 100644 (file)
@@ -3251,10 +3251,8 @@ Return a titlecased version of S, i.e. words start with title case\n\
 characters, all remaining cased characters have lower case.";
 
 static PyObject*
-unicode_title(PyUnicodeObject *self, PyObject *args)
+unicode_title(PyUnicodeObject *self)
 {
-    if (!PyArg_NoArgs(args))
-        return NULL;
     return fixup(self, fixtitle);
 }
 
@@ -3265,10 +3263,8 @@ Return a capitalized version of S, i.e. make the first character\n\
 have upper case.";
 
 static PyObject*
-unicode_capitalize(PyUnicodeObject *self, PyObject *args)
+unicode_capitalize(PyUnicodeObject *self)
 {
-    if (!PyArg_NoArgs(args))
-        return NULL;
     return fixup(self, fixcapitalize);
 }
 
@@ -3280,15 +3276,12 @@ Apply .capitalize() to all words in S and return the result with\n\
 normalized whitespace (all whitespace strings are replaced by ' ').";
 
 static PyObject*
-unicode_capwords(PyUnicodeObject *self, PyObject *args)
+unicode_capwords(PyUnicodeObject *self)
 {
     PyObject *list;
     PyObject *item;
     int i;
 
-    if (!PyArg_NoArgs(args))
-        return NULL;
-
     /* Split into words */
     list = split(self, NULL, -1);
     if (!list)
@@ -3771,15 +3764,12 @@ Return 1 if  all cased characters in S are lowercase and there is\n\
 at least one cased character in S, 0 otherwise.";
 
 static PyObject*
-unicode_islower(PyUnicodeObject *self, PyObject *args)
+unicode_islower(PyUnicodeObject *self)
 {
     register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self);
     register const Py_UNICODE *e;
     int cased;
 
-    if (!PyArg_NoArgs(args))
-        return NULL;
-
     /* Shortcut for single character strings */
     if (PyUnicode_GET_SIZE(self) == 1)
        return PyInt_FromLong(Py_UNICODE_ISLOWER(*p) != 0);
@@ -3808,15 +3798,12 @@ Return 1 if  all cased characters in S are uppercase and there is\n\
 at least one cased character in S, 0 otherwise.";
 
 static PyObject*
-unicode_isupper(PyUnicodeObject *self, PyObject *args)
+unicode_isupper(PyUnicodeObject *self)
 {
     register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self);
     register const Py_UNICODE *e;
     int cased;
 
-    if (!PyArg_NoArgs(args))
-        return NULL;
-
     /* Shortcut for single character strings */
     if (PyUnicode_GET_SIZE(self) == 1)
        return PyInt_FromLong(Py_UNICODE_ISUPPER(*p) != 0);
@@ -3846,15 +3833,12 @@ may only follow uncased characters and lowercase characters only cased\n\
 ones. Return 0 otherwise.";
 
 static PyObject*
-unicode_istitle(PyUnicodeObject *self, PyObject *args)
+unicode_istitle(PyUnicodeObject *self)
 {
     register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self);
     register const Py_UNICODE *e;
     int cased, previous_is_cased;
 
-    if (!PyArg_NoArgs(args))
-        return NULL;
-
     /* Shortcut for single character strings */
     if (PyUnicode_GET_SIZE(self) == 1)
        return PyInt_FromLong((Py_UNICODE_ISTITLE(*p) != 0) ||
@@ -3895,14 +3879,11 @@ Return 1 if there are only whitespace characters in S,\n\
 0 otherwise.";
 
 static PyObject*
-unicode_isspace(PyUnicodeObject *self, PyObject *args)
+unicode_isspace(PyUnicodeObject *self)
 {
     register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self);
     register const Py_UNICODE *e;
 
-    if (!PyArg_NoArgs(args))
-        return NULL;
-
     /* Shortcut for single character strings */
     if (PyUnicode_GET_SIZE(self) == 1 &&
        Py_UNICODE_ISSPACE(*p))
@@ -3927,14 +3908,11 @@ Return 1 if  all characters in S are alphabetic\n\
 and there is at least one character in S, 0 otherwise.";
 
 static PyObject*
-unicode_isalpha(PyUnicodeObject *self, PyObject *args)
+unicode_isalpha(PyUnicodeObject *self)
 {
     register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self);
     register const Py_UNICODE *e;
 
-    if (!PyArg_NoArgs(args))
-        return NULL;
-
     /* Shortcut for single character strings */
     if (PyUnicode_GET_SIZE(self) == 1 &&
        Py_UNICODE_ISALPHA(*p))
@@ -3959,14 +3937,11 @@ Return 1 if  all characters in S are alphanumeric\n\
 and there is at least one character in S, 0 otherwise.";
 
 static PyObject*
-unicode_isalnum(PyUnicodeObject *self, PyObject *args)
+unicode_isalnum(PyUnicodeObject *self)
 {
     register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self);
     register const Py_UNICODE *e;
 
-    if (!PyArg_NoArgs(args))
-        return NULL;
-
     /* Shortcut for single character strings */
     if (PyUnicode_GET_SIZE(self) == 1 &&
        Py_UNICODE_ISALNUM(*p))
@@ -3991,14 +3966,11 @@ Return 1 if there are only decimal characters in S,\n\
 0 otherwise.";
 
 static PyObject*
-unicode_isdecimal(PyUnicodeObject *self, PyObject *args)
+unicode_isdecimal(PyUnicodeObject *self)
 {
     register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self);
     register const Py_UNICODE *e;
 
-    if (!PyArg_NoArgs(args))
-        return NULL;
-
     /* Shortcut for single character strings */
     if (PyUnicode_GET_SIZE(self) == 1 &&
        Py_UNICODE_ISDECIMAL(*p))
@@ -4023,14 +3995,11 @@ Return 1 if there are only digit characters in S,\n\
 0 otherwise.";
 
 static PyObject*
-unicode_isdigit(PyUnicodeObject *self, PyObject *args)
+unicode_isdigit(PyUnicodeObject *self)
 {
     register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self);
     register const Py_UNICODE *e;
 
-    if (!PyArg_NoArgs(args))
-        return NULL;
-
     /* Shortcut for single character strings */
     if (PyUnicode_GET_SIZE(self) == 1 &&
        Py_UNICODE_ISDIGIT(*p))
@@ -4055,14 +4024,11 @@ Return 1 if there are only numeric characters in S,\n\
 0 otherwise.";
 
 static PyObject*
-unicode_isnumeric(PyUnicodeObject *self, PyObject *args)
+unicode_isnumeric(PyUnicodeObject *self)
 {
     register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self);
     register const Py_UNICODE *e;
 
-    if (!PyArg_NoArgs(args))
-        return NULL;
-
     /* Shortcut for single character strings */
     if (PyUnicode_GET_SIZE(self) == 1 &&
        Py_UNICODE_ISNUMERIC(*p))
@@ -4087,13 +4053,9 @@ Return a string which is the concatenation of the strings in the\n\
 sequence.  The separator between elements is S.";
 
 static PyObject*
-unicode_join(PyUnicodeObject *self, PyObject *args)
+unicode_join(PyObject *self, PyObject *data)
 {
-    PyObject *data;
-    if (!PyArg_ParseTuple(args, "O:join", &data))
-        return NULL;
-
-    return PyUnicode_Join((PyObject *)self, data);
+    return PyUnicode_Join(self, data);
 }
 
 static int
@@ -4129,10 +4091,8 @@ static char lower__doc__[] =
 Return a copy of the string S converted to lowercase.";
 
 static PyObject*
-unicode_lower(PyUnicodeObject *self, PyObject *args)
+unicode_lower(PyUnicodeObject *self)
 {
-    if (!PyArg_NoArgs(args))
-        return NULL;
     return fixup(self, fixlower);
 }
 
@@ -4142,10 +4102,8 @@ static char lstrip__doc__[] =
 Return a copy of the string S with leading whitespace removed.";
 
 static PyObject *
-unicode_lstrip(PyUnicodeObject *self, PyObject *args)
+unicode_lstrip(PyUnicodeObject *self)
 {
-    if (!PyArg_NoArgs(args))
-        return NULL;
     return strip(self, 1, 0);
 }
 
@@ -4357,10 +4315,8 @@ static char rstrip__doc__[] =
 Return a copy of the string S with trailing whitespace removed.";
 
 static PyObject *
-unicode_rstrip(PyUnicodeObject *self, PyObject *args)
+unicode_rstrip(PyUnicodeObject *self)
 {
-    if (!PyArg_NoArgs(args))
-        return NULL;
     return strip(self, 0, 1);
 }
 
@@ -4465,10 +4421,8 @@ static char strip__doc__[] =
 Return a copy of S with leading and trailing whitespace removed.";
 
 static PyObject *
-unicode_strip(PyUnicodeObject *self, PyObject *args)
+unicode_strip(PyUnicodeObject *self)
 {
-    if (!PyArg_NoArgs(args))
-        return NULL;
     return strip(self, 1, 1);
 }
 
@@ -4479,10 +4433,8 @@ Return a copy of S with uppercase characters converted to lowercase\n\
 and vice versa.";
 
 static PyObject*
-unicode_swapcase(PyUnicodeObject *self, PyObject *args)
+unicode_swapcase(PyUnicodeObject *self)
 {
-    if (!PyArg_NoArgs(args))
-        return NULL;
     return fixup(self, fixswapcase);
 }
 
@@ -4495,12 +4447,8 @@ Unicode ordinals to Unicode ordinals or None. Unmapped characters\n\
 are left untouched. Characters mapped to None are deleted.";
 
 static PyObject*
-unicode_translate(PyUnicodeObject *self, PyObject *args)
+unicode_translate(PyUnicodeObject *self, PyObject *table)
 {
-    PyObject *table;
-    
-    if (!PyArg_ParseTuple(args, "O:translate", &table))
-       return NULL;
     return PyUnicode_TranslateCharmap(self->str, 
                                      self->length,
                                      table, 
@@ -4513,10 +4461,8 @@ static char upper__doc__[] =
 Return a copy of S converted to uppercase.";
 
 static PyObject*
-unicode_upper(PyUnicodeObject *self, PyObject *args)
+unicode_upper(PyUnicodeObject *self)
 {
-    if (!PyArg_NoArgs(args))
-        return NULL;
     return fixup(self, fixupper);
 }
 
@@ -4558,10 +4504,8 @@ unicode_zfill(PyUnicodeObject *self, PyObject *args)
 
 #if 0
 static PyObject*
-unicode_freelistsize(PyUnicodeObject *self, PyObject *args)
+unicode_freelistsize(PyUnicodeObject *self)
 {
-    if (!PyArg_NoArgs(args))
-        return NULL;
     return PyInt_FromLong(unicode_freelist_size);
 }
 #endif
@@ -4633,49 +4577,49 @@ static PyMethodDef unicode_methods[] = {
     /* Order is according to common usage: often used methods should
        appear first, since lookup is done sequentially. */
 
-    {"encode", (PyCFunction) unicode_encode, 1, encode__doc__},
-    {"replace", (PyCFunction) unicode_replace, 1, replace__doc__},
-    {"split", (PyCFunction) unicode_split, 1, split__doc__},
-    {"join", (PyCFunction) unicode_join, 1, join__doc__},
-    {"capitalize", (PyCFunction) unicode_capitalize, 0, capitalize__doc__},
-    {"title", (PyCFunction) unicode_title, 0, title__doc__},
-    {"center", (PyCFunction) unicode_center, 1, center__doc__},
-    {"count", (PyCFunction) unicode_count, 1, count__doc__},
-    {"expandtabs", (PyCFunction) unicode_expandtabs, 1, expandtabs__doc__},
-    {"find", (PyCFunction) unicode_find, 1, find__doc__},
-    {"index", (PyCFunction) unicode_index, 1, index__doc__},
-    {"ljust", (PyCFunction) unicode_ljust, 1, ljust__doc__},
-    {"lower", (PyCFunction) unicode_lower, 0, lower__doc__},
-    {"lstrip", (PyCFunction) unicode_lstrip, 0, lstrip__doc__},
-/*  {"maketrans", (PyCFunction) unicode_maketrans, 1, maketrans__doc__}, */
-    {"rfind", (PyCFunction) unicode_rfind, 1, rfind__doc__},
-    {"rindex", (PyCFunction) unicode_rindex, 1, rindex__doc__},
-    {"rjust", (PyCFunction) unicode_rjust, 1, rjust__doc__},
-    {"rstrip", (PyCFunction) unicode_rstrip, 0, rstrip__doc__},
-    {"splitlines", (PyCFunction) unicode_splitlines, 1, splitlines__doc__},
-    {"strip", (PyCFunction) unicode_strip, 0, strip__doc__},
-    {"swapcase", (PyCFunction) unicode_swapcase, 0, swapcase__doc__},
-    {"translate", (PyCFunction) unicode_translate, 1, translate__doc__},
-    {"upper", (PyCFunction) unicode_upper, 0, upper__doc__},
-    {"startswith", (PyCFunction) unicode_startswith, 1, startswith__doc__},
-    {"endswith", (PyCFunction) unicode_endswith, 1, endswith__doc__},
-    {"islower", (PyCFunction) unicode_islower, 0, islower__doc__},
-    {"isupper", (PyCFunction) unicode_isupper, 0, isupper__doc__},
-    {"istitle", (PyCFunction) unicode_istitle, 0, istitle__doc__},
-    {"isspace", (PyCFunction) unicode_isspace, 0, isspace__doc__},
-    {"isdecimal", (PyCFunction) unicode_isdecimal, 0, isdecimal__doc__},
-    {"isdigit", (PyCFunction) unicode_isdigit, 0, isdigit__doc__},
-    {"isnumeric", (PyCFunction) unicode_isnumeric, 0, isnumeric__doc__},
-    {"isalpha", (PyCFunction) unicode_isalpha, 0, isalpha__doc__},
-    {"isalnum", (PyCFunction) unicode_isalnum, 0, isalnum__doc__},
+    {"encode", (PyCFunction) unicode_encode, METH_VARARGS, encode__doc__},
+    {"replace", (PyCFunction) unicode_replace, METH_VARARGS, replace__doc__},
+    {"split", (PyCFunction) unicode_split, METH_VARARGS, split__doc__},
+    {"join", (PyCFunction) unicode_join, METH_O, join__doc__},
+    {"capitalize", (PyCFunction) unicode_capitalize, METH_NOARGS, capitalize__doc__},
+    {"title", (PyCFunction) unicode_title, METH_NOARGS, title__doc__},
+    {"center", (PyCFunction) unicode_center, METH_VARARGS, center__doc__},
+    {"count", (PyCFunction) unicode_count, METH_VARARGS, count__doc__},
+    {"expandtabs", (PyCFunction) unicode_expandtabs, METH_VARARGS, expandtabs__doc__},
+    {"find", (PyCFunction) unicode_find, METH_VARARGS, find__doc__},
+    {"index", (PyCFunction) unicode_index, METH_VARARGS, index__doc__},
+    {"ljust", (PyCFunction) unicode_ljust, METH_VARARGS, ljust__doc__},
+    {"lower", (PyCFunction) unicode_lower, METH_NOARGS, lower__doc__},
+    {"lstrip", (PyCFunction) unicode_lstrip, METH_NOARGS, lstrip__doc__},
+/*  {"maketrans", (PyCFunction) unicode_maketrans, METH_VARARGS, maketrans__doc__}, */
+    {"rfind", (PyCFunction) unicode_rfind, METH_VARARGS, rfind__doc__},
+    {"rindex", (PyCFunction) unicode_rindex, METH_VARARGS, rindex__doc__},
+    {"rjust", (PyCFunction) unicode_rjust, METH_VARARGS, rjust__doc__},
+    {"rstrip", (PyCFunction) unicode_rstrip, METH_NOARGS, rstrip__doc__},
+    {"splitlines", (PyCFunction) unicode_splitlines, METH_VARARGS, splitlines__doc__},
+    {"strip", (PyCFunction) unicode_strip, METH_NOARGS, strip__doc__},
+    {"swapcase", (PyCFunction) unicode_swapcase, METH_NOARGS, swapcase__doc__},
+    {"translate", (PyCFunction) unicode_translate, METH_O, translate__doc__},
+    {"upper", (PyCFunction) unicode_upper, METH_NOARGS, upper__doc__},
+    {"startswith", (PyCFunction) unicode_startswith, METH_VARARGS, startswith__doc__},
+    {"endswith", (PyCFunction) unicode_endswith, METH_VARARGS, endswith__doc__},
+    {"islower", (PyCFunction) unicode_islower, METH_NOARGS, islower__doc__},
+    {"isupper", (PyCFunction) unicode_isupper, METH_NOARGS, isupper__doc__},
+    {"istitle", (PyCFunction) unicode_istitle, METH_NOARGS, istitle__doc__},
+    {"isspace", (PyCFunction) unicode_isspace, METH_NOARGS, isspace__doc__},
+    {"isdecimal", (PyCFunction) unicode_isdecimal, METH_NOARGS, isdecimal__doc__},
+    {"isdigit", (PyCFunction) unicode_isdigit, METH_NOARGS, isdigit__doc__},
+    {"isnumeric", (PyCFunction) unicode_isnumeric, METH_NOARGS, isnumeric__doc__},
+    {"isalpha", (PyCFunction) unicode_isalpha, METH_NOARGS, isalpha__doc__},
+    {"isalnum", (PyCFunction) unicode_isalnum, METH_NOARGS, isalnum__doc__},
 #if 0
-    {"zfill", (PyCFunction) unicode_zfill, 1, zfill__doc__},
-    {"capwords", (PyCFunction) unicode_capwords, 0, capwords__doc__},
+    {"zfill", (PyCFunction) unicode_zfill, METH_VARARGS, zfill__doc__},
+    {"capwords", (PyCFunction) unicode_capwords, METH_NOARGS, capwords__doc__},
 #endif
 
 #if 0
     /* This one is just used for debugging the implementation. */
-    {"freelistsize", (PyCFunction) unicode_freelistsize, 0},
+    {"freelistsize", (PyCFunction) unicode_freelistsize, METH_NOARGS},
 #endif
 
     {NULL, NULL}
index fa6816279dfd5d3052bf4a5d5dd629eddadbc7d1..12af47f25c7d71e531a0277afba2520903daefc0 100644 (file)
@@ -53,12 +53,8 @@ fromlist is not empty.";
 
 
 static PyObject *
-builtin_abs(PyObject *self, PyObject *args)
+builtin_abs(PyObject *self, PyObject *v)
 {
-       PyObject *v;
-
-       if (!PyArg_ParseTuple(args, "O:abs", &v))
-               return NULL;
        return PyNumber_Absolute(v);
 }
 
@@ -132,12 +128,8 @@ extend to the end of the target object (or with the specified size).";
 
 
 static PyObject *
-builtin_callable(PyObject *self, PyObject *args)
+builtin_callable(PyObject *self, PyObject *v)
 {
-       PyObject *v;
-
-       if (!PyArg_ParseTuple(args, "O:callable", &v))
-               return NULL;
        return PyInt_FromLong((long)PyCallable_Check(v));
 }
 
@@ -667,12 +659,10 @@ exist; without it, an exception is raised in that case.";
 
 
 static PyObject *
-builtin_globals(PyObject *self, PyObject *args)
+builtin_globals(PyObject *self)
 {
        PyObject *d;
 
-       if (!PyArg_ParseTuple(args, ":globals"))
-               return NULL;
        d = PyEval_GetGlobals();
        Py_INCREF(d);
        return d;
@@ -722,12 +712,8 @@ Return whether the object has an attribute with the given name.\n\
 
 
 static PyObject *
-builtin_id(PyObject *self, PyObject *args)
+builtin_id(PyObject *self, PyObject *v)
 {
-       PyObject *v;
-
-       if (!PyArg_ParseTuple(args, "O:id", &v))
-               return NULL;
        return PyLong_FromVoidPtr(v);
 }
 
@@ -949,13 +935,10 @@ Delete a named attribute on an object; delattr(x, 'y') is equivalent to\n\
 
 
 static PyObject *
-builtin_hash(PyObject *self, PyObject *args)
+builtin_hash(PyObject *self, PyObject *v)
 {
-       PyObject *v;
        long x;
 
-       if (!PyArg_ParseTuple(args, "O:hash", &v))
-               return NULL;
        x = PyObject_Hash(v);
        if (x == -1)
                return NULL;
@@ -970,14 +953,10 @@ the same hash value.  The reverse is not necessarily true, but likely.";
 
 
 static PyObject *
-builtin_hex(PyObject *self, PyObject *args)
+builtin_hex(PyObject *self, PyObject *v)
 {
-       PyObject *v;
        PyNumberMethods *nb;
 
-       if (!PyArg_ParseTuple(args, "O:hex", &v))
-               return NULL;
-
        if ((nb = v->ob_type->tp_as_number) == NULL ||
            nb->nb_hex == NULL) {
                PyErr_SetString(PyExc_TypeError,
@@ -1075,13 +1054,10 @@ In the second form, the callable is called until it returns the sentinel.";
 
 
 static PyObject *
-builtin_len(PyObject *self, PyObject *args)
+builtin_len(PyObject *self, PyObject *v)
 {
-       PyObject *v;
        long res;
 
-       if (!PyArg_ParseTuple(args, "O:len", &v))
-               return NULL;
        res = PyObject_Size(v);
        if (res < 0 && PyErr_Occurred())
                return NULL;
@@ -1120,12 +1096,10 @@ Create a slice object.  This is used for slicing by the Numeric extensions.";
 
 
 static PyObject *
-builtin_locals(PyObject *self, PyObject *args)
+builtin_locals(PyObject *self)
 {
        PyObject *d;
 
-       if (!PyArg_ParseTuple(args, ":locals"))
-               return NULL;
        d = PyEval_GetLocals();
        Py_INCREF(d);
        return d;
@@ -1217,13 +1191,10 @@ With two or more arguments, return the largest argument.";
 
 
 static PyObject *
-builtin_oct(PyObject *self, PyObject *args)
+builtin_oct(PyObject *self, PyObject *v)
 {
-       PyObject *v;
        PyNumberMethods *nb;
 
-       if (!PyArg_ParseTuple(args, "O:oct", &v))
-               return NULL;
        if (v == NULL || (nb = v->ob_type->tp_as_number) == NULL ||
            nb->nb_oct == NULL) {
                PyErr_SetString(PyExc_TypeError,
@@ -1270,15 +1241,11 @@ buffered, and larger numbers specify the buffer size.";
 
 
 static PyObject *
-builtin_ord(PyObject *self, PyObject *args)
+builtin_ord(PyObject *self, PyObject* obj)
 {
-       PyObject *obj;
        long ord;
        int size;
 
-       if (!PyArg_ParseTuple(args, "O:ord", &obj))
-               return NULL;
-
        if (PyString_Check(obj)) {
                size = PyString_GET_SIZE(obj);
                if (size == 1) {
@@ -1611,12 +1578,8 @@ sequence is empty.";
 
 
 static PyObject *
-builtin_reload(PyObject *self, PyObject *args)
+builtin_reload(PyObject *self, PyObject *v)
 {
-       PyObject *v;
-
-       if (!PyArg_ParseTuple(args, "O:reload", &v))
-               return NULL;
        return PyImport_ReloadModule(v);
 }
 
@@ -1627,12 +1590,8 @@ Reload the module.  The module must have been successfully imported before.";
 
 
 static PyObject *
-builtin_repr(PyObject *self, PyObject *args)
+builtin_repr(PyObject *self, PyObject *v)
 {
-       PyObject *v;
-
-       if (!PyArg_ParseTuple(args, "O:repr", &v))
-               return NULL;
        return PyObject_Repr(v);
 }
 
@@ -1841,53 +1800,53 @@ in length to the length of the shortest argument sequence.";
 
 
 static PyMethodDef builtin_methods[] = {
-       {"__import__",  builtin___import__, 1, import_doc},
-       {"abs",         builtin_abs, 1, abs_doc},
-       {"apply",       builtin_apply, 1, apply_doc},
-       {"buffer",      builtin_buffer, 1, buffer_doc},
-       {"callable",    builtin_callable, 1, callable_doc},
-       {"chr",         builtin_chr, 1, chr_doc},
-       {"cmp",         builtin_cmp, 1, cmp_doc},
-       {"coerce",      builtin_coerce, 1, coerce_doc},
-       {"compile",     builtin_compile, 1, compile_doc},
-       {"delattr",     builtin_delattr, 1, delattr_doc},
-       {"dir",         builtin_dir, 1, dir_doc},
-       {"divmod",      builtin_divmod, 1, divmod_doc},
-       {"eval",        builtin_eval, 1, eval_doc},
-       {"execfile",    builtin_execfile, 1, execfile_doc},
-       {"filter",      builtin_filter, 1, filter_doc},
-       {"getattr",     builtin_getattr, 1, getattr_doc},
-       {"globals",     builtin_globals, 1, globals_doc},
-       {"hasattr",     builtin_hasattr, 1, hasattr_doc},
-       {"hash",        builtin_hash, 1, hash_doc},
-       {"hex",         builtin_hex, 1, hex_doc},
-       {"id",          builtin_id, 1, id_doc},
-       {"input",       builtin_input, 1, input_doc},
-       {"intern",      builtin_intern, 1, intern_doc},
-       {"isinstance",  builtin_isinstance, 1, isinstance_doc},
-       {"issubclass",  builtin_issubclass, 1, issubclass_doc},
-       {"iter",        builtin_iter, 1, iter_doc},
-       {"len",         builtin_len, 1, len_doc},
-       {"locals",      builtin_locals, 1, locals_doc},
-       {"map",         builtin_map, 1, map_doc},
-       {"max",         builtin_max, 1, max_doc},
-       {"min",         builtin_min, 1, min_doc},
-       {"oct",         builtin_oct, 1, oct_doc},
-       {"open",        builtin_open, 1, open_doc},
-       {"ord",         builtin_ord, 1, ord_doc},
-       {"pow",         builtin_pow, 1, pow_doc},
-       {"range",       builtin_range, 1, range_doc},
-       {"raw_input",   builtin_raw_input, 1, raw_input_doc},
-       {"reduce",      builtin_reduce, 1, reduce_doc},
-       {"reload",      builtin_reload, 1, reload_doc},
-       {"repr",        builtin_repr, 1, repr_doc},
-       {"round",       builtin_round, 1, round_doc},
-       {"setattr",     builtin_setattr, 1, setattr_doc},
-       {"slice",       builtin_slice, 1, slice_doc},
-       {"unichr",      builtin_unichr, 1, unichr_doc},
-       {"vars",        builtin_vars, 1, vars_doc},
-       {"xrange",      builtin_xrange, 1, xrange_doc},
-       {"zip",         builtin_zip, 1, zip_doc},
+       {"__import__",  builtin___import__, METH_VARARGS, import_doc},
+       {"abs",         builtin_abs,        METH_O, abs_doc},
+       {"apply",       builtin_apply,      METH_VARARGS, apply_doc},
+       {"buffer",      builtin_buffer,     METH_VARARGS, buffer_doc},
+       {"callable",    builtin_callable,   METH_O, callable_doc},
+       {"chr",         builtin_chr,        METH_VARARGS, chr_doc},
+       {"cmp",         builtin_cmp,        METH_VARARGS, cmp_doc},
+       {"coerce",      builtin_coerce,     METH_VARARGS, coerce_doc},
+       {"compile",     builtin_compile,    METH_VARARGS, compile_doc},
+       {"delattr",     builtin_delattr,    METH_VARARGS, delattr_doc},
+       {"dir",         builtin_dir,        METH_VARARGS, dir_doc},
+       {"divmod",      builtin_divmod,     METH_VARARGS, divmod_doc},
+       {"eval",        builtin_eval,       METH_VARARGS, eval_doc},
+       {"execfile",    builtin_execfile,   METH_VARARGS, execfile_doc},
+       {"filter",      builtin_filter,     METH_VARARGS, filter_doc},
+       {"getattr",     builtin_getattr,    METH_VARARGS, getattr_doc},
+       {"globals",     (PyCFunction)builtin_globals,    METH_NOARGS, globals_doc},
+       {"hasattr",     builtin_hasattr,    METH_VARARGS, hasattr_doc},
+       {"hash",        builtin_hash,       METH_O, hash_doc},
+       {"hex",         builtin_hex,        METH_O, hex_doc},
+       {"id",          builtin_id,         METH_O, id_doc},
+       {"input",       builtin_input,      METH_VARARGS, input_doc},
+       {"intern",      builtin_intern,     METH_VARARGS, intern_doc},
+       {"isinstance",  builtin_isinstance, METH_VARARGS, isinstance_doc},
+       {"issubclass",  builtin_issubclass, METH_VARARGS, issubclass_doc},
+       {"iter",        builtin_iter,       METH_VARARGS, iter_doc},
+       {"len",         builtin_len,        METH_O, len_doc},
+       {"locals",      (PyCFunction)builtin_locals,     METH_NOARGS, locals_doc},
+       {"map",         builtin_map,        METH_VARARGS, map_doc},
+       {"max",         builtin_max,        METH_VARARGS, max_doc},
+       {"min",         builtin_min,        METH_VARARGS, min_doc},
+       {"oct",         builtin_oct,        METH_O, oct_doc},
+       {"open",        builtin_open,       METH_VARARGS, open_doc},
+       {"ord",         builtin_ord,        METH_O, ord_doc},
+       {"pow",         builtin_pow,        METH_VARARGS, pow_doc},
+       {"range",       builtin_range,      METH_VARARGS, range_doc},
+       {"raw_input",   builtin_raw_input,  METH_VARARGS, raw_input_doc},
+       {"reduce",      builtin_reduce,     METH_VARARGS, reduce_doc},
+       {"reload",      builtin_reload,     METH_O, reload_doc},
+       {"repr",        builtin_repr,       METH_O, repr_doc},
+       {"round",       builtin_round,      METH_VARARGS, round_doc},
+       {"setattr",     builtin_setattr,    METH_VARARGS, setattr_doc},
+       {"slice",       builtin_slice,      METH_VARARGS, slice_doc},
+       {"unichr",      builtin_unichr,     METH_VARARGS, unichr_doc},
+       {"vars",        builtin_vars,       METH_VARARGS, vars_doc},
+       {"xrange",      builtin_xrange,     METH_VARARGS, xrange_doc},
+       {"zip",         builtin_zip,        METH_VARARGS, zip_doc},
        {NULL,          NULL},
 };
 
index 7e98a250405a9452b393ce8f0906bb3c81c2ef59..6ee8ae36a30cb0e59080e77485c2539ba5554011 100644 (file)
@@ -166,13 +166,10 @@ gen_iternext(genobject *gen)
 }
 
 static PyObject *
-gen_next(genobject *gen, PyObject *args)
+gen_next(genobject *gen)
 {
        PyObject *result;
 
-       if (!PyArg_ParseTuple(args, ":next"))
-               return NULL;
-
        result = gen_iternext(gen);
 
        if (result == NULL && !PyErr_Occurred()) {
@@ -191,7 +188,7 @@ gen_getiter(PyObject *gen)
 }
 
 static struct PyMethodDef gen_methods[] = {
-       {"next",     (PyCFunction)gen_next, METH_VARARGS,
+       {"next",     (PyCFunction)gen_next, METH_NOARGS,
                "next() -- get the next value, or raise StopIteration"},
        {NULL,          NULL}   /* Sentinel */
 };
@@ -1938,7 +1935,7 @@ eval_frame(PyFrameObject *f)
                    */
                    if (PyCFunction_Check(func)) {
                            int flags = PyCFunction_GET_FLAGS(func);
-                           if (flags > 1 || nk != 0) 
+                           if (nk != 0 || (flags & METH_KEYWORDS))
                                    x = do_call(func, &stack_pointer,
                                                na, nk);
                            else if (flags == METH_VARARGS) {
@@ -1946,9 +1943,9 @@ eval_frame(PyFrameObject *f)
                                    callargs = load_args(&stack_pointer, na);
                                    x = PyCFunction_Call(func, callargs, NULL);
                                    Py_XDECREF(callargs); 
-                           } else if (!(flags & METH_KEYWORDS))
-                                      x = fast_cfunction(func,
-                                                         &stack_pointer, na);
+                           } else
+                                   x = fast_cfunction(func,
+                                                      &stack_pointer, na);
                    } else {
                            if (PyMethod_Check(func)
                                && PyMethod_GET_SELF(func) != NULL) {
@@ -3046,20 +3043,50 @@ fast_cfunction(PyObject *func, PyObject ***pp_stack, int na)
 {
        PyCFunction meth = PyCFunction_GET_FUNCTION(func);
        PyObject *self = PyCFunction_GET_SELF(func);
-
-       if (na == 0)
-               return (*meth)(self, NULL);
-       else if (na == 1) {
-               PyObject *arg = EXT_POP(*pp_stack);
-               PyObject *result =  (*meth)(self, arg);
-               Py_DECREF(arg);
-               return result;
-       } else {
-               PyObject *args = load_args(pp_stack, na);
-               PyObject *result = (*meth)(self, args);
-               Py_DECREF(args);
-               return result;
-       }
+       int flags = PyCFunction_GET_FLAGS(func);
+
+       switch (flags) {
+       case METH_OLDARGS:
+               if (na == 0)
+                       return (*meth)(self, NULL);
+               else if (na == 1) {
+                       PyObject *arg = EXT_POP(*pp_stack);
+                       PyObject *result =  (*meth)(self, arg);
+                       Py_DECREF(arg);
+                       return result;
+               } else {
+                       PyObject *args = load_args(pp_stack, na);
+                       PyObject *result = (*meth)(self, args);
+                       Py_DECREF(args);
+                       return result;
+               }
+               break;
+       case METH_NOARGS:
+               if (na == 0)
+                       return (*meth)(self, NULL);
+               PyErr_Format(PyExc_TypeError,
+                            "%.200s() takes no arguments (%d given)",
+                            ((PyCFunctionObject*)func)->m_ml->ml_name, na);
+               return NULL;
+               break;
+       case METH_O:
+               if (na == 1) {
+                       PyObject *arg = EXT_POP(*pp_stack);
+                       PyObject *result = (*meth)(self, arg);
+                       Py_DECREF(arg);
+                       return result;
+               }
+               PyErr_Format(PyExc_TypeError,
+                            "%.200s() takes exactly one argument (%d given)",
+                            ((PyCFunctionObject*)func)->m_ml->ml_name, na);
+               return NULL;
+               break;
+       default:
+               fprintf(stderr, "%.200s() flags = %d\n", 
+                       ((PyCFunctionObject*)func)->m_ml->ml_name, flags);
+               PyErr_BadInternalCall();
+               return NULL;
+       }               
 }
 
 static PyObject *
index 4ae207b3c0c3e4ec37bff1cb108f1b11e3abdbe5..2eae03d0b8c43702432f9bc82b3813d72e7f8515 100644 (file)
@@ -68,9 +68,9 @@ PySys_SetObject(char *name, PyObject *v)
 }
 
 static PyObject *
-sys_displayhook(PyObject *self, PyObject *args)
+sys_displayhook(PyObject *self, PyObject *o)
 {
-       PyObject *o, *outf;
+       PyObject *outf;
        PyInterpreterState *interp = PyThreadState_Get()->interp;
        PyObject *modules = interp->modules;
        PyObject *builtins = PyDict_GetItemString(modules, "__builtin__");
@@ -80,10 +80,6 @@ sys_displayhook(PyObject *self, PyObject *args)
                return NULL;
        }
 
-       /* parse arguments */
-       if (!PyArg_ParseTuple(args, "O:displayhook", &o))
-               return NULL;
-
        /* Print value except if None */
        /* After printing, also assign to '_' */
        /* Before, set '_' to None to avoid recursion */
@@ -133,11 +129,9 @@ static char excepthook_doc[] =
 "Handle an exception by displaying it with a traceback on sys.stderr.\n";
 
 static PyObject *
-sys_exc_info(PyObject *self, PyObject *args)
+sys_exc_info(PyObject *self)
 {
        PyThreadState *tstate;
-       if (!PyArg_ParseTuple(args, ":exc_info"))
-               return NULL;
        tstate = PyThreadState_Get();
        return Py_BuildValue(
                "(OOO)",
@@ -171,10 +165,8 @@ If it is another kind of object, it will be printed and the system\n\
 exit status will be one (i.e., failure).";
 
 static PyObject *
-sys_getdefaultencoding(PyObject *self, PyObject *args)
+sys_getdefaultencoding(PyObject *self)
 {
-       if (!PyArg_ParseTuple(args, ":getdefaultencoding"))
-               return NULL;
        return PyString_FromString(PyUnicode_GetDefaultEncoding());
 }
 
@@ -385,10 +377,8 @@ stack and crashing Python.  The highest possible limit is platform-\n\
 dependent.";
 
 static PyObject *
-sys_getrecursionlimit(PyObject *self, PyObject *args)
+sys_getrecursionlimit(PyObject *self)
 {
-       if (!PyArg_ParseTuple(args, ":getrecursionlimit"))
-               return NULL;
        return PyInt_FromLong(Py_GetRecursionLimit());
 }
 
@@ -427,8 +417,6 @@ static PyObject *
 sys_getdlopenflags(PyObject *self, PyObject *args)
 {
         PyThreadState *tstate = PyThreadState_Get();
-       if (!PyArg_ParseTuple(args, ":getdlopenflags"))
-               return NULL;
         if (!tstate)
                return NULL;
         return PyInt_FromLong(tstate->interp->dlopenflags);
@@ -468,11 +456,9 @@ sys_getrefcount(PyObject *self, PyObject *args)
 
 #ifdef Py_TRACE_REFS
 static PyObject *
-sys_gettotalrefcount(PyObject *self, PyObject *args)
+sys_gettotalrefcount(PyObject *self)
 {
        extern long _Py_RefTotal;
-       if (!PyArg_ParseTuple(args, ":gettotalrefcount"))
-               return NULL;
        return PyInt_FromLong(_Py_RefTotal);
 }
 
@@ -486,12 +472,10 @@ temporary reference in the argument list, so it is at least 2.";
 
 #ifdef COUNT_ALLOCS
 static PyObject *
-sys_getcounts(PyObject *self, PyObject *args)
+sys_getcounts(PyObject *self)
 {
        extern PyObject *get_counts(void);
 
-       if (!PyArg_ParseTuple(args, ":getcounts"))
-               return NULL;
        return get_counts();
 }
 #endif
@@ -542,45 +526,45 @@ extern PyObject *_Py_GetDXProfile(PyObject *,  PyObject *);
 
 static PyMethodDef sys_methods[] = {
        /* Might as well keep this in alphabetic order */
-       {"displayhook", sys_displayhook, 1, displayhook_doc},
-       {"exc_info",    sys_exc_info, 1, exc_info_doc},
-       {"excepthook",  sys_excepthook, 1, excepthook_doc},
-       {"exit",        sys_exit, 0, exit_doc},
-       {"getdefaultencoding", sys_getdefaultencoding, 1,
+       {"displayhook", sys_displayhook, METH_O, displayhook_doc},
+       {"exc_info",    (PyCFunction)sys_exc_info, METH_NOARGS, exc_info_doc},
+       {"excepthook",  sys_excepthook, METH_VARARGS, excepthook_doc},
+       {"exit",        sys_exit, METH_OLDARGS, exit_doc},
+       {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding, METH_NOARGS,
         getdefaultencoding_doc}, 
 #ifdef HAVE_DLOPEN
-        {"getdlopenflags", sys_getdlopenflags, 1
-         getdlopenflags_doc},
+       {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS
+        getdlopenflags_doc},
 #endif
 #ifdef COUNT_ALLOCS
-       {"getcounts",   sys_getcounts, 1},
+       {"getcounts",   (PyCFunction)sys_getcounts, METH_NOARGS},
 #endif
 #ifdef DYNAMIC_EXECUTION_PROFILE
-       {"getdxp",      _Py_GetDXProfile, 1},
+       {"getdxp",      _Py_GetDXProfile, METH_VARARGS},
 #endif
 #ifdef Py_TRACE_REFS
-       {"getobjects",  _Py_GetObjects, 1},
-       {"gettotalrefcount", sys_gettotalrefcount, 1},
+       {"getobjects",  _Py_GetObjects, METH_VARARGS},
+       {"gettotalrefcount", (PyCFunction)sys_gettotalrefcount, METH_NOARGS},
 #endif
-       {"getrefcount", sys_getrefcount, 1, getrefcount_doc},
-       {"getrecursionlimit", sys_getrecursionlimit, 1,
+       {"getrefcount", sys_getrefcount, METH_VARARGS, getrefcount_doc},
+       {"getrecursionlimit", (PyCFunction)sys_getrecursionlimit, METH_NOARGS,
         getrecursionlimit_doc},
-       {"_getframe", sys_getframe, 1, getframe_doc},
+       {"_getframe", sys_getframe, METH_VARARGS, getframe_doc},
 #ifdef USE_MALLOPT
-       {"mdebug",      sys_mdebug, 1},
+       {"mdebug",      sys_mdebug, METH_VARARGS},
 #endif
-       {"setdefaultencoding", sys_setdefaultencoding, 1,
+       {"setdefaultencoding", sys_setdefaultencoding, METH_VARARGS,
         setdefaultencoding_doc}, 
-       {"setcheckinterval",    sys_setcheckinterval, 1,
+       {"setcheckinterval",    sys_setcheckinterval, METH_VARARGS,
         setcheckinterval_doc}, 
 #ifdef HAVE_DLOPEN
-        {"setdlopenflags", sys_setdlopenflags, 1
-         setdlopenflags_doc},
+       {"setdlopenflags", sys_setdlopenflags, METH_VARARGS
+        setdlopenflags_doc},
 #endif
-       {"setprofile",  sys_setprofile, 0, setprofile_doc},
-       {"setrecursionlimit", sys_setrecursionlimit, 1,
+       {"setprofile",  sys_setprofile, METH_OLDARGS, setprofile_doc},
+       {"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS,
         setrecursionlimit_doc},
-       {"settrace",    sys_settrace, 0, settrace_doc},
+       {"settrace",    sys_settrace, METH_OLDARGS, settrace_doc},
        {NULL,          NULL}           /* sentinel */
 };
 
index 0e06ff013ac34402beb2b15f353d62c4bbfc4406..0a71e8fa81c48c0ffce4931119abcdf9c25581b0 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 
-# From configure.in Revision: 1.246 
+# From configure.in Revision: 1.247 
 
 # Guess values for system-dependent variables and create Makefiles.
 # Generated automatically using autoconf version 2.13