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

Question: Is `typedef xxxOpaque` needed, when there is no `selftype xxx` ? #431

Closed stephan57160 closed 2 years ago

stephan57160 commented 2 years ago

Input in glue.rs.in:

foreign_class!(
    class Foo {

        /// do_nothing() does nothing at all.
        fn do_nothing();
    }
);

Output in c_Foo.h:

#ifdef __cplusplus
static_assert(sizeof(uintptr_t) == sizeof(uint8_t) * 8,
   "our conversion usize <-> uintptr_t is wrong");
extern "C" {
#endif

    typedef struct FooOpaque FooOpaque;

    //do_nothing() does nothing at all.
    void Foo_do_nothing();

#ifdef __cplusplus
}
#endif

But as there is no struct FooOpaque defined anywhere, is there a need for this ?

    typedef struct FooOpaque FooOpaque;
Dushistov commented 2 years ago

Yes, in case of class with methods without "self" argument there are no need for this typedef.

stephan57160 commented 2 years ago

OK. I'll check for a fix. Sorry, I just saw that with my own enum test cases :-)