[pypy-commit] pypy default: merge heads
arigo
noreply at buildbot.pypy.org
Fri Apr 3 14:37:48 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r76699:25109032512b
Date: 2015-04-03 14:37 +0200
http://bitbucket.org/pypy/pypy/changeset/25109032512b/
Log: merge heads
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
@@ -186,6 +186,17 @@
pend[0] = rffi.ptradd(str, len(s))
return space.call_function(space.w_long, w_str, w_base)
+ at cpython_api([rffi.CWCHARP, Py_ssize_t, rffi.INT_real], PyObject)
+def PyLong_FromUnicode(space, u, length, base):
+ """Convert a sequence of Unicode digits to a Python long integer value.
+ The first parameter, u, points to the first character of the Unicode
+ string, length gives the number of characters, and base is the radix
+ 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))
+ 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):
"""Create a Python integer or long integer from the pointer p. The pointer value
diff --git a/pypy/module/cpyext/stubs.py b/pypy/module/cpyext/stubs.py
--- a/pypy/module/cpyext/stubs.py
+++ b/pypy/module/cpyext/stubs.py
@@ -1395,18 +1395,6 @@
"""
raise NotImplementedError
- at cpython_api([rffi.CWCHARP, Py_ssize_t, rffi.INT_real], PyObject)
-def PyLong_FromUnicode(space, u, length, base):
- """Convert a sequence of Unicode digits to a Python long integer value. The first
- parameter, u, points to the first character of the Unicode string, length
- gives the number of characters, and base is the radix for the conversion. The
- radix must be in the range [2, 36]; if it is out of range, ValueError
- will be raised.
-
- This function used an int for length. This might require
- changes in your code for properly supporting 64-bit systems."""
- raise NotImplementedError
-
@cpython_api([PyObject, rffi.CCHARP], rffi.INT_real, error=-1)
def PyMapping_DelItemString(space, o, key):
"""Remove the mapping for object key from the object o. Return -1 on
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
@@ -180,3 +180,16 @@
assert module.from_bytearray(False, False) == 0xBC9A
assert module.from_bytearray(False, True) == -0x4365
+ def test_fromunicode(self):
+ module = self.import_extension('foo', [
+ ("from_unicode", "METH_O",
+ """
+ Py_UNICODE* u = PyUnicode_AsUnicode(args);
+ 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, 4660)
+
More information about the pypy-commit
mailing list