Skip to content

Clean-up interface of COEFF_TO_PTR and COEFF_IS_MPZ? #2555

@user202729

Description

@user202729

Is your feature request related to a problem? Please describe.
Currently, COEFF_TO_PTR is supposed to take in a fmpz = slong instead of a fmpz_t = fmpz[1], but if you accidentally pass a fmpz_t into it, it will still compile, but does the wrong thing (usually segmentation fault) later.

COEFF_IS_MPZ has a similar issue, but at least it will compile error instead of segmentation fault.

In addition to the segmentation fault, this leads to code of the form

    fmpz c = *f;

    if (!COEFF_IS_MPZ(c))    /* f is small */

Describe the solution you'd like
I suggest doing one of the following

  • Use _Generic macro (requires C11 or later) to make it accept both fmpz and fmpz_t.
  • make them a FLINT_FORCE_INLINE function to allow type checking.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions