On Fri, Sep 2, 2011 at 1:19 AM, Philippe Hanrigou <span dir="ltr"><<a href="mailto:philippe.hanrigou@gmail.com">philippe.hanrigou@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi,<br>
<br>
I am having some problems using ffi to relay pointers between<br>
ECL and a custom C library. It looks as if the pointers end up<br>
being truncated to 32 bits for a reason that completely escapes<br>
me...<br clear="all"></blockquote></div><br>The reason is simple: in the lisp file you call C functions without having them declared beforehand. If you do not provide a declaration of "use_pointer" then C assumes that all of the arguments are integers (32-bits in this compiler) and similar for the output.<br>
<br>I would advise you to use some other FFI, such as UFFI or CFFI, until you are confident enough to resort to low-level C-type programming, which is what c-inline does.<br><br>A quick hack that solves your problem:<br>
<br>
(ffi:clines "<br>extern const char *use_pointer(void *);<br>extern void *create_pointer();<br>")<br><br>(defpackage :foo<br> (:use :common-lisp :ffi))<br>(in-package :foo)<br><br>(proclaim '(OPTIMIZE (SAFETY 3) (DEBUG 3) (SPEED 0)))<br>
<br>(ffi:load-foreign-library "foo" :system-library t)<br><br>(defun new-p ()<br> (c-inline () () :pointer-void "create_pointer()" :side-effects t :one-liner t))<br><br>(defun use-p (p)<br> (c-inline (p) (:pointer-void) :cstring "use_pointer(#0)" :side-effects t :one-liner t))<br>
<br>(defun use2-p (p)<br> (c-inline (p) (:pointer-void) :cstring "use_pointer(#0)" :side-effects t :one-liner t))<br><br>(use-p (new-p))<br><br><br>-- <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>