id summary reporter owner description type status priority milestone component resolution keywords cc merged author reviewer upstream work_issues branch commit dependencies stopgaps
27721 Add wrappers around flint headers in Sage embray "There is a problem in a few of the packages they use (flint is not the only one, but it is one where this specific problem is most pervasive) in that they all use the name `ulong` in some way or other. flint also has an `slong` but that does not seem to have as many conflicts.
I first reported this in #27714 but this ticket is to propose a specific fix.
I've noted this problem in at least:
* flint/flint.h:
{{{
#define ulong mp_limb_t
#define slong mp_limb_signed_t
}}}
* zn_poly/zn_poly.h:
{{{
/*
I get really sick of typing unsigned long.
*/
typedef unsigned long ulong;
}}}
* pari/parigen.h:
{{{
#ifdef _WIN64
typedef unsigned long long pari_ulong;
#define long long long
#define labs llabs
#else
typedef unsigned long pari_ulong;
#endif
#define ulong pari_ulong
}}}
And for completeness, it's worth noting these definitions from gmp.h:
{{{
#ifdef __GMP_SHORT_LIMB
typedef unsigned int mp_limb_t;
typedef int mp_limb_signed_t;
#else
#ifdef _LONG_LONG_LIMB
typedef unsigned long long int mp_limb_t;
typedef long long int mp_limb_signed_t;
#else
typedef unsigned long int mp_limb_t;
typedef long int mp_limb_signed_t;
#endif
#endif
typedef unsigned long int mp_bitcnt_t;
}}}
The problem is most evident in modules that happen to combine any two of these headers. For example in src/sage/rings/polynomial/polynomial_zmod_flint.pyx both flint.h and zn_poly.h are used. Because of the `#define ulong mp_limb_t` in flint.h, the typedef in zn_poly.h expands to: `typedef unsigned long mp_limb_t`.
Because this compiles to a C++ file this happens to be just fine most of the time because C++ allows benign re-typedefs and indeed it just happens that this is compatible with the original definition of `mp_limb_t` from gmp.h, at least most of the time.
However, as I found in #27714 that doesn't always have to be true. The GMP system package on Cygwin has GMP configured in such a way that `_LONG_LONG_LIMB` is defined, so it defines `typedef long long int mp_limb_t`, and all this fragile overloading breaks down.
I think in some sense flint is the ""worst"" problem here since it ties its `ulong` and `slong` macros to typedefs in GMP which themselves can, we now know, be platform-dependent. So this introduces a lot of problems.
I'm experimenting with adding a wrapper around all includes of flint headers in Sage in order to work around this problem, but I'd be happy to have other suggestions." defect closed critical sage-8.9 interfaces fixed jdemeyer wbhart dimpase fredrik.johansson Erik Bray Volker Braun N/A 0aa0177220205a67e4981b994f2efecdadb057ac