How to use the cython.cfunc function in Cython

To help you get started, we’ve selected a few Cython examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cython / cython / tests / errors / pure_errors.py View on Github external
@cython.cfunc
@cython.nogil(False)
@cython.locals(x=cython.int)
@cython.returns(cython.int)
def cdef_nogil_false(x):
    return x + 1
github cython / cython / tests / run / pure_py.py View on Github external
@cython.cfunc
@cython.returns(cython.long)
@cython.exceptval(-1)
def cdef_except(x):
    if x == 0:
        raise ValueError
    return x+1
github cython / cython / tests / run / pure_py3.py View on Github external
@cython.cfunc
@cython.inline
def cdef_inline(x) -> cython.double:
    return x + 1
github cython / cython / tests / run / purecdef.py View on Github external
        @cython.cfunc
        def f(self, a):
            return a*10
github Kozea / tinycss2 / tinycss2 / tokenizer.py View on Github external
@cython.cfunc
@cython.locals(
    css=cython.unicode,
    c=cython.Py_UCS4,
    start_pos=cython.Py_ssize_t,
    pos=cython.Py_ssize_t,
    length=cython.Py_ssize_t,
    chunks=cython.list,
)
def _consume_url(css, pos):
    """Return (unescaped_url, new_pos)

    The given pos is assumed to be just after the '(' of 'url('.

    """
    length = len(css)
    # http://dev.w3.org/csswg/css-syntax/#consume-a-url-token
github Kozea / tinycss2 / tinycss2 / tokenizer.py View on Github external
@cython.cfunc
@cython.locals(
    css=cython.unicode,
    c=cython.Py_UCS4,
    pos=cython.Py_ssize_t,
    codepoint=cython.int,
)
def _consume_escape(css, pos):
    r"""Return (unescaped_char, new_pos).

    Assumes a valid escape: pos is just after '\' and not followed by '\n'.

    """
    # http://dev.w3.org/csswg/css-syntax/#consume-an-escaped-character
    hex_match = _HEX_ESCAPE_RE.match(css, pos)
    if hex_match:
        codepoint = int(hex_match.group(1), 16)
github cython / cython / Cython / Compiler / Pythran.py View on Github external
@cython.cfunc
def _index_access(index_code, indices):
    indexing = ",".join([index_code(idx) for idx in indices])
    return ('[%s]' if len(indices) == 1 else '(%s)') % indexing
github Kozea / tinycss2 / tinycss2 / tokenizer.py View on Github external
@cython.cfunc
@cython.locals(
    css=cython.unicode,
    c=cython.Py_UCS4,
    start_pos=cython.Py_ssize_t,
    pos=cython.Py_ssize_t,
    length=cython.Py_ssize_t,
    max_pos=cython.Py_ssize_t,
)
def _consume_unicode_range(css, pos):
    """Return (range, new_pos)

    The given pos is assume to be just after the '+' of 'U+' or 'u+'.

    """
    # http://dev.w3.org/csswg/css-syntax/#consume-a-unicode-range-token
    length = len(css)
github Kozea / tinycss2 / tinycss2 / tokenizer.py View on Github external
@cython.cfunc
@cython.locals(
    css=cython.unicode,
    c=cython.Py_UCS4,
    start_pos=cython.Py_ssize_t,
    pos=cython.Py_ssize_t,
    length=cython.Py_ssize_t,
    chunks=cython.list,
)
def _consume_ident(css, pos):
    """Return (unescaped_value, new_pos).

    Assumes pos starts at a valid identifier. See :func:`_is_ident_start`.

    """
    # http://dev.w3.org/csswg/css-syntax/#consume-a-name
    chunks = []
github cython / cython / Cython / Compiler / Pythran.py View on Github external
@cython.cfunc
def type_remove_ref(ty):
    return "typename std::remove_reference<%s>::type" % ty