-
Notifications
You must be signed in to change notification settings - Fork 157
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
String parameter of a callback function gets messed when passed from DLL (Rust) to Java #335
Comments
Same issue here. JNA returns normal result but JNR returns with a small number of corrupted data, involking the same C function. JNR code: import jnr.ffi.LibraryLoader;
public interface JNRUtils {
JNRUtils INSTANCE = LibraryLoader.create(JNRUtils.class).load("QGram");
public double calc_similarity(String str1, String str2, int q);
public String purge_duplicated_spaces(String s);
} C code: char *purge_duplicated_spaces(char *str)
{
re_length_t re_match_start;
struct re_context *re_ctx = (struct re_context *)calloc(1, sizeof(struct re_context));
while (true)
{
re_ctx->match_length = 0;
re_match(re_ctx, "\\s+", text_args(str), &re_match_start);
if (re_ctx->match_length == 0)
{
free(re_ctx);
break;
}
delete_sub_str(str, re_match_start, re_ctx->match_length); // Another function to delete some substring from a string
}
int p = 0;
while(str[p] != '\0')
{
if (str[p] == '\1') {
str[p] = ' ';
}
p++;
}
return str;
} |
I assume the conversion is done by It is just a guess, but maybe your default charset results in a width > 1. |
I got bit by this bug as well, but fortunately there's a workaround.
Yeah, this seems to be issue. On my machine, the default charset is You can work around this problem by telling JNR to use UTF-8 encoding for the public interface WrenWriteFn {
@Delegate
void invoke(Pointer vm, @Encoding("utf8") String text);
} This fixed the issue for me, at least. |
o/ I'm migrating from JNA to JNR, and almost everything works fine. However, I've run into a really odd bug when using callback functions. I've built a minimal project that reproduces it. The JNA equivilent works fine.
Note: My native library is written in Rust
How to reproduce
Java:
Rust:
The output:
(The corruption is different every time)
Any idea what could be causing this?
The text was updated successfully, but these errors were encountered: