[cffi-devel] foreign-alloc
Martin Simmons
martin at lispworks.com
Tue Sep 6 14:36:35 UTC 2005
Hi there,
I've been lurking here for a couple of weeks to see how cffi is progressing.
It looks good so far!
>>>>> On Sun, 4 Sep 2005 20:03:54 +0100, Luis Oliveira <luismbo at gmail.com> said:
Luis> CFFI> (foreign-alloc :int :initial-contents #(1 2 3))
Luis> #<A Mac Pointer #x1022E0>
Luis> CFFI> (loop for i from 0 below 3
Luis> collect (mem-ref * :int i))
Luis> (1 2 3)
Luis> ;; Another note: what should should be in (mem-ref ** :int 3)?
Luis> ;; Zero? Ie. Should these previous two calls to foreign-alloc
Luis> ;; allocate 3*sizeof(int) or 4*sizeof(int) bytes? Lispworks seems to
Luis> ;; do the latter.
LispWorks allocates 3*sizeof(int), but the C heap manager might round this up
to 4. (mem-ref ** :int 3) should be expected to give a random result or a
crash.
Luis> CFFI> (foreign-alloc :string :initial-element "foo")
Luis> ;; I think this should do something similar to CLISP's
Luis> ;; FFI:ALLOCATE-DEEP, and it should Just Work if we apply the :to-c
Luis> ;; translator, which will allocate space for "foo".
I think it depends on whether the :STRING type is an array type, a pointer
type or some magic.
Luis> ;; A problem here is freeing this memory. Should we tell the user
Luis> ;; he has to free the complex stuff inside by himself. Or should we
Luis> ;; come up with something similar to CLISP's FFI:FOREIGN-FREE when
Luis> ;; passed ":full t". (In this case CFFI:FOREIGN-FREE would have to
Luis> ;; take an optional type or something to describe what needs
Luis> ;; freeing.)
Complex stuff is complex to free, so I would say that the user has to do it.
--
Martin Simmons
LispWorks Ltd
More information about the cffi-devel
mailing list