bytedeco/javacpp

infinite recursion when calling virtualized inherited function

Open

#723 aperta il 21 ott 2023

Vedi su GitHub
 (4 commenti) (0 reazioni) (0 assegnatari)Java (620 fork)batch import
enhancementhelp wanted

Metriche repository

Star
 (4279 star)
Metriche merge PR
 (Merge medio 2g) (1 PR mergiata in 30 g)

Descrizione

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. ?

Guida contributor