Re: a return to struct madness?

Kevin Rosenberg <kevin-HJRc7zDS/[email protected]> Wed, 29 Dec 2004 13:12:40 -0700
Newsgroups gmane.lisp.uffi.devel
Message-ID <[email protected]>
[email protected] wrote:
> If it's something that's insoluble at the UFFI layer, that's probably
> okay; right now, my code uses a wrapper around with-foreign-objects,
> that uses a simpler expansion on SBCL/CMU without the alien:addr call.
> Then, when I make calls that require a pointer to the alien value, I use
> a macro pointer-to-object which expands to (alien:alien-sap object) on
> SBCL/CMU, and just object on other platforms.  That's a bit ugly, but it
> works for me for the moment.

Thanks for the sample code. I've never tried allocating structures on
the stack like that. Sounds like you have a reasonable work-around.

I suppose the best that UFFI could do is provide an alternate
with-foreign-object macro that did not use alien:addr and then provide
and document a method of using those objects using a UFFI wrapper
around alien:alien-sap. It's not a small undertaking, but if you felt
strongly about providing an API like this, I'd be glad to review
patches.

Kevin


> Cheers.
> 

> (asdf:oos 'asdf:load-op :uffi)
> 
> (uffi:load-foreign-library "./uffi-test.so" :module "uffi-test")
> 
> (uffi:def-struct foo-s (x :int))
> 
> (uffi:def-function "get_a_foo" ((foo (* foo-s)))
>   :returning :void :module "uffi-test")
> 
> (defun lots-of-foo ()
>   (dotimes (i 100000)
>     (uffi:with-foreign-object (foo '(:struct foo-s))
>       (get-a-foo foo)
>       (assert (= (uffi:get-slot-value foo foo-s 'x) 42)))))
> 
> (time (lots-of-foo))
> 

> 
> struct foo_s {
>     int x;
> };
> 
> void get_a_foo(struct foo_s *foo)
> {
>     foo->x = 42;
>     return;
> }

> _______________________________________________
> UFFI-Devel mailing list
> [email protected]
> http://lists.b9.com/mailman/listinfo/uffi-devel

-- 
Kevin Rosenberg
kevin-HJRc7zDS/[email protected]