bytedeco/javacpp

infinite recursion when calling virtualized inherited function

Open

#723 aberto em 21 de out. de 2023

Ver no GitHub
 (4 comments) (0 reactions) (0 assignees)Java (620 forks)batch import
enhancementhelp wanted

Métricas do repositório

Stars
 (4.279 stars)
Métricas de merge de PR
 (Mesclagem média 2d) (1 fundiu PR em 30d)

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:

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

Guia do colaborador