Passing Structs by Value using cffi-libffi doesn't work well
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
CFFI |
New
|
Undecided
|
Unassigned |
Bug Description
C codes in the file test.c as below:
struct complex {
double real;
double imag;
};
double magnitude_squared (struct complex c) {
return c.real * c.real + c.imag * c.imag;
};
Compile this into a shared library:
gcc -fpic -shared test.c -o test.so
then typing in REPL:
shows below:
CFFI-LIBFFI-TEST> (ql:quickload :cffi-libffi)
To load "cffi-libffi":
Load 1 ASDF system:
cffi-libffi
; Loading "cffi-libffi"
(:CFFI-LIBFFI)
CFFI-LIBFFI-TEST> (cffi:load-
#<CFFI:
CFFI-LIBFFI-TEST> (cffi:defcstruct c-complex
(real :double)
(imag :double))
(:STRUCT C-COMPLEX)
CFFI-LIBFFI-TEST> (cffi:defcfun ("magnitude_
(c (:struct c-complex)))
WARNING: redefining CFFI-LIBFFI-
MS
CFFI-LIBFFI-TEST> (cffi:with-
(setf (cffi:foreign-
'real)
3d0
(cffi:foreign-
'imag)
4d0)
(sqrt (ms c)))
Then comes with error:
There is no applicable method for the generic function
#<STANDARD-
when called with arguments
(#.(SB-
#<C-
#.(SB-
[Condition of type SB-PCL:
See also:
Common Lisp Hyperspec, 7.6.6 [:section]
Restarts:
0: [RETRY] Retry calling the generic function.
1: [RETRY] Retry SLIME REPL evaluation request.
2: [*ABORT] Return to SLIME's top level.
3: [ABORT] abort thread (#<THREAD "repl-thread" RUNNING {1003039B63}>)
.
And I have tested that the subsystem CFFI-LIBFFI has been loaded and I have installed LIBFFI and it works well.
cffi_0.24.1 + SBCL 1.4.16.debian x8664 + GNU Emacs 26.1 + slime
summary: |
- Passing Structs by Value using cffi-libffi doesn't work wel + Passing Structs by Value using cffi-libffi doesn't work well |