From: Valient G. <va...@gm...> - 2006-07-22 21:26:17
|
I'm creating a Java wrapper using Swig 1.3.29 and having some trouble with arrays. I have a struct which contains a byte array, the size of which is not known at compile time. I would like the regular get accessor to return a byte[]. I've reduced the code to a simple example: test.h: typedef const char * buffer_p; struct Test { #ifdef SWIG %immutable; #endif buffer_p buf; int bufSize; }; test.i: %module TestWrapper %{ #include "test.h" %} %include "typemaps.i" %include "arrays_java.i" %apply signed char[] { buffer_p } %include "test.h" Then I run "swig -java test.i" The problem here is that swig doesn't know the size of Test.buf. It produces JNI code which contains the following in the buf_get method: jresult = SWIG_JavaArrayOutSchar(jenv, result, FillMeInAsSizeCannotBeDeterminedAutomatically); How can I tell SWIG that the size of Test.buf is Test.bufSize? I figured my options would go something like: 1. replace the JNI code for buf_get. I tried to use %native to replace the JNI code for Test_buf_get , but then I get errors from swig saying that Test_buf_get is defined more then once. 2. somehow tell SWIG what the size is I tried adding "%apply signed char [bufSize] { buf }" before the buf definition, but then I get an error message "test.h:8: Warning(453): Can't apply (signed char [Test::bufSize]). No typemaps are defined. " 3. post-process the wrapper function to fill in the FillMeIn... vars... Possible but ugly. Any ideas? TIA, Valient |