[Ecls-list] Safety of vector addresses.
David Brown
lisp at davidb.org
Tue Oct 14 02:03:12 UTC 2008
I was wondering about the stability of item->vector.self pointers in
ECL. As I understand, the conservative GC never moves blocks of
memory around, but I wanted to make sure this is correct.
Basically, I'm looking to implement the shareable-byte-vector
interface in CFFI, and wanted to make sure what I was doing was safe.
Are there any plans to ever add a GC that can relocate, or is using a
conservative GC kind of in line with the embedable part of ECL?
This is the code I'm thinking of putting into CFFI, into
cffi-ecl.lisp:
(defun make-shareable-byte-vector (size)
"Create a Lisp vector of SIZE bytes that can passed to
WITH-POINTER-TO-VECTOR-DATA."
(make-array size :element-type '(unsigned-byte 8)))
;;; ECL, built with the Boehm GC never moves allocated data.
(defun %vector-address (vector)
"Return the address of VECTOR's data."
(check-type vector (vector (unsigned-byte 8)))
(ffi:c-inline (vector) (object) :unsigned-long
"(unsigned long) #0->vector.self.b8"
:side-effects nil
:one-liner t))
(defmacro with-pointer-to-vector-data ((ptr-var vector) &body body)
"Bind PTR-VAR to a foreign pointer to the data in VECTOR."
`(let ((,ptr-var (make-pointer (%vector-address ,vector))))
, at body))
Previously defined
(defun make-pointer (address)
"Return a pointer pointing to ADDRESS."
(ffi:make-pointer address :void))
Thanks,
David
More information about the ecl-devel
mailing list