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

Fix: AttributeError with anonymous unions #57

Conversation

@vgvassilev
Copy link

This looks good to me. @aaronj0 can you take a look? What’s the reason for the failing bot, is it still missing some suppression configuration?

@aaronj0
Copy link
Collaborator

aaronj0 commented Sep 9, 2024

This looks good to me. @aaronj0 can you take a look? What’s the reason for the failing bot, is it still missing some suppression configuration?

Yep, I think we are using the latest llvm19(rc2) on these repos, but not on InterOp(rc1), hence the discrepancy.

@vgvassilev
Copy link

@aaronj0, should we merge this or we should wait for you to update the suppression file?

@aaronj0
Copy link
Collaborator

aaronj0 commented Sep 9, 2024

@aaronj0, should we merge this or we should wait for you to update the suppression file?

We don't need to add the suppression now, but I have left some review comments that would be great if addressed

@vgvassilev
Copy link

@aaronj0, should we merge this or we should wait for you to update the suppression file?

We don't need to add the suppression now, but I have left some review comments that would be great if addressed

I don’t see any review comments. Can you click on finish review?

@vgvassilev
Copy link

@aaronj0 ping.

// already exists, so check for it and move on if set
PyObject* eset = PyObject_GetAttrString(pyclass,
const_cast<char*>(Cppyy::GetFinalName(datamember).c_str()));
if (eset) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should get by with less refactoring (i.e. retain the changes in the anonymus enum block in BuildScopeProxyDict(adding the offset), instead of moving the whole block that collects datamembers to AddPropertyToClass

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The reason behind moving the entire logic into AddPropertyToClass is to be able to use recursion for nested anonymous structs and unions.
Test cases do not fail, so the refactor is safe.

Let me know if there is a specific change that looks off to you.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes I was wondering whether the recursion is a good idea but I guess since it only happens when we have anonymous structs and unions, it should not be too expensive in the normal case.

I was wondering how masters support nested anonymous structs and unions without recursion?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was wondering how masters support nested anonymous structs and unions without recursion?

I did not have a look at it. I saw the problem and came up with a solution. The solution looked simple and easy to implement. So I did not look at how master does this.

Copy link
Collaborator

@aaronj0 aaronj0 Sep 10, 2024

Choose a reason for hiding this comment

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

I understand that but one of the main points here is not to diverge from master as much as possible. We can make as many changes in clingwrapper and add interfaces in InterOp to facilitate/emulate what is made available to CPyCppyy to achieve the same result. Since the support does not use recursion in master and is achieved with the interfaces at hand, I would recommend a side-by-side debug to emulate the same on the backend side. @vgvassilev what do you think?

Choose a reason for hiding this comment

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

Yes, eventually we should merge all of this work back to upstream and if that change is not mergeable will be a problem. I cannot judge that now but perhaps we could discuss that at the meeting later today.

Comment on lines +117 to +125
if (strstr(Cppyy::GetDatamemberTypeAsString(data).c_str(), "anonymous struct at") ||
strstr(Cppyy::GetDatamemberTypeAsString(data).c_str(), "anonymous union at")) {
std::vector<Cppyy::TCppScope_t> datamembers = Cppyy::GetDatamembers(Cppyy::GetTypeScope(data));
for (auto &datamember: datamembers) {
// properties (aka public (static) data members)
AddPropertyToClass(pyclass, scope, datamember,
additional_offset + Cppyy::GetDatamemberOffset(data));
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Recursion is used here.

I can undo the changes in BuildScopeProxyDict, but then I will have to duplicate the same things in AddPropertyToClass for recursion to work.

@Vipul-Cariappa
Copy link
Collaborator Author

@aaronj0 @vgvassilev
closing this PR as this issue is fixed by compiler-research/CppInterOp#321

@Vipul-Cariappa Vipul-Cariappa deleted the anonymous-union branch September 17, 2024 06:46
@vgvassilev
Copy link

@aaronj0 @vgvassilev closing this PR as this issue is fixed by compiler-research/CppInterOp#321

That is great. Can you open a PR against cppyy to enable the tests that this fixed?

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.

3 participants