[pypy-issue] [issue1241] [cpyext] PyUnicode_Tailmatch() fails to match with high end bounds

Stefan Behnel tracker at bugs.pypy.org
Sat Aug 25 12:03:46 CEST 2012


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

Here we go:

"""
diff -r 028b65a5a45f pypy/module/cpyext/test/test_unicodeobject.py
--- a/pypy/module/cpyext/test/test_unicodeobject.py     Wed Aug 22 19:57:33 2012
+0200
+++ b/pypy/module/cpyext/test/test_unicodeobject.py     Sat Aug 25 12:02:58 2012
+0200
@@ -496,11 +496,15 @@
         assert api.PyUnicode_Tailmatch(w_str, space.wrap("cde"), 2, 4, -1) == 0
# ends at 'd'
         assert api.PyUnicode_Tailmatch(w_str, space.wrap("cde"), 1, 6, -1) == 0
# starts at 'b'
         assert api.PyUnicode_Tailmatch(w_str, space.wrap("cdf"), 2, 6, -1) == 0
+        assert api.PyUnicode_Tailmatch(w_str, space.wrap("abc"), -10, 6, -1) == 1
+        assert api.PyUnicode_Tailmatch(w_str, space.wrap("abc"), -10, 60, -1) == 1
         # suffix match
         assert api.PyUnicode_Tailmatch(w_str, space.wrap("cde"), 1, 5,  1) == 1
         assert api.PyUnicode_Tailmatch(w_str, space.wrap("cde"), 3, 5,  1) == 0
# starts at 'd'
         assert api.PyUnicode_Tailmatch(w_str, space.wrap("cde"), 1, 6,  1) == 0
# ends at 'f'
         assert api.PyUnicode_Tailmatch(w_str, space.wrap("bde"), 1, 5,  1) == 0
+        assert api.PyUnicode_Tailmatch(w_str, space.wrap("def"), 1, 99,  1) == 1
+        assert api.PyUnicode_Tailmatch(w_str, space.wrap("def"), -99, 99,  1) == 1
         # type checks
         self.raises(space, api, TypeError,
                     api.PyUnicode_Tailmatch, w_str, space.wrap(3), 2, 10, 1)
"""

CPython (3.3) uses this internally:

"""
#define ADJUST_INDICES(start, end, len)         \
    if (end > len)                              \
        end = len;                              \
    else if (end < 0) {                         \
        end += len;                             \
        if (end < 0)                            \
            end = 0;                            \
    }                                           \
    if (start < 0) {                            \
        start += len;                           \
        if (start < 0)                          \
            start = 0;                          \
    }

[...]
    ADJUST_INDICES(start, end, PyUnicode_GET_LENGTH(self));
"""

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


More information about the pypy-issue mailing list