daoswald/Inline-CPP

virtual dtor causes bad wrappers to be generated for all methods

Opened this issue · 1 comments

jimav commented

Hi,
if a destructor is virtual, then bad wrappers are generated for methods. The generated code seems like it thinks the methods are global functions, not methods.

Note: There are no "pure" virtual methods, so the class is not abstract:

#!/usr/bin/perl
use strict; use warnings;

use Inline CPP => <<'CPPEND';
class MyClass {
  public:
    MyClass() {}
    virtual ~MyClass() {}
    void meth() { printf("Hello from MyClass::meth\n"); }
};
CPPEND

my $obj = MyClass->new();
$obj->meth;

The generated .xs code looks like this:

MODULE = t_pl_8615        PACKAGE = main  

PROTOTYPES: DISABLE

void
meth()
    PREINIT:
    I32 *   __temp_markstack_ptr;
    PPCODE:
    __temp_markstack_ptr = PL_markstack_ptr++;
    meth();     //*** COMPILE ERROR "meth was not declared in this scope"
        if (PL_markstack_ptr != __temp_markstack_ptr) {
          /* truly void, because dXSARGS not invoked */
          PL_markstack_ptr = __temp_markstack_ptr;
          XSRETURN_EMPTY; /* return empty stack */
        }
        /* must have used dXSARGS; list context implied */
        return; /* assume stack size is correct */

I cloned master on github but couldn't figure out what was going wrong.
Thanks.

The best approach would be:

  • make a branch
  • write a test case (or add to an existing one) with something you think should work
  • put that on the branch
  • pull-request that branch, ask for comments

Your posting achieves the heart of this (clearly expressing what you think should work), but is only 90% as actionable :-)