-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Allow specifying custom base classes #4247
base: master
Are you sure you want to change the base?
Conversation
- Useful for object hierarchies that don't use C++ inheritance (such as GObject)
static void init(const custom_base<T> &b, type_record *r) { | ||
r->add_base(typeid(T), b.fn); | ||
// TODO: rename this to 'nonsimple'? | ||
r->multiple_inheritance = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You really mean simple_ancestors=False, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't set that here, but that's what setting multiple_inheritance causes. See the TODO comment. :)
First impression: amazing 1. how small the core changes are and 2. CI full success on first try. I'm wondering about limitations and pitfalls, without having anything specific in mind, due to lack of familiarity with the internals you're touching. Can you think of any? Some slightly random questions:
|
I expect that as I play with it I'll run into some pitfalls, but I have some other priorities to attend to before doing that. I suspect trampolines might not work, and if someone really wanted to bind GObject you'd need a custom metaclass.
Definitely expect it to, since that's what the multiple-inheritance stuff is for.
Maybe. The limitation is that in
If you had a function that was of the form |
This weekend I played a bit with this concept. There's definitely a bit of work one needs to do to fully flesh this out. In particular, to support inheritance I needed to add an |
Description
In the GObject* (and others, such as QEMU's qdev) type system, C-compatible 'inheritance' is implemented by embedding the parent struct in the child struct:
One can already implement a polymorphic_type_hook to go from
Parent
toChild
objects, but currently you can't do:This allows specification of arbitrary base classes for a bound object, which allows this use case (and others as well).
Suggested changelog entry: