bytedeco/javacpp
在 GitHub 查看infinite recursion when calling virtualized inherited function
Open
#723 创建于 2023年10月21日
enhancementhelp wanted
描述
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. ?