Re: use strict; and O_WRONLY

From: Tassilo v. Parseval (tassilo.von.parseval_at_rwth-aachen.de)
Date: 02/18/05


Date: Fri, 18 Feb 2005 17:50:17 +0100

Also sprach Sherm Pendley:

> Tassilo v. Parseval wrote:
>
>> const-xs.inc is the XS implementation of the 'constant' function as
>> available from AUTOLOAD. 'XS_constant' then calls the C function
>> 'constant' (defined in const-c.inc).
>
> When I was dealing with constants in my XS code, I managed to follow things
> up to this point...
>
>> This one then works a bit like a
>> finite state machine that does pattern matching on the name of the
>> requested constant.
>
> But this is where I got lost. When I created a new XS module with h2xs, it
> had skeletons of both *.inc files, but I couldn't figure out how those were
> generated, nor how to update them. I suppose there's a discussion about it
> to be found in the p5p archives, but I didn't want to dive into Perl's
> guts, all I wanted to do is export some constants.

It's done from Makefile.PL with the help of ExtUtils::Constants. The
relevant code in Makefile.PL looks like this:

    if (eval {require ExtUtils::Constant; 1}) {
        my @names = qw/CONSTANT1 CONSTANT2 .../;
        ExtUtils::Constant::WriteConstants(
            NAME => 'Module',
            NAMES => \@names,
            DEFAULT_TYPE => 'IV',
            C_FILE => 'const-c.inc',
            XS_FILE => 'const-xs.inc',
        );
    }

@names' content is determined by h2xs' flimsy C-header parser which will
ever so often miss important #defines or enums or find some that
actually don't exist in the header.

It's also possible to provide one's own set of symbols for @names.

In pre-ExtUtils::Constants times h2xs would create even messier C-code
for the constant exportation and inline it into the XS file. The code
thusly generated was often buggy and you were forced to debug this
machine-generated code. For an anecdote on this, see

    <http://use.perl.org/~ethan/journal/9230>

and the comment by Nicholas Clark who's responsible for
ExtUtils::Constants. In his comment you'll find a few explanations on
how the constant-handling in XS works.

> Eventually, I gave up - I wrote a simple text file with the names of the
> constants I wanted to export to Perl. For each name in it I call a short C
> function that uses dlsym() to check for the existence and location of that
> symbol. If it exists, I pass its value to newCONSTSUB() to create the
> constant in Perl.

I wonder about the necessity of dlsym(). Public symbols somehow need to
be mentioned in the header which has to be included in the XS file.
Under these premises, a simple '#ifdef' should be enough. Non-existing
symbols would then yield an error at compile-time already.

Tassilo

-- 
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);


Relevant Pages

  • RE: Help Me with shell script please
    ... Because to my untrained eye your perl script ... > script that accesses the shell a wrapper. ... The "around the mail command" is the important part of ... and any fake header we want to make up on our own). ...
    (RedHat)
  • Re: Downgrade storable under Perl 5.8
    ... Hence Storable running on perl ... with 64 bit integers will read the header from a file written by a 32 bit ... correct backwards compatibility mode. ...
    (comp.lang.perl.modules)
  • Re: Text File Cleanup Utility
    ... but commercial tools such as TextPipe Pro and ... If you know how many header and footer lines need to be deleted, ... Perl script I've pasted at the end of this message will do the job. ... warn "$iofile doesn't have enough lines!\n"; ...
    (microsoft.public.access.externaldata)
  • Re: Broken pipe problem? If so, why?
    ... > message, reads the header, does some processing, and exits. ... > I am invoking this program in a pipe from procmail. ... Since your Perl program is only reading the header, ...
    (comp.lang.perl.misc)
  • FW: Re: Urgent help in h2xs
    ... I have installed activeperl version 5.8.7 for win32 applications on windows 2000. ... I am using MSVC for compiling the programs and after running h2xs.bat when i run the makefile.pl command it gives me the following error message: ... Can you be more precise in telling how to use VC++ for h2xs as i dont have ... project using perl h2xs. ...
    (perl.beginners)