Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

ethan (3163)

  reversethis-{ed. ... rap.nov.olissat}

Being a 25-year old chap living in the western-most town of Germany. Stuying communication and information science and being a huge fan of XS-related things.

Journal of ethan (3163)

Thursday December 12, 2002
05:22 AM

My first typemap

[ #9402 ]

I just came up with my first working INPUT custom type-map that converts a hash-ref into an aa_renderparams C-struct. Looks slightly untypical for a typemap but it gets the job done quite nicely:

                SV **val;
                HV *h = (HV*)SvRV($arg);
                $var = (aa_renderparams*)safemalloc(sizeof(aa_renderparams));
                val = hv_fetch(h, \"-bright\", 7, FALSE);
                $var->bright = val ? (int) SvIV(*val) : 0;
                val = hv_fetch(h, \"-contrast\", 9, FALSE);
                $var->contrast = val ? (int) SvIV(*val) : 127; /* and so forth for the other members */

You really gotta love these typemaps.

After a while one starts to understand how XS works: It's basically one big preprocessor. xsubpp takes the default typemap plus your custom one and along with that runs through your .xs file to produce an eventually compilable .c file. This is very nice for Perl-programmers because if there is one thing they know about it is text-processing. And if anything doesn't quite work, you just look into the generated .c code and quickly find the delinquent.

I wonder how long it took other people to find it out (I was probably one of the slower chaps).

And before I forget! Kudos to nicholas for his ExtUtils::Constant module. I followed his advice to use 5.8.0 as development environment, passed the -b switch to h2xs and am happy ever since! It even produced a test-file for all the constants (something I previously had to do myself for MP3::Mplib). I was a little anxious at first because I thought that using this module would clearly infer some extra work (like some adaptions to the Makefile.PL or so) to make it work properly. But none at all! All worked splendidly out of the box. Thanks, Nick!

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.