9 messages in net.java.dev.jna.usersRe: [jna-users] Re: EXC_BAD_ACCESS Ca...
FromSent OnAttachments
Duncan McGregorNov 22, 2007 4:34 am 
Duncan McGregorNov 22, 2007 8:24 am 
Timothy WallNov 22, 2007 8:39 am 
Duncan McGregorNov 22, 2007 10:35 am 
Timothy WallNov 22, 2007 1:01 pm 
Duncan McGregorNov 22, 2007 1:57 pm 
Timothy WallNov 22, 2007 3:58 pm 
Duncan McGregorNov 22, 2007 4:04 pm 
Wayne MeissnerNov 26, 2007 8:07 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Re: EXC_BAD_ACCESS Calling method with Structure on Mac (long and tortuous, sorry)Actions...
From:Timothy Wall (twal@dev.java.net)
Date:Nov 22, 2007 3:58:20 pm
List:net.java.dev.jna.users

On Nov 22, 2007, at 4:58 PM, Duncan McGregor wrote:

On 22 Nov 2007, at 21:01, Timothy Wall wrote:

The return value part of the cast ensures that the compiler properly handles the value returned. Defining your JNA method interface is equivalent to doing the cast; all type information is passed to the libffi layer, which handles stack setup and capture of the return value. Currently all returned structures are assumed to be as pointers by JNA; you might write up some simple tests with a custom shared lib to see if small structs are handled properly as an argument and/or return value. libffi for powerpc looks like it handles small structs, as does x86; JNA may need to be tweaked a bit to pass structure size information down to libffi, though.

So fighting my way down through libffi, I'd pass the instance of the Structure in along with an ffi_type describing it, pass that to ffi_prep_cif, let the invoke happen giving it the pointer to the structure as the return value, as currently happens.

So I guess that libffi uses the contents of the ffi_type to work out how to copy the value to the buffer?

I'm in so deep I can't even see the bottom any more.

That's basically it, if you want to do auto-magic structure-by-value.

Given that Structure results are currently return by pointer, how would you signal that you wanted return by value? It would seem logical to make that the default, but would break current code.

An easier workaround would be to simply replace the structure with an int or long (depending on structure size) and provide "toInt/fromInt" methods on the Structure definition for convenience.