bytedeco/javacpp

infinite recursion when calling virtualized inherited function

開放

#723 建立於 2023年10月21日

 (4 則留言) (0 個反應) (0 位負責人)Java (620 個分叉)batch import
enhancementhelp wanted

倉庫指標

星標
 (4,279 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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:

  1. Java d.f is called. f is not overridden in Java, so Java B.f is called
  2. JNI Java_B_f is called. Since B is virtualized, instead of calling C++ B::f, the object is checked whether if's an instance of the peer class JavaCPP_B. It's not the case, the object is a JavaCPP_D, and JavaCPP_D doesn't derive from JavaCPP_B. So f is called on the object, that is JavaCPP_D::f.
  3. JavaCPP_D::f calls Java d.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. ?

貢獻者指南