12 messages in net.java.dev.jna.usersRe: [jna-users] Structure
FromSent OnAttachments
Paul LoyJan 10, 2008 8:29 am.java
Paul LoyJan 10, 2008 9:31 am.java
Paul LoyJan 10, 2008 9:47 am.java
Timothy WallJan 14, 2008 5:08 am 
Timothy WallJan 14, 2008 5:23 am 
Paul LoyJan 14, 2008 5:46 am 
Paul LoyJan 14, 2008 8:56 am 
Paul LoyJan 14, 2008 9:21 am 
Timothy WallJan 14, 2008 9:57 am 
Timothy WallJan 14, 2008 11:32 am 
Paul LoyJan 15, 2008 2:05 am 
Timothy WallJan 15, 2008 5:41 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] StructureActions...
From:Paul Loy (pa@keteracel.com)
Date:Jan 14, 2008 8:56:07 am
List:net.java.dev.jna.users

Hi Tim,

I built the latest code from SVN and this allows me to call TrackProperty.size() without a NPE if both the TrackProperty and ChannelDescription are ByReference.

By calling TrackProperty.size(), for 2 channels I get 12 when the actual size of this struct is 36 (2xChannelDescription+4). This makes the native call fail. If I botch it and send the 'correct' size, the call passes, although I guess I can't be sure it's writing to the correct memory. If I set ChannelDescription to be ByValue, I get a "Cannot inline ChannelDescription" exception.

So I think that we need a way to inline the memory for the ChannelDescriptions inside the TrackProperty as this is what the Native API is expecting.

Paul.

PS: I think JNA is great BTW. I've been using it for a couple of months now, and for everything up to this point it has worked perfectly first-time. JNA has drastically simplified our build and enables us to try things out much much more quickly. Thank you!

On Jan 14, 2008 1:23 PM, Timothy Wall <twal@dev.java.net> wrote:

On Jan 10, 2008, at 11:30 AM, Paul Loy wrote:

Hi All,

I am trying to create a Variable length Structure, where the variability is the length of an array of Structures inside the Variable length Structure. (please see attached unit tests)

I get a NPE in Structure.getNativeSize(Class, Object) due to the fact that in Structure.getNativeAlignment(Class, Object, boolean), when it finds an Array it sends null as value back into itself:

... else if (type.isArray()) { alignment = getNativeAlignment(type.getComponentType(), null, firstElement); } ...

I guess this is a bug?

Your description doesn't match up against your test. An inner array of fixed-size structures must be initialized before Structure.allocateMemory/calculateSize is called; are you using the latest SVN sources?

Note that the inner, fixed-size structure must have a public no-arg constructor, and that Structure.size() must return a valid value after the object is created.

When I run your test, the explicit "fail" is invoked on the last two test methods, so perhaps we're using different codebases.

(BTW, I'll be posting an "official" 3.0 release sometime this week)

T.