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] Segfault when creating proxy to derived class with multiple overloads #7686

Closed
stwunsch opened this issue Mar 25, 2021 · 4 comments
Closed

Comments

@stwunsch
Copy link
Contributor

Following reproducer fails with a segfault:

import cppyy

cppyy.cppdef('''
struct Base {
    float data;
    float& operator[](int idx) { return data; }
};

struct Derived: public Base {
    float data;

    // Note that you have to derive from Base to make it break!
    float& operator[](int idx) { return data; }

    // Note that you must put the template here!
    template <typename T>
    float& operator[](int idx) { return data; }
};
''')

cppyy.gbl.Derived()

There's a corresponding issue submitted to upstream cppyy: https://bitbucket.org/wlav/cppyy/issues/334/segfault-when-creating-proxy-to-derived

This issues were found in the wake of RVec 2.0 (#7502) and may just scratch the surface of an issue in cppyy with picking up methods from derived classes. See the workarounds for operator[] and size in RVec 2.0 to avoid this problem.

@stwunsch stwunsch added the bug label Mar 25, 2021
stwunsch added a commit to eguiraud/root that referenced this issue Mar 25, 2021
PyROOT does not pick up correctly methods such as `operator[]` or `size`
from the parent classes and therefore fails to pythonize the proxies in
Python correctly. Raising the respective methods in the hierarchy is a
workaround for these issues, which are tracked in root-project#7686.
@stwunsch
Copy link
Contributor Author

Another reproducer pointing in the same direction is here. The iteration over the vector class fails because the size method is not picked up from the base class:

import ROOT

ROOT.gInterpreter.Declare('''
struct Base {
    std::vector<float> data;
    int size() { return data.size(); }
};

struct Vec : public Base {
    // using Base::size; // comment in this line to fix the iteration!
    void push_back(float x) { data.push_back(x); }
    float* begin() { return &data[0]; }
    float* end() { return &data[data.size() - 1]; }
    float& operator[](int idx) { return data[idx]; }
    void print() { for (auto x : data) std::cout << x << std::endl; }
};
''')

v = ROOT.Vec()
for i in [42, 43, 44]:
    v.push_back(i)
v.print()

c = 0
for x in v:
    print(c, x)
    if c > 10:
        raise Exception('Iteration failed!')
    c += 1

eguiraud pushed a commit to eguiraud/root that referenced this issue Apr 16, 2021
PyROOT does not pick up correctly methods such as `operator[]` or `size`
from the parent classes and therefore fails to pythonize the proxies in
Python correctly. Raising the respective methods in the hierarchy is a
workaround for these issues, which are tracked in root-project#7686.
eguiraud pushed a commit to eguiraud/root that referenced this issue May 4, 2021
PyROOT does not pick up correctly methods such as `operator[]` or `size`
from the parent classes and therefore fails to pythonize the proxies in
Python correctly. Raising the respective methods in the hierarchy is a
workaround for these issues, which are tracked in root-project#7686.
eguiraud pushed a commit to eguiraud/root that referenced this issue Jun 1, 2021
PyROOT does not pick up correctly methods such as `operator[]` or `size`
from the parent classes and therefore fails to pythonize the proxies in
Python correctly. Raising the respective methods in the hierarchy is a
workaround for these issues, which are tracked in root-project#7686.
eguiraud pushed a commit to eguiraud/root that referenced this issue Jun 15, 2021
PyROOT does not pick up correctly methods such as `operator[]` or `size`
from the parent classes and therefore fails to pythonize the proxies in
Python correctly. Raising the respective methods in the hierarchy is a
workaround for these issues, which are tracked in root-project#7686.
eguiraud pushed a commit to eguiraud/root that referenced this issue Jun 28, 2021
PyROOT does not pick up correctly methods such as `operator[]` or `size`
from the parent classes and therefore fails to pythonize the proxies in
Python correctly. Raising the respective methods in the hierarchy is a
workaround for these issues, which are tracked in root-project#7686.
eguiraud pushed a commit to eguiraud/root that referenced this issue Jul 8, 2021
PyROOT does not pick up correctly methods such as `operator[]` or `size`
from the parent classes and therefore fails to pythonize the proxies in
Python correctly. Raising the respective methods in the hierarchy is a
workaround for these issues, which are tracked in root-project#7686.
eguiraud pushed a commit to eguiraud/root that referenced this issue Jul 23, 2021
PyROOT does not pick up correctly methods such as `operator[]` or `size`
from the parent classes and therefore fails to pythonize the proxies in
Python correctly. Raising the respective methods in the hierarchy is a
workaround for these issues, which are tracked in root-project#7686.
eguiraud pushed a commit to eguiraud/root that referenced this issue Sep 29, 2021
PyROOT does not pick up correctly methods such as `operator[]` or `size`
from the parent classes and therefore fails to pythonize the proxies in
Python correctly. Raising the respective methods in the hierarchy is a
workaround for these issues, which are tracked in root-project#7686.
eguiraud pushed a commit that referenced this issue Sep 29, 2021
PyROOT does not pick up correctly methods such as `operator[]` or `size`
from the parent classes and therefore fails to pythonize the proxies in
Python correctly. Raising the respective methods in the hierarchy is a
workaround for these issues, which are tracked in #7686.
@dpiparo dpiparo assigned guitargeek and unassigned etejedor Feb 3, 2024
@dpiparo
Copy link
Member

dpiparo commented Feb 3, 2024

To be checked with the latest cppyy in the first place. Perhaps this will be fixed once we upgrade.

@guitargeek
Copy link
Contributor

Indeed, this will be fixed with the CPyCppyy update.

@guitargeek guitargeek added this to the 6.32/00 milestone Mar 19, 2024
Copy link

Hi @guitargeek,

It appears this issue is closed, but wasn't yet added to a project. Please add upcoming versions that will include the fix, or 'not applicable' otherwise.

Sincerely,
🤖

@guitargeek guitargeek removed this from the 6.32/00 milestone Mar 20, 2024
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

4 participants