[pypy-issue] [issue1120] [cpyext] missing PyUnicode_Count() and other PyUnicode_*() functions

Stefan Behnel tracker at bugs.pypy.org
Wed Apr 11 10:28:00 CEST 2012


Stefan Behnel <stefan_ml at behnel.de> added the comment:

One issue though, the "sep" argument to PyUnicode_Split() can be NULL, the
equivalent of passing None in Python. Would this work?


diff -r 859f1579f2bd pypy/module/cpyext/test/test_unicodeobject.py
--- a/pypy/module/cpyext/test/test_unicodeobject.py     Tue Apr 10 23:19:41 2012
+0200
+++ b/pypy/module/cpyext/test/test_unicodeobject.py     Wed Apr 11 10:24:10 2012
+0200
@@ -474,11 +474,13 @@
         assert api.PyUnicode_Find(w_str, space.wrap(u"z"), 0, 4, -1) == -1
 
     def test_split(self, space, api):
-        w_str = space.wrap(u"a\nb\nc\nd")
-        assert "[u'a', u'b', u'c', u'd']" == space.unwrap(space.repr(
+        w_str = space.wrap(u"a\nb\nc\nd e")
+        assert "[u'a', u'b', u'c', u'd e']" == space.unwrap(space.repr(
                 api.PyUnicode_Split(w_str, space.wrap('\n'), -1)))
-        assert r"[u'a', u'b', u'c\nd']" == space.unwrap(space.repr(
+        assert r"[u'a', u'b', u'c\nd e']" == space.unwrap(space.repr(
                 api.PyUnicode_Split(w_str, space.wrap('\n'), 2)))
+        assert r"[u'a', u'b', u'c', u'd', u'e']" == space.unwrap(space.repr(
+                api.PyUnicode_Split(w_str, lltype.nullptr(PyObject.TO), -1)))
         assert "[u'a', u'b', u'c', u'd']" == space.unwrap(space.repr(
                 api.PyUnicode_Splitlines(w_str, 0)))
         assert r"[u'a\n', u'b\n', u'c\n', u'd']" == space.unwrap(space.repr(
diff -r 859f1579f2bd pypy/module/cpyext/unicodeobject.py
--- a/pypy/module/cpyext/unicodeobject.py       Tue Apr 10 23:19:41 2012 +0200
+++ b/pypy/module/cpyext/unicodeobject.py       Wed Apr 11 10:24:10 2012 +0200
@@ -630,6 +630,8 @@
     Otherwise, splits occur at the given separator.  At most maxsplit
     splits will be done.  If negative, no limit is set.  Separators
     are not included in the resulting list."""
+    if w_sep == lltype.nullptr(PyObject.TO):
+        w_sep = None
     return space.call_method(w_str, "split", w_sep, space.wrap(maxsplit))
 
 @cpython_api([PyObject, rffi.INT_real], PyObject)

________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue1120>
________________________________________


More information about the pypy-issue mailing list