Skip to content Skip to sidebar Skip to footer

How To Call A C-api Function Such As Pyunicode_read_char From Cython?

I'm using Cython to speed up a function that operates over a string (unicode, CPython 3.6). How do I call CPython's Py_UCS4 val = PyUnicode_READ_CHAR(my_string, my_index) from my C

Solution 1:

Cython doesn't wrap the whole CPython's C-API in cpython.*-headers, only the most important part. If a function is not wrapped, it can be always done on the fly, e.g.:

#instead of from cpython.unicode cimport PyUnicode_READ_CHAR
cdef externfrom *:
    Py_UCS4 PyUnicode_READ_CHAR(object o, Py_ssize_t index)

After that the function can be used in Cython.

Post a Comment for "How To Call A C-api Function Such As Pyunicode_read_char From Cython?"