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

[PyROOT] Automatic downcasting of smart pointers to actual type #16210

Open
guitargeek opened this issue Aug 9, 2024 · 0 comments
Open

[PyROOT] Automatic downcasting of smart pointers to actual type #16210

guitargeek opened this issue Aug 9, 2024 · 0 comments

Comments

@guitargeek
Copy link
Contributor

guitargeek commented Aug 9, 2024

It would greatly help memory safety if ROOT could use more smart pointers in its interfaces.

However, the automatic downcasting of returned values is only working for raw pointers. It should work for smart pointers as well.

For example, right now this doesn't work:

class ClassA {
public:

ClassDef(ClassA, 0);
};

class ClassB : public ClassA {
public:
void helloB() {}

ClassDef(ClassB, 0);
};

ClassA *fooRawPtr() { return new ClassB{}; }

std::unique_ptr<ClassA> fooUniquePtr() { return std::make_unique<ClassB>(); }

Output:

<class cppyy.gbl.ClassB at 0x5e1ddf85ed20>
Traceback (most recent call last):
  File "/home/rembserj/repro.py", line 30, in <module>
    out_2.helloB()
    ^^^^^^^^^^^^
AttributeError: 'ClassA' object has no attribute 'helloB'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants