sql - Java JNI and ellipsis mess -
i have function in c adds row table. function takes arguments various orderings of ints, floats, , strings using ellipsis add_row(int arg1, int arg2, ...)
, parses information based on how columns set up.
i need call function java , using jni. i'm not sure best way java's stricter typing. i've considered few solutions none of them seem / i'm not sure how implement them: passing strings, passing jobjectarray, or passing cell values 1 @ time.
any appreciated.
thanks,
ben
this less problem java , jni , more problem of how call var args function in c dynamic list of arguments. see calling c function varargs argument dynamically suggests having 2 versions of var args function (although think convention more allow passthrough of existing va_list
, rather constructing 1 (which seems quite involved)).
the jni bit should define java native method object array arguments have c equivalent receiving array. use jni api convert values c equivalents (ints , ansi strings) load them var args structure , call vadd_row()
function.
java:
package mypackage; public class myclass { ... public native void addrow(object[] args); ... }
c:
void vadd_row(int arg1, int arg2, va_list argp) { ... function ... } void add_row(int arg1, int arg2, ...) { va_list argp; va_start(argp, arg2); vadd_row(int arg1, int arg2, argp); va_end(argp); } jniexport void jnicall mypackage_myclass_addrow(jnienv *env, jobject this, jint arg1, jint arg2, jobjectarray jarg_array) { va_list argp; /* need construct argp, see link below hints[1]; go through each element of java array, object; convert primitive value or ansi string, encode va_list */ vadd_row((int)arg1, (int)arg2, argp); }
[1] https://bbs.archlinux.org/viewtopic.php?pid=238721
is worth hassle?
consider writing simpler c function receives arguments in array, create wrapper uses var args if needed.
Comments
Post a Comment