<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">I think there's an issue with void functions, for example:<div><br></div><div>(cffi:defcfun ("srand" c-srand) :void '(:unsigned-int))</div><div><br></div><div><div>(defun test-srand ()</div><div> "invokes srand function"</div><div> (cffi:foreign-funcall "srand"))</div><div><br></div><div>(test-srand)</div><div><br></div><div><br></div><div><div>;;;</div><div>;;; Compiling cffi-test.lisp.</div><div>;;; OPTIMIZE levels: Safety=2, Space=0, Speed=3, Debug=0</div><div>;;;</div><div>;;; Compiling (CFFI:DEFCFUN ("srand" C-SRAND) ...).</div><div>;;; Compiling (DEFUN TEST-SRAND ...).</div><div>;;; End of Pass 1.</div><div>;;; Emitting code for C-SRAND.</div><div>;;; Error:</div><div>;;; in file cffi-test.lisp, position 415</div><div>;;; at (DEFCFUN (srand C-SRAND) ...)</div><div>;;; * Used @(RETURN 0) in a C-INLINE form with 0 output values</div><div>;;; Loading "/Users/sylvain/src/LISP/cffi_ecl/cffi-test.fas"</div></div><div><br></div><div><br></div><div><br><div><div>On Nov 22, 2012, at 11:53 AM, Sylvain Ageneau <<a href="mailto:ageneau@gmail.com">ageneau@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Great!<div><br></div><div>I'll try that and report back. Many thanks.</div><div><br><div><div>On Nov 22, 2012, at 11:16 AM, Juan Jose Garcia-Ripoll <<a href="mailto:juanjose.garciaripoll@gmail.com">juanjose.garciaripoll@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">I am attaching a patch for CFFI that allows ECL to build code that does not use dlopen() but rather uses the function symbols as they are know to the C compiler. This is best explained in the code comments, which I reproduce below, and in the example.<div>
<br></div><div>The patched CFFI is available at my github account</div><div><a href="https://github.com/juanjosegarciaripoll/cffi">https://github.com/juanjosegarciaripoll/cffi</a><br><div><br></div><div>This is how the example is used<br clear="all">
<div><br></div><div><div>bash-3.2$ ecl -norc</div><div>ECL (Embeddable Common-Lisp) 12.7.1 (git:e95fa190ccab10a5dcca791658d7d3ff24a77240)</div><div>Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya</div><div>Copyright (C) 1993 Giuseppe Attardi</div>
<div>Copyright (C) 2000 Juan J. Garcia-Ripoll</div><div>ECL is free software, and you are welcome to redistribute it</div><div>under certain conditions; see file 'Copyright' for details.</div><div>Type :h for Help. </div>
<div>Top level in: #<process TOP-LEVEL>.</div><div>> (load "build")</div><div>[...]</div><div>To load "cffi":</div><div> Load 1 ASDF system:</div><div> cffi</div><div>; Loading "cffi"</div>
<div><br></div><div>;;;</div><div>;;; Compiling cffi-test.lisp.</div><div>;;; OPTIMIZE levels: Safety=2, Space=0, Speed=3, Debug=0</div><div>;;;</div><div>;;; Compiling (CFFI:DEFCFUN ("sin" C-SINE) ...).</div><div>
;;; Compiling (DEFUN FF-C-SINE ...).</div><div>;;; End of Pass 1.</div><div>;;; Emitting code for C-SINE.</div><div>;;; Emitting code for FF-C-SINE.</div><div>;;; Finished compiling cffi-test.lisp.</div><div>;;;</div><div>
;;; Loading "/Users/jjgarcia/build/cffi-static/cffi-test.fas"</div><div><br></div><div> sin(pi) = 1.22464679914735320720000000000000d-16</div><div>#P"/Users/jjgarcia/build/cffi-static/build.lisp"</div>
</div><div><br></div><div>This is the self-explanatory comment</div><div><br></div><div><div>;;;</div><div>;;; ECL allows many ways of calling a foreign function, and also many</div><div>;;; ways of finding the pointer associated to a function name. They</div>
<div>;;; depend on whether the FFI relies on libffi or on the C/C++ compiler,</div><div>;;; and whether they use the shared library loader to locate symbols</div><div>;;; or they are linked by the linker.</div><div>;;;</div>
<div>;;; :DFFI</div><div>;;;</div><div>;;; ECL uses libffi to call foreign functions. The only way to find out</div><div>;;; foreign symbols is by loading shared libraries and using dlopen()</div><div>;;; or similar.</div>
<div>;;;</div><div>;;; :DLOPEN</div><div>;;;</div><div>;;; ECL compiles FFI code as C/C++ statements. The names are resolved</div><div>;;; at run time by the shared library loader every time the function</div><div>;;; is called</div>
<div>;;;</div><div>;;; :C/C++</div><div>;;;</div><div>;;; ECL compiles FFI code as C/C++ statements, but the name resolution</div><div>;;; happens at link time. In this case you have to tell the ECL</div><div>;;; compiler which are the right ld-flags (c:*ld-flags*) to link in</div>
<div>;;; the library.</div><div>;;;</div><div>(defvar *cffi-ecl-method*</div><div> #+dffi :dffi</div><div> #+(and dlopen (not dffi)) :dlopen</div><div> #-(or dffi dlopen) :c/c++</div><div> "The type of code that CFFI generates for ECL: :DFFI when using the</div>
<div>dynamical foreign function interface; :DLOPEN when using C code and</div><div>dynamical references to symbols; :C/C++ for C/C++ code with static</div><div>references to symbols.")</div></div><div><br></div><div>
<br></div>-- <br>Instituto de Física Fundamental, CSIC<br>c/ Serrano, 113b, Madrid 28006 (Spain) <br><a href="http://juanjose.garciaripoll.googlepages.com/" target="_blank">http://juanjose.garciaripoll.googlepages.com</a><br>
</div></div>
<span><build.lisp></span><span><cffi-test.lisp></span><span><0001-Allow-the-ECL-backend-to-support-different-combinati.patch></span></blockquote></div><br></div></div></blockquote></div><br></div></div></body></html>