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

agaynor at codespeak.net agaynor at codespeak.net
Sun Mar 28 00:23:02 CET 2010


Author: agaynor
Date: Sun Mar 28 00:23:00 2010
New Revision: 73002

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/stringobject.py
   pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
   pypy/branch/cpython-extension/pypy/module/cpyext/test/test_stringobject.py
Log:
Implement PyString_Check.

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/stringobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/stringobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/stringobject.py	Sun Mar 28 00:23:00 2010
@@ -1,8 +1,18 @@
 from pypy.rpython.lltypesystem import rffi, lltype
 from pypy.module.cpyext.api import cpython_api, PyObject, PyVarObjectFields, \
-    PyStringObject, Py_ssize_t, cpython_struct, make_ref, from_ref
+    PyStringObject, Py_ssize_t, cpython_struct, make_ref, from_ref, CANNOT_FAIL, \
+    general_check
 
 
+ at cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
+def PyString_Check(space, w_obj):
+    """Return true if the object o is a string object or an instance of a subtype of
+    the string type.
+    
+    Allowed subtypes to be accepted."""
+    w_type = space.w_str
+    return general_check(space, w_obj, w_type)
+
 @cpython_api([rffi.CCHARP, Py_ssize_t], PyStringObject, error=lltype.nullptr(PyStringObject.TO))
 def PyString_FromStringAndSize(space, char_p, length):
     if char_p:

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	Sun Mar 28 00:23:00 2010
@@ -5274,14 +5274,6 @@
     raise NotImplementedError
 
 @cpython_api([PyObject], rffi.INT_real)
-def PyString_Check(space, o):
-    """Return true if the object o is a string object or an instance of a subtype of
-    the string type.
-    
-    Allowed subtypes to be accepted."""
-    raise NotImplementedError
-
- at cpython_api([PyObject], rffi.INT_real)
 def PyString_CheckExact(space, o):
     """Return true if the object o is a string object, but not an instance of a
     subtype of the string type.

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_stringobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_stringobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_stringobject.py	Sun Mar 28 00:23:00 2010
@@ -41,11 +41,18 @@
                  Py_DECREF(f);
                  return NULL;
              """),
+             ("test_is_string", "METH_VARARGS",
+             """
+                return PyBool_FromLong(PyString_Check(PyTuple_GetItem(args, 0)));
+             """),
             ])
         assert module.get_hello1() == 'Hello world'
         assert module.get_hello2() == 'Hello world'
         assert module.test_Size()
         raises(TypeError, module.test_Size_exception)
+    
+        assert module.test_is_string("")
+        assert not module.test_is_string(())
 
     def test_string_buffer_init(self):
         module = self.import_extension('foo', [



More information about the Pypy-commit mailing list