in reply to XS module typemap

$var is the name of the C variable for a particular funcion argument. $arg is the Perl SV that matches $var. So an "input" typemap sets $var to be some value based on $arg. An "output" typemap sets $arg based on $var. No, I don't recall where that is documented [ other than the source code :( so you might want to read bits of perl/lib/ExtUtils/*.pm from time to time ].

I would not recommend doing C-struct-to-Perl-hash conversion (or vice versa) via a typemap for two reasons:

  1. You'd have to do the conversion once or twice per call and the performance penalty can easily be too high.
  2. This takes at least a few lines of C code and putting that much C code into a typemap is a pain and hard to maintain.

I find it is better to keep C structs either "packed" into a Perl string if possible, or hidden in a Perl integer if necessary (as far as the XS interface is concerned). The first method is possible if the C code that you are interfacing to allows the caller to allocate the memory for the structs. The second method (or something similar or perhaps lots of memory copying) is required if the C API insists on passing back pointers to memory that it allocated itself.

Then you can write pack/unpack and/or insert/extract routines (in XS and/or Perl) and probably provide one or more Perl wrappers that do the pack-then-call-XS-then-unpack to make things easy for certain cases.

There are a ton of ways to write these pack/unpack and/or insert/extract routines. I'd probably have:

$packed= mystructPack( \%unpacked ); $refToUnpacked= mystructUnpack( $packed );
If you want more details then post more details like the specific struct and what you typically do with it.

Also, buffers.h in Win32API::Registry includes some macros for dealing with typemaps of pointers to structs.

        - tye (but my friends call me "Tye")