1# distutils: language = c++ 2# cython: language_level = 3 3 4from cysignals.signals cimport sig_check 5from cysignals.memory cimport check_allocarray 6 7 8def recip_sum(long count): 9 cdef double s = 0 10 cdef long i 11 for i in range(1, count + 1): 12 sig_check() 13 s += 1 / <double>i 14 return s 15 16 17cdef long* safe_range_long(long count) except? NULL: 18 """ 19 This function can be safely called within a sig_on block. 20 21 With an ordinary malloc, this is not the case since the internal 22 state of the heap would be messed up if an interrupt happens during 23 malloc(). 24 """ 25 cdef long* a = <long*>check_allocarray(count, sizeof(long)) 26 for i in range(count): 27 a[i] = i 28 return a 29