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

Support cxx opaque types for subclassing #1328

Closed
rzhw opened this issue Sep 5, 2023 · 2 comments
Closed

Support cxx opaque types for subclassing #1328

rzhw opened this issue Sep 5, 2023 · 2 comments

Comments

@rzhw
Copy link

rzhw commented Sep 5, 2023

When attempting to subclass a type that refers to types that can't be automatically converted by autocxx, compile will fail:

main.h

class MySuperType {
  public:
    virtual void DoSomething(MyUnsupportedType* foo, MySupportedType* bar) const = 0;
    virtual ~MySuperType() = default;
};

main.rs

include_cpp! {
    #include "main.h"
    safety!(unsafe_ffi)
    // This won't help, autocxx will still attempt to generate against the real MyUnsupportedType
    extern_cpp_opaque_type!("MyUnsupportedType", ffi2::MyUnsupportedType)
    subclass!("MySuperType", MyDerivedType)
}

#[cxx::bridge]
mod ffi2 {
    unsafe extern "C++" {
        type MyUnsupportedType;
    }
}

#[subclass]
#[derive(Default)]
pub struct MyDerivedType {}

impl ffi::MySuperType_methods for MyDerivedType {
    unsafe fn DoSomething(&self, foo: *mut ffi::MyUnsupportedType, bar: *mut ffi:MySupportedType) {
        unimplemented!("no lol")
    }
}
  Error:   × cxx couldn't handle our generated bindings - could be a bug in autocxx:
    │ unsupported type: MyUnsupportedType

Expected Behavior

It could be nice to allow the above (or similar) to work, i.e. if cxx can't handle a type then allow it to be used in an opaque manner.

Actual Behavior

Compile fails as above.

(Could this be related to #1278?)

Steps to Reproduce the Problem

See code above.

@adetaylor
Copy link
Collaborator

I see. Would you be kind enough to make a pull request which has a reproducible test case? (Ideally as a new integration test but failing that, changes to one of the existing demos/examples).

@adetaylor
Copy link
Collaborator

I spent a while trying to reproduce this but couldn't. I landed a test case in #1330. Please raise a new bug with a test case if you're still having trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants