I found a strange and annoying thing with typemaps..
At least I figured it out finally.
Consider this .xs file (for a C++ class):

MODULE = Ogre     PACKAGE = Ogre::Renderable

void
Renderable::DESTROY()

void
Renderable::CREATE()


with this typemap file:

TYPEMAP

Renderable *    O_OGREOBJ

INPUT

O_OGREOBJ
        whatever

OUTPUT

O_OGREOBJ
        whatever


I actually had several .xs files like that with a DESTROY method
along with corresponding typemappings.
  xsubpp would output the XSUB for CREATE (or any other non-DESTROY)
method just fine. But it would give this puzzling error
for DESTROY:

  Error: No INPUT definition for type 'Renderable *',
   typekind 'O_OGREOBJ' found in Test.xs, line 4

After much screaming and hair-pulling, I tried adding a "typekind"
of O_OGREPINKY which was just a copy of O_OGREOBJ (to rule out
that the problem wasn't the syntax of the type definition).
And suddenly it worked!
  I thought I was going to have to duplicate the "typekinds",
after just having finally reworked them all to get rid of
the duplication... But I tried something else: instead of just
copying the typekind, I removed the original one and left
the renamed one, "O_OGREPINKY". It still worked!
  In the end, it turns out to be that xsubpp explicitly
RENAMES THE TYPEKIND if it ends with "OBJ" and the method
name is "DESTROY":

  $tk =~ s/OBJ$/REF/ if $func_name =~ /DESTROY$/;

There's apparently a convention for typekinds
ending with Ptr. In perlxs, there is a section
"Perl Objects And C Structures" which I'm trying to reconcile
with the section "Using XS With C++". I guess I should ignore
the C structs section, and just name the typekind
something not ending with "OBJ". Or do I need to create
these special *Ptr packages. A C++ class is basically a struct.
Argh...

Reply via email to