Lisp HUG Maillist Archive

Passing aggregate types by value to FLI functions

I have a C library [that I didn't write] that passes (and returns) a lot of small, aggregate types by value. I was wondering if there was a method of generating temporary values on the stack with a :wrapper so that I don't have to use with-dynamic-foreign-objects, which I assume will always allocate a heap object just to free it immediately after a function call?

The objc package seems to do this successfully with ns-point and ns-rect values. And - in fact - these are very much what this library is doing as well (simple float points and rectangles).

Currently, I do <below>, and I'd like to have a way of passing a list of (x y) to a FLI function that takes a point. I'm totally willing to wrap it if I need to, but if I could use a wrapper FLI type that would be ideal.

(define-c-struct %point (x :float) (y :float))

(defun point-to-lisp (p)
  (list (foreign-slot-value p 'x)
        (foreign-slot-value p 'y)))

(define-c-typedef point (:wrapper %point :foreign-to-lisp point-to-lisp))

Thanks!

Jeff M.

Re: Passing aggregate types by value to FLI functions

Unable to parse email body. Email id is 13090

Updated at: 2020-12-10 08:33 UTC