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

Guido van Rossum python-dev@python.org
Fri, 4 Aug 2000 08:35:38 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory slayer.i.sourceforge.net:/tmp/cvs-serv9274/Objects

Modified Files:
      Tag: cnri-16-start
	unicodeobject.c 
Log Message:
Reapply Marc-Andres patest patch in the 1.6 branch

Index: unicodeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/unicodeobject.c,v
retrieving revision 2.54.2.1
retrieving revision 2.54.2.2
diff -C2 -r2.54.2.1 -r2.54.2.2
*** unicodeobject.c	2000/08/03 16:35:00	2.54.2.1
--- unicodeobject.c	2000/08/04 15:35:36	2.54.2.2
***************
*** 167,173 ****
   reset:
      /* Reset the object caches */
!     if (unicode->utf8str) {
!         Py_DECREF(unicode->utf8str);
!         unicode->utf8str = NULL;
      }
      unicode->hash = -1;
--- 167,173 ----
   reset:
      /* Reset the object caches */
!     if (unicode->defenc) {
!         Py_DECREF(unicode->defenc);
!         unicode->defenc = NULL;
      }
      unicode->hash = -1;
***************
*** 245,249 ****
      unicode->length = length;
      unicode->hash = -1;
!     unicode->utf8str = NULL;
      return unicode;
  
--- 245,249 ----
      unicode->length = length;
      unicode->hash = -1;
!     unicode->defenc = NULL;
      return unicode;
  
***************
*** 264,270 ****
  	    unicode->length = 0;
  	}
! 	if (unicode->utf8str) {
! 	    Py_DECREF(unicode->utf8str);
! 	    unicode->utf8str = NULL;
  	}
  	/* Add to free list */
--- 264,270 ----
  	    unicode->length = 0;
  	}
! 	if (unicode->defenc) {
! 	    Py_DECREF(unicode->defenc);
! 	    unicode->defenc = NULL;
  	}
  	/* Add to free list */
***************
*** 275,279 ****
      else {
  	PyMem_DEL(unicode->str);
! 	Py_XDECREF(unicode->utf8str);
  	PyObject_DEL(unicode);
      }
--- 275,279 ----
      else {
  	PyMem_DEL(unicode->str);
! 	Py_XDECREF(unicode->defenc);
  	PyObject_DEL(unicode);
      }
***************
*** 531,534 ****
--- 531,561 ----
  }
  
+ /* Return a Python string holding the default encoded value of the
+    Unicode object. 
+ 
+    The resulting string is cached in the Unicode object for subsequent
+    usage by this function. The cached version is needed to implement
+    the character buffer interface and will live (at least) as long as
+    the Unicode object itself.
+ 
+    The refcount of the string is *not* incremented.
+ 
+    *** Exported for internal use by the interpreter only !!! ***
+ 
+ */
+ 
+ PyObject *_PyUnicode_AsDefaultEncodedString(PyObject *unicode,
+ 					    const char *errors)
+ {
+     PyObject *v = ((PyUnicodeObject *)unicode)->defenc;
+ 
+     if (v)
+         return v;
+     v = PyUnicode_AsEncodedString(unicode, NULL, errors);
+     if (v && errors == NULL)
+         ((PyUnicodeObject *)unicode)->defenc = v;
+     return v;
+ }
+ 
  Py_UNICODE *PyUnicode_AsUnicode(PyObject *unicode)
  {
***************
*** 876,908 ****
  }
  
- /* Return a Python string holding the UTF-8 encoded value of the
-    Unicode object. 
- 
-    The resulting string is cached in the Unicode object for subsequent
-    usage by this function. The cached version is needed to implement
-    the character buffer interface and will live (at least) as long as
-    the Unicode object itself.
- 
-    The refcount of the string is *not* incremented.
- 
-    *** Exported for internal use by the interpreter only !!! ***
- 
- */
- 
- PyObject *_PyUnicode_AsUTF8String(PyObject *unicode,
- 				  const char *errors)
- {
-     PyObject *v = ((PyUnicodeObject *)unicode)->utf8str;
- 
-     if (v)
-         return v;
-     v = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(unicode),
- 			     PyUnicode_GET_SIZE(unicode),
- 			     errors);
-     if (v && errors == NULL)
-         ((PyUnicodeObject *)unicode)->utf8str = v;
-     return v;
- }
- 
  PyObject *PyUnicode_AsUTF8String(PyObject *unicode)
  {
--- 903,906 ----
***************
*** 913,917 ****
          return NULL;
      }
!     str = _PyUnicode_AsUTF8String(unicode, NULL);
      if (str == NULL)
          return NULL;
--- 911,917 ----
          return NULL;
      }
!     str = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(unicode),
! 			       PyUnicode_GET_SIZE(unicode),
! 			       NULL);
      if (str == NULL)
          return NULL;
***************
*** 4521,4525 ****
          return -1;
      }
!     str = _PyUnicode_AsUTF8String((PyObject *)self, NULL);
      if (str == NULL)
  	return -1;
--- 4521,4525 ----
          return -1;
      }
!     str = _PyUnicode_AsDefaultEncodedString((PyObject *)self, NULL);
      if (str == NULL)
  	return -1;
***************
*** 5132,5136 ****
  	if (v->str)
  	    PyMem_DEL(v->str);
! 	Py_XDECREF(v->utf8str);
  	PyObject_DEL(v);
      }
--- 5132,5136 ----
  	if (v->str)
  	    PyMem_DEL(v->str);
! 	Py_XDECREF(v->defenc);
  	PyObject_DEL(v);
      }