1cimport cython 2 3cdef char* c_string = b'abcdefg' 4cdef void* void_ptr = c_string 5 6cdef int i = 42 7cdef int* int_ptr = &i 8 9cdef float x = 42.2 10cdef float* float_ptr = &x 11 12def compare(): 13 """ 14 >>> compare() 15 True 16 True 17 True 18 False 19 False 20 True 21 True 22 """ 23 print c_string == c_string 24 print c_string == void_ptr 25 print c_string is void_ptr 26 print c_string != void_ptr 27 print c_string is not void_ptr 28 print void_ptr != int_ptr 29 print void_ptr != float_ptr 30 31def if_tests(): 32 """ 33 >>> if_tests() 34 True 35 True 36 """ 37 if c_string == void_ptr: 38 print True 39 if c_string != void_ptr: 40 print False 41 if int_ptr != void_ptr: 42 print True 43 44def bool_binop(): 45 """ 46 >>> bool_binop() 47 True 48 """ 49 if c_string == void_ptr and c_string == c_string and int_ptr != void_ptr and void_ptr != float_ptr: 50 print True 51 52def bool_binop_truth(int x): 53 """ 54 >>> bool_binop_truth(1) 55 True 56 True 57 >>> bool_binop_truth(0) 58 True 59 """ 60 if c_string and void_ptr and int_ptr and (c_string == c_string or int_ptr != void_ptr): 61 print True 62 if c_string and x or not (void_ptr or int_ptr and float_ptr) or x: 63 print True 64 65 66def binop_voidptr(int x, long y, char* z): 67 """ 68 >>> binop_voidptr(1, 3, b'abc') 69 'void *' 70 """ 71 result = &x and &y and z 72 return cython.typeof(result) 73 74 75def cond_expr_voidptr(int x, long y, char* z): 76 """ 77 >>> cond_expr_voidptr(0, -1, b'abc') 78 ('void *', 0) 79 >>> cond_expr_voidptr(-1, 0, b'abc') 80 ('void *', -1) 81 >>> cond_expr_voidptr(-1, 0, b'') 82 ('void *', 0) 83 >>> cond_expr_voidptr(0, -1, b'') 84 ('void *', -1) 85 """ 86 result = &x if len(z) else &y 87 assert sizeof(long) >= sizeof(int) 88 assert -1 == <int>(-1L) 89 return cython.typeof(result), (<int*>result)[0] 90