Re: use strict; and O_WRONLY
From: Tassilo v. Parseval (tassilo.von.parseval_at_rwth-aachen.de)
Date: 02/18/05
- Next message: PerlFAQ Server: "FAQ 5.30 How do I do a "tail -f" in perl?"
- Previous message: Paul Lalli: "Re: simple map query"
- In reply to: Sherm Pendley: "Re: use strict; and O_WRONLY"
- Next in thread: Sherm Pendley: "Re: use strict; and O_WRONLY"
- Reply: Sherm Pendley: "Re: use strict; and O_WRONLY"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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);
- Next message: PerlFAQ Server: "FAQ 5.30 How do I do a "tail -f" in perl?"
- Previous message: Paul Lalli: "Re: simple map query"
- In reply to: Sherm Pendley: "Re: use strict; and O_WRONLY"
- Next in thread: Sherm Pendley: "Re: use strict; and O_WRONLY"
- Reply: Sherm Pendley: "Re: use strict; and O_WRONLY"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|