develooper Front page | perl.perl5.porters | Postings from November 2008

use of PERL_CORE in perly.h (was Re: modules on CPAN defining PERL_CORE)

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
November 25, 2008 08:54
Subject:
use of PERL_CORE in perly.h (was Re: modules on CPAN defining PERL_CORE)
Message ID:
20081125165413.GH49335@plum.flirble.org
On Mon, Nov 24, 2008 at 04:36:01PM +0100, Rafael Garcia-Suarez wrote:
> 2008/11/24 Nicholas Clark <nick@ccl4.org>:

> > 2: constants in perly.h
> 
> Constants are cheap to add, and cheap to test for. Like
> 
> #ifdef PERL_PERLY_DO
>     ...
> #endif

I don't think that that's going to work that well. If I understand things
correctly now in the brave new world of bison, perly.h is generated from
perly.y, so we'd have to rewrite the grammar with the longer names, and toke.c

The #ifdef PERL_CORE is added by regen_perly.h here in this code:

# Wrap PERL_CORE round the symbol definitions. Also,  the
# C<#line 30 "perly.y"> confuses the Win32 resource compiler and the
# C<#line 188 "perlytmp.h"> gets picked up by make depend, so remove them.

open TMPH_FILE, $tmph_file or die "Can't open $tmph_file: $!\n";
chmod 0644, $h_file;
open H_FILE, ">$h_file" or die "Can't open $h_file: $!\n";
my $endcore_done = 0;
while (<TMPH_FILE>) {
    print H_FILE "#ifdef PERL_CORE\n" if $. == 1;
    if (!$endcore_done and /YYSTYPE_IS_DECLARED/) {
	print H_FILE "#endif /* PERL_CORE */\n";
	$endcore_done = 1;
    }
    next if /^#line \d+ ".*"/;
    print H_FILE $_;
}
close TMPH_FILE;
close H_FILE;
chmod 0444, $h_file;
unlink $tmph_file;

__END__


So I wonder whether we could change it to move the constants in question
into a second header file, which isn't protected by #ifdef PERL_CORE, because
it is not included by any Perl header, but instead is directly included by
toke.c. This would allow XS modules to bring in the the grammar's constants
by including the header file, without needing to define PERL_CORE, and without
massive #ifdef pollution for anything "just" including the perl headers.

Nicholas Clark

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About