Subject: AW: [clisp-list] FFI - Creating c-places in LISP?

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Tue Oct 1 08:12:12 2002

Dave Richards wrote:
>> outside the LISP heap, i.e. have static storage class.  One could 
>> infer that
>> C code could malloc() a region and return this, but how then 
>do we ensure
>> free() is called at GC finalization?

>Ah!  WITH-FOREIGN-OBJECT.  That'll do it.

Please report your experience here. You might be the first one to use this newly added code of mine.

Especially interesting is whether stack-allocated C space is really enough for applications. malloc/free and GC finalization have many pitfalls. But let's only talk about those if you are not satisfied with stack allocations.

Regards,
	Jörg Höhle.

---

From: "Dave Richards" <[email-masked]>
Date: Tue Oct 1 09:55:16 2002

> Especially interesting is whether stack-allocated C space is
> really enough for applications. malloc/free and GC finalization
> have many pitfalls. But let's only talk about those if you are
> not satisfied with stack allocations.

Will do.  However, I can anticipate one problem already.

I have an abstraction I call the network queue layer.  It implements a byte
queue:

(defclass nqueue ()
  ((size   :accessor nq-size
           :initarg  :size)
   (length :accessor nq-length
           :initform 0)
   (rptr   :accessor nq-rptr
           :initform 0)
   (wptr   :accessor nq-wptr
           :initform 0)
   (data   :accessor nq-data)))

followed by tons of routines to manipulate the queue.

; data is allocated in initialize-instance as:
; (make-array (nq-size nq) :element-type '(unsigned-byte 8))

My desire is to be able to call send() and recv() on the data part of
(nq-data nq), i.e. I want a c-pointer to (aref (nq-data data) index).
Lacking this, I am going to have to declare a c-type, then inside a
with-foreign-object construct I am going to have to stage the data between
my nqueue's data vector and the c-var.  This effectively is a user-space to
user-space copy followed by a user-space to kernel-space (for send(), and
the reverse for recv()).

I realize providing such a c-pointer is scary, even inside a with-
construct, but have you considered it?

	Dave