-
Notifications
You must be signed in to change notification settings - Fork 42
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
Incorrect values & MemoryError with protected variable and cross-inheritance #280
Comments
As the warning says:
Add one, i.e. I forget why it's just a warning. The git log shows that it used to be an error, so I guess someone asked for it to just be a warning. Maybe the warning should be refined to an error if the base class has data, but even in C++ the above code would be problematic, so I don't expect it to be common. |
Hi @wlav, please look at this example: cppyy.cppdef("""
class BaseA {
protected:
int Ai;
std::string As;
public:
BaseA(int i, std::string s) : Ai(i), As(s) {}
virtual ~BaseA() {}
int get_Ai() { return Ai; }
std::string get_As() { return As; }
};
class BaseB {
protected:
std::string Bs;
int Bi;
public:
BaseB(int i, std::string s) : Bi(i), Bs(s) {}
virtual ~BaseB() {}
int get_Bi() { return Bi; }
std::string get_Bs() { return Bs; }
};
""")
class Klass(cppyy.multi(gbl.BaseA, gbl.BaseB)):
def __init__(self, int1, int2, str1, str2):
super().__init__((int1, str1), (int2, str2))
k = Klass(5, 10, "Cpp", "Python")
print(f"{k.get_Ai() = }\t{k.Ai = }")
print(f"{k.get_Bi() = }\t{k.Bi = }")
print(f"{k.get_As() = }\t{k.As = }")
print(f"{k.get_Bs() = }\t{k.Bs = }") Output:
I believe this is a genuine bug? |
Yes, in as much. Still, you should shoot anyone who writes code like that. ;) See e.g.: https://isocpp.org/wiki/faq/multiple-inheritance#mi-disciplines IIRC, the base address used is the one of the stub, so most likely the problem is with the relative offset from there (and hence the problem with the 2nd class, with the first being fine as the in-class offset is 0 for it). Will have a look later; having a break for a bit now that the new release is just out. |
The offsets as I get them from ROOT/meta are off (to be sure, upstream ROOT/meta doesn't support |
I faced a similar problem at the compiler-research's fork. If it is to do with offsets; I fixed it with compiler-research/CppInterOp#396. May help.
|
Thanks, but it's a wee bit simpler in my case: the
The problem here being that the target decl gives the incorrect offset. There was already a special case using the I just did the same for the offset calculation: add a special case to use the |
Python Code to reproduce the bug
Output:
You can see that
derived.get_x()
andderived.x
returns different values.The text was updated successfully, but these errors were encountered: