[Python-checkins] CVS: python/dist/src/Objects unicodeobject.c,2.103,2.104

M.-A. Lemburg lemburg@users.sourceforge.net
Wed, 25 Jul 2001 09:06:01 -0700


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

Modified Files:
	unicodeobject.c 
Log Message:
Fix for bug #444493: u'\U00010001' segfaults with current CVS on
wide builds.



Index: unicodeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/unicodeobject.c,v
retrieving revision 2.103
retrieving revision 2.104
diff -C2 -d -r2.103 -r2.104
*** unicodeobject.c	2001/07/20 17:39:11	2.103
--- unicodeobject.c	2001/07/25 16:05:59	2.104
***************
*** 1416,1420 ****
      PyObject *repr;
      char *p;
-     char *q;
  
      static const char *hexdigit = "0123456789abcdef";
--- 1416,1419 ----
***************
*** 1424,1428 ****
          return NULL;
  
!     p = q = PyString_AS_STRING(repr);
  
      if (quotes) {
--- 1423,1427 ----
          return NULL;
  
!     p = PyString_AS_STRING(repr);
  
      if (quotes) {
***************
*** 1433,1444 ****
      while (size-- > 0) {
          Py_UNICODE ch = *s++;
          /* Escape quotes */
!         if (quotes && (ch == (Py_UNICODE) q[1] || ch == '\\')) {
              *p++ = '\\';
              *p++ = (char) ch;
          } 
  #ifdef Py_UNICODE_WIDE
          /* Map 21-bit characters to '\U00xxxxxx' */
          else if (ch >= 0x10000) {
              *p++ = '\\';
              *p++ = 'U';
--- 1432,1455 ----
      while (size-- > 0) {
          Py_UNICODE ch = *s++;
+ 
          /* Escape quotes */
!         if (quotes && 
! 	    (ch == (Py_UNICODE) PyString_AS_STRING(repr)[1] || ch == '\\')) {
              *p++ = '\\';
              *p++ = (char) ch;
          } 
+ 
  #ifdef Py_UNICODE_WIDE
          /* Map 21-bit characters to '\U00xxxxxx' */
          else if (ch >= 0x10000) {
+ 	    int offset = p - PyString_AS_STRING(repr);
+ 	    
+ 	    /* Resize the string if necessary */
+ 	    if (offset + 12 > PyString_GET_SIZE(repr)) {
+ 		if (_PyString_Resize(&repr, PyString_GET_SIZE(repr) + 100))
+ 		    goto onError;
+ 		p = PyString_AS_STRING(repr) + offset;
+ 	    }
+ 
              *p++ = '\\';
              *p++ = 'U';
***************
*** 1450,1454 ****
              *p++ = hexdigit[(ch >> 8) & 0x0000000F];
              *p++ = hexdigit[(ch >> 4) & 0x0000000F];
!             *p++ = hexdigit[ch & 15];
          }
  #endif
--- 1461,1466 ----
              *p++ = hexdigit[(ch >> 8) & 0x0000000F];
              *p++ = hexdigit[(ch >> 4) & 0x0000000F];
!             *p++ = hexdigit[ch & 0x0000000F];
! 	    continue;
          }
  #endif
***************
*** 1488,1491 ****
--- 1500,1504 ----
              *p++ = hexdigit[ch & 0x000F];
          }
+ 
          /* Map special whitespace to '\t', \n', '\r' */
          else if (ch == '\t') {
***************
*** 1501,1504 ****
--- 1514,1518 ----
              *p++ = 'r';
          }
+ 
          /* Map non-printable US ASCII to '\xhh' */
          else if (ch < ' ' || ch >= 128) {
***************
*** 1508,1511 ****
--- 1522,1526 ----
              *p++ = hexdigit[ch & 0x000F];
          } 
+ 
          /* Copy everything else as-is */
          else
***************
*** 1513,1520 ****
      }
      if (quotes)
!         *p++ = q[1];
  
      *p = '\0';
!     if (_PyString_Resize(&repr, p - q))
  	goto onError;
  
--- 1528,1535 ----
      }
      if (quotes)
!         *p++ = PyString_AS_STRING(repr)[1];
  
      *p = '\0';
!     if (_PyString_Resize(&repr, p - PyString_AS_STRING(repr)))
  	goto onError;