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] False positive in cppyy proxy cache #17109

Open
guitargeek opened this issue Nov 27, 2024 · 0 comments
Open

[PyROOT] False positive in cppyy proxy cache #17109

guitargeek opened this issue Nov 27, 2024 · 0 comments

Comments

@guitargeek
Copy link
Contributor

guitargeek commented Nov 27, 2024

Reproducer:

import ROOT

ROOT.gInterpreter.Declare("""
struct A {
   int a;
   A(int _a) : a(_a) {}
};

std::unique_ptr<A> create() { return std::make_unique<A>(42); }

struct Consumer {
public:
   Consumer(std::unique_ptr<A> & ptr) : fPtr{std::move(ptr)}
     { ptr.reset(); }

   const A &get() const { return *fPtr; }

private:
   std::unique_ptr<A> fPtr;
};

""")


x = ROOT.create()
print(x)
print(x.a)
c = ROOT.Consumer(x)
print(x)
x = c.get()
print(x)
print(x.a)

Output:

<cppyy.gbl.A object at 0x5d77cc252e40 held by std::unique_ptr<A,default_delete<A> > at 0x5d77cc2432e0>
42
<cppyy.gbl.A object at 0x(nil) held by std::unique_ptr<A,default_delete<A> > at 0x5d77cc2432e0>
<cppyy.gbl.A object at 0x(nil) held by std::unique_ptr<A,default_delete<A> > at 0x5d77cc2432e0>
Traceback (most recent call last):
  File "/home/rembserj/spaces/master/root/src/root/jonas.py", line 32, in <module>
    print(x.a)
          ^^^
ReferenceError: attempt to access a null-pointer

The new x should not be a nullptr anymore, but a reference to the object that the Consumer points to internally.

Thanks to @hahnjo for finding this problem!

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

1 participant