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

trundle at codespeak.net trundle at codespeak.net
Mon Apr 5 02:22:57 CEST 2010


Author: trundle
Date: Mon Apr  5 02:22:55 2010
New Revision: 73395

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
   pypy/branch/cpython-extension/pypy/module/cpyext/test/test_unicodeobject.py
   pypy/branch/cpython-extension/pypy/module/cpyext/unicodeobject.py
Log:
Add PyUnicode_GET_SIZE.


Modified: pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py	Mon Apr  5 02:22:55 2010
@@ -5654,15 +5654,6 @@
     raise NotImplementedError
 
 @cpython_api([PyObject], Py_ssize_t)
-def PyUnicode_GET_SIZE(space, o):
-    """Return the size of the object.  o has to be a PyUnicodeObject (not
-    checked).
-    
-    This function returned an int type. This might require changes
-    in your code for properly supporting 64-bit systems."""
-    raise NotImplementedError
-
- at cpython_api([PyObject], Py_ssize_t)
 def PyUnicode_GET_DATA_SIZE(space, o):
     """Return the size of the object's internal buffer in bytes.  o has to be a
     PyUnicodeObject (not checked).

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 02:22:55 2010
@@ -2,6 +2,9 @@
 from pypy.module.cpyext.test.test_api import BaseApiTest
 
 class TestUnicode(BaseApiTest):
+    def test_unicodeobject(self, space, api):
+        assert space.unwrap(api.PyUnicode_GET_SIZE(space.wrap(u'späm'))) == 4
+
     def test_IS(self, space, api):
         for char in [0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x1c, 0x1d, 0x1e, 0x1f,
                      0x20, 0x85, 0xa0, 0x1680, 0x2000, 0x2001, 0x2002,

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 02:22:55 2010
@@ -1,6 +1,9 @@
 from pypy.rpython.lltypesystem import rffi
 from pypy.module.unicodedata import unicodedb_4_1_0 as unicodedb
-from pypy.module.cpyext.api import CANNOT_FAIL, build_type_checkers, cpython_api
+from pypy.module.cpyext.api import (CANNOT_FAIL, Py_ssize_t,
+                                    build_type_checkers, cpython_api)
+from pypy.module.cpyext.pyobject import PyObject
+from pypy.objspace.std import unicodeobject
 
 PyUnicode_Check, PyUnicode_CheckExact = build_type_checkers("Unicode", "w_unicode")
 
@@ -51,3 +54,13 @@
 def Py_UNICODE_TOLOWER(space, w_ch):
     """Return the character ch converted to lower case."""
     return unicodedb.tolower(w_ch)
+
+ at cpython_api([PyObject], Py_ssize_t, error=CANNOT_FAIL)
+def PyUnicode_GET_SIZE(space, w_obj):
+    """Return the size of the object.  o has to be a PyUnicodeObject (not
+    checked).
+
+    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)



More information about the Pypy-commit mailing list