[Python-checkins] CVS: python/dist/src/Objects listobject.c,2.63,2.64

Guido van Rossum guido@cnri.reston.va.us
2000年2月24日 10:23:05 -0500 (EST)


Update of /projects/cvsroot/python/dist/src/Objects
In directory eric:/projects/python/develop/guido/src/Objects
Modified Files:
	listobject.c 
Log Message:
Made all list methods use PyArg_ParseTuple(), for more accurate
diagnostics.
*** INCOMPATIBLE CHANGE: This changes append(), remove(), index(), and
*** count() to require exactly one argument -- previously, multiple
*** arguments were silently assumed to be a tuple.
Index: listobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/listobject.c,v
retrieving revision 2.63
retrieving revision 2.64
diff -C2 -r2.63 -r2.64
*** listobject.c	2000年01月20日 22:32:54	2.63
--- listobject.c	2000年02月24日 15:23:03	2.64
***************
*** 558,562 ****
 	int i;
 	PyObject *v;
! 	if (!PyArg_Parse(args, "(iO)", &i, &v))
 		return NULL;
 	return ins(self, i, v);
--- 558,562 ----
 	int i;
 	PyObject *v;
! 	if (!PyArg_ParseTuple(args, "iO", &i, &v))
 		return NULL;
 	return ins(self, i, v);
***************
*** 569,573 ****
 {
 	PyObject *v;
! 	if (!PyArg_Parse(args, "O", &v))
 		return NULL;
 	return ins(self, (int) self->ob_size, v);
--- 569,573 ----
 {
 	PyObject *v;
! 	if (!PyArg_ParseTuple(args, "O", &v))
 		return NULL;
 	return ins(self, (int) self->ob_size, v);
***************
*** 1217,1226 ****
 
 static PyObject *
! listsort(self, compare)
 	PyListObject *self;
! 	PyObject *compare;
 {
 	int err;
 
 	self->ob_type = &immutable_list_type;
 	err = samplesortslice(self->ob_item,
--- 1217,1231 ----
 
 static PyObject *
! listsort(self, args)
 	PyListObject *self;
! 	PyObject *args;
 {
 	int err;
+ 	PyObject *compare = NULL;
 
+ 	if (args != NULL) {
+ 		if (!PyArg_ParseTuple(args, "|O", &compare))
+ 			return NULL;
+ 	}
 	self->ob_type = &immutable_list_type;
 	err = samplesortslice(self->ob_item,
***************
*** 1257,1264 ****
 	register PyObject *tmp;
 	
! 	if (args != NULL) {
! 		PyErr_BadArgument();
 		return NULL;
- 	}
 
 	if (self->ob_size > 1) {
--- 1262,1267 ----
 	register PyObject *tmp;
 	
! 	if (!PyArg_ParseTuple(args, ""))
 		return NULL;
 
 	if (self->ob_size > 1) {
***************
*** 1322,1332 ****
 {
 	int i;
! 	
! 	if (args == NULL) {
! 		PyErr_BadArgument();
 		return NULL;
- 	}
 	for (i = 0; i < self->ob_size; i++) {
! 		if (PyObject_Compare(self->ob_item[i], args) == 0)
 			return PyInt_FromLong((long)i);
 		if (PyErr_Occurred())
--- 1325,1334 ----
 {
 	int i;
! 	PyObject *v;
! 
! 	if (!PyArg_ParseTuple(args, "O", &v))
 		return NULL;
 	for (i = 0; i < self->ob_size; i++) {
! 		if (PyObject_Compare(self->ob_item[i], v) == 0)
 			return PyInt_FromLong((long)i);
 		if (PyErr_Occurred())
***************
*** 1344,1355 ****
 	int count = 0;
 	int i;
! 	
! 	if (args == NULL) {
! 		PyErr_SetString(PyExc_TypeError,
! 				"list.count(x): argument missing");
 		return NULL;
- 	}
 	for (i = 0; i < self->ob_size; i++) {
! 		if (PyObject_Compare(self->ob_item[i], args) == 0)
 			count++;
 		if (PyErr_Occurred())
--- 1346,1355 ----
 	int count = 0;
 	int i;
! 	PyObject *v;
! 
! 	if (!PyArg_ParseTuple(args, "O", &v))
 		return NULL;
 	for (i = 0; i < self->ob_size; i++) {
! 		if (PyObject_Compare(self->ob_item[i], v) == 0)
 			count++;
 		if (PyErr_Occurred())
***************
*** 1365,1375 ****
 {
 	int i;
! 	
! 	if (args == NULL) {
! 		PyErr_BadArgument();
 		return NULL;
- 	}
 	for (i = 0; i < self->ob_size; i++) {
! 		if (PyObject_Compare(self->ob_item[i], args) == 0) {
 			if (list_ass_slice(self, i, i+1,
 					 (PyObject *)NULL) != 0)
--- 1365,1374 ----
 {
 	int i;
! 	PyObject *v;
! 
! 	if (!PyArg_ParseTuple(args, "O", &v))
 		return NULL;
 	for (i = 0; i < self->ob_size; i++) {
! 		if (PyObject_Compare(self->ob_item[i], v) == 0) {
 			if (list_ass_slice(self, i, i+1,
 					 (PyObject *)NULL) != 0)
***************
*** 1405,1417 ****
 
 static PyMethodDef list_methods[] = {
! 	{"append",	(PyCFunction)listappend, 0, append_doc},
! 	{"insert",	(PyCFunction)listinsert, 0, insert_doc},
 	{"extend", (PyCFunction)listextend, 1, extend_doc},
 	{"pop",		(PyCFunction)listpop, 1, pop_doc},
! 	{"remove",	(PyCFunction)listremove, 0, remove_doc},
! 	{"index",	(PyCFunction)listindex, 0, index_doc},
! 	{"count",	(PyCFunction)listcount, 0, count_doc},
! 	{"reverse",	(PyCFunction)listreverse, 0, reverse_doc},
! 	{"sort",	(PyCFunction)listsort, 0, sort_doc},
 	{NULL,		NULL}		/* sentinel */
 };
--- 1404,1416 ----
 
 static PyMethodDef list_methods[] = {
! 	{"append",	(PyCFunction)listappend, 1, append_doc},
! 	{"insert",	(PyCFunction)listinsert, 1, insert_doc},
 	{"extend", (PyCFunction)listextend, 1, extend_doc},
 	{"pop",		(PyCFunction)listpop, 1, pop_doc},
! 	{"remove",	(PyCFunction)listremove, 1, remove_doc},
! 	{"index",	(PyCFunction)listindex, 1, index_doc},
! 	{"count",	(PyCFunction)listcount, 1, count_doc},
! 	{"reverse",	(PyCFunction)listreverse, 1, reverse_doc},
! 	{"sort",	(PyCFunction)listsort, 1, sort_doc},
 	{NULL,		NULL}		/* sentinel */
 };

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