google/autocxx

Method `alloc` breaks moveit (compilation error)

hfiguiere opened this issue · 4 comments

Describe the bug
Method alloc breaks moveit (compilation error)

To Reproduce

struct DataBuf {                                                                                                                                      
    void alloc();                                                                                                                                     
};
generate!("DataBuf");

This cause the follow compilation error.

┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
error[E0046]: not all trait items implemented, missing: `allocate_uninitialized_cpp_storage`
 --> /tmp/.tmpwE2POD/autocxx-ffi-default-gen.rs:1:1415
  |
1 | ...88849ba138 (this) }) } } } unsafe impl autocxx :: moveit :: MakeCppStorage for root :: DataBuf { unsafe fn free_uninitialized_cpp_stor...
  |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `allocate_uninitialized_cpp_storage` in implementation
  |
  = help: implement the missing item: `unsafe fn allocate_uninitialized_cpp_storage() -> *mut Self { todo!() }`
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈

Reroducer: #1319

Expected behavior

Compiles

Additional context

A similar issue also occurs for the free method, resulting in a missing free_uninitialized_cpp_storage in the moveit::MakeCppStorage implementation.

Would adding a simple prefix/suffix (e.g. cxx) to the names of these methods have any undesired effects? It resolves the compilation error, but I am quite unfamiliar with this codebase. Thanks.

pub(crate) fn get_alloc_name(ty_name: &QualifiedName) -> QualifiedName {
get_name(ty_name, "alloc")
}
pub(crate) fn get_free_name(ty_name: &QualifiedName) -> QualifiedName {
get_name(ty_name, "free")
}

Thanks for this report, and thanks for the reproducer. I think there's a good chance that you're right and that simply calling this autocxx_alloc will do the trick. I'll try it!

I'd like to be able to accept your test case directly from #1319 but I can't do that unless you accept the CLA there (sorry.) That way you can get well deserved credit for actually submitting a test case, which is quite rare, and much appreciated. If for some reason you can't accept the CLA no worries, I will write a new test case.

Ah I now see your comment on #1317 that you can't sign the CLA, fair enough. Thanks for the reproducer anyway.

Thank you for the fix!