[pypy-svn] pypy default: (iko, rguillebert, arigo)

arigo commits-noreply at bitbucket.org
Thu Apr 28 17:46:42 CEST 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r43726:79fa6adbce6c
Date: 2011-04-28 17:45 +0200
http://bitbucket.org/pypy/pypy/changeset/79fa6adbce6c/

Log:	(iko, rguillebert, arigo)

	Fix interp_locale to call charp2str() before freeing some apparently
	unrelated string, because the string may turn out to not be
	unrelated after all.

diff --git a/pypy/module/_locale/interp_locale.py b/pypy/module/_locale/interp_locale.py
--- a/pypy/module/_locale/interp_locale.py
+++ b/pypy/module/_locale/interp_locale.py
@@ -221,6 +221,10 @@
             msg_c = rffi.str2charp(msg)
             try:
                 result = _dgettext(domain, msg_c)
+                # note that 'result' may be the same pointer as 'msg_c',
+                # so it must be converted to an RPython string *before*
+                # we free msg_c.
+                result = rffi.charp2str(result)
             finally:
                 rffi.free_charp(msg_c)
         else:
@@ -229,11 +233,15 @@
             msg_c = rffi.str2charp(msg)
             try:
                 result = _dgettext(domain_c, msg_c)
+                # note that 'result' may be the same pointer as 'msg_c',
+                # so it must be converted to an RPython string *before*
+                # we free msg_c.
+                result = rffi.charp2str(result)
             finally:
                 rffi.free_charp(domain_c)
                 rffi.free_charp(msg_c)
 
-        return space.wrap(rffi.charp2str(result))
+        return space.wrap(result)
 
     _dcgettext = rlocale.external('dcgettext', [rffi.CCHARP, rffi.CCHARP, rffi.INT],
                                                                 rffi.CCHARP)
@@ -248,6 +256,10 @@
             msg_c = rffi.str2charp(msg)
             try:
                 result = _dcgettext(domain, msg_c, rffi.cast(rffi.INT, category))
+                # note that 'result' may be the same pointer as 'msg_c',
+                # so it must be converted to an RPython string *before*
+                # we free msg_c.
+                result = rffi.charp2str(result)
             finally:
                 rffi.free_charp(msg_c)
         else:
@@ -257,11 +269,15 @@
             try:
                 result = _dcgettext(domain_c, msg_c,
                                     rffi.cast(rffi.INT, category))
+                # note that 'result' may be the same pointer as 'msg_c',
+                # so it must be converted to an RPython string *before*
+                # we free msg_c.
+                result = rffi.charp2str(result)
             finally:
                 rffi.free_charp(domain_c)
                 rffi.free_charp(msg_c)
 
-        return space.wrap(rffi.charp2str(result))
+        return space.wrap(result)
 
 
     _textdomain = rlocale.external('textdomain', [rffi.CCHARP], rffi.CCHARP)
@@ -273,15 +289,20 @@
         if space.is_w(w_domain, space.w_None):
             domain = None
             result = _textdomain(domain)
+            result = rffi.charp2str(result)
         else:
             domain = space.str_w(w_domain)
             domain_c = rffi.str2charp(domain)
             try:
                 result = _textdomain(domain_c)
+                # note that 'result' may be the same pointer as 'domain_c'
+                # (maybe?) so it must be converted to an RPython string
+                # *before* we free domain_c.
+                result = rffi.charp2str(result)
             finally:
                 rffi.free_charp(domain_c)
 
-        return space.wrap(rffi.charp2str(result))
+        return space.wrap(result)
 
     _bindtextdomain = rlocale.external('bindtextdomain', [rffi.CCHARP, rffi.CCHARP],
                                                                 rffi.CCHARP)

diff --git a/lib_pypy/_locale.py b/lib_pypy/_locale.py
--- a/lib_pypy/_locale.py
+++ b/lib_pypy/_locale.py
@@ -1,4 +1,9 @@
 # ctypes implementation of _locale module by Victor Stinner, 2008-03-27
+
+# ------------------------------------------------------------
+#  Note that we also have our own interp-level implementation
+# ------------------------------------------------------------
+
 """
 Support for POSIX locales.
 """


More information about the Pypy-commit mailing list