File: cysignals_example.pyx

package info (click to toggle)
cysignals 1.3.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 504 kB
  • sloc: ansic: 485; python: 442; makefile: 300; sh: 41
file content (25 lines) | stat: -rw-r--r-- 657 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
include "cysignals/signals.pxi"
include "cysignals/memory.pxi"

from libc.math cimport sin

def sine_sum(double x, long count):
    cdef double s = 0
    cdef long i
    for i in range(count):
        sig_check()
        s += sin(i*x)
    return s

cdef long* safe_range_long(long count) except? NULL:
    """
    This function can be safely called within a sig_on block.

    With an ordinary malloc, this is not the case since the internal
    state of the heap would be messed up if an interrupt happens during
    malloc().
    """
    cdef long* a = <long*>check_allocarray(count, sizeof(long))
    for i in range(count):
        a[i] = i
    return a