12 messages in net.java.dev.jna.users[jna-users] Problem returning Structu...
FromSent OnAttachments
Duncan McGregorFeb 9, 2009 2:13 pm 
Timothy WallFeb 9, 2009 2:24 pm 
Timothy WallFeb 9, 2009 2:31 pm 
Duncan McGregorFeb 9, 2009 4:22 pm 
Timothy WallFeb 9, 2009 4:57 pm 
Duncan McGregorFeb 9, 2009 5:39 pm 
Timothy WallFeb 9, 2009 5:48 pm 
Timothy WallFeb 9, 2009 6:00 pm 
Timothy WallFeb 9, 2009 6:07 pm 
Duncan McGregorFeb 9, 2009 6:10 pm 
Duncan McGregorFeb 10, 2009 2:53 am 
Duncan McGregorFeb 10, 2009 7:42 am 
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:[jna-users] Problem returning Structure.ByValue on Mac, JNA 3.0.6+Actions...
From:Duncan McGregor (dun@oneeyedmen.com)
Date:Feb 9, 2009 2:13:46 pm
List:net.java.dev.jna.users

Hello JNA

Rococoa, our little free Java / Cocoa bridge project has an issue with JNA versions after 3.0.5 that I'm finally getting round to trying to diagnose. This is going to be a bit random I'm afraid, but I'm banging my head against a wall, as this used to work.

Given

public class NSSize extends Structure implements Structure.ByValue { public float width; public float height;

public NSSize() {}

public NSSize(int width, int height) { this.width = width; this.height = height; } }

I have a test case

public class StructsInObjectsTest extends RococoaTestCase {

public interface MyLibrary extends Library { NSSize objc_msgSend(ID receiver, Selector selector, Object... args); }

public void test() { NSSize aSize = new NSSize(1, 3); ID idOfNSValueClass = Foundation.getClass("NSValue"); Foundation.nsLog("%@", idOfNSValueClass);

ID idOfValueInstance = Foundation.sendReturnsID(idOfNSValueClass, "valueWithSize:", aSize); Foundation.nsLog("%@", idOfValueInstance);

MyLibrary messageSendLibrary = (MyLibrary) Native.loadLibrary("Foundation", MsgSendLibrary.class); NSSize size = messageSendLibrary.objc_msgSend(idOfValueInstance, Foundation.selector("sizeValue"));

assertEquals(1.0, size.width, 0.0001); assertEquals(3.0, size.height, 0.0001); } }

It isn't usually like this - but that's the lowest level code that fails.

If you trust that the code up to messageSendLibrary.objc_msgSend(... does what it appears to, creating an NSValue with an NSSize

2009-02-09 22:01:25.258 java[28068:1003] NSValue 2009-02-09 22:01:25.260 java[28068:1003] NSSize: {1, 3}

then the objc_msgSend succeeds with JNA 3.0.5, but fails with all versions after that.

Invalid memory access of location 00000020 eip=95afb688

The deepest Java is Function invokeStructure(int callingConvention, Object[] args, Structure result).

Did anything significant change in the underlying native code between 3.0.5 and 3.0.6? Can you offer any help diagnosing, or building a debug native library?

Thanks in anticipation