

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
17 messages in net.java.dev.jna.usersRe: [jna-users] Array of Structures i...| From | Sent On | Attachments |
|---|---|---|
| RWAD...@UP.COM | Jul 18, 2008 8:39 am | |
| Timothy Wall | Jul 18, 2008 9:26 am | |
| RWAD...@UP.COM | Jul 18, 2008 9:46 am | |
| Timothy Wall | Jul 18, 2008 10:18 am | |
| RWAD...@UP.COM | Jul 18, 2008 11:07 am | |
| RWAD...@UP.COM | Jul 18, 2008 11:19 am | |
| Timothy Wall | Jul 18, 2008 11:35 am | |
| Timothy Wall | Jul 18, 2008 11:40 am | |
| Timothy Wall | Jul 18, 2008 11:44 am | |
| Timothy Wall | Jul 18, 2008 11:46 am | |
| RWAD...@UP.COM | Jul 18, 2008 12:01 pm | |
| RWAD...@UP.COM | Jul 18, 2008 12:07 pm | |
| RWAD...@UP.COM | Jul 18, 2008 12:09 pm | |
| RWAD...@UP.COM | Jul 18, 2008 12:28 pm | |
| Timothy Wall | Jul 18, 2008 12:46 pm | |
| RWAD...@UP.COM | Jul 18, 2008 12:55 pm | |
| RWAD...@UP.COM | Jul 18, 2008 1:16 pm |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: [jna-users] Array of Structures in a Structure | Actions... |
|---|---|---|
| From: | RWAD...@UP.COM (RWAD...@UP.COM) | |
| Date: | Jul 18, 2008 9:46:12 am | |
| List: | net.java.dev.jna.users | |
This is getting more puzzling the longer I look at it. I had both the Java code & the C code output the size of the array that's being initialized, and they both agree that it's 592 bytes (red text below is from Java, blue is from C).
Size of ObjectPointAndOrientationStructure: 296 bytes Size of opo array: 592 # # An unexpected error has been detected by HotSpot Virtual Machine: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x03cdebf1, pid=5936, tid=3792 # # Java VM: Java HotSpot(TM) Client VM (1.5.0_04-b05 mixed mode, sharing) # Problematic frame: # C [efms-api.dll+0x2ebf1] # # An error report file with more information is saved as hs_err_pid5936.log # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp # Connected to dev091 as dtns999 Entered efm111 PROPO array pointer was NOT null. Building log entry About to write log entry Wrote log entry Building log entry with PROPO data About to write PROPO data to log Wrote PROPO data to log Sizeof(Op_And_Ornt_Struct) = 296 bytes About to initialize SOP output array (592 bytes).
This the offending C code. The print() before the memset succeeds, but we never see the output from the puts() call after the memset. Is it possible the array doesn't have ownership of its own memory?
printf("About to initialize SOP output array (%i bytes).\n", sizeof(Op_And_Ornt_Struct)*MAX_SOPS_AT_RL); memset(&(sop[0]),'\0', sizeof(Op_And_Ornt_Struct)*MAX_SOPS_AT_RL); puts("Initialized"); (doesn't get here)
_______________________________
Hardware /nm./: the part of the computer you can kick.
Timothy Wall <twal...@dev.java.net> 07/18/2008 11:27 AM Please respond to use...@jna.dev.java.net
To use...@jna.dev.java.net cc
Subject Re: [jna-users] Array of Structures in a Structure
On Jul 18, 2008, at 11:39 AM, RWAD...@UP.COM wrote:
I'm having trouble properly initializing a C structure which contains an array of other structures. The C structure definition is:
typedef struct op_and_ornt_struct { Obj_Pnt_Struct obj_pnt; short int num_rpls; struct { Rail_Path_Loca_Struct rpl; Ropo_Struct ropo; double dist_from; } ornt[3]; } Op_And_Ornt_Struct;
____________________________________________________________
The Java code I'm using to emulate this structure is as follows:
package com.uprr.efm.nativ.struct; import java.util.List; import com.uprr.net.Orientation; import com.uprr.point.ObjectPointOrientation;
public class ObjectPointAndOrientationStructure extends Structure {
public ObjectPointStructure obj_pnt ; public int num_rpls ; public OrientationStructure[] orientations ;
You can initialize here with "orientations = new OrientationStructure[3];". JNA will auto-initialize the array as needed. You only need to initialize it if you need to initialize the data.
/** Default constructor. */ public ObjectPointAndOrientationStructure() { orientations = (OrientationStructure[])new OrientationStructure().toArray(3); } }
____________________________________________________________
I then create a 2-element array of these structures & pass it to a C function as follows:
final ObjectPointAndOrientationStructure opo = new ObjectPointAndOrientationStructure() ; final ObjectPointAndOrientationStructure[] opos = (ObjectPointAndOrientationStructure[])opo.toArray(2); myFunction(opos);
____________________________________________________________
The C function then tries to fill the 2-element "opos" array with zeroes, but crashes. Apparently the Java structure size differs from the C structure size.
That's a different problem than just initializing the array.
I'm guessing that may that the "orientations" array in the structure is not being inlined as intended, & that the Java constructor above is not creating it correctly. Does this make sense? If so, how do i instantiate the 3-element orientation array correctly so that it's inline inside of its parent structure?
The only way an array of structures would *not* be inlined is if they're declared to implement Structure.ByReference, in which case you'd get an array of structure pointers instead.
Check to see if the structure sizes match and if they don't use Structure.toString to figure out where they don't match.
You're using java "int" for native "short", which in most cases is incorrect. You probably want Java short instead.
--------------------------------------------------------------------- To unsubscribe, e-mail: user...@jna.dev.java.net For additional commands, e-mail: user...@jna.dev.java.net
.
This message and any attachments contain information from Union Pacific which
may be confidential and/or privileged.
If you are not the intended recipient, be aware that any disclosure, copying,
distribution or use of the contents of this message is strictly prohibited by
law. If you receive this message in error, please contact the sender immediately
and delete the message and any attachments.







