bytedeco/javacpp
View on GitHubinfinite recursion when calling virtualized inherited function
Open
#723 opened on Oct 21, 2023
enhancementhelp wanted
Description
struct B {
int x;
virtual void f() { }
virtual ~B() { };
};
struct D: public B {
int y;
};
infoMap
.put(new Info("B").virtualize())
.put(new Info("B::x").annotations("@NoOffset"));
class Test {
public static void main(String[] a) {
D d = new D();
d.f();
}
}
This triggers an infinite recursion:
- Java
d.fis called.fis not overridden in Java, so JavaB.fis called - JNI
Java_B_fis called. SinceBis virtualized, instead of calling C++B::f, the object is checked whether if's an instance of the peer classJavaCPP_B. It's not the case, the object is aJavaCPP_D, andJavaCPP_Ddoesn't derive fromJavaCPP_B. Sofis called on the object, that isJavaCPP_D::f. JavaCPP_D::fcalls Javad.f.
How to solve this ?
Shouldn't JavaCPP_D derives from JavaCPP_B in addition of deriving from D ?
Or should we call explicity B::f and bypass dynamic invocation at the end of 2. ?