[pypy-svn] r73411 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test

trundle at codespeak.net trundle at codespeak.net
Mon Apr 5 16:08:45 CEST 2010


Author: trundle
Date: Mon Apr  5 16:08:44 2010
New Revision: 73411

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/test/test_unicodeobject.py
   pypy/branch/cpython-extension/pypy/module/cpyext/unicodeobject.py
Log:
Fix PyUnicode_GET_DATA_SIZE and PyUnicode_GET_SIZE.



Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_unicodeobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_unicodeobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_unicodeobject.py	Mon Apr  5 16:08:44 2010
@@ -5,7 +5,9 @@
 
 class TestUnicode(BaseApiTest):
     def test_unicodeobject(self, space, api):
-        assert space.unwrap(api.PyUnicode_GET_SIZE(space.wrap(u'späm'))) == 4
+        assert api.PyUnicode_GET_SIZE(space.wrap(u'späm')) == 4
+        # XXX assuming UCS-4
+        assert api.PyUnicode_GET_DATA_SIZE(space.wrap(u'späm')) == 16
 
     def test_AS_DATA(self, space, api):
         word = space.wrap(u'spam')

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/unicodeobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/unicodeobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/unicodeobject.py	Mon Apr  5 16:08:44 2010
@@ -71,7 +71,7 @@
 def PyUnicode_GET_DATA_SIZE(space, obj):
     """Return the size of the object's internal buffer in bytes.  o has to be a
     PyUnicodeObject (not checked)."""
-    return rffi.sizeof(lltype.UniChar) * (PyUnicode_GET_SIZE(space, obj) + 1)
+    return rffi.sizeof(lltype.UniChar) * PyUnicode_GET_SIZE(space, obj)
 
 @cpython_api([PyObject], Py_ssize_t, error=CANNOT_FAIL)
 def PyUnicode_GET_SIZE(space, w_obj):
@@ -81,4 +81,4 @@
     This function returned an int type. This might require changes
     in your code for properly supporting 64-bit systems."""
     assert isinstance(w_obj, unicodeobject.W_UnicodeObject)
-    return space.len(w_obj)
+    return space.int_w(space.len(w_obj))



More information about the Pypy-commit mailing list