[Python-checkins] CVS: python/dist/src/Modules arraymodule.c,2.50,2.51

Peter Schneider-Kamp python-dev@python.org
2000年7月31日 14:57:33 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv2155
Modified Files:
	arraymodule.c 
Log Message:
replaced PyArgs_Parse by PyArgs_ParseTuple
changed error messages for extend method from "append" to "extend"
Index: arraymodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/arraymodule.c,v
retrieving revision 2.50
retrieving revision 2.51
diff -C2 -r2.50 -r2.51
*** arraymodule.c	2000年07月31日 20:47:15	2.50
--- arraymodule.c	2000年07月31日 21:57:30	2.51
***************
*** 802,806 ****
 	if (!is_arrayobject(bb)) {
 		PyErr_Format(PyExc_TypeError,
! 			 "can only append array (not \"%.200s\") to array",
 			 bb->ob_type->tp_name);
 		return NULL;
--- 802,806 ----
 	if (!is_arrayobject(bb)) {
 		PyErr_Format(PyExc_TypeError,
! 			 "can only extend array with array (not \"%.200s\")",
 			 bb->ob_type->tp_name);
 		return NULL;
***************
*** 809,813 ****
 	if (self->ob_descr != b->ob_descr) {
 		PyErr_SetString(PyExc_TypeError,
! 			 "can only append arrays of same kind");
 		return NULL;
 	}
--- 809,813 ----
 	if (self->ob_descr != b->ob_descr) {
 		PyErr_SetString(PyExc_TypeError,
! 			 "can only extend with array of same kind");
 		return NULL;
 	}
***************
*** 836,840 ****
 	int i;
 	PyObject *v;
! 	if (!PyArg_Parse(args, "(iO)", &i, &v))
 		return NULL;
 	return ins(self, i, v);
--- 836,840 ----
 	int i;
 	PyObject *v;
! if (!PyArg_ParseTuple(args, "iO:insert", &i, &v))
 		return NULL;
 	return ins(self, i, v);
***************
*** 870,874 ****
 {
 	PyObject *v;
! 	if (!PyArg_Parse(args, "O", &v))
 		return NULL;
 	return ins(self, (int) self->ob_size, v);
--- 870,874 ----
 {
 	PyObject *v;
! if (!PyArg_ParseTuple(args, "O:append", &v))
 		return NULL;
 	return ins(self, (int) self->ob_size, v);
***************
*** 980,984 ****
 	int n;
 	FILE *fp;
! 	if (!PyArg_Parse(args, "(Oi)", &f, &n))
 		return NULL;
 	fp = PyFile_AsFile(f);
--- 980,984 ----
 	int n;
 	FILE *fp;
! if (!PyArg_ParseTuple(args, "Oi:fromfile", &f, &n))
 		return NULL;
 	fp = PyFile_AsFile(f);
***************
*** 1033,1037 ****
 	PyObject *f;
 	FILE *fp;
! 	if (!PyArg_Parse(args, "O", &f))
 		return NULL;
 	fp = PyFile_AsFile(f);
--- 1033,1037 ----
 	PyObject *f;
 	FILE *fp;
! if (!PyArg_ParseTuple(args, "O:tofile", &f))
 		return NULL;
 	fp = PyFile_AsFile(f);
***************
*** 1065,1069 ****
 	PyObject *list;
 	int itemsize = self->ob_descr->itemsize;
! 	if (!PyArg_Parse(args, "O", &list))
 		return NULL;
 	if (!PyList_Check(list)) {
--- 1065,1069 ----
 	PyObject *list;
 	int itemsize = self->ob_descr->itemsize;
! if (!PyArg_ParseTuple(args, "O:fromlist", &list))
 		return NULL;
 	if (!PyList_Check(list)) {
***************
*** 1109,1112 ****
--- 1109,1114 ----
 	PyObject *list = PyList_New(self->ob_size);
 	int i;
+ if (!PyArg_ParseTuple(args, ":tolist"))
+ return NULL;
 	if (list == NULL)
 		return NULL;
***************
*** 1134,1138 ****
 	int n;
 	int itemsize = self->ob_descr->itemsize;
! 	if (!PyArg_Parse(args, "s#", &str, &n))
 		return NULL;
 	if (n % itemsize != 0) {
--- 1136,1140 ----
 	int n;
 	int itemsize = self->ob_descr->itemsize;
! if (!PyArg_ParseTuple(args, "s#:fromstring", &str, &n))
 		return NULL;
 	if (n % itemsize != 0) {
***************
*** 1168,1172 ****
 array_tostring(arrayobject *self, PyObject *args)
 {
! 	if (!PyArg_Parse(args, ""))
 		return NULL;
 	return PyString_FromStringAndSize(self->ob_item,
--- 1170,1174 ----
 array_tostring(arrayobject *self, PyObject *args)
 {
! 	if (!PyArg_ParseTuple(args, ":tostring"))
 		return NULL;
 	return PyString_FromStringAndSize(self->ob_item,
***************
*** 1181,1204 ****
 
 PyMethodDef array_methods[] = {
! 	{"append",	(PyCFunction)array_append, 0, append_doc},
! 	{"buffer_info", (PyCFunction)array_buffer_info, 0, buffer_info_doc},
! 	{"byteswap",	(PyCFunction)array_byteswap, METH_VARARGS,
! byteswap_doc},
! 	{"count",	(PyCFunction)array_count, 1, count_doc},
! 	{"extend", (PyCFunction)array_extend, 1, extend_doc},
! 	{"fromfile",	(PyCFunction)array_fromfile, 0, fromfile_doc},
! 	{"fromlist",	(PyCFunction)array_fromlist, 0, fromlist_doc},
! 	{"fromstring",	(PyCFunction)array_fromstring, 0, fromstring_doc},
! 	{"index",	(PyCFunction)array_index, 1, index_doc},
! 	{"insert",	(PyCFunction)array_insert, 0, insert_doc},
! 	{"pop",		(PyCFunction)array_pop, 1, pop_doc},
! 	{"read",	(PyCFunction)array_fromfile, 0, fromfile_doc},
! 	{"remove",	(PyCFunction)array_remove, 1, remove_doc},
! 	{"reverse",	(PyCFunction)array_reverse, 0, reverse_doc},
! /*	{"sort",	(PyCFunction)array_sort, 0, sort_doc},*/
! 	{"tofile",	(PyCFunction)array_tofile, 0, tofile_doc},
! 	{"tolist",	(PyCFunction)array_tolist, 0, tolist_doc},
! 	{"tostring",	(PyCFunction)array_tostring, 0, tostring_doc},
! 	{"write",	(PyCFunction)array_tofile, 0, tofile_doc},
 	{NULL,		NULL}		/* sentinel */
 };
--- 1183,1205 ----
 
 PyMethodDef array_methods[] = {
! 	{"append",	(PyCFunction)array_append, METH_VARARGS, append_doc},
! 	{"buffer_info", (PyCFunction)array_buffer_info, METH_VARARGS, buffer_info_doc},
! 	{"byteswap",	(PyCFunction)array_byteswap, METH_VARARGS, byteswap_doc},
! 	{"count",	(PyCFunction)array_count, METH_VARARGS, count_doc},
! 	{"extend", (PyCFunction)array_extend, METH_VARARGS, extend_doc},
! 	{"fromfile",	(PyCFunction)array_fromfile, METH_VARARGS, fromfile_doc},
! 	{"fromlist",	(PyCFunction)array_fromlist, METH_VARARGS, fromlist_doc},
! 	{"fromstring",	(PyCFunction)array_fromstring, METH_VARARGS, fromstring_doc},
! 	{"index",	(PyCFunction)array_index, METH_VARARGS, index_doc},
! 	{"insert",	(PyCFunction)array_insert, METH_VARARGS, insert_doc},
! 	{"pop",		(PyCFunction)array_pop, METH_VARARGS, pop_doc},
! 	{"read",	(PyCFunction)array_fromfile, METH_VARARGS, fromfile_doc},
! 	{"remove",	(PyCFunction)array_remove, METH_VARARGS, remove_doc},
! 	{"reverse",	(PyCFunction)array_reverse, METH_VARARGS, reverse_doc},
! /*	{"sort",	(PyCFunction)array_sort, METH_VARARGS, sort_doc},*/
! 	{"tofile",	(PyCFunction)array_tofile, METH_VARARGS, tofile_doc},
! 	{"tolist",	(PyCFunction)array_tolist, METH_VARARGS, tolist_doc},
! 	{"tostring",	(PyCFunction)array_tostring, METH_VARARGS, tostring_doc},
! 	{"write",	(PyCFunction)array_tofile, METH_VARARGS, tofile_doc},
 	{NULL,		NULL}		/* sentinel */
 };
***************
*** 1236,1239 ****
--- 1237,1241 ----
 	int ok = 0;
 	int i, len;
+ 	PyObject *t_empty = PyTuple_New(0);
 	PyObject *v;
 	len = a->ob_size;
***************
*** 1244,1248 ****
 	if (a->ob_descr->typecode == 'c') {
 		fprintf(fp, "array('c', ");
! 		v = array_tostring(a, (PyObject *)NULL);
 		ok = PyObject_Print(v, fp, 0);
 		Py_XDECREF(v);
--- 1246,1251 ----
 	if (a->ob_descr->typecode == 'c') {
 		fprintf(fp, "array('c', ");
! 		v = array_tostring(a, t_empty);
! 		Py_DECREF(t_empty);;
 		ok = PyObject_Print(v, fp, 0);
 		Py_XDECREF(v);
***************
*** 1356,1362 ****
 	PyObject *initial = NULL;
 	struct arraydescr *descr;
! 	if (!PyArg_Parse(args, "c", &c)) {
 		PyErr_Clear();
! 		if (!PyArg_Parse(args, "(cO)", &c, &initial))
 			return NULL;
 		if (!PyList_Check(initial) && !PyString_Check(initial)) {
--- 1359,1365 ----
 	PyObject *initial = NULL;
 	struct arraydescr *descr;
! if (!PyArg_ParseTuple(args, "c:array", &c)) {
 		PyErr_Clear();
! if (!PyArg_ParseTuple(args, "cO:array", &c, &initial))
 			return NULL;
 		if (!PyList_Check(initial) && !PyString_Check(initial)) {
***************
*** 1389,1394 ****
 			}
 			if (initial != NULL && PyString_Check(initial)) {
 				PyObject *v =
! 				 array_fromstring((arrayobject *)a, initial);
 				if (v == NULL) {
 					Py_DECREF(a);
--- 1392,1399 ----
 			}
 			if (initial != NULL && PyString_Check(initial)) {
+ 				PyObject *t_initial = Py_BuildValue("(O)", initial);
 				PyObject *v =
! 					array_fromstring((arrayobject *)a, t_initial);
! Py_DECREF(t_initial);
 				if (v == NULL) {
 					Py_DECREF(a);
***************
*** 1413,1417 ****
 
 static PyMethodDef a_methods[] = {
! 	{"array",	a_array, 0, a_array_doc},
 	{NULL,		NULL}		/* sentinel */
 };
--- 1418,1422 ----
 
 static PyMethodDef a_methods[] = {
! 	{"array",	a_array, METH_VARARGS, a_array_doc},
 	{NULL,		NULL}		/* sentinel */
 };

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