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 IsEnum check in cppyy/metacling #17775

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

Conversation

aaronj0
Copy link
Contributor

@aaronj0 aaronj0 commented Feb 20, 2025

Fixes #10454, and the following reproducer no longer seg faults:

import ROOT

ROOT.gInterpreter.Declare('''
class UponCopyPrinter {
public:
   ~UponCopyPrinter() = default;          
   UponCopyPrinter() = default;      
   UponCopyPrinter(const UponCopyPrinter &) { std::cout << "Invoking copy c'tor!" << std::endl; }
   UponCopyPrinter(UponCopyPrinter &&) = default;
   UponCopyPrinter &operator=(const UponCopyPrinter &) = default;
   UponCopyPrinter &operator=(UponCopyPrinter &&) = default;
};
''')

RVec_UponCopyPrinter = ROOT.ROOT.VecOps.RVec(ROOT.UponCopyPrinter)

v = RVec_UponCopyPrinter(3)
v2 = RVec_UponCopyPrinter(v.data(), v.size())
print("%s and %s" %(v.data(), v2.data()))

v2.resize(4)
print("%s and %s" %(v.data(), v2.data()))

This PR also enables InterOp API in clingwrapper, which is the first step towards performing clang-based reflection in cppyy, bypassing the limitations of the type system.

I am currently testing in TCling whether this is ready to use for ClassInfo_IsEnum(expecting some failures). Ideally we would patch Cppyy::IsEnum to fix this issue, which I will test in a following commit after the CI run, hence the changes in clingwrapper's cmake.

cc @vepadulano

This is the first step towards performing pure clang based reflection in cppyy, bypassing the limitations of the type system.
Copy link

github-actions bot commented Feb 20, 2025

Test Results

0 tests   0 ✅  0s ⏱️
0 suites  0 💤
0 files    0 ❌

Results for commit 59ef22e.

♻️ This comment has been updated with latest results.

@hahnjo
Copy link
Member

hahnjo commented Feb 20, 2025

Note that by relying on CppInterOp will not allow to backport to 6.32 and 6.34 releases...

@aaronj0 aaronj0 marked this pull request as draft February 20, 2025 09:48
@@ -1078,9 +1081,13 @@ bool Cppyy::IsAbstract(TCppType_t klass)
bool Cppyy::IsEnum(const std::string& type_name)
{
if (type_name.empty()) return false;
std::string tn_short = TClassEdit::ShortType(type_name.c_str(), 1);
if (tn_short.empty()) return false;
return gInterpreter->ClassInfo_IsEnum(tn_short.c_str());
Copy link
Member

Choose a reason for hiding this comment

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

Note: this solve the problem 'only' for Python. It would be even better to fix TCling::ClassInfo_IsEnum.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed! The initial fix was in TCling(https://github.com/root-project/root/actions/runs/13424841558), that caused a certain set of test failures. I was curious to know which of them happened only via the python interface leading me to temporarily patch clingwrapper instead

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.

[cling] Memory hogging when checking if type is an enum
3 participants