Dushistov / flapigen-rs

Tool for connecting programs or libraries written in Rust with other languages
BSD 3-Clause "New" or "Revised" License
775 stars 59 forks source link

C/C++ : Buggy conversion of ::std::os::raw::c_uint #427

Closed stephan57160 closed 2 years ago

stephan57160 commented 2 years ago

Found this buggy conversion, while reading cpp-include.rs :

foreign_typemap!(
    (r_type) ::std::os::raw::c_uint;
    (f_type) "unsgined int";
);

Should be

   (f_type) "unsigned int";

Sample testing code :

pub fn buggy_param(arg: ::std::os::raw::c_uint) {
    println!("LIB : buggy_param({})", arg);
}

pub fn buggy_return() -> ::std::os::raw::c_uint {
    println!("LIB : buggy_return() -> c_uint");
    return 42 as ::std::os::raw::c_uint;
}

foreign_class!(
    class Foo {
    fn buggy_param(arg: ::std::os::raw::c_uint);
    fn buggy_return() -> ::std::os::raw::c_uint;
    }
);

Produces the following c_Foo.h :

...
    void Foo_buggy_param(unsgined int arg);
    unsgined int Foo_buggy_return();
...

and Foo.hpp :

    static void buggy_param(unsgined int arg) noexcept;
    static unsgined int buggy_return() noexcept;

Even the C compiler indicates the correction :

gcc -c -Wall -I../library/bindings/cpp/debug/include -g -o debug/obj/test-000.o test-000.c
In file included from test-000.c:3:
../library/bindings/cpp/debug/include/c_Foo.h:30:26: error: unknown type name ‘unsgined’; did you mean ‘unsigned’?
   30 |     void Foo_buggy_param(unsgined int arg);
      |                          ^~~~~~~~
      |                          unsigned
../library/bindings/cpp/debug/include/c_Foo.h:32:13: error: expected ‘;’ before ‘int’
   32 |     unsgined int Foo_buggy_return();
      |             ^~~~
      |             ;