[pypy-issue] [issue1120] [cpyext] missing PyUnicode_Count()

Stefan Behnel tracker at bugs.pypy.org
Tue Apr 10 21:37:50 CEST 2012

New submission from Stefan Behnel <stefan_ml at behnel.de>:

The C-API function PyUnicode_Count(ustring, substring, start_index, end_index)
is unimplemented (has a stub in stubs.py). It should be rather straight forward,
given that there is an equivalent ustring.count(substring, start_index,
end_index) method.

Something like this might do the trick:

@cpython_api([PyObject, PyObject, Py_ssize_t, Py_ssize_t], Py_ssize_t, error=-1)
def PyUnicode_Count(space, w_str, w_substr, start, end):
    """Return the number of non-overlapping occurrences of substr in
    str[start:end].  Return -1 if an error occurred.

    This function returned an int type and used an int
    type for start and end. This might require changes in your code for
    properly supporting 64-bit systems.

    return space.call_method(w_str, "count", w_substr,
                             space.wrap(start), space.wrap(end))

messages: 4215
nosy: pypy-issue, sbehnel
priority: bug
status: unread
title: [cpyext] missing PyUnicode_Count()

PyPy bug tracker <tracker at bugs.pypy.org>

More information about the pypy-issue mailing list