Unable to define some FFI functions in libm
Hello! I am trying to use ECL's FFI functionality via CFFI. I set cffi-sys:*cffi-ecl-method* to :c/c++ and then tried to define some functions from libm using cffi:defcfun, such as:
(cffi:defcfun ("frexp" frexp)
:double
(%%x :double)
(%%exponent (:pointer :int)))
(cffi:defcfun ("frexpf" frexpf)
:float
(%%x :float)
(%%exponent (:pointer :int)))
(cffi:defcfun ("modf" modf)
:double
(%%x :double)
(%%iptr (:pointer :double)))
(cffi:defcfun ("modff" modff)
:float
(%%x :float)
(%%iptr (:pointer :float)))
(cffi:defcfun ("nan" nan) :double (%%tagb :string))
(cffi:defcfun ("nanf" nanf) :float (%%tagb :string))
(cffi:defcfun ("remquo" remquo)
:double
(%%x :double)
(%%y :double)
(%%quo (:pointer :int)))
(cffi:defcfun ("remquof" remquof)
:float
(%%x :float)
(%%y :float)
(%%quo (:pointer :int)))
The common characteristic of these functions is that they involve typed pointers in their arguments or return values. As I read the manual, I found that in ECL, the FFI pointer type seems to be only :pointer-void. This results in the generated C pointer type always being void *, making GCC complain about the following pointer type incompatibility error:
/home/coco24/.cache/common-lisp/ecl-23.9.9-unknown-linux-x64/home/coco24/.quicklisp/local-projects/claw-raylib/raylib/x86_64-pc-linux-gnu.eclh:754:15: ERROR:conflicting types for ‘frexp’; have ‘double(double, void *)’
754 | extern double frexp(double, void*);
| ^~~~~
In file included from /usr/include/features.h:503,
from /usr/include/sys/types.h:25,
from /usr/include/ecl/ecl.h:22,
from /usr/include/ecl/ecl-cmp.h:36,
from /home/coco24/.cache/common-lisp/ecl-23.9.9-unknown-linux-x64/home/coco24/.quicklisp/local-projects/claw-raylib/raylib/x86_64-pc-linux-gnu.c:5:
/usr/include/bits/mathcalls.h:98:1: NOTE:previous declaration of ‘frexp’ with type ‘double(double, int *)’
98 | __MATHCALL (frexp,, (_Mdouble_ __x, int *__exponent));
| ^~~~~~~~~~
/home/coco24/.cache/common-lisp/ecl-23.9.9-unknown-linux-x64/home/coco24/.quicklisp/local-projects/claw-raylib/raylib/x86_64-pc-linux-gnu.eclh:755:14: ERROR:conflicting types for ‘frexpf’; have ‘float(float, void *)’
755 | extern float frexpf(float, void*);
| ^~~~~~
In file included from /usr/include/ecl/ecl-cmp.h:37:
/usr/include/bits/mathcalls.h:98:1: NOTE:previous declaration of ‘frexpf’ with type ‘float(float, int *)’
98 | __MATHCALL (frexp,, (_Mdouble_ __x, int *__exponent));
| ^~~~~~~~~~
/home/coco24/.cache/common-lisp/ecl-23.9.9-unknown-linux-x64/home/coco24/.quicklisp/local-projects/claw-raylib/raylib/x86_64-pc-linux-gnu.eclh:793:15: ERROR:conflicting types for ‘modf’; have ‘double(double, void *)’
793 | extern double modf(double, void*);
| ^~~~
/usr/include/bits/mathcalls.h:110:1: NOTE:previous declaration of ‘modf’ with type ‘double(double, double *)’
110 | __MATHCALL (modf,, (_Mdouble_ __x, _Mdouble_ *__iptr)) __nonnull ((2));
| ^~~~~~~~~~
/home/coco24/.cache/common-lisp/ecl-23.9.9-unknown-linux-x64/home/coco24/.quicklisp/local-projects/claw-raylib/raylib/x86_64-pc-linux-gnu.eclh:794:14: ERROR:conflicting types for ‘modff’; have ‘float(float, void *)’
794 | extern float modff(float, void*);
| ^~~~~
/usr/include/bits/mathcalls.h:110:1: NOTE:previous declaration of ‘modff’ with type ‘float(float, float *)’
110 | __MATHCALL (modf,, (_Mdouble_ __x, _Mdouble_ *__iptr)) __nonnull ((2));
| ^~~~~~~~~~
/home/coco24/.cache/common-lisp/ecl-23.9.9-unknown-linux-x64/home/coco24/.quicklisp/local-projects/claw-raylib/raylib/x86_64-pc-linux-gnu.eclh:796:15: ERROR:conflicting types for ‘nan’; have ‘double(void *)’
796 | extern double nan(void*);
| ^~~
/usr/include/bits/mathcalls.h:203:1: NOTE:previous declaration of ‘nan’ with type ‘double(const char *)’
203 | __MATHCALL (nan,, (const char *__tagb));
| ^~~~~~~~~~
/home/coco24/.cache/common-lisp/ecl-23.9.9-unknown-linux-x64/home/coco24/.quicklisp/local-projects/claw-raylib/raylib/x86_64-pc-linux-gnu.eclh:797:14: ERROR:conflicting types for ‘nanf’; have ‘float(void *)’
797 | extern float nanf(void*);
| ^~~~
/usr/include/bits/mathcalls.h:203:1: NOTE:previous declaration of ‘nanf’ with type ‘float(const char *)’
203 | __MATHCALL (nan,, (const char *__tagb));
| ^~~~~~~~~~
/home/coco24/.cache/common-lisp/ecl-23.9.9-unknown-linux-x64/home/coco24/.quicklisp/local-projects/claw-raylib/raylib/x86_64-pc-linux-gnu.eclh:814:15: ERROR:conflicting types for ‘remquo’; have ‘double(double, double, void *)’
814 | extern double remquo(double, double, void*);
| ^~~~~~
/usr/include/bits/mathcalls.h:310:1: NOTE:previous declaration of ‘remquo’ with type ‘double(double, double, int *)’
310 | __MATHCALL (remquo,, (_Mdouble_ __x, _Mdouble_ __y, int *__quo));
| ^~~~~~~~~~
/home/coco24/.cache/common-lisp/ecl-23.9.9-unknown-linux-x64/home/coco24/.quicklisp/local-projects/claw-raylib/raylib/x86_64-pc-linux-gnu.eclh:815:14: ERROR:conflicting types for ‘remquof’; have ‘float(float, float, void *)’
815 | extern float remquof(float, float, void*);
| ^~~~~~~
/usr/include/bits/mathcalls.h:310:1: NOTE:previous declaration of ‘remquof’ with type ‘float(float, float, int *)’
310 | __MATHCALL (remquo,, (_Mdouble_ __x, _Mdouble_ __y, int *__quo));
| ^~~~~~~~~~
However, since math.h is included by ecl-cmp.h, such conflicts are unavoidable. Is there any way to resolve this issue?