8 messages in net.java.dev.jna.usersRe: [jna-users] call to sysinfo() cau...
FromSent OnAttachments
Joel UckelmanApr 7, 2009 8:37 am 
Timothy WallApr 7, 2009 8:47 am 
Joel UckelmanApr 7, 2009 9:05 am 
Kevin BurtonApr 7, 2009 9:56 am 
Timothy WallApr 7, 2009 9:58 am 
Joel UckelmanApr 7, 2009 12:19 pm 
Joel UckelmanApr 7, 2009 12:22 pm 
Kevin BurtonApr 7, 2009 1:33 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] call to sysinfo() causes crashActions...
From:Joel Uckelman (ucke@nomic.net)
Date:Apr 7, 2009 12:22:25 pm
List:net.java.dev.jna.users

Thus spake Timothy Wall:

I changed the last element of the structure on the Java side to be this, to match the definition given in the C header:

public byte[] _f = new byte[20-2*NativeLong.SIZE-Native.getNativeSize(int.class)];

After that, it worked perfectly for me on 32-bit machines, but fails with this exception on 64-bit machines:

Exception in thread "main" java.lang.IllegalArgumentException: Arrays of length zero not allowed in structure

Two 8-byte longs and one 4-byte int are 20 bytes together, so that makes the byte array _f have zero length on a 64-bit machine. In C, that would just make _f point to the end of the struct.

Well, since in C you have two distinct structure definitions, you could do the same in Java. Alternatively, you can simply ensure the array is not zero length, since padding beyond the end of the structure will be ignored, unless you have an array of structures. Or you could make the final field an array as well and include the necessary padding in that.

The simplest solution seems to be to add 1 to the length of the _f byte array, just to ensure that _f always has nonzero length. (I've tested that, and it works.)