Skip to content

Commit

Permalink
Trac #33176: Fix a few cython "referenced before assignment" warnings
Browse files Browse the repository at this point in the history
Our build displays several warnings like

> warning: sage/libs/ntl/ntl_ZZ.pyx:274:23: local variable 'ans'
referenced before assignment

for variables that are passed by reference to a C function that
overwrites them (meaning that there is no real bug). Here we fix a few
easy ones by initializing the variable.

URL: https://trac.sagemath.org/33176
Reported by: mjo
Ticket author(s): Michael Orlitzky
Reviewer(s): Markus Wageringel, Marc Mezzarobba
  • Loading branch information
Release Manager committed Oct 30, 2022
2 parents 89af346 + 93f2e90 commit bff11ac
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/sage/libs/gap/element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ cdef Obj make_gap_string(sage_string) except NULL:
try:
GAP_Enter()
b = str_to_bytes(sage_string)
C_NEW_STRING(result, len(b), b)
result = MakeStringWithLen(b, len(b))
return result
finally:
GAP_Leave()
Expand Down
2 changes: 1 addition & 1 deletion src/sage/libs/gap/gap_includes.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,4 @@ cdef extern from "gap/stringobj.h" nogil:
bint IS_STRING(Obj obj)
bint IsStringConv(Obj obj)
Obj NEW_STRING(Int)
void C_NEW_STRING(Obj new_gap_string, int length, char* c_string)
Obj MakeStringWithLen(const char* buf, size_t len)
2 changes: 1 addition & 1 deletion src/sage/libs/ntl/ntl_ZZ.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ cdef class ntl_ZZ():
AUTHOR: David Harvey (2006-08-05)
"""
cdef int ans
cdef int ans = 0
ZZ_conv_to_int(ans, self.x)
return ans

Expand Down
4 changes: 2 additions & 2 deletions src/sage/libs/ntl/ntl_ZZ_pX.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ cdef class ntl_ZZ_pX():
"""
self.c.restore_c()
cdef ZZ_p_c r
cdef long l
cdef long l = 0
sig_on()
r = ZZ_pX_coeff( self.x, i)
ZZ_conv_to_long(l, ZZ_p_rep(r))
Expand Down Expand Up @@ -1154,7 +1154,7 @@ cdef class ntl_ZZ_pX():
ZZ_pX_Modulus_build(mod, modulus.x)
cdef ntl_ZZ_pX mod_prime
cdef ntl_ZZ_pContext_class ctx
cdef long mini, minval
cdef long mini = 0, minval = 0
if Integer(modulus[0].lift()).valuation(p) == 1:
eisenstein = True
for c in modulus.list()[1:-1]:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/libs/singular/groebner_strategy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ cdef class NCGroebnerStrategy(SageObject):
if unlikely(self._parent._ring != currRing):
rChangeCurrRing(self._parent._ring)

cdef int max_ind
cdef int max_ind = 0
cdef poly *_p = redNF(p_Copy(p._poly, self._parent._ring), max_ind, 0, self._strat)
if likely(_p!=NULL):
_p = redtailBba(_p, max_ind, self._strat)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matrix/matrix_modn_dense_template.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ cdef inline celement linbox_det(celement modulus, celement* entries, Py_ssize_t
cdef ModField *F = new ModField(<long>modulus)
cdef celement *cpy = linbox_copy(modulus, entries, n, n)

cdef celement d
cdef celement d = 0
cdef size_t nbthreads
nbthreads = Parallelism().get('linbox')

Expand Down

0 comments on commit bff11ac

Please sign in to comment.