Problem converting int* in c struct to int[] in java wrapped object
IGNATIUS EVANS <dtd3835 <at> bellsouth.net>
2010-04-08 23:57:25 GMT
I am working on a project where i am using a C library for my backend, and a java GUI for my frontend. In a header file i have the following C struct:
typedef struct {
PixelType type;
int num_bands;
int num_rows;
int num_cols;
int max_pix_val;
int num_cc;
union {
byte *byte_data;
int *int_data;
double *double_data;
} data_1d;
union { byte *byte_data_1b;
byte *byte_data_3b;
int *int_data_1b;
int *int_data_3b;
double *double_data_1b;
double *double_data_3b;
} data_nd;
} Image;
The byte type has a typedef declaring it an unsigned char. All *byte, *int, and *double
pointers are unbounded C arrays. I have the following in the interface file used for this header file:
%include typemaps.i %include arrays_java.i
typedef unsigned char byte;
%apply byte[] {byte *}; %apply int[] {int *}; %apply double[] {double *};
In the data_1d file i get the following output:
public void setByte_data(short[] value) { zernike_momentsJNI.Image_data_1d_byte_data_set(swigCPtr, this, value); }
public short[] getByte_data() { return zernike_momentsJNI.Image_data_1d_byte_data_get(swigCPtr, this); }
public void setInt_data(int[] value) { zernike_momentsJNI.Image_data_1d_int_data_set(swigCPtr, this, value); }
public int[] getInt_data() { return zernike_momentsJNI.Image_data_1d_int_data_get(swigCPtr, this); }
public void
setDouble_data(double[] value) { zernike_momentsJNI.Image_data_1d_double_data_set(swigCPtr, this, value); }
public double[] getDouble_data() { return zernike_momentsJNI.Image_data_1d_double_data_get(swigCPtr, this); }
All this looks correct, but only works part of the time. Most of the time my app crashes giving me an error about a function in array_java.i:
An unexpected error has been detected by HotSpot Virtual Machine: # # SIGSEGV (0xb) at pc=0x6d24674d, pid=18669, tid=1822944176 # # Java VM: Java HotSpot(TM) Server VM (1.5.0_06-b05 mixed mode) # Problematic frame: # C [libfourier_project.so+0x2cb74d] SWIG_JavaArrayOutUchar+0x82 # # An error report file with more information is saved as hs_err_pid18669.log # # If you would like to submit a bug report, please visit: #
http://java.sun.com/webapps/bugreport/crash.jsp
Can anyone point me in the right direction on how to wrap these arrays correctly using SWIG where my app doesn't crash. I have extensively tested my solution, and haven't noticed any patterns that make my app crash. It seems to randomly crash, and i have to present my work soon. Can anyone help me??????????????????????????????????
|
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev