cython icon indicating copy to clipboard operation
cython copied to clipboard

Improve detection of C complex.h

Open da-woods opened this issue 2 years ago • 3 comments

The existing check didn't really work (but I've left it...). I think it's based on the quote:

POSIX recommends checking if the macro _Imaginary_I is defined to identify imaginary number support.

My reading is that this is a way to determine if a special imaginary type exists, but only after including the header. Until you've included complex.h the macro won't be defined anyway.

From C11 there's a feature macro to determine if complex.h exists so I've used that as the main way of detecting it.

In principle this could be backported to 0.29.x, but I don't think it should be.

I've also fixed a couple of existing bugs that this exposed:

  • integer complex types can't be handled by C (or C++ in principle) so must use the Cython implementation
  • extern typedef complex types can't be handled by C so must use the Cython implementation

da-woods avatar Sep 12 '22 06:09 da-woods

Fixes https://github.com/cython/cython/issues/2513

da-woods avatar Sep 12 '22 06:09 da-woods

The bug in "complex_int_T446" - neither C or C++ directly support complex integer types (practically C++ will probably work because it's just a template, but it isn't required to by the standard). Therefore I think Cython has to use its own definition for these. That requires a little restructure of the utility code (which can happen, but not immediately)

da-woods avatar Sep 12 '22 19:09 da-woods

Similarly for complex_extern_GH1433 the issue is

typedef npy_float64 _Complex __pyx_t_npy_float64_complex;

It doesn't look like you can create a complex typedef of a complex (both GCC and clang agree on this) so again this is likely to have to fall back on the Cython utility code version here.

da-woods avatar Sep 12 '22 19:09 da-woods