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

Bug Report: Invalid Type in Bindgen IR with foreign_class! Macro #468

Open
Florian9M opened this issue Jan 9, 2025 · 1 comment
Open
Labels
enhancement Java/JNI Case specific only for Java/JNI interface generation

Comments

@Florian9M
Copy link

Bug Report: Invalid Type in Bindgen IR with foreign_class! Macro

Description

Hello, I'm encountering an issue with the bindgen tool when using the foreign_class! macro. The error message is as follows:

The issue seems to be related to the add_char method, which modifies the information field of the Paris struct by adding a character. When this method is included in the foreign_class! macro, bindgen generates a warning about an invalid type. This suggests that bindgen may have difficulty handling the char type or the mutable reference (&mut self) used in this method.

Code with Error

Here is the code that generates the error:

//Automatically generated by rifgen
use crate::jni_c_header::*;

struct Paris {
    information: String,
}

impl Paris {
    fn new(top: String) -> Paris {
        Paris { information: top }
    }

    fn get_info(&self) -> &str {
        &self.information
    }

    fn add_char(&mut self, c: char) {
        self.information.push(c);
    }
}

foreign_class!(
class Paris {
    self_type Paris;
    constructor Paris::new(top : String)->Paris;
    fn Paris::get_info(& self)->&str; alias getInfo;
    fn Paris::add_char(& mut self , c : char); alias addChar;
}
);

Error

[WARN bindgen::ir::ty] invalid type Type(, kind: Invalid, cconv: 100, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None))

Code without Error

The following code does not produce the error:


//Automatically generated by rifgen
use crate::jni_c_header::*;

struct Paris {
    information: String,
}

impl Paris {
    fn new(top: String) -> Paris {
        Paris { information: top }
    }

    fn get_info(&self) -> &str {
        &self.information
    }
}

foreign_class!(
class Paris {
    self_type Paris;
    constructor Paris::new(top : String)->Paris;
    fn Paris::get_info(& self)->&str; alias getInfo;
}
);

Expected Behavior

The bindgen tool should generate valid bindings without any warnings or errors.

Actual Behavior

The bindgen tool generates a warning about an invalid type.

I would appreciate any assistance in resolving this issue. If more information is needed, please let me know.

@Dushistov Dushistov added enhancement Java/JNI Case specific only for Java/JNI interface generation labels Jan 9, 2025
@Dushistov
Copy link
Owner

Yes, at the moment flapigen do not support Rust's char to Java's char conversation.
You can work around using &str with one char to pass char from java to rust.

Though error message that you provide is strange.
That I got when I try to compile your code:

 --- stderr
  error in flapigen_test_jni: src/java_glue.rs.in
  parsing of flapigen_test_jni: src/java_glue.rs.in failed
  error: Do not know conversion from Java type to such rust type 'char'
      fn Paris::add_char(& mut self , c : char); alias addChar;
                                          ^^^^

have no idea what bindgen message is about,
may be you should report bindgen part (I suppose you use it to convert jni.h to Rust) to proper issue tracker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Java/JNI Case specific only for Java/JNI interface generation
Projects
None yet
Development

No branches or pull requests

2 participants