Skip to content

Commit

Permalink
Merge pull request #160 from tornaria/implicit_noexcept
Browse files Browse the repository at this point in the history
Add missing noexcept clauses
  • Loading branch information
mkoeppe committed Mar 16, 2024
2 parents b4d154d + 07528a6 commit 3f64df6
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion cypari2/closure.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down
12 changes: 6 additions & 6 deletions cypari2/convert.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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))

Expand Down
4 changes: 2 additions & 2 deletions cypari2/convert.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -496,7 +496,7 @@ cdef GEN PyLong_AS_GEN(py_long x):
w += <ulong>(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)

Expand Down
2 changes: 1 addition & 1 deletion cypari2/gen.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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 <pari_sp>self.address

# The Gen objects on the PARI stack form a linked list, from the
Expand Down
2 changes: 1 addition & 1 deletion cypari2/gen.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions cypari2/handle_error.pxd
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions cypari2/handle_error.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions cypari2/pari_instance.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions cypari2/pari_instance.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -459,15 +459,15 @@ 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)
except AttributeError:
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'
Expand Down Expand Up @@ -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 (<int(*)()>before_resize)():
cdef GEN patched_parisize(const char* v, long flag) noexcept:
# Cast to `int(*)() noexcept` to avoid exception handling
if (<int(*)() noexcept>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 (<int(*)()>before_resize)():
cdef GEN patched_parisizemax(const char* v, long flag) noexcept:
# Cast to `int(*)() noexcept` to avoid exception handling
if (<int(*)() noexcept>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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cypari2/paridecl.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
8 changes: 4 additions & 4 deletions cypari2/stack.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions cypari2/stack.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ cdef Gen top_of_stack = Gen_new(gnil, NULL)
cdef PyObject* stackbottom = <PyObject*>top_of_stack


cdef void remove_from_pari_stack(Gen self):
cdef void remove_from_pari_stack(Gen self) noexcept:
global avma, stackbottom
if <PyObject*>self is not stackbottom:
print("ERROR: removing wrong instance of Gen")
Expand Down Expand Up @@ -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.
Expand All @@ -104,7 +104,7 @@ cdef void reset_avma():
avma = (<Gen>stackbottom).sp()


cdef void clear_stack():
cdef void clear_stack() noexcept:
"""
Call ``sig_off()`` and clean the PARI stack.
"""
Expand Down Expand Up @@ -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
"""
Expand Down

0 comments on commit 3f64df6

Please sign in to comment.