Ticket #14080: 14080_cdefs.patch
File 14080_cdefs.patch, 8.5 KB (added by , 8 years ago) |
---|
-
sage/combinat/degree_sequences.pyx
# HG changeset patch # User Jeroen Demeyer <jdemeyer@cage.ugent.be> # Date 1360249588 -3600 # Node ID c137b6e209e3211404b6dccd1a631626c14c4425 # Parent a6fe6b3fabaeba221b0764f81e64ed3b6c8c4d11 Simplify cdefs.pxi using Cython's libc module diff --git a/sage/combinat/degree_sequences.pyx b/sage/combinat/degree_sequences.pyx
a b 372 372 Freeing the memory 373 373 """ 374 374 if seq != NULL: 375 free(seq)375 sage_free(seq) 376 376 377 377 cdef init(int n): 378 378 """ … … 387 387 elif n == 1: 388 388 return [[0]] 389 389 390 seq = <unsigned char *> malloc((n+1)*sizeof(unsigned char)) 390 sig_on() 391 seq = <unsigned char *> sage_malloc((n+1)*sizeof(unsigned char)) 391 392 memset(seq,0,(n+1)*sizeof(unsigned char)) 393 sig_off() 392 394 393 395 # We begin with one vertex of degree 0 394 396 seq[0] = 1 … … 396 398 N = n 397 399 sequences = [] 398 400 enum(1,0) 399 free(seq)401 sage_free(seq) 400 402 return sequences 401 403 402 404 cdef inline add_seq(): -
sage/ext/cdefs.pxi
diff --git a/sage/ext/cdefs.pxi b/sage/ext/cdefs.pxi
a b 1 # 2 # Declare C library functions used in Sage 3 # 1 4 2 5 include "python.pxi" 3 6 4 cdef extern from "stdlib.h": 5 void free(void *ptr) 6 void *malloc(size_t size) 7 void *realloc(void *ptr, size_t size) 8 size_t strlen(char *s) 9 char *strcpy(char *dest, char *src) 7 from libc.stdio cimport * 8 from libc.string cimport strlen, strcpy, memset, memcpy 10 9 11 cdef extern from "string.h": 12 void *memset(void *dest, int c, size_t n) 13 void *memcpy(void *dest, void *src, size_t n) 10 from libc.math cimport sqrt 11 # Cython misdeclares these: http://trac.cython.org/cython_trac/ticket/801 12 cdef extern from "<math.h>": 13 double frexp(double x, int* exponent) 14 double ldexp(double x, int exponent) 14 15 15 cdef extern from "stdio.h":16 ctypedef struct FILE17 cdef FILE *stdin18 cdef FILE *stdout19 cdef FILE *stderr20 int printf(char *format, ...)21 int fprintf(FILE *stream, char *format, ...)22 int sprintf(char *str, char *format, ...)23 FILE *fopen(char *path, char *mode)24 int fclose(FILE *stream)25 int fflush(FILE *stream)26 int scanf(char *format, ...)27 28 cdef extern from "math.h":29 double sqrt(double x)30 float roundf(float x) # linux-ish and non-standard; avoid!31 double ldexp(double x, int exp)32 double frexp(double x, int *exp)33 16 34 17 from sage.libs.gmp.all cimport * 35 cdef extern from "gmp.h": 36 pass # cython bug sometimes includes this in the wrong place 37 38 ########################################################################## 39 # stdsage.pxi declares the macros, etc., that got used a lot in SAGE. 40 ########################################################################## 41 18 cdef extern from "<gmp.h>": 19 pass # Cython bug sometimes includes this in the wrong place -
sage/ext/gmp.pxi
diff --git a/sage/ext/gmp.pxi b/sage/ext/gmp.pxi
a b 11 11 12 12 include '../ext/interrupt.pxi' 13 13 14 cimport libc.stdlib 15 14 16 ############ The following is the "one global set of vars" 15 17 cdef extern from "gmp_globals.h": 16 18 cdef mpz_t u, v, q, u0, u1, u2, v0, v1, v2, t0, t1, t2, x, y, ssqr, m2 … … 41 43 Convert a GMP integer to a Python string. 42 44 """ 43 45 cdef char *s 46 sig_on() 44 47 s = mpz_get_str(NULL, 10, x) 45 48 t = str(s) 46 free(s) 49 # Emulate sage_free() to avoid needing to include stdsage.pxi 50 sig_block() 51 libc.stdlib.free(s) 52 sig_unblock() 53 sig_off() 47 54 return t 48 55 49 56 cdef int mpz_print(mpz_t x) except -1: -
new file sage/ext/signals.pxi
diff --git a/sage/ext/signals.pxi b/sage/ext/signals.pxi new file mode 100644
- + 1 # Declare system calls related to signal handling 2 3 cdef extern from "<stdlib.h>": 4 void abort() 5 6 cdef extern from "<signal.h>": 7 ctypedef void *sigset_t 8 # Renaming of this struct is necessary because Cython folds the 9 # "struct" namespace into the normal namespace. 10 struct Sigaction "sigaction": 11 void (*sa_handler)(int) 12 sigset_t sa_mask 13 int sa_flags 14 15 int SIG_BLOCK, SIG_UNBLOCK, SIG_SETMASK 16 int SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGKILL 17 int SIGSEGV, SIGPIPE, SIGALRM, SIGTERM, SIGBUS 18 int signal_raise "raise"(int signum) 19 int sigprocmask(int how, sigset_t *set, sigset_t *oldset) 20 int sigemptyset(sigset_t *set) 21 int sigaddset(sigset_t *set, int signum) 22 int sigaction(int signum, Sigaction *act, Sigaction *oldact) 23 24 cdef extern from "<sys/time.h>": 25 struct timespec: 26 long tv_sec 27 long tv_nsec 28 29 cdef extern from "<sys/select.h>": 30 ctypedef void *fd_set 31 void FD_CLR(int fd, fd_set *set) 32 bint FD_ISSET(int fd, fd_set *set) 33 void FD_SET(int fd, fd_set *set) 34 void FD_ZERO(fd_set *set) 35 int FD_SETSIZE 36 37 int pselect(int nfds, fd_set *readfds, fd_set *writefds, 38 fd_set *exceptfds, timespec *timeout, 39 sigset_t *sigmask) -
sage/gsl/probability_distribution.pyx
diff --git a/sage/gsl/probability_distribution.pyx b/sage/gsl/probability_distribution.pyx
a b 687 687 map(float, parameters) 688 688 except StandardError: 689 689 raise TypeError, "F-distribution requires real parameters" 690 self.parameters = <double *> malloc(sizeof(double)*2)690 self.parameters = <double *>sage_malloc(sizeof(double)*2) 691 691 self.parameters[0] = float(parameters[0]) 692 692 self.parameters[1] = float(parameters[1]) 693 693 self.distribution_type = F -
sage/libs/ecl.pyx
diff --git a/sage/libs/ecl.pyx b/sage/libs/ecl.pyx
a b 14 14 #rationals to SAGE types Integer and Rational. These parts could easily be 15 15 #adapted to work with pure Python types. 16 16 17 include '../ext/interrupt.pxi' 17 include "../ext/signals.pxi" 18 include "../ext/interrupt.pxi" 18 19 include "../ext/cdefs.pxi" 19 20 20 21 from sage.rings.integer cimport Integer … … 36 37 cdef bint bint_rationalp(cl_object obj): 37 38 return not(cl_rationalp(obj) == Cnil) 38 39 39 cdef extern from "stdlib.h":40 void abort()41 42 cdef extern from "signal.h":43 int signal_raise "raise"(int sig)44 #rename of struct is necessary because cython folds the "struct" namespace45 #into the normal namespace46 struct Sigaction "sigaction":47 pass48 int sigaction(int sig, Sigaction * act, Sigaction * oact)49 int SIGINT, SIGBUS, SIGSEGV50 51 40 cdef extern from "eclsig.c": 52 41 int ecl_sig_on() except 0 53 42 void ecl_sig_off() -
sage/matrix/matrix_modn_dense_template.pxi
diff --git a/sage/matrix/matrix_modn_dense_template.pxi b/sage/matrix/matrix_modn_dense_template.pxi
a b 94 94 cdef sage.rings.fast_arith.arith_int ArithIntObj 95 95 ArithIntObj = sage.rings.fast_arith.arith_int() 96 96 97 # for copying 98 cdef extern from *: 99 void* memcpy(void* dst, void* src, long n) 100 101 # for pickling 102 cdef extern from "stdio.h": 103 int snprintf(char *str, size_t size, char *format, ...) 97 # for copying/pickling 98 from libc.string cimport memcpy 99 from libc.stdio cimport snprintf 104 100 105 101 from sage.modules.vector_modn_dense cimport Vector_modn_dense 106 102 -
sage/modular/modsym/heilbronn.pyx
diff --git a/sage/modular/modsym/heilbronn.pyx b/sage/modular/modsym/heilbronn.pyx
a b 27 27 from sage.libs.flint.flint cimport * 28 28 include "../../libs/flint/fmpz_poly.pxi" 29 29 30 cdef extern from "<math.h>": 31 float roundf(float x) 32 30 33 cimport p1list 31 34 import p1list 32 35 cdef p1list.export export -
sage/tests/interrupt.pyx
diff --git a/sage/tests/interrupt.pyx b/sage/tests/interrupt.pyx
a b 18 18 19 19 import signal 20 20 21 cdef extern from 'stdlib.h':22 void abort()23 24 cdef extern from 'signal.h':25 int SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGKILL, \26 SIGSEGV, SIGPIPE, SIGALRM, SIGTERM, SIGBUS27 28 21 cdef extern from '../tests/c_lib.h': 29 22 void ms_sleep(long ms) 30 23 void signal_after_delay(int signum, long ms) … … 34 27 ctypedef int volatile_int "volatile int" 35 28 36 29 30 include '../ext/signals.pxi' 37 31 include '../ext/interrupt.pxi' 38 32 include '../ext/stdsage.pxi' 39 33 -
setup.py
diff --git a/setup.py b/setup.py
a b 521 521 system_header_files = \ 522 522 ['complex.h', 'signal.h', 'math.h', 'limits.h', 'stdlib.h', 523 523 'arpa/inet.h', 'float.h', 'string.h', 'stdint.h', 'stdio.h', 524 'dlfcn.h', 'setjmp.h' ]524 'dlfcn.h', 'setjmp.h', 'errno.h' ] 525 525 526 526 class DependencyTree: 527 527 """