Skip to content

Generator: Fix condition on which shell classes are generated - #374

Open
usiems wants to merge 3 commits into
mainfrom
fix_shell_class_generation
Open

usiems wants to merge 3 commits into
mainfrom
fix_shell_class_generation

Conversation

@usiems

@usiems usiems commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Shell classes are a mechanism in generated wrapper code by which Python code can override virtual methods of wrapped classes. They are derived from the wrapped classes and override all virtual methods to first look for a Python implementation.

We have now noticed that these shell classes are also generated for classes that are not virtual at all. This has the big problem that the destructor of such an overridden class also is not virtual, so that that the destructor of such a shell class is never called, just the destructor of the base class. Also the shell classes didn't serve any purpose, since there were no virtual functions. (This is not the whole truth, the shell classes were also needed if there were protected constructors one wanted to use in a derived class, but a virtual destructor is still a hard requirement for a shell class to work correctly.)

The fix is to change the condition on which shell classes are generated to include a check if the destructor is virtual, and some other condition fixes. The PR also contains some minor related clean-ups.

I compared the generated wrappers for Qt 6.11.2 with the previous state, and didn't notice any problematic omissions of shell classes.

or field accessors - those were not created in the shell classes, and
the shell classes were not used for that (this might be a remnant of the
original Java wrapper generator).
Instead require additionally that the destructor is virtual. Otherwise
the wrong destructor will be called for objects created from Python.
(this method isn't currently used anymore, though)

bool AbstractMetaClass::hasProtectedConstructors() const
{
return queryFunctions(Constructors | WasProtected).size() != 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

size() != 0 is a bit strange. I would expect size() > 0, or better !isEmpty().
A matter of taste, I guess...

{
for (const AbstractMetaField* field : fields()) {
if (field->getter() || field->setter())
if (field->isPublic() && (field->getter() || field->setter()))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If it's not used, why not just remove it?

This branch has not been deployed

No deployments
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.

2 participants