[Patches] unicode tweaks, part 3

Fredrik Lundh Fredrik Lundh" <effbot@telia.com
Sat, 22 Apr 2000 14:44:16 +0200


This is a multi-part message in MIME format.

------=_NextPart_000_0067_01BFAC69.3C3F7B00
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

this patch must be installed on top of parts 1 and 2.

changes:

    PyUnicode_AsEncodedString and PyUnicode_AsUTF8String
    both use as_string directly, to save some code.

    fixed reference leak in _tkinter.c (AsUTF8 increments the
    reference count, despite what the name implies)

(I think most PyUnicode_As functions should be renamed to
PyUnicode_To, but I'll leave that for another patch)

this is the last part in this round.  the forth part changes
as_string to use 8-bit unicode (and puts utf8_string back
in again), but I won't post that one just yet.

</F>

I confirm that, to the best of my knowledge and belief, this =
contribution
is free of any claims of third parties under copyright, patent or
other rights or interests ("claims").  To the extent that I have
any such claims, I hereby grant to CNRI a nonexclusive, irrevocable,
royalty-free, worldwide license to reproduce, distribute, perform and/or
display publicly, prepare derivative versions, and otherwise use this
contribution as part of the Python software and its related =
documentation,
or any derivative versions thereof, at no cost to CNRI or its licensed
users, and to authorize others to do so.
        =20
I acknowledge that CNRI may, at its sole discretion, decide whether
or not to incorporate this contribution in the Python software and its
related documentation.  I further grant CNRI permission to use my name
and other identifying information provided to CNRI by me for use in
connection with the Python software and its related documentation.

------=_NextPart_000_0067_01BFAC69.3C3F7B00
Content-Type: application/octet-stream;
	name="unicode-patch-3"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="unicode-patch-3"

*** Objects/bak/unicodeobject.c	Sat Apr 22 13:24:21 2000
--- Objects/unicodeobject.c	Sat Apr 22 14:22:43 2000
***************
*** 389,398 ****
      if (!v) {
          
          /* default encoding is UTF-8 */
!         v = PyUnicode_EncodeUTF8(
!             PyUnicode_AS_UNICODE(self),
!             PyUnicode_GET_SIZE(self),
!             NULL); /* strict */
  
          /* XXX: note that if we change this to an encoding that may
             fail, the encode function will be called over and over
--- 389,397 ----
      if (!v) {
          
          /* default encoding is UTF-8 */
!         v = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(self),
!                                  PyUnicode_GET_SIZE(self),
!                                  NULL); /* strict */
  
          /* XXX: note that if we change this to an encoding that may
             fail, the encode function will be called over and over
***************
*** 474,484 ****
          PyErr_BadArgument();
          goto onError;
      }
!     /* Shortcut for the default encoding UTF-8 */
      if ((encoding == NULL || 
  	 (strcmp(encoding, "utf-8") == 0)) &&
! 	errors == NULL)
!         return PyUnicode_AsUTF8String(unicode);
  
      /* Encode via the codec registry */
      v = PyCodec_Encode(unicode, encoding, errors);
--- 473,488 ----
          PyErr_BadArgument();
          goto onError;
      }
! 
!     /* Shortcut for the built-in encoding UTF-8 */
      if ((encoding == NULL || 
  	 (strcmp(encoding, "utf-8") == 0)) &&
! 	errors == NULL) {
!         /* default encoding is UTF-8 */
!         v = as_string((PyUnicodeObject*) unicode);
!         Py_XINCREF(v);
!         return v;
!     }
  
      /* Encode via the codec registry */
      v = PyCodec_Encode(unicode, encoding, errors);
***************
*** 755,766 ****
          PyErr_BadArgument();
          return NULL;
      }
!     /* XXX: this breaks down if we change the default encoding
!        to something that isn't UTF-8 */
      str = as_string((PyUnicodeObject *)unicode);
!     if (str == NULL)
!         return NULL;
!     Py_INCREF(str);
      return str;
  }
  
--- 759,767 ----
          PyErr_BadArgument();
          return NULL;
      }
!     /* default encoding is UTF-8 */
      str = as_string((PyUnicodeObject *)unicode);
!     Py_XINCREF(str);
      return str;
  }
  
*** Modules/bak/_tkinter.c	Fri Mar 31 12:08:53 2000
--- Modules/_tkinter.c	Sat Apr 22 14:15:39 2000
***************
*** 550,560 ****
  		return result;
  	}
  	else if (PyUnicode_Check(value)) {
! 		PyObject* utf8 = PyUnicode_AsUTF8String (value);
  		if (!utf8)
  			return 0;
! 		return Tcl_NewStringObj (PyString_AS_STRING (utf8),
! 					 PyString_GET_SIZE (utf8));
  	}
  	else {
  		PyObject *v = PyObject_Str(value);
--- 550,562 ----
  		return result;
  	}
  	else if (PyUnicode_Check(value)) {
! 		PyObject* utf8 = PyUnicode_AsUTF8String(value);
  		if (!utf8)
  			return 0;
! 		result = Tcl_NewStringObj(PyString_AS_STRING(utf8),
!                                           PyString_GET_SIZE(utf8));
!                 Py_DECREF(utf8);
!                 return result;
  	}
  	else {
  		PyObject *v = PyObject_Str(value);

------=_NextPart_000_0067_01BFAC69.3C3F7B00--