Greetings, oh fellow monks! I've recently uploaded my first Perl module to CPAN (Math::FastGF2) and was very interested to see the automated test results on different platforms. But if you look there you'll see a lot of failed tests. I'm pretty sure that the problem with all the failed tests is that the test machines use different word sizes for C data types such as "unsigned short" and "unsigned long" and that's what's causing all the failures.

Recognising that this could have been an issue, I made sure to declare all the particular word sizes (1, 2 and 4-byte words) as typedefs in my C code, and made mention that these might need to be changed in the header files. However, as these are automated tests, nobody is looking at the header file to see what what might need to be changed in order to get the code to compile and run cleanly. So, what I'm looking for is an easy way to figure out which native C types have 8, 16 and 32 bits apiece at compilation time and to have my C/XS code use those data types. Can anyone help me?

There are a few more details I can add. First, I've noticed that if I define my XS prototypes using my user-defined data types (gf2_u8, gf2_u16 and gf2_u32) then the program won't compile correctly (I've tried using both typedefs and #defines). So at the moment I'm reduced to using my user-defined types for internal function calls and data structures, but having to use types like unsigned long for any function prototype that I want to be visible from Perl. Obviously this isn't ideal, as someone wanting to compile the code has to change all the typedefs and all the function prototypes that are meant to be visible to the Perl interpreter.

Second, I thought it should probably be possible to do this using typemaps, but my limited searching didn't turn up any information on doing something like I want.

The third and final bit of extra information is that I'm fairly used to using C-based configure scripts to figure out things like this and create header files based on the local configuration. I must admit that I'm only getting to grips with the MakeMaker system and the XS system in general, so I'm not even sure how to make my configuration script happen before the compilation proper. I hope you be mindful of my inexperience if you have a solution to offer.

Thank you, oh worthy ones!


In reply to A clean way to account for machine word sizes in XS code? by dec

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.