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

Extend trampoline class pattern to support nesting #4547

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Chekov2k
Copy link
Contributor

@Chekov2k Chekov2k commented Mar 4, 2023

Description

Extend documentation for multiple inheritance using trampoline classes. Adds a pattern to support nesting of two or more trampoline class inheritance hierarchies. Simple unit test showing the pattern has been added as well.

For some reason the MSVC linker needs a default implementation of the pure virtual base class methods in the unit tests. Should I add a pitfall section to the documentation? Something like:

Pitfall for MSVC: You might need to provide a hidden default implementation for the pure virtual base class methods due to missing symbols during linking, see https://devblogs.microsoft.com/oldnewthing/20131011-00/?p=2953

Suggested changelog entry:

The trampoline pattern for supporting virtual method binding for multiple inheritance class hierarchies has been extended.
An example for supporting the interleaving of two or more trampoline class hierarchies has been added.

@Chekov2k Chekov2k force-pushed the multiple_inheritance_documentation branch 5 times, most recently from b74490e to 7953a56 Compare March 4, 2023 12:14
@Chekov2k Chekov2k force-pushed the multiple_inheritance_documentation branch 13 times, most recently from 0c204ee to 7909393 Compare March 6, 2023 09:32
@Chekov2k Chekov2k force-pushed the multiple_inheritance_documentation branch from 7909393 to cbb0590 Compare March 6, 2023 19:49
Comment on lines +2884 to +2891
#define PYBIND11_OVERRIDE_TEMPLATE_NAME(base, ret_type, cname, name, fn, ...) \
if (std::is_same<base, cname>::value) { \
PYBIND11_OVERRIDE_PURE_NAME( \
PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, fn, __VA_ARGS__); \
} else { \
PYBIND11_OVERRIDE_NAME( \
PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, fn, __VA_ARGS__); \
}
Copy link
Collaborator

@rwgk rwgk Mar 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a lot of meat, especially given the total size of this PR.

There is no significant complexity in this macro, and it's catering only to a niche case.

In contrast, the added documentation is overwhelming. If that's reflective of a typical use case, having to implement this helper macro is a relatively insignificant amount of extra code.

I don't see a lot of value in adding this pair of macros (this one and the one below).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Ralf for having a look at my PR. I understand your sentiment and it is perfectly fine to not merge this. The only thing I would like to point out is that the first part of the PR is a pure documentation update. It shows a trampoline class pattern for combining two (or more) separate class inheritance
hierarchies avoiding code duplication (backed by some unit tests). Only the second part requires the new macros for reducing code duplication with pure virtual functions. Cheers Arnim

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe

  • it's too much detail and too much code in that part of the documentation. (Especially because we're not set up to unit-test code in documentation.)
  • that view is biased by: I wouldn't want to encourage creating that kind of complexity. I live more by "minimize use of multiple inheritance", it tends to get too confusing too quickly. (Which absolutely does not mean "never" btw.)

@henryiii do you think the code in the documentation under this PR could be a useful addition as an example somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All valid points! Let me know what you decide and if things need moving around, stripping down, ...

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

Successfully merging this pull request may close these issues.

None yet

3 participants