r_pythonapi.pyx 422 Bytes
Newer Older
1
__doc__ = u"""
2
    >>> x = spam()
Stefan Behnel's avatar
Stefan Behnel committed
3
    >>> print(repr(x))
4
    u'Ftang\\x00Ftang!'
5 6
"""

Stefan Behnel's avatar
Stefan Behnel committed
7
import sys
8 9
if sys.version_info[0] >= 3:
    __doc__ = __doc__.replace(u" u'", u" '")
Stefan Behnel's avatar
Stefan Behnel committed
10

11 12 13
cdef extern from "string.h":
    void memcpy(char *d, char *s, int n)

14
from cpython cimport PyUnicode_DecodeUTF8
15

16 17 18
def spam():
    cdef char buf[12]
    memcpy(buf, "Ftang\0Ftang!", sizeof(buf))
19
    return PyUnicode_DecodeUTF8(buf, sizeof(buf), NULL)