[pypy-commit] pypy py3.6: merge default into branch, use unicodehelper.wcharpsize2utf8 which can raise

mattip pypy.commits at gmail.com
Wed Feb 20 02:47:46 EST 2019


Author: Matti Picus <matti.picus at gmail.com>
Branch: py3.6
Changeset: r96105:8c13dfd0c64b
Date: 2019-02-20 09:15 +0200
http://bitbucket.org/pypy/pypy/changeset/8c13dfd0c64b/

Log:	merge default into branch, use unicodehelper.wcharpsize2utf8 which
	can raise

diff --git a/pypy/interpreter/unicodehelper.py b/pypy/interpreter/unicodehelper.py
--- a/pypy/interpreter/unicodehelper.py
+++ b/pypy/interpreter/unicodehelper.py
@@ -660,14 +660,14 @@
 def wcharpsize2utf8(space, wcharp, size):
     """Safe version of rffi.wcharpsize2utf8.
 
-    Raises app-level ValueError if any wchar value is outside the valid
+    Raises app-level rutf8.OutOfRange if any wchar value is outside the valid
     codepoint range.
     """
     try:
         return rffi.wcharpsize2utf8(wcharp, size)
-    except ValueError:
+    except rutf8.OutOfRange as e:
         raise oefmt(space.w_ValueError,
-            "character is not in range [U+0000; U+10ffff]")
+            "character %s is not in range [U+0000; U+10ffff]", 'U+%x' % e.code)
 
 
 # ____________________________________________________________
diff --git a/pypy/module/cpyext/unicodeobject.py b/pypy/module/cpyext/unicodeobject.py
--- a/pypy/module/cpyext/unicodeobject.py
+++ b/pypy/module/cpyext/unicodeobject.py
@@ -88,14 +88,10 @@
 def unicode_realize(space, py_obj):
     """
     Creates the unicode in the interpreter. The PyUnicodeObject buffer must not
-    be modified after this call.
+    be modified after this call. Can raise in wcharpsize2utf8
     """
     lgt = get_wsize(py_obj)
-    try:
-        s_utf8 = rffi.wcharpsize2utf8(get_wbuffer(py_obj), lgt)
-    except rutf8.OutOfRange as e:
-        raise oefmt(space.w_ValueError,
-                   'character U+%x is not in range [U+0000; U+10ffff]' % e.code)
+    s_utf8 = wcharpsize2utf8(space, get_wbuffer(py_obj), lgt)
     w_type = from_ref(space, rffi.cast(PyObject, py_obj.c_ob_type))
     w_obj = space.allocate_instance(unicodeobject.W_UnicodeObject, w_type)
     w_obj.__init__(s_utf8, lgt)
@@ -300,8 +296,8 @@
             maxchar = c
             if maxchar > MAX_UNICODE:
                 raise oefmt(space.w_ValueError,
-                    "Character U+%d is not in range [U+0000; U+10ffff]",
-                    maxchar)
+                    "Character U+%s is not in range [U+0000; U+10ffff]",
+                    '%x' % maxchar)
     if maxchar < 256:
         ucs1_data = rffi.str2charp(value)
         set_data(py_obj, cts.cast('void*', ucs1_data))
@@ -916,7 +912,7 @@
 
     Returns 0 on success, -1 on failure.
     """
-    u = rffi.wcharpsize2utf8(s, length)
+    u = wcharpsize2utf8(space, s, length)
     if llerrors:
         errors = rffi.charp2str(llerrors)
     else:


More information about the pypy-commit mailing list