cython

Форк
0
/
cpdef_extern_func.pyx 
43 строки · 1.0 Кб
1
# cython: c_string_type=str
2
# cython: c_string_encoding=ascii
3

4
__doc__ = """
5
>>> sqrt(1)
6
1.0
7
>>> pyx_sqrt(4)
8
2.0
9
>>> pxd_sqrt(9)
10
3.0
11

12
>>> log(10)  # doctest: +ELLIPSIS
13
Traceback (most recent call last):
14
NameError: ...name 'log' is not defined
15

16
>>> my_strchr('abcabc', ord('c'))
17
'cabc'
18
>>> my_strchr(needle=ord('c'), haystack='abcabc')
19
'cabc'
20

21
>>> strchr('abcabc', ord('c'))
22
'cabc'
23
>>> strchr(needle=ord('c'), haystack='abcabc')
24
'cabc'
25
"""
26

27
cdef extern from "math.h":
28
    cpdef double sqrt(double)
29
    cpdef double pyx_sqrt "sqrt"(double)
30
    cdef double log(double) # not wrapped
31

32
cdef extern from "string.h":
33
    """
34
    /* The return type of strchr differs between C and C++.
35
       This test is not interested in that, so create a wrapper function
36
       with a known return type.
37
    */
38
    static const char* my_strchr(const char *haystack, int needle) {
39
        return strchr(haystack, needle);
40
    }
41
    """
42
    cpdef const char* my_strchr(const char *haystack, int needle)
43
    cpdef const char* strchr "my_strchr" (const char *haystack, int needle)
44

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.