简体   繁体   中英

Disable conversion from char* to java.lang.String

on C side I have something like

void fn(char *s) {
  if(s != NULL) {
    sprintf(s, "some string");
  }
}

I want to get the value on java side using carrays.i SWIG module. But SWIG generates for me somthing like fn(String s) . How to prevent such conversion to have something like fn(char_p s) to use carrays functionality.

The docs say that carrays.i is for treating a C pointer as a Java array. Also, signed char won't be mapped to String . So, void fn(signed char *INOUT) gives you public final static native void fn(byte[] jarg1)

You override your C declaration (probably in a C header file) within the module .i file:

%module test
%include "typemaps.i"
%include "carrays.i"

%{
extern void fn(char *);
%}
extern void fn(signed char *INOUT);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM