[pypy-commit] pypy default: PyLong_FromUnicode: Add support for the "base" parameter.

amauryfa noreply at buildbot.pypy.org
Thu Apr 2 22:35:01 CEST 2015


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r76692:d8d5f2097351
Date: 2015-04-02 22:35 +0200
http://bitbucket.org/pypy/pypy/changeset/d8d5f2097351/

Log:	PyLong_FromUnicode: Add support for the "base" parameter.

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
@@ -194,7 +194,8 @@
     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.wrap(rffi.wcharpsize2unicode(u, length))
-    return space.call_function(space.w_long, w_value)
+    w_base = space.wrap(rffi.cast(lltype.Signed, base))
+    return space.call_function(space.w_long, w_value, w_base)
 
 @cpython_api([rffi.VOIDP], PyObject)
 def PyLong_FromVoidPtr(space, p):
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
@@ -185,9 +185,11 @@
             ("from_unicode", "METH_O",
              """
                  Py_UNICODE* u = PyUnicode_AsUnicode(args);
-                 return PyLong_FromUnicode(u, 6, 10);
+                 return Py_BuildValue("NN",
+                     PyLong_FromUnicode(u, 6, 10),
+                     PyLong_FromUnicode(u, 6, 16));
              """),
             ])
         # A string with arabic digits. 'BAD' is after the 6th character.
-        assert module.from_unicode(u'  1\u0662\u0663\u0664BAD') == 1234
+        assert module.from_unicode(u'  1\u0662\u0663\u0664BAD') == (1234, 4660)
 


More information about the pypy-commit mailing list