[Python-checkins] python/dist/src/Objects sliceobject.c,2.15,2.16

mwh@users.sourceforge.net mwh@users.sourceforge.net
Fri, 19 Jul 2002 08:47:08 -0700


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

Modified Files:
	sliceobject.c 
Log Message:
A few days ago, Guido said (in the thread "[Python-Dev] Python 
version of PySlice_GetIndicesEx"):

> OK.  Michael, if you want to check in indices(), go ahead.

Then I did what was needed, but didn't check it in.  Here it is.


Index: sliceobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/sliceobject.c,v
retrieving revision 2.15
retrieving revision 2.16
diff -C2 -d -r2.15 -r2.16
*** sliceobject.c	14 Jun 2002 20:41:15 -0000	2.15
--- sliceobject.c	19 Jul 2002 15:47:06 -0000	2.16
***************
*** 222,225 ****
--- 222,258 ----
  };
  
+ static PyObject*
+ slice_indices(PySliceObject* self, PyObject* len)
+ {
+ 	int ilen, start, stop, step, slicelength;
+ 
+ 	ilen = PyInt_AsLong(len);
+ 
+ 	if (ilen == -1 && PyErr_Occurred()) {
+ 		return NULL;
+ 	}
+ 
+ 	if (PySlice_GetIndicesEx(self, ilen, &start, &stop, 
+ 				 &step, &slicelength) < 0) {
+ 		return NULL;
+ 	}
+ 
+ 	return Py_BuildValue("(lll)", start, stop, step);
+ }
+ 
+ PyDoc_STRVAR(slice_indices_doc,
+ "S.indices(len) -> (start, stop, stride)\n\
+ \n\
+ Assuming a sequence of length len, calculate the start and stop\n\
+ indices, and the stride length of the extended slice described by\n\
+ S. Out of bounds indices are clipped in a manner consistent with the\n\
+ handling of normal slices.");
+ 
+ static PyMethodDef slice_methods[] = {
+ 	{"indices",	(PyCFuntion)slice_indices,
+ 	 METH_O,	slice_indices_doc},
+ 	{NULL, NULL}
+ };
+ 
  static int
  slice_compare(PySliceObject *v, PySliceObject *w)
***************
*** 272,276 ****
  	0,					/* tp_iter */
  	0,					/* tp_iternext */
! 	0,					/* tp_methods */
  	slice_members,				/* tp_members */
  	0,					/* tp_getset */
--- 305,309 ----
  	0,					/* tp_iter */
  	0,					/* tp_iternext */
! 	slice_methods,				/* tp_methods */
  	slice_members,				/* tp_members */
  	0,					/* tp_getset */