Skip to content

[Python] Don't call TClass::GetClass() on branch type in TTreePyz #18604

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

Merged
merged 1 commit into from
May 5, 2025

Conversation

guitargeek
Copy link
Contributor

@guitargeek guitargeek commented May 5, 2025

It's not clear to me how it can even happen that TClass::GetClass() is nullptr for the type of a TTree branch.

It looks like the check is superfluous, and by not doing it we can avoid the memory hogging of GetClass() for standard vector types.

My suspicion is that the klass variable was there because many years ago, cppyy used ROOT casting via TClass, which got replaced at some point from BindRootObjectNoCast( *(char**)branch->GetAddress(), klass ) to BindCppObjectNoCast( *(char**)branch->GetAddress(), Cppyy::GetScope( branch->GetClassName() ) ) (see commit 9687598). Before that refactor, making the sanity check that klass was not nullptr made sense. But it looks like this is not needed anymore since the casting is done exclusively with cppyy.

Closes #18524.

It's not clear to me how it can even happen that TClass::GetClass() is
`nullptr` for the type of a TTree branch.

It looks like the check is superfluous, and by not doing it we can avoid
the memory hogging of `GetClass()` for standard vector types.

Closes root-project#18524.
Copy link
Member

@vepadulano vepadulano left a comment

Choose a reason for hiding this comment

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

LGTM because the class was already retrieved via branch->GetClassName(). Even in the case where this returns an empty string, it will be practically the same behaviour as before: we would return a pointer and an empty string which would then cause this other part of the code to eventually raise an exception.

@guitargeek guitargeek merged commit 9a9e769 into root-project:master May 5, 2025
22 checks passed
@guitargeek guitargeek deleted the issue-18524 branch May 5, 2025 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory not released after TTree GetEntry() in PyROOT
2 participants