I'm having trouble passing a struct to a library function.
The C declaration for S is:
struct CS {
unsigned char *barray;
long *iarray;
}
I need (at least for now) to be able to write Java that looks like the following
C code, with f() being in a .dll library:
struct CS cs;
cs.barray = new unsigned char[len];
cs.iarray = 0;
int rv = f(cs);
I have code that looks like the following, and it is failing. During invocation
the field s.memory is still null, causing an exception. What am I doing wrong?
(I hope that during simplification of my code to get the snippet below, I didn't
discard the problem...) I think the problem is not barray, but rather iarray.
How do I set it null?
public class S extends Structure {
public byte[] barray;
public int[] iarray;
public S(byte []obs) {
barray = obs;
iarray = null;
}
}
byte[] obs = new[len];
S s = new S(obs); // s.size == CALCULATE_SIZE on exit from ctor.
int rv = Lib.INSTANCE.f(s); // null pointer exception here, because s.memory ==
null, because s.size == CALCULATE_SIZE still, because for iarray both
value==null and type.isArray() are true in s.calculateSize().