[Python-checkins] python/dist/src/Objects listobject.c,2.138,2.139

mwh@users.sourceforge.net mwh@users.sourceforge.net
Tue, 05 Nov 2002 09:38:07 -0800


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv3659/Objects

Modified Files:
	listobject.c 
Log Message:
This is Alex Martelli's patch 

[ 633870 ] allow any seq assignment to a list slice

plus a very silly little test case of my own.



Index: listobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/listobject.c,v
retrieving revision 2.138
retrieving revision 2.139
diff -C2 -d -r2.138 -r2.139
*** listobject.c	11 Oct 2002 23:39:35 -0000	2.138
--- listobject.c	5 Nov 2002 17:38:05 -0000	2.139
***************
*** 449,452 ****
--- 449,453 ----
  	PyObject **recycle, **p;
  	PyObject **item;
+ 	PyObject *v_as_SF = NULL; /* PySequence_Fast(v) */
  	int n; /* Size of replacement list */
  	int d; /* Change in size */
***************
*** 455,460 ****
  	if (v == NULL)
  		n = 0;
! 	else if (PyList_Check(v)) {
! 		n = b->ob_size;
  		if (a == b) {
  			/* Special case "a[i:j] = a" -- copy b first */
--- 456,468 ----
  	if (v == NULL)
  		n = 0;
! 	else {
! 		char msg[256];
! 		sprintf(msg, "must assign sequence (not \"%.200s\") to slice",
! 			     v->ob_type->tp_name);
! 		v_as_SF = PySequence_Fast(v, msg);
! 		if(v_as_SF == NULL)
! 			return -1;
! 		n = PySequence_Fast_GET_SIZE(v_as_SF);
! 
  		if (a == b) {
  			/* Special case "a[i:j] = a" -- copy b first */
***************
*** 466,475 ****
  		}
  	}
- 	else {
- 		PyErr_Format(PyExc_TypeError,
- 			     "must assign list (not \"%.200s\") to slice",
- 			     v->ob_type->tp_name);
- 		return -1;
- 	}
  	if (ilow < 0)
  		ilow = 0;
--- 474,477 ----
***************
*** 513,517 ****
  	}
  	for (k = 0; k < n; k++, ilow++) {
! 		PyObject *w = b->ob_item[k];
  		Py_XINCREF(w);
  		item[ilow] = w;
--- 515,519 ----
  	}
  	for (k = 0; k < n; k++, ilow++) {
! 		PyObject *w = PySequence_Fast_GET_ITEM(v_as_SF, k);
  		Py_XINCREF(w);
  		item[ilow] = w;
***************
*** 526,529 ****
--- 528,532 ----
  		a->ob_item = NULL;
  	}
+ 	Py_XDECREF(v_as_SF);
  	return 0;
  #undef b