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

Fixed harlmess duplicate generated code with Vec<T> and possibly other cases. #436

Closed stephan57160 closed 2 years ago

stephan57160 commented 2 years ago

As discussed on #435, the code generation may create duplicate generated code. Most of the time, it's harmless, but it may bring troubles later or with other parts of code.

This happens in the following scenario when there is a function having a Vec in parameter and another one as return value:

    class Foo {
        fn Foo::return_is_array_u8() -> Vec<u8>;
        fn Foo::param_is_array_u8(_: Vec<u8>);
    }

If there is :

In this fix, a foreign_code_cache is added to CppContext. This cache is checked before writing from cpp-include.rs code rules. When the code entry is already present in the cache, it's no more written to FileWriteCache.

stephan57160 commented 2 years ago

Then, I don't see yet why there is a test case failure ...

Dushistov commented 2 years ago

Thanks for PR, I don't like cloning on every lookup, but I suppose this is can be addressed later.

stephan57160 commented 2 years ago

I don't like it either, but did not find anything better, for now... Thx to accept it anyway.