Discussion:
typemap variables docs
(too old to reply)
Scott Lanning
2007-09-07 09:50:01 UTC
Permalink
Is it documented somewhere which variables are
available to typemaps and what they are?
Like $arg, $var, $type, but I also see different
and mysterious ones. I tried looking around ExtUtils,
but ran in circles.
I find myself copy/paste/editing typemaps a zillion times,
but I think I could surely doing it much more concisely
if I knew which variable to use.
Steve Fink
2007-09-08 03:55:44 UTC
Permalink
Post by Scott Lanning
Is it documented somewhere which variables are
available to typemaps and what they are?
I have a vague memory of seeing such a thing, but I can't track it
down. I may have been making it up.
Post by Scott Lanning
Like $arg, $var, $type, but I also see different
and mysterious ones. I tried looking around ExtUtils,
but ran in circles.
What's an example of such a thing? I scanned through xsubpp, but
didn't see any more '$' things other than those three.

I think there may be constructs usable in different parts (prototypes,
something to do with lengths or STRLEN, ...?) Are those what you are
thinking of?
Post by Scott Lanning
I find myself copy/paste/editing typemaps a zillion times,
but I think I could surely doing it much more concisely
if I knew which variable to use.
Yes, mine tend to grow too. The only thing I've come up with is
defining subroutines for the commonly repeated actions. For example,
all of my OUTPUT typemaps for pointers to objects look like

$arg = $var ? wrap("Some::Class", $var) : &PL_sv_undef;

where wrap() is a subroutine defined in a file whose header I include
in all of my XS files. I don't think I made it inline, though I
probably should; instead, the definition is in my main application in
which I am embedding Perl.

That doesn't really help, I know. I have been somewhat tempted to
autogenerate my typemap file, but I only have nine pointer-to-object
types, so I don't mind the duplication all that much.
Marvin Humphrey
2007-09-08 13:36:43 UTC
Permalink
Post by Steve Fink
Post by Scott Lanning
Like $arg, $var, $type, but I also see different
and mysterious ones. I tried looking around ExtUtils,
but ran in circles.
What's an example of such a thing?
'locate typemap' on my system came up with this file, which had some
pretty rich examples:

/System/Library/Perl/5.8.6/ExtUtils/typemap
Post by Steve Fink
I scanned through xsubpp, but
didn't see any more '$' things other than those three.
Theres $ntype. See <http://world.std.com/~swmcd/steven/perl/pm/xs/
tools/index.html>.

Looks like $Package might be another, though I haven't used it myself.
Post by Steve Fink
I have been somewhat tempted to
autogenerate my typemap file, but I only have nine pointer-to-object
types, so I don't mind the duplication all that much.
One of my distros has over 100 that follow the same pattern, so I
autogenerate mine.

Marvin Humphrey
Rectangular Research
http://www.rectangular.com/
Scott Lanning
2007-09-10 08:40:13 UTC
Permalink
Post by Steve Fink
Post by Scott Lanning
Is it documented somewhere which variables are
available to typemaps and what they are?
I have a vague memory of seeing such a thing, but I can't track it
down. I may have been making it up.
Post by Scott Lanning
Like $arg, $var, $type, but I also see different
and mysterious ones. I tried looking around ExtUtils,
but ran in circles.
What's an example of such a thing? I scanned through xsubpp, but
didn't see any more '$' things other than those three.
I think there may be constructs usable in different parts (prototypes,
something to do with lengths or STRLEN, ...?) Are those what you are
thinking of?
I'm currently using $arg, $var, $type, $Package, and $func_name
(in http://search.cpan.org/src/SLANNING/Ogre-0.26/typemap
which are passed to macros in
http://search.cpan.org/src/SLANNING/Ogre-0.26/perlOGRE.h ).
I copied those from somewhere.

I guess the answer will eventually be
"whatever variables happen to be in scope when
that part of the typemap is `eval`ed"
(which seems to be all variables in `xsubpp`....).

Loading...