Patch #427190: Implement and use METH_NOARGS and METH_O.
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index fa68162..12af47f 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -53,12 +53,8 @@
 
 
 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 @@
 
 
 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 @@
 
 
 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 @@
 
 
 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 @@
 
 
 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 @@
 
 
 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 @@
 
 
 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 @@
 
 
 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 @@
 
 
 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 @@
 
 
 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 @@
 
 
 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 @@
 
 
 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 @@
 
 
 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},
 };
 
diff --git a/Python/ceval.c b/Python/ceval.c
index 7e98a25..6ee8ae3 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -166,13 +166,10 @@
 }
 
 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 @@
 }
 
 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 @@
 		    */
 		    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 @@
 				    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 @@
 {
 	PyCFunction meth = PyCFunction_GET_FUNCTION(func);
 	PyObject *self = PyCFunction_GET_SELF(func);
+	int flags = PyCFunction_GET_FLAGS(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;
-	}
+	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 *
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 4ae207b..2eae03d 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -68,9 +68,9 @@
 }
 
 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 @@
 		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 @@
 "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 @@
 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 @@
 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 @@
 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 @@
 
 #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 @@
 
 #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 @@
 
 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 */
 };