1cdef extern from "verbatiminclude.h": 2 long cube(long) 3 4cdef extern from *: 5 """ 6 static long square(long x) 7 { 8 return x * x; 9 } 10 """ 11 long square(long) 12 13 14cdef extern from "verbatiminclude.h": 15 "typedef int myint;" 16 ctypedef int myint 17 18cdef extern from "verbatiminclude.h": 19 "#undef long" 20 21 22cdef class C: 23 cdef myint val 24 25 26cdef extern from "Python.h": 27 """ 28 #define my_SET_SIZE(obj, size) __Pyx_SET_SIZE(obj, size) 29 """ 30 void my_SET_SIZE(object, Py_ssize_t) 31 32 33def test_square(x): 34 """ 35 >>> test_square(4) 36 16 37 """ 38 return square(x) 39 40 41def test_cube(x): 42 """ 43 >>> test_cube(4) 44 64 45 """ 46 return cube(x) 47 48 49def test_class(): 50 """ 51 >>> test_class() 52 42 53 """ 54 cdef C x = C() 55 x.val = 42 56 return x.val 57 58 59def test_set_size(x, size): 60 # This function manipulates Python objects in a bad way, so we 61 # do not call it. The real test is that it compiles. 62 my_SET_SIZE(x, size) 63