Skip to content

Commit 8f8ec55

Browse files
committed
Simplify type() method
1 parent 0e63371 commit 8f8ec55

File tree

1 file changed

+1
-41
lines changed

1 file changed

+1
-41
lines changed

cypari2/gen.pyx

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4654,47 +4654,7 @@ cdef class Gen(Gen_auto):
46544654
>>> pari('oo').type()
46554655
't_INFINITY'
46564656
"""
4657-
# The following original code leaks memory:
4658-
# return str(type_name(typ(self.g)))
4659-
#
4660-
# This code is the usual workaround:
4661-
# cdef char* s= <char*>type_name(typ(self.g))
4662-
# t=str(s)
4663-
# free(s)
4664-
# return(t)
4665-
# However, it causes segfaults with t_INTs on some
4666-
# machines, and errors about freeing non-aligned
4667-
# pointers on others. So we settle for the following
4668-
# fast but ugly code. Note that should the list of
4669-
# valid PARI types ever be updated, this code would
4670-
# need to be updated accordingly.
4671-
#
4672-
cdef long t = typ(self.g)
4673-
4674-
if t == t_INT: return 't_INT'
4675-
elif t == t_REAL: return 't_REAL'
4676-
elif t == t_INTMOD: return 't_INTMOD'
4677-
elif t == t_FRAC: return 't_FRAC'
4678-
elif t == t_FFELT: return 't_FFELT'
4679-
elif t == t_COMPLEX: return 't_COMPLEX'
4680-
elif t == t_PADIC: return 't_PADIC'
4681-
elif t == t_QUAD: return 't_QUAD'
4682-
elif t == t_POLMOD: return 't_POLMOD'
4683-
elif t == t_POL: return 't_POL'
4684-
elif t == t_SER: return 't_SER'
4685-
elif t == t_RFRAC: return 't_RFRAC'
4686-
elif t == t_QFR: return 't_QFR'
4687-
elif t == t_QFI: return 't_QFI'
4688-
elif t == t_VEC: return 't_VEC'
4689-
elif t == t_COL: return 't_COL'
4690-
elif t == t_MAT: return 't_MAT'
4691-
elif t == t_LIST: return 't_LIST'
4692-
elif t == t_STR: return 't_STR'
4693-
elif t == t_VECSMALL: return 't_VECSMALL'
4694-
elif t == t_CLOSURE: return 't_CLOSURE'
4695-
elif t == t_INFINITY: return 't_INFINITY'
4696-
else:
4697-
raise TypeError("Unknown PARI type: %s" % t)
4657+
return to_string(type_name(typ(self.g)))
46984658

46994659
def polinterpolate(self, ya, x):
47004660
"""

0 commit comments

Comments
 (0)