Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java array typemap of type signed char[] cannot be applied to type const char* in swig v4.2.1 #3000

Open
Golden-Wang opened this issue Aug 21, 2024 · 0 comments

Comments

@Golden-Wang
Copy link

Golden-Wang commented Aug 21, 2024

My use case will have C++ code be compiled with -fsigned-char. I want to typemap char pointer as array of signed char rather than string. I ran into this error when upgrading from an earlier version of swig to the latest v4.2.1. See the example below:

test.i

%module test
%include "arrays_java.i"

%apply signed char[] {const char*};

%include test.h

%{
void bar(const char *s) {
    return;
}

int main() {
    const char *foo = "hello world";
    bar(foo);
    return 0;
}
%}

test.h

void bar(const char*);

Bash Commands

swig -c++ -java -package com.test -outdir . test.i
g++ -I/opt/jdk1.8.0_212/include -I/opt/jdk1.8.0_212/include/linux test_wrap.cxx

Error

test_warp.cxx: In function 'void Java_com_test_testJNI_bar(JNIEnv*, jclass, jbyteArray)':
test_wrap.cxx:915:44: error: invalid conversion from 'char**' to 'signed char**' [-fpermissive]
  915 |   if(!SWIG_JavaArrayInSchar(jenv, &jarr1, (char **)&arg1, jarg1)) return ;

Versions

I found v4.2.0 and v4.2.1 both have this error.
This error does not happen in v4.1.1 and earlier versions, where the example given above can be compiled successfully.
I narrowed down the breaking change to commit 7bba06b by @wsfulton .
Please let me know if my use case is valid and any recommended alternatives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant