diff --git a/lib/cm-impl.h b/lib/cm-impl.h index ea7644fbce9c66046021e7ae4611c7e90eb3b537..9146df69a5e6c1a5fd15395d8da1a270ffd00055 100644 --- a/lib/cm-impl.h +++ b/lib/cm-impl.h @@ -35,25 +35,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <unistd.h> /* for usleep */ #include <mpi.h> #endif -#include <pari/pari.h> #include "cm.h" -#ifdef HAVE_FLINT -/* Work around what looks like bug in flint-3, see - https://github.com/flintlib/flint2/issues/1390 - https://github.com/flintlib/flint2/issues/1391 - None of the undefined constants are used in CM, so it does not matter - that they end up as FLINT specific values. */ -#undef ulong -#undef PACKAGE_BUGREPORT -#undef PACKAGE_NAME -#undef PACKAGE_STRING -#undef PACKAGE_TARNAME -#undef PACKAGE_URL -#undef PACKAGE_VERSION -#include <flint/fmpz.h> -#include <flint/fmpz_mod.h> -#include <flint/fmpz_mod_poly.h> -#endif #define CM_CLASS_DATADIR "." #define CM_CLASS_TMPDIR "." @@ -150,10 +132,6 @@ extern char* cm_pari_sprintf_hfactor (int_cl_t d); #ifdef HAVE_FLINT /* functions depending on FLINT */ -void mpzx_set_fmpz_mod_poly (mpzx_ptr f, fmpz_mod_poly_t ff, - const fmpz_mod_ctx_t ctx); -void fmpz_mod_poly_set_mpzx (fmpz_mod_poly_t ff, mpzx_srcptr f, - const fmpz_mod_ctx_t ctx); extern void cm_flint_mpzx_xplusa_pow_modmod (mpzx_ptr g, unsigned long int a, mpz_srcptr e, mpzx_srcptr m, mpz_srcptr p); extern void cm_flint_mpzx_gcd_mod (mpzx_ptr h, mpzx_srcptr f, mpzx_srcptr g, diff --git a/lib/cm.h b/lib/cm.h index b9dea11b4396b2bbf1dd43145c243cd786dd8684..9a03c687016fe0d27dcdc437d5652a84856a8bbc 100644 --- a/lib/cm.h +++ b/lib/cm.h @@ -291,10 +291,18 @@ extern bool cm_param_init (cm_param_ptr param, int_cl_t d, char invariant, int maxdeg, int subfield, bool verbose); /* functions depending on PARI */ +extern void cm_pari_print_library (void); extern void cm_pari_init (void); extern void cm_pari_clear (void); extern bool cm_pari_eval_int (mpz_ptr n, char *e); +/* functions depending on FLINT */ +#ifdef HAVE_FLINT +extern void cm_flint_print_library (void); +extern void cm_flint_init (void); +extern void cm_flint_clear (void); +#endif + /* functions for class polynomials */ extern void cm_class_init (cm_class_ptr c, cm_param_srcptr param, bool verbose); diff --git a/lib/flint.c b/lib/flint.c index fc5d71266308d86831f8d56b56a2621d20bd61a0..7a625d2a28bb022b789244bc6bee8e8098a6dd15 100644 --- a/lib/flint.c +++ b/lib/flint.c @@ -20,9 +20,28 @@ You should have received a copy of the GNU General Public License along with CM; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + #include "cm-impl.h" #ifdef HAVE_FLINT +/* Work around what looks like a bug in flint-3, see + https://github.com/flintlib/flint2/issues/1390 + None of the undefined constants are used in CM, so it does not matter + that they end up as FLINT specific values. */ +#undef PACKAGE_BUGREPORT +#undef PACKAGE_NAME +#undef PACKAGE_STRING +#undef PACKAGE_TARNAME +#undef PACKAGE_URL +#undef PACKAGE_VERSION +#include <flint/fmpz.h> +#include <flint/fmpz_mod.h> +#include <flint/fmpz_mod_poly.h> + +static void mpzx_set_fmpz_mod_poly (mpzx_ptr f, fmpz_mod_poly_t ff, + const fmpz_mod_ctx_t ctx); +static void fmpz_mod_poly_set_mpzx (fmpz_mod_poly_t ff, mpzx_srcptr f, + const fmpz_mod_ctx_t ctx); /*****************************************************************************/ /* */ @@ -30,7 +49,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /* */ /*****************************************************************************/ -void mpzx_set_fmpz_mod_poly (mpzx_ptr f, fmpz_mod_poly_t ff, +static void mpzx_set_fmpz_mod_poly (mpzx_ptr f, fmpz_mod_poly_t ff, const fmpz_mod_ctx_t ctx) { int deg, i; @@ -50,7 +69,7 @@ void mpzx_set_fmpz_mod_poly (mpzx_ptr f, fmpz_mod_poly_t ff, /*****************************************************************************/ -void fmpz_mod_poly_set_mpzx (fmpz_mod_poly_t ff, mpzx_srcptr f, +static void fmpz_mod_poly_set_mpzx (fmpz_mod_poly_t ff, mpzx_srcptr f, const fmpz_mod_ctx_t ctx) { int deg, i; @@ -68,6 +87,32 @@ void fmpz_mod_poly_set_mpzx (fmpz_mod_poly_t ff, mpzx_srcptr f, fmpz_clear (tmp); } +/*****************************************************************************/ +/* */ +/* Various simple functions. */ +/* */ +/*****************************************************************************/ + +void cm_flint_init () +{ +} + +/*****************************************************************************/ + +void cm_flint_clear () + +{ + /* Clear FLINT cache. */ + flint_cleanup (); +} + +/*****************************************************************************/ + +void cm_flint_print_library () +{ + printf ("FLINT: include %s, lib %s\n", FLINT_VERSION, flint_version); +} + /*****************************************************************************/ /* */ /* Functions for mpzx modulo p relying on FLINT. */ diff --git a/lib/pari.c b/lib/pari.c index b3e8e070dc4c95da064cf2c9309ada655eda2dcb..f4032226c78aa9daf8e086241daa33f2c66d6eaa 100644 --- a/lib/pari.c +++ b/lib/pari.c @@ -21,6 +21,7 @@ You should have received a copy of the GNU General Public License along with CM; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include <pari/pari.h> #include "cm-impl.h" static GEN mpz_get_Z (mpz_srcptr z); @@ -159,6 +160,9 @@ void cm_pari_init () pari_init_opts (1ul<<23, 0, INIT_JMPm | INIT_DFTm); /* Do not capture SIGSEGV. */ paristack_setsize (1ul<<23, 1ul<<31); +#ifdef HAVE_FLINT + cm_flint_init (); +#endif } /*****************************************************************************/ @@ -168,13 +172,30 @@ void cm_pari_clear () { pari_close (); #ifdef HAVE_FLINT - /* Clear FLINT cache. */ - flint_cleanup (); + cm_flint_clear (); #endif } /*****************************************************************************/ +void cm_pari_print_library () +{ + pari_sp av; + GEN v; + + av = avma; + + v = pari_version (); + printf ("PARI: include %i.%li.%li, lib %li.%li.%li\n", + PARI_VERSION_CODE >> 16, (PARI_VERSION_CODE >> 8) & 255ul, + PARI_VERSION_CODE & 255ul, + itos (gel (v, 1)), itos (gel (v, 2)), itos (gel (v, 3))); + + avma = av; +} + +/*****************************************************************************/ + bool cm_pari_eval_int (mpz_ptr n, char *e) /* If the PARI expression e evaluates to a t_INT, set n to this integer and return true; otherwise keep n unchanged and return false. */ diff --git a/src/params.c b/src/params.c index efc9eacfca3e8f7125b62eb8347b0c54be04f21d..d80b09b74780e4185724c3116cae94b27fe39192 100644 --- a/src/params.c +++ b/src/params.c @@ -2,7 +2,7 @@ params.c - command line parameter evaluation -Copyright (C) 2009, 2010, 2021, 2022 Andreas Enge +Copyright (C) 2009, 2010, 2021, 2022, 2023 Andreas Enge This file is part of CM. @@ -154,7 +154,6 @@ static void print_help_ecpp (void) static void print_libraries (void) { - GEN v; printf ("CM: include %s, lib %s\n", CM_VERSION_STRING, cm_get_version ()); printf ("GMP: include %d.%d.%d, lib %s\n", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL, @@ -166,13 +165,9 @@ static void print_libraries (void) mpc_get_version ()); printf ("MPFRCX: include %s, lib %s\n", MPFRCX_VERSION_STRING, mpfrcx_get_version ()); - v = pari_version (); - printf ("PARI: include %i.%li.%li, lib %li.%li.%li\n", - PARI_VERSION_CODE >> 16, (PARI_VERSION_CODE >> 8) & 255ul, - PARI_VERSION_CODE & 255ul, - itos (gel (v, 1)), itos (gel (v, 2)), itos (gel (v, 3))); + cm_pari_print_library (); #ifdef HAVE_FLINT - printf ("FLINT: include %s, lib %s\n", FLINT_VERSION, flint_version); + cm_flint_print_library (); #endif fflush (stdout); } diff --git a/src/params.h b/src/params.h index cf0f04cf577437df2f0022979a8604c536849770..adee2ffb1f3ace1617462c32f6e22c893ad268cf 100644 --- a/src/params.h +++ b/src/params.h @@ -2,7 +2,7 @@ params.h - header file for params.c -Copyright (C) 2009, 2010, 2015, 2021, 2022 Andreas Enge +Copyright (C) 2009, 2010, 2015, 2021, 2022, 2023 Andreas Enge This file is part of CM. @@ -24,7 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef __PARAMS_H #define __PARAMS_H -#include <pari/pari.h> #include <string.h> #include <getopt.h> #include "cm-impl.h"