From 981c1241596fd372bdadc8b2bc25f0c59c865747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= Date: Sun, 10 Mar 2024 20:47:38 -0300 Subject: [PATCH 1/2] fix implicit noexcept warnings --- cypari2/closure.pyx | 2 +- cypari2/convert.pxd | 12 ++++++------ cypari2/convert.pyx | 2 +- cypari2/gen.pxd | 2 +- cypari2/gen.pyx | 2 +- cypari2/handle_error.pxd | 4 ++-- cypari2/handle_error.pyx | 4 ++-- cypari2/pari_instance.pxd | 6 +++--- cypari2/pari_instance.pyx | 28 ++++++++++++++-------------- cypari2/paridecl.pxd | 2 +- cypari2/stack.pxd | 8 ++++---- cypari2/stack.pyx | 8 ++++---- 12 files changed, 40 insertions(+), 40 deletions(-) diff --git a/cypari2/closure.pyx b/cypari2/closure.pyx index 7b77d67..44615fe 100644 --- a/cypari2/closure.pyx +++ b/cypari2/closure.pyx @@ -100,7 +100,7 @@ cdef extern from *: cdef GEN call_python(GEN arg1, GEN arg2, GEN arg3, GEN arg4, GEN arg5, - ulong nargs, ulong py_func): + ulong nargs, ulong py_func) noexcept: """ This function, which will be installed in PARI, is a front-end for ``call_python_func_impl``. diff --git a/cypari2/convert.pxd b/cypari2/convert.pxd index 1422511..a2b54da 100644 --- a/cypari2/convert.pxd +++ b/cypari2/convert.pxd @@ -22,7 +22,7 @@ cpdef gen_to_integer(Gen x) # Conversion C -> PARI -cdef inline GEN double_to_REAL(double x): +cdef inline GEN double_to_REAL(double x) noexcept: # PARI has an odd concept where it attempts to track the accuracy # of floating-point 0; a floating-point zero might be 0.0e-20 # (meaning roughly that it might represent any number in the @@ -42,7 +42,7 @@ cdef inline GEN double_to_REAL(double x): return dbltor(x) -cdef inline GEN doubles_to_COMPLEX(double re, double im): +cdef inline GEN doubles_to_COMPLEX(double re, double im) noexcept: cdef GEN g = cgetg(3, t_COMPLEX) if re == 0: set_gel(g, 1, gen_0) @@ -57,15 +57,15 @@ cdef inline GEN doubles_to_COMPLEX(double re, double im): # Conversion Python -> PARI -cdef inline GEN PyInt_AS_GEN(x): +cdef inline GEN PyInt_AS_GEN(x) except? NULL: return stoi(PyInt_AS_LONG(x)) -cdef GEN PyLong_AS_GEN(py_long x) +cdef GEN PyLong_AS_GEN(py_long x) noexcept -cdef inline GEN PyFloat_AS_GEN(x): +cdef inline GEN PyFloat_AS_GEN(x) except? NULL: return double_to_REAL(PyFloat_AS_DOUBLE(x)) -cdef inline GEN PyComplex_AS_GEN(x): +cdef inline GEN PyComplex_AS_GEN(x) except? NULL: return doubles_to_COMPLEX( PyComplex_RealAsDouble(x), PyComplex_ImagAsDouble(x)) diff --git a/cypari2/convert.pyx b/cypari2/convert.pyx index f6c0ca2..5c102e7 100644 --- a/cypari2/convert.pyx +++ b/cypari2/convert.pyx @@ -455,7 +455,7 @@ cdef PyLong_FromINT(GEN g): # Conversion Python -> PARI ######################################################################## -cdef GEN PyLong_AS_GEN(py_long x): +cdef GEN PyLong_AS_GEN(py_long x) noexcept: cdef const digit* D = ob_digit(x) # Size of the input diff --git a/cypari2/gen.pxd b/cypari2/gen.pxd index 2ac0669..0d51866 100644 --- a/cypari2/gen.pxd +++ b/cypari2/gen.pxd @@ -24,7 +24,7 @@ cdef class Gen(Gen_base): # memory allocated by gclone(). For constants, this is NULL. cdef GEN address - cdef inline pari_sp sp(self): + cdef inline pari_sp sp(self) noexcept: return self.address # The Gen objects on the PARI stack form a linked list, from the diff --git a/cypari2/gen.pyx b/cypari2/gen.pyx index 2a0862c..60a4b4f 100644 --- a/cypari2/gen.pyx +++ b/cypari2/gen.pyx @@ -81,7 +81,7 @@ include 'auto_gen.pxi' cdef bint ellwp_flag1_bug = -1 -cdef inline bint have_ellwp_flag1_bug(): +cdef inline bint have_ellwp_flag1_bug() except -1: """ The PARI function ``ellwp(..., flag=1)`` has a bug in PARI versions 2.9.x where the derivative is a factor 2 too small. diff --git a/cypari2/handle_error.pxd b/cypari2/handle_error.pxd index 62aa476..ef5e918 100644 --- a/cypari2/handle_error.pxd +++ b/cypari2/handle_error.pxd @@ -1,5 +1,5 @@ from .types cimport GEN -cdef void _pari_init_error_handling() +cdef void _pari_init_error_handling() noexcept cdef int _pari_err_handle(GEN E) except 0 -cdef void _pari_err_recover(long errnum) +cdef void _pari_err_recover(long errnum) noexcept diff --git a/cypari2/handle_error.pyx b/cypari2/handle_error.pyx index 6bf311b..f32664b 100644 --- a/cypari2/handle_error.pyx +++ b/cypari2/handle_error.pyx @@ -126,7 +126,7 @@ class PariError(RuntimeError): return self.errtext().rstrip(" .:") -cdef void _pari_init_error_handling(): +cdef void _pari_init_error_handling() noexcept: """ Set up our code for handling PARI errors. @@ -211,7 +211,7 @@ cdef int _pari_err_handle(GEN E) except 0: raise PariError(errnum, pari_error_string, clone_gen_noclear(E)) -cdef void _pari_err_recover(long errnum): +cdef void _pari_err_recover(long errnum) noexcept: """ Reset the error string and jump back to ``sig_on()``, either to retry the code (in case of no error) or to make the already-raised diff --git a/cypari2/pari_instance.pxd b/cypari2/pari_instance.pxd index 315122b..f239487 100644 --- a/cypari2/pari_instance.pxd +++ b/cypari2/pari_instance.pxd @@ -3,9 +3,9 @@ cimport cython from .gen cimport Gen -cpdef long prec_bits_to_words(unsigned long prec_in_bits) -cpdef long prec_words_to_bits(long prec_in_words) -cpdef long default_bitprec() +cpdef long prec_bits_to_words(unsigned long prec_in_bits) noexcept +cpdef long prec_words_to_bits(long prec_in_words) noexcept +cpdef long default_bitprec() noexcept cdef class Pari_auto: pass diff --git a/cypari2/pari_instance.pyx b/cypari2/pari_instance.pyx index 377c849..9a57fbc 100644 --- a/cypari2/pari_instance.pyx +++ b/cypari2/pari_instance.pyx @@ -334,7 +334,7 @@ def prec_dec_to_bits(long prec_in_dec): return int(prec_in_dec*log_10 + 1.0) # Add one to round up -cpdef long prec_bits_to_words(unsigned long prec_in_bits): +cpdef long prec_bits_to_words(unsigned long prec_in_bits) noexcept: r""" Convert from precision expressed in bits to pari real precision expressed in words. Note: this rounds up to the nearest word, @@ -362,7 +362,7 @@ cpdef long prec_bits_to_words(unsigned long prec_in_bits): return (prec_in_bits - 1)//wordsize + 3 -cpdef long prec_words_to_bits(long prec_in_words): +cpdef long prec_words_to_bits(long prec_in_words) noexcept: r""" Convert from pari real precision expressed in words to precision expressed in bits. Note: this adjusts for the two codewords of a @@ -385,7 +385,7 @@ cpdef long prec_words_to_bits(long prec_in_words): return (prec_in_words - 2) * BITS_IN_LONG -cpdef long default_bitprec(): +cpdef long default_bitprec() noexcept: r""" Return the default precision in bits. @@ -446,7 +446,7 @@ def prec_words_to_dec(long prec_in_words): # of C library functions like puts(). cdef PariOUT python_pariOut -cdef void python_putchar(char c): +cdef void python_putchar(char c) noexcept: cdef char s[2] s[0] = c s[1] = 0 @@ -459,7 +459,7 @@ cdef void python_putchar(char c): # so it doesn't print one when an error occurs. pari_set_last_newline(1) -cdef void python_puts(const char* s): +cdef void python_puts(const char* s) noexcept: try: # avoid string conversion if possible sys.stdout.buffer.write(s) @@ -467,7 +467,7 @@ cdef void python_puts(const char* s): sys.stdout.write(to_string(s)) pari_set_last_newline(1) -cdef void python_flush(): +cdef void python_flush() noexcept: sys.stdout.flush() include 'auto_instance.pxi' @@ -1436,22 +1436,22 @@ cdef long get_var(v) except -2: # Monkey-patched versions of default(parisize) and default(parisizemax) # which call before_resize() and after_resize(). # The monkey-patching is set up in PariInstance.__cinit__ -cdef GEN patched_parisize(const char* v, long flag): - # Cast to int(*)() to avoid exception handling - if (before_resize)(): +cdef GEN patched_parisize(const char* v, long flag) noexcept: + # Cast to `int(*)() noexcept` to avoid exception handling + if (before_resize)(): sig_error() return sd_parisize(v, flag) -cdef GEN patched_parisizemax(const char* v, long flag): - # Cast to int(*)() to avoid exception handling - if (before_resize)(): +cdef GEN patched_parisizemax(const char* v, long flag) noexcept: + # Cast to `int(*)() noexcept` to avoid exception handling + if (before_resize)(): sig_error() return sd_parisizemax(v, flag) IF HAVE_PLOT_SVG: - cdef void get_plot_ipython(PARI_plot* T): + cdef void get_plot_ipython(PARI_plot* T) noexcept: # Values copied from src/graph/plotsvg.c in PARI sources T.width = 480 T.height = 320 @@ -1462,7 +1462,7 @@ IF HAVE_PLOT_SVG: T.draw = draw_ipython - cdef void draw_ipython(PARI_plot *T, GEN w, GEN x, GEN y): + cdef void draw_ipython(PARI_plot *T, GEN w, GEN x, GEN y) noexcept: global avma cdef pari_sp av = avma cdef char* svg = rect2svg(w, x, y, T) diff --git a/cypari2/paridecl.pxd b/cypari2/paridecl.pxd index ddeb953..29cb8ef 100644 --- a/cypari2/paridecl.pxd +++ b/cypari2/paridecl.pxd @@ -5327,7 +5327,7 @@ cdef extern from *: # PARI headers already included by types.pxd # Work around a bug in PARI's is_universal_constant() -cdef inline int is_universal_constant(GEN x): +cdef inline int is_universal_constant(GEN x) noexcept: return _is_universal_constant(x) or (x is err_e_STACK) diff --git a/cypari2/stack.pxd b/cypari2/stack.pxd index 00ef3a0..1540d9b 100644 --- a/cypari2/stack.pxd +++ b/cypari2/stack.pxd @@ -8,15 +8,15 @@ cdef Gen new_gen_noclear(GEN x) cdef Gen clone_gen(GEN x) cdef Gen clone_gen_noclear(GEN x) -cdef void clear_stack() -cdef void reset_avma() +cdef void clear_stack() noexcept +cdef void reset_avma() noexcept -cdef void remove_from_pari_stack(Gen self) +cdef void remove_from_pari_stack(Gen self) noexcept cdef int move_gens_to_heap(pari_sp lim) except -1 cdef int before_resize() except -1 cdef int set_pari_stack_size(size_t size, size_t sizemax) except -1 -cdef void after_resize() +cdef void after_resize() noexcept cdef class DetachGen: diff --git a/cypari2/stack.pyx b/cypari2/stack.pyx index 5cc1dfc..04ffcca 100644 --- a/cypari2/stack.pyx +++ b/cypari2/stack.pyx @@ -48,7 +48,7 @@ cdef Gen top_of_stack = Gen_new(gnil, NULL) cdef PyObject* stackbottom = top_of_stack -cdef void remove_from_pari_stack(Gen self): +cdef void remove_from_pari_stack(Gen self) noexcept: global avma, stackbottom if self is not stackbottom: print("ERROR: removing wrong instance of Gen") @@ -91,7 +91,7 @@ cdef inline Gen Gen_stack_new(GEN x): return z -cdef void reset_avma(): +cdef void reset_avma() noexcept: """ Reset PARI stack pointer to remove unused stuff from the PARI stack. @@ -104,7 +104,7 @@ cdef void reset_avma(): avma = (stackbottom).sp() -cdef void clear_stack(): +cdef void clear_stack() noexcept: """ Call ``sig_off()`` and clean the PARI stack. """ @@ -160,7 +160,7 @@ cdef int set_pari_stack_size(size_t size, size_t sizemax) except -1: after_resize() -cdef void after_resize(): +cdef void after_resize() noexcept: """ This must be called after reallocating the PARI stack """ From 07528a6703bee206e3282c00468634ac4392730a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= Date: Sun, 10 Mar 2024 23:00:32 -0300 Subject: [PATCH 2/2] fix type to avoid size_t -> python -> size_t conversion --- cypari2/convert.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypari2/convert.pyx b/cypari2/convert.pyx index 5c102e7..667f922 100644 --- a/cypari2/convert.pyx +++ b/cypari2/convert.pyx @@ -496,7 +496,7 @@ cdef GEN PyLong_AS_GEN(py_long x) noexcept: w += (D[dgt+5]) << (5*PyLong_SHIFT - bit) # Effective size in words plus 2 special codewords - cdef pariwords = sizewords+2 if w else sizewords+1 + cdef size_t pariwords = sizewords+2 if w else sizewords+1 cdef GEN g = cgeti(pariwords) g[1] = sgn + evallgefint(pariwords)