[Patches] _PyUnicode_New

Vladimir Marangozov Vladimir.Marangozov@inrialpes.fr
Sat, 17 Jun 2000 21:58:48 +0200 (CEST)


This patch fixes an optimisation mystery in _PyUnicodeNew causing segfaults
on AIX when the interpreter is compiled with -O.

-- 
       Vladimir MARANGOZOV          | Vladimir.Marangozov@inrialpes.fr
http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252

--

Disclaimer:

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.

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.

-------------------------------[ cut here ]---------------------------
*** unicodeobject.c-orig	Sat Jun 17 21:36:34 2000
--- unicodeobject.c	Sat Jun 17 21:37:19 2000
***************
*** 213,221 ****
      /* Unicode freelist & memory allocation */
      if (unicode_freelist) {
          unicode = unicode_freelist;
!         unicode_freelist = *(PyUnicodeObject **)unicode_freelist;
          unicode_freelist_size--;
- 	PyObject_INIT(unicode, &PyUnicode_Type);
  	if (unicode->str) {
  	    /* Keep-Alive optimization: we only upsize the buffer,
  	       never downsize it. */
--- 213,220 ----
      /* Unicode freelist & memory allocation */
      if (unicode_freelist) {
          unicode = unicode_freelist;
!         unicode_freelist = *(PyUnicodeObject **)unicode;
          unicode_freelist_size--;
  	if (unicode->str) {
  	    /* Keep-Alive optimization: we only upsize the buffer,
  	       never downsize it. */
***************
*** 225,232 ****
  		goto onError;
  	    }
  	}
! 	else
  	    unicode->str = PyMem_NEW(Py_UNICODE, length + 1);
      }
      else {
          unicode = PyObject_NEW(PyUnicodeObject, &PyUnicode_Type);
--- 224,233 ----
  		goto onError;
  	    }
  	}
! 	else {
  	    unicode->str = PyMem_NEW(Py_UNICODE, length + 1);
+ 	}
+ 	PyObject_INIT(unicode, &PyUnicode_Type);
      }
      else {
          unicode = PyObject_NEW(PyUnicodeObject, &PyUnicode_Type);