root
root copied to clipboard
[PyROOT] Automatic downcasting of smart pointers to actual type
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'