[Python-checkins] python/dist/src/Python bltinmodule.c,2.304,2.305

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Wed Dec 17 15:43:35 EST 2003


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv9388/Python
Modified Files:
	bltinmodule.c 
Log Message:
Guido grants a Christmas wish: 
 sorted() becomes a regular function instead of a classmethod.
Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.304
retrieving revision 2.305
diff -C2 -d -r2.304 -r2.305
*** bltinmodule.c	5 Dec 2003 17:34:27 -0000	2.304
--- bltinmodule.c	17 Dec 2003 20:43:33 -0000	2.305
***************
*** 1759,1762 ****
--- 1759,1806 ----
 This always returns a floating point number. Precision may be negative.");
 
+ static PyObject *
+ builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds)
+ {
+ 	PyObject *newlist, *v, *seq, *compare=NULL, *keyfunc=NULL, *newargs;
+ 	PyObject *callable;
+ 	static char *kwlist[] = {"iterable", "cmp", "key", "reverse", 0};
+ 	long reverse;
+ 
+ 	if (args != NULL) {
+ 		if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OOi:sorted",
+ 			kwlist, &seq, &compare, &keyfunc, &reverse))
+ 			return NULL;
+ 	}
+ 
+ 	newlist = PySequence_List(seq);
+ 	if (newlist == NULL)
+ 		return NULL;
+ 
+ 	callable = PyObject_GetAttrString(newlist, "sort");
+ 	if (callable == NULL) {
+ 		Py_DECREF(newlist);
+ 		return NULL;
+ 	}
+ 	
+ 	newargs = PyTuple_GetSlice(args, 1, 4);
+ 	if (newargs == NULL) {
+ 		Py_DECREF(newlist);
+ 		Py_DECREF(callable);
+ 		return NULL;
+ 	}
+ 
+ 	v = PyObject_Call(callable, newargs, kwds);
+ 	Py_DECREF(newargs);
+ 	Py_DECREF(callable);
+ 	if (v == NULL) {
+ 		Py_DECREF(newlist);
+ 		return NULL;
+ 	}
+ 	Py_DECREF(v);
+ 	return newlist;
+ }
+ 
+ PyDoc_STRVAR(sorted_doc,
+ "sorted(iterable, cmp=None, key=None, reverse=False) --> new sorted list");
 
 static PyObject *
***************
*** 2056,2059 ****
--- 2100,2104 ----
 	{"round",	builtin_round, METH_VARARGS, round_doc},
 	{"setattr",	builtin_setattr, METH_VARARGS, setattr_doc},
+ 	{"sorted",	(PyCFunction)builtin_sorted, METH_VARARGS | METH_KEYWORDS, sorted_doc},
 	{"sum",		builtin_sum, METH_VARARGS, sum_doc},
 #ifdef Py_USING_UNICODE


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /