[Python-checkins] CVS: python/dist/src/Objects stringobject.c,2.59,2.60 unicodeobject.c,2.2,2.3

Barry A. Warsaw python-dev@python.org
Mon, 20 Mar 2000 11:36:47 -0500 (EST)


Update of /projects/cvsroot/python/dist/src/Objects
In directory anthem:/home/bwarsaw/projects/python/Objects

Modified Files:
	stringobject.c unicodeobject.c 
Log Message:
On 17-Mar-2000, Marc-Andre Lemburg said:

    Attached you find an update of the Unicode implementation.

    The patch is against the current CVS version. I would appreciate
    if someone with CVS checkin permissions could check the changes
    in.

    The patch contains all bugs and patches sent this week and also
    fixes a leak in the codecs code and a bug in the free list code
    for Unicode objects (which only shows up when compiling Python
    with Py_DEBUG; thanks to MarkH for spotting this one).


Index: stringobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/stringobject.c,v
retrieving revision 2.59
retrieving revision 2.60
diff -C2 -r2.59 -r2.60
*** stringobject.c	2000/03/13 15:56:08	2.59
--- stringobject.c	2000/03/20 16:36:43	2.60
***************
*** 1396,1400 ****
    strstr replacement for arbitrary blocks of memory.
  
!   Locates the first occurance in the memory pointed to by MEM of the
    contents of memory pointed to by PAT.  Returns the index into MEM if
    found, or -1 if not found.  If len of PAT is greater than length of
--- 1396,1400 ----
    strstr replacement for arbitrary blocks of memory.
  
!   Locates the first occurrence in the memory pointed to by MEM of the
    contents of memory pointed to by PAT.  Returns the index into MEM if
    found, or -1 if not found.  If len of PAT is greater than length of
***************
*** 1579,1583 ****
  
  	if (sub_len <= 0) {
! 		PyErr_SetString(PyExc_ValueError, "empty replacement string");
  		return NULL;
  	}
--- 1579,1583 ----
  
  	if (sub_len <= 0) {
! 		PyErr_SetString(PyExc_ValueError, "empty pattern string");
  		return NULL;
  	}

Index: unicodeobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/unicodeobject.c,v
retrieving revision 2.2
retrieving revision 2.3
diff -C2 -r2.2 -r2.3
*** unicodeobject.c	2000/03/13 15:55:09	2.2
--- unicodeobject.c	2000/03/20 16:36:44	2.3
***************
*** 84,88 ****
     limit. This reduces malloc() overhead for small Unicode objects.  
  
!    At worse this will result in MAX_UNICODE_FREELIST_SIZE *
     (sizeof(PyUnicodeObject) + STAYALIVE_SIZE_LIMIT +
     malloc()-overhead) bytes of unused garbage.
--- 84,88 ----
     limit. This reduces malloc() overhead for small Unicode objects.  
  
!    At worst this will result in MAX_UNICODE_FREELIST_SIZE *
     (sizeof(PyUnicodeObject) + STAYALIVE_SIZE_LIMIT +
     malloc()-overhead) bytes of unused garbage.
***************
*** 181,185 ****
          unicode_freelist_size--;
          unicode->ob_type = &PyUnicode_Type;
!         _Py_NewReference(unicode);
  	if (unicode->str) {
  	    if (unicode->length < length &&
--- 181,185 ----
          unicode_freelist_size--;
          unicode->ob_type = &PyUnicode_Type;
!         _Py_NewReference((PyObject *)unicode);
  	if (unicode->str) {
  	    if (unicode->length < length &&
***************
*** 200,208 ****
      }
  
!     if (!unicode->str) {
!         PyMem_DEL(unicode);
!         PyErr_NoMemory();
!         return NULL;
!     }
      unicode->str[length] = 0;
      unicode->length = length;
--- 200,205 ----
      }
  
!     if (!unicode->str) 
! 	goto onError;
      unicode->str[length] = 0;
      unicode->length = length;
***************
*** 210,213 ****
--- 207,216 ----
      unicode->utf8str = NULL;
      return unicode;
+ 
+  onError:
+     _Py_ForgetReference((PyObject *)unicode);
+     PyMem_DEL(unicode);
+     PyErr_NoMemory();
+     return NULL;
  }
  
***************
*** 225,229 ****
          unicode_freelist = unicode;
          unicode_freelist_size++;
-         _Py_ForgetReference(unicode);
      }
      else {
--- 228,231 ----
***************
*** 490,494 ****
      else {
          PyErr_Format(PyExc_ValueError,
!                      "UTF-8 decoding error; unkown error handling code: %s",
                       errors);
          return -1;
--- 492,496 ----
      else {
          PyErr_Format(PyExc_ValueError,
!                      "UTF-8 decoding error; unknown error handling code: %s",
                       errors);
          return -1;
***************
*** 612,616 ****
  	PyErr_Format(PyExc_ValueError,
  		     "UTF-8 encoding error; "
! 		     "unkown error handling code: %s",
  		     errors);
  	return -1;
--- 614,618 ----
  	PyErr_Format(PyExc_ValueError,
  		     "UTF-8 encoding error; "
! 		     "unknown error handling code: %s",
  		     errors);
  	return -1;
***************
*** 734,738 ****
      else {
          PyErr_Format(PyExc_ValueError,
!                      "UTF-16 decoding error; unkown error handling code: %s",
                       errors);
          return -1;
--- 736,740 ----
      else {
          PyErr_Format(PyExc_ValueError,
!                      "UTF-16 decoding error; unknown error handling code: %s",
                       errors);
          return -1;
***************
*** 922,926 ****
          PyErr_Format(PyExc_ValueError,
                       "Unicode-Escape decoding error; "
!                      "unkown error handling code: %s",
                       errors);
          return -1;
--- 924,928 ----
          PyErr_Format(PyExc_ValueError,
                       "Unicode-Escape decoding error; "
!                      "unknown error handling code: %s",
                       errors);
          return -1;
***************
*** 1052,1055 ****
--- 1054,1061 ----
  */
  
+ static const Py_UNICODE *findchar(const Py_UNICODE *s,
+ 				  int size,
+ 				  Py_UNICODE ch);
+ 
  static
  PyObject *unicodeescape_string(const Py_UNICODE *s,
***************
*** 1070,1076 ****
  
      if (quotes) {
-         static const Py_UNICODE *findchar(const Py_UNICODE *s,
- 					  int size,
- 					  Py_UNICODE ch);
          *p++ = 'u';
          *p++ = (findchar(s, size, '\'') && 
--- 1076,1079 ----
***************
*** 1299,1303 ****
  	PyErr_Format(PyExc_ValueError,
  		     "Latin-1 encoding error; "
! 		     "unkown error handling code: %s",
  		     errors);
  	return -1;
--- 1302,1306 ----
  	PyErr_Format(PyExc_ValueError,
  		     "Latin-1 encoding error; "
! 		     "unknown error handling code: %s",
  		     errors);
  	return -1;
***************
*** 1370,1374 ****
  	PyErr_Format(PyExc_ValueError,
  		     "ASCII decoding error; "
! 		     "unkown error handling code: %s",
  		     errors);
  	return -1;
--- 1373,1377 ----
  	PyErr_Format(PyExc_ValueError,
  		     "ASCII decoding error; "
! 		     "unknown error handling code: %s",
  		     errors);
  	return -1;
***************
*** 1432,1436 ****
  	PyErr_Format(PyExc_ValueError,
  		     "ASCII encoding error; "
! 		     "unkown error handling code: %s",
  		     errors);
  	return -1;
--- 1435,1439 ----
  	PyErr_Format(PyExc_ValueError,
  		     "ASCII encoding error; "
! 		     "unknown error handling code: %s",
  		     errors);
  	return -1;
***************
*** 1503,1507 ****
  	PyErr_Format(PyExc_ValueError,
  		     "charmap decoding error; "
! 		     "unkown error handling code: %s",
  		     errors);
  	return -1;
--- 1506,1510 ----
  	PyErr_Format(PyExc_ValueError,
  		     "charmap decoding error; "
! 		     "unknown error handling code: %s",
  		     errors);
  	return -1;
***************
*** 1619,1623 ****
  	PyErr_Format(PyExc_ValueError,
  		     "charmap encoding error; "
! 		     "unkown error handling code: %s",
  		     errors);
  	return -1;
--- 1622,1626 ----
  	PyErr_Format(PyExc_ValueError,
  		     "charmap encoding error; "
! 		     "unknown error handling code: %s",
  		     errors);
  	return -1;
***************
*** 1751,1755 ****
  	PyErr_Format(PyExc_ValueError,
  		     "translate error; "
! 		     "unkown error handling code: %s",
  		     errors);
  	return -1;
--- 1754,1758 ----
  	PyErr_Format(PyExc_ValueError,
  		     "translate error; "
! 		     "unknown error handling code: %s",
  		     errors);
  	return -1;