[Python-checkins] python/dist/src/Objects listobject.c,2.141,2.142

mwh@users.sourceforge.net mwh@users.sourceforge.net
Thu, 05 Dec 2002 13:32:34 -0800


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

Modified Files:
	listobject.c 
Log Message:
The final tweaks before closing

[ 633152 ] list slice ass ignores subtypes of list

Allow arbitrary sequences on the RHS of extended slices.


Index: listobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/listobject.c,v
retrieving revision 2.141
retrieving revision 2.142
diff -C2 -d -r2.141 -r2.142
*** listobject.c	12 Nov 2002 22:08:10 -0000	2.141
--- listobject.c	5 Dec 2002 21:32:32 -0000	2.142
***************
*** 2239,2269 ****
  		else {
  			/* assign slice */
! 			PyObject **garbage, *ins;
  			int cur, i;
  
! 			if (!PyList_Check(value)) {
! 				PyErr_Format(PyExc_TypeError,
! 			     "must assign list (not \"%.200s\") to slice",
! 					     value->ob_type->tp_name);
! 				return -1;
  			}
  
! 			if (PyList_GET_SIZE(value) != slicelength) {
  				PyErr_Format(PyExc_ValueError,
!             "attempt to assign list of size %d to extended slice of size %d",
! 					     PyList_Size(value), slicelength);
  				return -1;
  			}
  
! 			if (!slicelength)
  				return 0;
- 
- 			/* protect against a[::-1] = a */
- 			if (self == (PyListObject*)value) {
- 				value = list_slice((PyListObject*)value, 0,
- 						   PyList_GET_SIZE(value));
- 			}
- 			else {
- 				Py_INCREF(value);
  			}
  
--- 2239,2272 ----
  		else {
  			/* assign slice */
! 			PyObject **garbage, *ins, *seq;
  			int cur, i;
  
! 			/* protect against a[::-1] = a */
! 			if (self == (PyListObject*)value) {
! 				seq = list_slice((PyListObject*)value, 0,
! 						   PyList_GET_SIZE(value));
! 			}
! 			else {
! 				char msg[256];
! 				PyOS_snprintf(msg, sizeof(msg),
! 		      "must assign sequence (not \"%.200s\") to extended slice",
! 					      value->ob_type->tp_name);
! 				seq = PySequence_Fast(value, msg);
! 				if (!seq)
! 					return -1;
  			}
  
! 			if (PySequence_Fast_GET_SIZE(seq) != slicelength) {
  				PyErr_Format(PyExc_ValueError,
!             "attempt to assign sequence of size %d to extended slice of size %d",
! 					     PySequence_Fast_GET_SIZE(seq),
! 					     slicelength);
! 				Py_DECREF(seq);
  				return -1;
  			}
  
! 			if (!slicelength) {
! 				Py_DECREF(seq);
  				return 0;
  			}
  
***************
*** 2275,2279 ****
  				garbage[i] = PyList_GET_ITEM(self, cur);
  
! 				ins = PyList_GET_ITEM(value, i);
  				Py_INCREF(ins);
  				PyList_SET_ITEM(self, cur, ins);
--- 2278,2282 ----
  				garbage[i] = PyList_GET_ITEM(self, cur);
  
! 				ins = PySequence_Fast_GET_ITEM(seq, i);
  				Py_INCREF(ins);
  				PyList_SET_ITEM(self, cur, ins);
***************
*** 2285,2289 ****
  
  			PyMem_FREE(garbage);
! 			Py_DECREF(value);
  
  			return 0;
--- 2288,2292 ----
  
  			PyMem_FREE(garbage);
! 			Py_DECREF(seq);
  
  			return 0;