[pypy-commit] pypy null_byte_after_str: Revert a few places where it doesn't really help. This is also an

arigo pypy.commits at gmail.com
Tue Aug 2 09:26:05 EDT 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: null_byte_after_str
Changeset: r85986:f4cf210c8a79
Date: 2016-08-02 15:16 +0200
http://bitbucket.org/pypy/pypy/changeset/f4cf210c8a79/

Log:	Revert a few places where it doesn't really help. This is also an
	attempt to avoid obscure bugs in code that is not tested a lot.

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
@@ -126,9 +126,13 @@
         space.isinstance_w(w_s2, space.w_str)):
 
         s1, s2 = space.str_w(w_s1), space.str_w(w_s2)
-        with rffi.scoped_view_charp(s1) as s1_c:
-            with rffi.scoped_view_charp(s2) as s2_c:
-                return space.wrap(_strcoll(s1_c, s2_c))
+        s1_c = rffi.str2charp(s1)
+        s2_c = rffi.str2charp(s2)
+        try:
+            return space.wrap(_strcoll(s1_c, s2_c))
+        finally:
+            rffi.free_charp(s1_c)
+            rffi.free_charp(s2_c)
 
     s1, s2 = space.unicode_w(w_s1), space.unicode_w(w_s2)
 
@@ -151,15 +155,21 @@
     n1 = len(s) + 1
 
     buf = lltype.malloc(rffi.CCHARP.TO, n1, flavor="raw", zero=True)
-    with rffi.scoped_view_charp(s) as s_c:
+    s_c = rffi.str2charp(s)
+    try:
         n2 = _strxfrm(buf, s_c, n1) + 1
+    finally:
+        rffi.free_charp(s_c)
     if n2 > n1:
         # more space needed
         lltype.free(buf, flavor="raw")
         buf = lltype.malloc(rffi.CCHARP.TO, intmask(n2),
                             flavor="raw", zero=True)
-        with rffi.scoped_view_charp(s) as s_c:
+        s_c = rffi.str2charp(s)
+        try:
             _strxfrm(buf, s_c, n2)
+        finally:
+            rffi.free_charp(s_c)
 
     val = rffi.charp2str(buf)
     lltype.free(buf, flavor="raw")
@@ -188,8 +198,11 @@
     def gettext(space, msg):
         """gettext(msg) -> string
         Return translation of msg."""
-        with rffi.scoped_view_charp(msg) as msg_c:
+        msg_c = rffi.str2charp(msg)
+        try:
             return space.wrap(rffi.charp2str(_gettext(msg_c)))
+        finally:
+            rffi.free_charp(msg_c)
 
     _dgettext = rlocale.external('dgettext', [rffi.CCHARP, rffi.CCHARP], rffi.CCHARP)
 
@@ -199,21 +212,28 @@
         Return translation of msg in domain."""
         if space.is_w(w_domain, space.w_None):
             domain = None
-            with rffi.scoped_view_charp(msg) as msg_c:
+            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:
             domain = space.str_w(w_domain)
-            with rffi.scoped_view_charp(domain) as domain_c:
-                with rffi.scoped_view_charp(msg) as msg_c:
-                    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)
+            domain_c = rffi.str2charp(domain)
+            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(result)
 
@@ -227,22 +247,29 @@
 
         if space.is_w(w_domain, space.w_None):
             domain = None
-            with rffi.scoped_view_charp(msg) as msg_c:
+            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:
             domain = space.str_w(w_domain)
-            with rffi.scoped_view_charp(domain) as domain_c:
-                with rffi.scoped_view_charp(msg) as msg_c:
-                    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)
+            domain_c = rffi.str2charp(domain)
+            msg_c = rffi.str2charp(msg)
+            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(result)
 
@@ -259,12 +286,15 @@
             result = rffi.charp2str(result)
         else:
             domain = space.str_w(w_domain)
-            with rffi.scoped_view_charp(domain) as domain_c:
+            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(result)
 
@@ -279,13 +309,20 @@
 
         if space.is_w(w_dir, space.w_None):
             dir = None
-            with rffi.scoped_view_charp(domain) as domain_c:
+            domain_c = rffi.str2charp(domain)
+            try:
                 dirname = _bindtextdomain(domain_c, dir)
+            finally:
+                rffi.free_charp(domain_c)
         else:
             dir = space.str_w(w_dir)
-            with rffi.scoped_view_charp(domain) as domain_c:
-                with rffi.scoped_view_charp(dir) as dir_c:
-                    dirname = _bindtextdomain(domain_c, dir_c)
+            domain_c = rffi.str2charp(domain)
+            dir_c = rffi.str2charp(dir)
+            try:
+                dirname = _bindtextdomain(domain_c, dir_c)
+            finally:
+                rffi.free_charp(domain_c)
+                rffi.free_charp(dir_c)
 
         if not dirname:
             errno = rposix.get_saved_errno()
@@ -303,13 +340,20 @@
 
             if space.is_w(w_codeset, space.w_None):
                 codeset = None
-                with rffi.scoped_view_charp(domain) as domain_c:
+                domain_c = rffi.str2charp(domain)
+                try:
                     result = _bind_textdomain_codeset(domain_c, codeset)
+                finally:
+                    rffi.free_charp(domain_c)
             else:
                 codeset = space.str_w(w_codeset)
-                with rffi.scoped_view_charp(domain) as domain_c:
-                    with rffi.scoped_view_charp(codeset) as codeset_c:
-                        result = _bind_textdomain_codeset(domain_c, codeset_c)
+                domain_c = rffi.str2charp(domain)
+                codeset_c = rffi.str2charp(codeset)
+                try:
+                    result = _bind_textdomain_codeset(domain_c, codeset_c)
+                finally:
+                    rffi.free_charp(domain_c)
+                    rffi.free_charp(codeset_c)
 
             if not result:
                 return space.w_None
diff --git a/pypy/module/_pypyjson/interp_decoder.py b/pypy/module/_pypyjson/interp_decoder.py
--- a/pypy/module/_pypyjson/interp_decoder.py
+++ b/pypy/module/_pypyjson/interp_decoder.py
@@ -52,13 +52,13 @@
         # 1) we automatically get the '\0' sentinel at the end of the string,
         #    which means that we never have to check for the "end of string"
         # 2) we can pass the buffer directly to strtod
-        self.ll_chars, self.buf_flag = rffi.get_nonmovingbuffer_final_null(s)
+        self.ll_chars = rffi.str2charp(s)
         self.end_ptr = lltype.malloc(rffi.CCHARPP.TO, 1, flavor='raw')
         self.pos = 0
         self.last_type = TYPE_UNKNOWN
 
     def close(self):
-        rffi.free_nonmovingbuffer(self.s, self.ll_chars, self.buf_flag)
+        rffi.free_charp(self.ll_chars)
         lltype.free(self.end_ptr, flavor='raw')
 
     def getslice(self, start, end):
diff --git a/pypy/module/_winreg/interp_winreg.py b/pypy/module/_winreg/interp_winreg.py
--- a/pypy/module/_winreg/interp_winreg.py
+++ b/pypy/module/_winreg/interp_winreg.py
@@ -218,7 +218,7 @@
         subkey = None
     else:
         subkey = space.str_w(w_subkey)
-    with rffi.scoped_view_charp(value) as dataptr:
+    with rffi.scoped_str2charp(value) as dataptr:
         ret = rwinreg.RegSetValue(hkey, subkey, rwinreg.REG_SZ, dataptr, len(value))
         if ret != 0:
             raiseWindowsError(space, ret, 'RegSetValue')
diff --git a/rpython/rlib/_os_support.py b/rpython/rlib/_os_support.py
--- a/rpython/rlib/_os_support.py
+++ b/rpython/rlib/_os_support.py
@@ -20,7 +20,6 @@
     charp2str = staticmethod(rffi.charp2str)
     charpsize2str = staticmethod(rffi.charpsize2str)
     scoped_str2charp = staticmethod(rffi.scoped_str2charp)
-    scoped_view_charp = staticmethod(rffi.scoped_view_charp)
     str2charp = staticmethod(rffi.str2charp)
     free_charp = staticmethod(rffi.free_charp)
     scoped_alloc_buffer = staticmethod(rffi.scoped_alloc_buffer)
@@ -56,8 +55,6 @@
     charpsize2str = staticmethod(rffi.wcharpsize2unicode)
     str2charp = staticmethod(rffi.unicode2wcharp)
     scoped_str2charp = staticmethod(rffi.scoped_unicode2wcharp)
-    scoped_view_charp = staticmethod(rffi.scoped_unicode2wcharp)
-    # ^^^ XXX there is no unicode variant of rffi.scoped_view_charp
     free_charp = staticmethod(rffi.free_wcharp)
     scoped_alloc_buffer = staticmethod(rffi.scoped_alloc_unicodebuffer)
 
diff --git a/rpython/rlib/rposix_environ.py b/rpython/rlib/rposix_environ.py
--- a/rpython/rlib/rposix_environ.py
+++ b/rpython/rlib/rposix_environ.py
@@ -163,7 +163,7 @@
         return result
 
     def getenv_llimpl(name):
-        with traits.scoped_view_charp(name) as l_name:
+        with traits.scoped_str2charp(name) as l_name:
             l_result = getenv(l_name)
             return traits.charp2str(l_result) if l_result else None
 
@@ -206,7 +206,7 @@
                                   save_err=rffi.RFFI_SAVE_ERRNO)
 
     def unsetenv_llimpl(name):
-        with rffi.scoped_view_charp(name) as l_name:
+        with rffi.scoped_str2charp(name) as l_name:
             error = rffi.cast(lltype.Signed, os_unsetenv(l_name))
         if error:
             from rpython.rlib import rposix
diff --git a/rpython/rlib/rsocket.py b/rpython/rlib/rsocket.py
--- a/rpython/rlib/rsocket.py
+++ b/rpython/rlib/rsocket.py
@@ -963,7 +963,7 @@
         self.settimeout(timeout)
 
     def setsockopt(self, level, option, value):
-        with rffi.scoped_view_charp(value) as buf:
+        with rffi.scoped_str2charp(value) as buf:
             res = _c.socketsetsockopt(self.fd, level, option,
                                       rffi.cast(rffi.VOIDP, buf),
                                       len(value))


More information about the pypy-commit mailing list