12 messages in net.java.dev.jna.usersRe: [jna-users] Problem returning Str...
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:Re: [jna-users] Problem returning Structure.ByValue on Mac, JNA 3.0.6+Actions...
From:Timothy Wall (twal@dev.java.net)
Date:Feb 9, 2009 6:07:50 pm
List:net.java.dev.jna.users

looks like the problem is in native/libffi/src/ffi.c. The version from 3.0.5 works, so something is wrong with the win64 patch.

you might try pulling the native/libffi/src/ffi.c from 3.0.5 into the current build; 3.0.5 to 3.0.6 added win64 support, which is mostly protected by ifdefs but there were some minor changes to typecasts.

On Feb 9, 2009, at 8:40 PM, Duncan McGregor wrote:

On Tue, Feb 10, 2009 at 12:58 AM, Timothy Wall <twal@dev.java.net

wrote:

Actually, I was thinking of using the struct by value in a comparable situation exclusive of the OSX framework, thus eliminating improper usage or interaction with the framework as a contributing factor.

I'm trying! I have a number of regression tests for passing struct by value to plain old functions and they're all OK.

<snip/>

Seems to be just missing "Selector"...

Dammit, NativeLong will substitute there as well.

Object 0x11cdf0 of class NSConcreteValue autoreleased with no pool in place - just leaking

Is the autoreleased object the one being accessed?

Yes, but I get the same symptoms when I've set up a pool, its just too painful in a standalone test.

OK, I think I've isolated it. It seems to be that the NativeLong is being mangled on the way in, but only if Structure is being returned...

float floatFromNSValue(NSValue* value) { NSLog(@"floatFromNSValue %p", value); NSLog(@"floatFromNSValue %@", value); NSSize result = [value sizeValue]; return result.width; }

NSSize sizeFromNSValue(NSValue* value) { NSLog(@"sizeFromNSValue %p", value); NSLog(@"sizeFromNSValue %@", value); NSSize result = [value sizeValue]; return result; }

public interface TestLibrary extends Library { NSSize sizeFromNSValue(NativeLong value); float floatFromNSValue(NativeLong value); }

public void test() { FoundationLibrary library = (FoundationLibrary) Native.loadLibrary("Foundation", FoundationLibrary.class); NativeLong logTemplate = library.CFStringCreateWithCString(new NativeLong(0), "%@", 0);

NativeLong idOfNSValueClass = library.objc_getClass("NSValue");

NSSize aSize = new NSSize(1, 3); NativeLong idOfValueInstance = library.objc_msgSend( idOfNSValueClass, library.sel_registerName("valueWithSize:"), aSize); System.out.println("Address of instance " + Integer.toHexString(idOfValueInstance.intValue())); library.NSLog(logTemplate, idOfValueInstance);

TestLibrary library3 = (TestLibrary) Native.loadLibrary("Rococoa", TestLibrary.class); assertEquals(1.0, library3.floatFromNSValue(idOfValueInstance), 0.0001); NSSize size = library3.sizeFromNSValue(idOfValueInstance);

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

Then with 3.0.5 I get

Address of instance 122990 2009-02-10 01:31:39.924 java[50063:1003] NSSize: {1, 3} 2009-02-10 01:31:39.928 java[50063:1003] floatFromNSValue 0x122990 2009-02-10 01:31:39.929 java[50063:1003] floatFromNSValue NSSize: {1, 3} 2009-02-10 01:31:39.931 java[50063:1003] sizeFromNSValue 0x122990 2009-02-10 01:31:39.932 java[50063:1003] sizeFromNSValue NSSize: {1, 3}

But 3.0.6 gives

Address of instance 122990 2009-02-10 01:33:56.199 java[50086:1003] NSSize: {1, 3} 2009-02-10 01:33:56.202 java[50086:1003] floatFromNSValue 0x122990 2009-02-10 01:33:56.203 java[50086:1003] floatFromNSValue NSSize: {1, 3} 2009-02-10 01:33:56.204 java[50086:1003] sizeFromNSValue 0x122cb0 Invalid memory access of location 00000020 eip=95afb688

The pointer set off to sizeFromNSValue as 0x122990 and arrived as 0x122cb0 !

It's 1:40 am here - I'm off to clean my teeth! Let me know if there's anything else I can do before bed.