Hello everybody, I face a weird situation with LW and CFFI on OS X 10.4.
When I evaluate the form :
(cffi:with-foreign-pointer (ptr 2)
(setf (cffi:mem-ref ptr :int 0) 0) (setf (cffi:mem-ref ptr :int 1) 1) (let ((i 0)) (loop for i from 0 below 2 collect (cffi:mem-ref ptr :int i))))
The result is :
(256 1)
The first value of the pointer has been turned from 0 to 256.
I tried other similar tests using explicit "foreign-alloc" with similar results.
Note that in each case, the last modified place of the pointer keeps his right value while the value of the other places of the pointer are changed.
I use the correct package. So I am wondering if it could be a problem in my system.
Any idea or ptoposition welcome.
Regards.
Hello,
On Wed, Jun 25, 2008 at 4:09 PM, Antoine Allombert antoine.allombert@labri.fr wrote:
(cffi:with-foreign-pointer (ptr 2)
(setf (cffi:mem-ref ptr :int 0) 0) (setf (cffi:mem-ref ptr :int 1) 1) (let ((i 0)) (loop for i from 0 below 2 collect (cffi:mem-ref ptr :int i))))
You've allocated 2 bytes and then referenced 2 ints (8 bytes probably). Try (with-foreign-object (ptr :int 2) ...).
HTH.
Luís Oliveira a écrit :
Hello,
On Wed, Jun 25, 2008 at 4:09 PM, Antoine Allombert antoine.allombert@labri.fr wrote:
(cffi:with-foreign-pointer (ptr 2)
(setf (cffi:mem-ref ptr :int 0) 0) (setf (cffi:mem-ref ptr :int 1) 1) (let ((i 0)) (loop for i from 0 below 2 collect (cffi:mem-ref ptr :int i))))
You've allocated 2 bytes and then referenced 2 ints (8 bytes probably). Try (with-foreign-object (ptr :int 2) ...).
HTH.
It gives the same result.
I evaluated my form on other machines with good result but I was unable to find the difference between the systems (same LW, same cffi). That's why I am asking about the use by cffi of local libraries or files.
On Wed, Jun 25, 2008 at 4:21 PM, Antoine Allombert antoine.allombert@labri.fr wrote:
You've allocated 2 bytes and then referenced 2 ints (8 bytes probably). Try (with-foreign-object (ptr :int 2) ...).
[...]
It gives the same result.
Right, while that was a problem with your code, it's not the main problem: MEM-REF's offset is measured in bytes. You want to use MEM-AREF instead.
Luís Oliveira a écrit :
On Wed, Jun 25, 2008 at 4:21 PM, Antoine Allombert antoine.allombert@labri.fr wrote:
You've allocated 2 bytes and then referenced 2 ints (8 bytes probably). Try (with-foreign-object (ptr :int 2) ...).
[...]
It gives the same result.
Right, while that was a problem with your code, it's not the main problem: MEM-REF's offset is measured in bytes. You want to use MEM-AREF instead.
Right, it works. Thanks !
On Wed, 2008-06-25 at 16:14 +0100, Luís Oliveira wrote:
Hello,
On Wed, Jun 25, 2008 at 4:09 PM, Antoine Allombert antoine.allombert@labri.fr wrote:
(cffi:with-foreign-pointer (ptr 2)
(setf (cffi:mem-ref ptr :int 0) 0) (setf (cffi:mem-ref ptr :int 1) 1) (let ((i 0)) (loop for i from 0 below 2 collect (cffi:mem-ref ptr :int i))))
HU> (setf *print-base* 16) 10 HU> (cffi:with-foreign-object (ptr :int 2) (setf (cffi:mem-ref ptr :int 0) #x07) (setf (cffi:mem-ref ptr :int 1) #x15) (values (cffi:mem-ref ptr :int 0) (cffi:mem-ref ptr :int 1))) 1507 15
On Wed, 2008-06-25 at 17:09 +0200, Antoine Allombert wrote:
Hello everybody, I face a weird situation with LW and CFFI on OS X 10.4.
When I evaluate the form :
(cffi:with-foreign-pointer (ptr 2)
(setf (cffi:mem-ref ptr :int 0) 0) (setf (cffi:mem-ref ptr :int 1) 1) (let ((i 0)) (loop for i from 0 below 2 collect (cffi:mem-ref ptr :int i))))
The result is :
(256 1)
I get the same behaviour with SBCL 1.0.17.42