[Python-checkins] CVS: python/dist/src/Objects stringobject.c,2.91.2.1,2.91.2.2 unicodeobject.c,2.66,2.66.2.1

Moshe Zadka moshez@users.sourceforge.net
Fri, 30 Mar 2001 22:48:54 -0800


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

Modified Files:
      Tag: release20-maint
	stringobject.c unicodeobject.c 
Log Message:
- #122162 -- unicodeobject.c --- Fix unicode .split() off-by-one

- Loosely based on patch #103249 -- Fix core dumps in PyUnicode_Count


Index: stringobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/stringobject.c,v
retrieving revision 2.91.2.1
retrieving revision 2.91.2.2
diff -C2 -r2.91.2.1 -r2.91.2.2
*** stringobject.c	2001/03/30 20:44:51	2.91.2.1
--- stringobject.c	2001/03/31 06:48:51	2.91.2.2
***************
*** 1237,1243 ****
  		n = PyString_GET_SIZE(subobj);
  	}
! 	else if (PyUnicode_Check(subobj))
! 		return PyInt_FromLong(
! 		        PyUnicode_Count((PyObject *)self, subobj, i, last));
  	else if (PyObject_AsCharBuffer(subobj, &sub, &n))
  		return NULL;
--- 1237,1248 ----
  		n = PyString_GET_SIZE(subobj);
  	}
! 	else if (PyUnicode_Check(subobj)) {
! 		int count;
! 		count = PyUnicode_Count((PyObject *)self, subobj, i, last);
! 		if (count == -1)
! 			return NULL;
! 		else
! 		    	return PyInt_FromLong((long) count);
! 	}
  	else if (PyObject_AsCharBuffer(subobj, &sub, &n))
  		return NULL;
***************
*** 1638,1645 ****
  		plen = PyString_GET_SIZE(subobj);
  	}
! 	else if (PyUnicode_Check(subobj))
! 		return PyInt_FromLong(
! 		        PyUnicode_Tailmatch((PyObject *)self, 
! 					    subobj, start, end, -1));
  	else if (PyObject_AsCharBuffer(subobj, &prefix, &plen))
  		return NULL;
--- 1643,1655 ----
  		plen = PyString_GET_SIZE(subobj);
  	}
! 	else if (PyUnicode_Check(subobj)) {
! 	    	int rc;
! 		rc = PyUnicode_Tailmatch((PyObject *)self, 
! 					  subobj, start, end, -1);
! 		if (rc == -1)
! 			return NULL;
! 		else
! 			return PyInt_FromLong((long) rc);
! 	}
  	else if (PyObject_AsCharBuffer(subobj, &prefix, &plen))
  		return NULL;
***************
*** 1691,1698 ****
  		slen = PyString_GET_SIZE(subobj);
  	}
! 	else if (PyUnicode_Check(subobj))
! 		return PyInt_FromLong(
! 		        PyUnicode_Tailmatch((PyObject *)self, 
! 					    subobj, start, end, +1));
  	else if (PyObject_AsCharBuffer(subobj, &suffix, &slen))
  		return NULL;
--- 1701,1713 ----
  		slen = PyString_GET_SIZE(subobj);
  	}
! 	else if (PyUnicode_Check(subobj)) {
! 	    	int rc;
! 		rc = PyUnicode_Tailmatch((PyObject *)self, 
! 					  subobj, start, end, +1);
! 		if (rc == -1)
! 			return NULL;
! 		else
! 			return PyInt_FromLong((long) rc);
! 	}
  	else if (PyObject_AsCharBuffer(subobj, &suffix, &slen))
  		return NULL;

Index: unicodeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/unicodeobject.c,v
retrieving revision 2.66
retrieving revision 2.66.2.1
diff -C2 -r2.66 -r2.66.2.1
*** unicodeobject.c	2000/10/03 20:45:26	2.66
--- unicodeobject.c	2001/03/31 06:48:51	2.66.2.1
***************
*** 2358,2361 ****
--- 2358,2372 ----
      int count = 0;
  
+     if (start < 0)
+         start += self->length;
+     if (start < 0)
+         start = 0;
+     if (end > self->length)
+         end = self->length;
+     if (end < 0)
+         end += self->length;
+     if (end < 0)
+         end = 0;
+ 
      if (substring->length == 0)
  	return (end - start + 1);
***************
*** 2926,2930 ****
      PyObject *str;
  
!     for (i = j = 0; i < len - sublen; ) {
  	if (Py_UNICODE_MATCH(self, i, substring)) {
  	    if (maxcount-- <= 0)
--- 2937,2941 ----
      PyObject *str;
  
!     for (i = j = 0; i <= len - sublen; ) {
  	if (Py_UNICODE_MATCH(self, i, substring)) {
  	    if (maxcount-- <= 0)