atilaneves / dpp

Directly include C headers in D source code
Boost Software License 1.0
231 stars 31 forks source link

Wrong function argument type translation #282

Open dataPulverizer opened 3 years ago

dataPulverizer commented 3 years ago

Hello,

I am trying to call the fftw3 library using dpp however there is an issue with type translation in particular with function definitions. Within the C library mentioned, consider the function fftw_plan_dft_1d, within the library documentation the type signature is:

fftw_plan fftw_plan_dft_1d(int n, fftw_complex *in, fftw_complex *out,
                           int sign, unsigned flags);

where fftw_complex is defined by

typedef double fftw_complex[2];

The dpp library correctly converts the type fftw_complex as

alias fftw_complex = double[2];

however incorrectly converts the function signature to:

fftw_plan_s* fftw_plan_dft_1d(int, double**, double**, int, uint)

and the compiler gives an error:

Error: function `fftw_plan_dft_1d(int, double**, double**, int, uint)` is not 
          callable using argument types `(int, double[2]*, double[2]*, int, uint)`

Though double* is a generalization of double[2] in this case the substitution is undesirable, not only because it contravenes Data Type Compatibiity as defined in D's spec, and prevents the programmer from using the correct type alias for fftw_complex which is actually safer, but also because it looses type information, and where it to be the case where it inserted the correct aternative double[2] for fftw_complex some flexibility in controlling the behaviour of fftw_complex over the whole library is lost. Also attemping to using double* as fftw_complex could cause the function not to work at all (this has happened to me).

For me the issue is not a show stopper because I'm using dstep and direct translation methods.

All the best.

Thank you

atilaneves commented 3 years ago

Oof. I never thought I'd see pointers to arrays in actual production C code as opposed to examples, even if it's hidden behind a typedef.