Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r92472:d350c77746fc
Date: 2017-09-26 08:46 +0200
http://bitbucket.org/pypy/pypy/changeset/d350c77746fc/

Log:    PyLong_FromUnicodeObject()

diff --git a/pypy/module/cpyext/longobject.py b/pypy/module/cpyext/longobject.py
--- a/pypy/module/cpyext/longobject.py
+++ b/pypy/module/cpyext/longobject.py
@@ -201,6 +201,10 @@
     for the conversion.  The radix must be in the range [2, 36]; if it is
     out of range, ValueError will be raised."""
     w_value = space.newunicode(rffi.wcharpsize2unicode(u, length))
+    return PyLong_FromUnicodeObject(space, w_value, base)
+
+@cpython_api([PyObject, rffi.INT_real], PyObject)
+def PyLong_FromUnicodeObject(space, w_value, base):
     w_base = space.newint(rffi.cast(lltype.Signed, base))
     return space.call_function(space.w_long, w_value, w_base)
 
diff --git a/pypy/module/cpyext/test/test_longobject.py 
b/pypy/module/cpyext/test/test_longobject.py
--- a/pypy/module/cpyext/test/test_longobject.py
+++ b/pypy/module/cpyext/test/test_longobject.py
@@ -272,6 +272,19 @@
         # A string with arabic digits. 'BAD' is after the 6th character.
         assert module.from_unicode(u'  1\u0662\u0663\u0664BAD') == (1234, 4660)
 
+    def test_fromunicodeobject(self):
+        module = self.import_extension('foo', [
+            ("from_unicodeobject", "METH_O",
+             """
+                 return Py_BuildValue("NN",
+                     PyLong_FromUnicodeObject(args, 10),
+                     PyLong_FromUnicodeObject(args, 16));
+             """),
+            ])
+        # A string with arabic digits.
+        assert (module.from_unicodeobject(u'  1\u0662\u0663\u0664')
+                == (1234, 4660))
+
     def test_aslong(self):
         module = self.import_extension('foo', [
             ("as_long", "METH_O",
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to