@@ -14,6 +14,7 @@ from flint.types.fmpz_vec cimport fmpz_vec
1414
1515from flint.types.nmod cimport nmod
1616
17+ from flint.flintlib.flint cimport FLINT_BITS
1718from flint.flintlib.fmpz cimport fmpz_set
1819from flint.flintlib.nmod_mpoly cimport (
1920 nmod_mpoly_add,
@@ -690,18 +691,22 @@ cdef class nmod_mpoly(flint_mpoly):
690691 elif nargs > nvars:
691692 raise ValueError("more arguments provided than variables")
692693
694+ args = [int (x) for x in args]
695+
693696 cdef:
697+ # Using sizeof(ulong ) here breaks on 64 windows machines because of the `ctypedef unsigned long ulong` in
698+ # flintlib/flint.pxd. Cython will inline this definition and then allocate the wrong amount of memory.
699+ ulong *vals = < ulong * > libc.stdlib.malloc(nargs * (FLINT_BITS // 4 ))
694700 ulong res
695- ulong *V = < ulong * > libc.stdlib.malloc(len (args) * sizeof(ulong))
696- if V is NULL:
701+ if vals is NULL:
697702 raise MemoryError("malloc returned a null pointer") # pragma: no cover
698703
699704 try:
700- for i in range(len( args ) ):
701- V [i] = args[i]
702- res = nmod_mpoly_evaluate_all_ui(self .val, V , self .ctx.val)
705+ for i in range(nargs ):
706+ vals [i] = args[i]
707+ res = nmod_mpoly_evaluate_all_ui(self .val, vals , self .ctx.val)
703708 finally :
704- libc.stdlib.free(V )
709+ libc.stdlib.free(vals )
705710
706711 return res
707712
@@ -895,7 +900,7 @@ cdef class nmod_mpoly(flint_mpoly):
895900 nmod_mpoly res
896901 nmod_mpoly_ctx res_ctx
897902 nmod_mpoly_vec C
898- slong i , nvars = self .ctx.nvars(), nargs = len (args)
903+ slong nvars = self .ctx.nvars(), nargs = len (args)
899904
900905 if nargs < nvars:
901906 raise ValueError("not enough arguments provided")
0 commit comments