This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In embed.pl, remove unused parameter $keep_pre from readvars().
[perl5.git] / regen / embed.pl
1 #!/usr/bin/perl -w
2
3 # Regenerate (overwriting only if changed):
4 #
5 #    embed.h
6 #    embedvar.h
7 #    global.sym
8 #    perlapi.c
9 #    perlapi.h
10 #    proto.h
11 #
12 # from information stored in
13 #
14 #    embed.fnc
15 #    intrpvar.h
16 #    perlvars.h
17 #    regen/opcodes
18 #
19 # Accepts the standard regen_lib -q and -v args.
20 #
21 # This script is normally invoked from regen.pl.
22
23 require 5.004;  # keep this compatible, an old perl is all we may have before
24                 # we build the new one
25
26 use strict;
27
28 BEGIN {
29     # Get function prototypes
30     require 'regen/regen_lib.pl';
31 }
32
33 my $SPLINT = 0; # Turn true for experimental splint support http://www.splint.org
34 my $unflagged_pointers;
35
36 #
37 # See database of global and static function prototypes in embed.fnc
38 # This is used to generate prototype headers under various configurations,
39 # export symbols lists for different platforms, and macros to provide an
40 # implicit interpreter context argument.
41 #
42
43 sub open_print_header {
44     my ($file, $quote) = @_;
45
46     return open_new($file, '>',
47                     { file => $file, style => '*', by => 'regen/embed.pl',
48                       from => ['data in embed.fnc', 'regen/embed.pl',
49                                'regen/opcodes', 'intrpvar.h', 'perlvars.h'],
50                       final => "\nEdit those files and run 'make regen_headers' to effect changes.\n",
51                       copyright => [1993 .. 2009], quote => $quote });
52 }
53
54 open IN, "embed.fnc" or die $!;
55
56 my @embed;
57 my (%has_va, %has_nocontext);
58
59 while (<IN>) {
60     chomp;
61     next if /^:/;
62     next if /^$/;
63     while (s|\\$||) {
64         $_ .= <IN>;
65         chomp;
66     }
67     s/\s+$//;
68     my @args;
69     if (/^\s*(#|$)/) {
70         @args = $_;
71     }
72     else {
73         @args = split /\s*\|\s*/, $_;
74         my $func = $args[2];
75         if ($func) {
76             ++$has_va{$func} if $args[-1] =~ /\.\.\./;
77             ++$has_nocontext{$1} if $func =~ /(.*)_nocontext/;
78         }
79     }
80     if (@args == 1 && $args[0] !~ /^#\s*(?:if|ifdef|ifndef|else|endif)/) {
81         die "Illegal line $. '$args[0]' in embed.fnc";
82     }
83     push @embed, \@args;
84 }
85
86 open IN, 'regen/opcodes' or die $!;
87 {
88     my %syms;
89
90     while (<IN>) {
91         chop;
92         next unless $_;
93         next if /^#/;
94         my (undef, undef, $check) = split /\t+/, $_;
95         ++$syms{$check};
96     }
97
98     foreach (keys %syms) {
99         # These are all indirectly referenced by globals.c.
100         push @embed, ['pR', 'OP *', $_, 'NN OP *o'];
101     }
102 }
103 close IN;
104
105 my (@core, @ext, @api);
106 {
107     # Cluster entries in embed.fnc that have the same #ifdef guards.
108     # Also, split out at the top level the three classes of functions.
109     my @state;
110     my %groups;
111     my $current;
112     foreach (@embed) {
113         if (@$_ > 1) {
114             push @$current, $_;
115             next;
116         }
117         $_->[0] =~ s/^#\s+/#/;
118         $_->[0] =~ /^\S*/;
119         $_->[0] =~ s/^#ifdef\s+(\S+)/#if defined($1)/;
120         $_->[0] =~ s/^#ifndef\s+(\S+)/#if !defined($1)/;
121         if ($_->[0] =~ /^#if\s*(.*)/) {
122             push @state, $1;
123         } elsif ($_->[0] =~ /^#else\s*$/) {
124             die "Unmatched #else in embed.fnc" unless @state;
125             $state[-1] = "!($state[-1])";
126         } elsif ($_->[0] =~ m!^#endif\s*(?:/\*.*\*/)?$!) {
127             die "Unmatched #endif in embed.fnc" unless @state;
128             pop @state;
129         } else {
130             die "Unhandled pre-processor directive '$_->[0]' in embed.fnc";
131         }
132         $current = \%groups;
133         # Nested #if blocks are effectively &&ed together
134         # For embed.fnc, ordering withing the && isn't relevant, so we can
135         # sort them to try to group more functions together.
136         my @sorted = sort @state;
137         while (my $directive = shift @sorted) {
138             $current->{$directive} ||= {};
139             $current = $current->{$directive};
140         }
141         $current->{''} ||= [];
142         $current = $current->{''};
143     }
144
145     sub add_level {
146         my ($level, $indent, $wanted) = @_;
147         my $funcs = $level->{''};
148         my @entries;
149         if ($funcs) {
150             if (!defined $wanted) {
151                 @entries = @$funcs;
152             } else {
153                 foreach (@$funcs) {
154                     if ($_->[0] =~ /A/) {
155                         push @entries, $_ if $wanted eq 'A';
156                     } elsif ($_->[0] =~ /E/) {
157                         push @entries, $_ if $wanted eq 'E';
158                     } else {
159                         push @entries, $_ if $wanted eq '';
160                     }
161                 }
162             }
163             @entries = sort {$a->[2] cmp $b->[2]} @entries;
164         }
165         foreach (sort grep {length $_} keys %$level) {
166             my @conditional = add_level($level->{$_}, $indent . '  ', $wanted);
167             push @entries,
168                 ["#${indent}if $_"], @conditional, ["#${indent}endif"]
169                     if @conditional;
170         }
171         return @entries;
172     }
173     @core = add_level(\%groups, '', '');
174     @ext = add_level(\%groups, '', 'E');
175     @api = add_level(\%groups, '', 'A');
176
177     @embed = add_level(\%groups, '');
178 }
179
180 # walk table providing an array of components in each line to
181 # subroutine, printing the result
182 sub walk_table (&@) {
183     my ($function, $filename) = @_;
184     my $F;
185     if (ref $filename) {        # filehandle
186         $F = $filename;
187     }
188     else {
189         $F = open_print_header($filename);
190     }
191     foreach (@embed) {
192         my @outs = &{$function}(@$_);
193         # $function->(@args) is not 5.003
194         print $F @outs;
195     }
196     unless (ref $filename) {
197         read_only_bottom_close_and_rename($F);
198     }
199 }
200
201 # generate proto.h
202 {
203     my $pr = open_print_header("proto.h");
204     print $pr "START_EXTERN_C\n";
205     my $ret;
206
207     foreach (@embed) {
208         if (@$_ == 1) {
209             print $pr "$_->[0]\n";
210             next;
211         }
212
213         my ($flags,$retval,$plain_func,@args) = @$_;
214         my @nonnull;
215         my $has_context = ( $flags !~ /n/ );
216         my $never_returns = ( $flags =~ /r/ );
217         my $commented_out = ( $flags =~ /m/ );
218         my $binarycompat = ( $flags =~ /b/ );
219         my $is_malloc = ( $flags =~ /a/ );
220         my $can_ignore = ( $flags !~ /R/ ) && !$is_malloc;
221         my @names_of_nn;
222         my $func;
223
224         my $splint_flags = "";
225         if ( $SPLINT && !$commented_out ) {
226             $splint_flags .= '/*@noreturn@*/ ' if $never_returns;
227             if ($can_ignore && ($retval ne 'void') && ($retval !~ /\*/)) {
228                 $retval .= " /*\@alt void\@*/";
229             }
230         }
231
232         if ($flags =~ /([si])/) {
233             my $type = ($1 eq 's') ? "STATIC" : "PERL_STATIC_INLINE";
234             warn "$func: i and s flags are mutually exclusive"
235                                             if $flags =~ /s/ && $flags =~ /i/;
236             $retval = "$type $splint_flags$retval";
237             $func = "S_$plain_func";
238         }
239         else {
240             $retval = "PERL_CALLCONV $splint_flags$retval";
241             if ($flags =~ /[bp]/) {
242                 $func = "Perl_$plain_func";
243             } else {
244                 $func = $plain_func;
245             }
246         }
247         $ret = "$retval\t$func(";
248         if ( $has_context ) {
249             $ret .= @args ? "pTHX_ " : "pTHX";
250         }
251         if (@args) {
252             my $n;
253             for my $arg ( @args ) {
254                 ++$n;
255                 if ( $arg =~ /\*/ && $arg !~ /\b(NN|NULLOK)\b/ ) {
256                     warn "$func: $arg needs NN or NULLOK\n";
257                     ++$unflagged_pointers;
258                 }
259                 my $nn = ( $arg =~ s/\s*\bNN\b\s+// );
260                 push( @nonnull, $n ) if $nn;
261
262                 my $nullok = ( $arg =~ s/\s*\bNULLOK\b\s+// ); # strip NULLOK with no effect
263
264                 # Make sure each arg has at least a type and a var name.
265                 # An arg of "int" is valid C, but want it to be "int foo".
266                 my $temp_arg = $arg;
267                 $temp_arg =~ s/\*//g;
268                 $temp_arg =~ s/\s*\bstruct\b\s*/ /g;
269                 if ( ($temp_arg ne "...")
270                      && ($temp_arg !~ /\w+\s+(\w+)(?:\[\d+\])?\s*$/) ) {
271                     warn "$func: $arg ($n) doesn't have a name\n";
272                 }
273                 if ( $SPLINT && $nullok && !$commented_out ) {
274                     $arg = '/*@null@*/ ' . $arg;
275                 }
276                 if (defined $1 && $nn && !($commented_out && !$binarycompat)) {
277                     push @names_of_nn, $1;
278                 }
279             }
280             $ret .= join ", ", @args;
281         }
282         else {
283             $ret .= "void" if !$has_context;
284         }
285         $ret .= ")";
286         my @attrs;
287         if ( $flags =~ /r/ ) {
288             push @attrs, "__attribute__noreturn__";
289         }
290         if ( $flags =~ /D/ ) {
291             push @attrs, "__attribute__deprecated__";
292         }
293         if ( $is_malloc ) {
294             push @attrs, "__attribute__malloc__";
295         }
296         if ( !$can_ignore ) {
297             push @attrs, "__attribute__warn_unused_result__";
298         }
299         if ( $flags =~ /P/ ) {
300             push @attrs, "__attribute__pure__";
301         }
302         if( $flags =~ /f/ ) {
303             my $prefix  = $has_context ? 'pTHX_' : '';
304             my $args    = scalar @args;
305             my $pat     = $args - 1;
306             my $macro   = @nonnull && $nonnull[-1] == $pat  
307                                 ? '__attribute__format__'
308                                 : '__attribute__format__null_ok__';
309             push @attrs, sprintf "%s(__printf__,%s%d,%s%d)", $macro,
310                                 $prefix, $pat, $prefix, $args;
311         }
312         if ( @nonnull ) {
313             my @pos = map { $has_context ? "pTHX_$_" : $_ } @nonnull;
314             push @attrs, map { sprintf( "__attribute__nonnull__(%s)", $_ ) } @pos;
315         }
316         if ( @attrs ) {
317             $ret .= "\n";
318             $ret .= join( "\n", map { "\t\t\t$_" } @attrs );
319         }
320         $ret .= ";";
321         $ret = "/* $ret */" if $commented_out;
322         if (@names_of_nn) {
323             $ret .= "\n#define PERL_ARGS_ASSERT_\U$plain_func\E\t\\\n\t"
324                 . join '; ', map "assert($_)", @names_of_nn;
325         }
326         $ret .= @attrs ? "\n\n" : "\n";
327
328         print $pr $ret;
329     }
330
331     print $pr <<'EOF';
332 #ifdef PERL_CORE
333 #  include "pp_proto.h"
334 #endif
335 END_EXTERN_C
336 EOF
337
338     read_only_bottom_close_and_rename($pr);
339 }
340
341 # generates global.sym (API export list)
342 {
343   my %seen;
344   sub write_global_sym {
345       if (@_ > 1) {
346           my ($flags,$retval,$func,@args) = @_;
347           if ($flags =~ /[AX]/ && $flags !~ /[xm]/
348               || $flags =~ /b/) { # public API, so export
349               # If a function is defined twice, for example before and after
350               # an #else, only export its name once.
351               return '' if $seen{$func}++;
352               $func = "Perl_$func" if $flags =~ /[pbX]/;
353               return "$func\n";
354           }
355       }
356       return '';
357   }
358 }
359
360 warn "$unflagged_pointers pointer arguments to clean up\n" if $unflagged_pointers;
361 walk_table(\&write_global_sym, "global.sym");
362
363 sub readvars(\%$$) {
364     my ($syms, $file, $pre) = @_;
365     local (*FILE, $_);
366     open(FILE, "< $file")
367         or die "embed.pl: Can't open $file: $!\n";
368     while (<FILE>) {
369         s/[ \t]*#.*//;          # Delete comments.
370         if (/PERLVARA?I?C?\($pre(\w+)/) {
371             my $sym = $1;
372             warn "duplicate symbol $sym while processing $file line $.\n"
373                 if exists $$syms{$sym};
374             $$syms{$sym} = $pre || 1;
375         }
376     }
377     close(FILE);
378 }
379
380 my %intrp;
381 my %globvar;
382
383 readvars %intrp,  'intrpvar.h','I';
384 readvars %globvar, 'perlvars.h','G';
385
386 my $sym;
387
388 sub undefine ($) {
389     my ($sym) = @_;
390     "#undef  $sym\n";
391 }
392
393 sub hide {
394     my ($from, $to, $indent) = @_;
395     $indent = '' unless defined $indent;
396     my $t = int(length("$indent$from") / 8);
397     "#${indent}define $from" . "\t" x ($t < 3 ? 3 - $t : 1) . "$to\n";
398 }
399
400 sub bincompat_var ($$) {
401     my ($pfx, $sym) = @_;
402     my $arg = ($pfx eq 'G' ? 'NULL' : 'aTHX');
403     undefine("PL_$sym") . hide("PL_$sym", "(*Perl_${pfx}${sym}_ptr($arg))");
404 }
405
406 sub multon ($$$) {
407     my ($sym,$pre,$ptr) = @_;
408     hide("PL_$sym", "($ptr$pre$sym)");
409 }
410
411 sub multoff ($$) {
412     my ($sym,$pre) = @_;
413     return hide("PL_$pre$sym", "PL_$sym");
414 }
415
416 my $em = open_print_header('embed.h');
417
418 print $em <<'END';
419 /* (Doing namespace management portably in C is really gross.) */
420
421 /* By defining PERL_NO_SHORT_NAMES (not done by default) the short forms
422  * (like warn instead of Perl_warn) for the API are not defined.
423  * Not defining the short forms is a good thing for cleaner embedding. */
424
425 #ifndef PERL_NO_SHORT_NAMES
426
427 /* Hide global symbols */
428
429 END
430
431 my @az = ('a'..'z');
432
433 sub embed_h {
434     my ($guard, $funcs) = @_;
435     print $em "$guard\n" if $guard;
436
437     my $lines;
438     foreach (@$funcs) {
439         if (@$_ == 1) {
440             my $cond = $_->[0];
441             # Indent the conditionals if we are wrapped in an #if/#endif pair.
442             $cond =~ s/#(.*)/#  $1/ if $guard;
443             $lines .= "$cond\n";
444             next;
445         }
446         my $ret = "";
447         my ($flags,$retval,$func,@args) = @$_;
448         unless ($flags =~ /[om]/) {
449             my $args = scalar @args;
450             if ($flags =~ /n/) {
451                 if ($flags =~ /s/) {
452                     $ret = hide($func,"S_$func");
453                 }
454                 elsif ($flags =~ /p/) {
455                     $ret = hide($func,"Perl_$func");
456                 }
457             }
458             elsif ($args and $args[$args-1] =~ /\.\.\./) {
459                 if ($flags =~ /p/) {
460                     # we're out of luck for varargs functions under CPP
461                     # So we can only do these macros for no implicit context:
462                     $ret = "#ifndef PERL_IMPLICIT_CONTEXT\n"
463                         . hide($func,"Perl_$func") . "#endif\n";
464                 }
465             }
466             else {
467                 my $alist = join(",", @az[0..$args-1]);
468                 $ret = "#define $func($alist)";
469                 my $t = int(length($ret) / 8);
470                 $ret .=  "\t" x ($t < 4 ? 4 - $t : 1);
471                 if ($flags =~ /[si]/) {
472                     $ret .= "S_$func(aTHX";
473                 }
474                 elsif ($flags =~ /p/) {
475                     $ret .= "Perl_$func(aTHX";
476                 }
477                 $ret .= "_ " if $alist;
478                 $ret .= $alist . ")\n";
479             }
480         }
481         $lines .= $ret;
482     }
483     # Prune empty #if/#endif pairs.
484     while ($lines =~ s/#\s*if[^\n]+\n#\s*endif\n//) {
485     }
486     # Merge adjacent blocks.
487     while ($lines =~ s/(#ifndef PERL_IMPLICIT_CONTEXT
488 [^\n]+
489 )#endif
490 #ifndef PERL_IMPLICIT_CONTEXT
491 /$1/) {
492     }
493
494     print $em $lines;
495     print $em "#endif\n" if $guard;
496 }
497
498 embed_h('', \@api);
499 embed_h('#if defined(PERL_CORE) || defined(PERL_EXT)', \@ext);
500 embed_h('#ifdef PERL_CORE', \@core);
501
502 print $em <<'END';
503
504 #endif  /* #ifndef PERL_NO_SHORT_NAMES */
505
506 /* Compatibility stubs.  Compile extensions with -DPERL_NOCOMPAT to
507    disable them.
508  */
509
510 #if !defined(PERL_CORE)
511 #  define sv_setptrobj(rv,ptr,name)     sv_setref_iv(rv,name,PTR2IV(ptr))
512 #  define sv_setptrref(rv,ptr)          sv_setref_iv(rv,NULL,PTR2IV(ptr))
513 #endif
514
515 #if !defined(PERL_CORE) && !defined(PERL_NOCOMPAT)
516
517 /* Compatibility for various misnamed functions.  All functions
518    in the API that begin with "perl_" (not "Perl_") take an explicit
519    interpreter context pointer.
520    The following are not like that, but since they had a "perl_"
521    prefix in previous versions, we provide compatibility macros.
522  */
523 #  define perl_atexit(a,b)              call_atexit(a,b)
524 END
525
526 walk_table {
527     my ($flags,$retval,$func,@args) = @_;
528     return unless $func;
529     return unless $flags =~ /O/;
530
531     my $alist = join ",", @az[0..$#args];
532     my $ret = "#  define perl_$func($alist)";
533     my $t = (length $ret) >> 3;
534     $ret .=  "\t" x ($t < 5 ? 5 - $t : 1);
535     "$ret$func($alist)\n";
536 } $em;
537
538 print $em <<'END';
539
540 /* varargs functions can't be handled with CPP macros. :-(
541    This provides a set of compatibility functions that don't take
542    an extra argument but grab the context pointer using the macro
543    dTHX.
544  */
545 #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_NO_SHORT_NAMES)
546 END
547
548 foreach (sort keys %has_va) {
549     next unless $has_nocontext{$_};
550     next if /printf/; # Not clear to me why these are skipped but they are.
551     print $em hide($_, "Perl_${_}_nocontext", "  ");
552 }
553
554 print $em <<'END';
555 #endif
556
557 #endif /* !defined(PERL_CORE) && !defined(PERL_NOCOMPAT) */
558
559 #if !defined(PERL_IMPLICIT_CONTEXT)
560 /* undefined symbols, point them back at the usual ones */
561 END
562
563 foreach (sort keys %has_va) {
564     next unless $has_nocontext{$_};
565     next if /printf/; # Not clear to me why these are skipped but they are.
566     print $em hide("Perl_${_}_nocontext", "Perl_$_", "  ");
567 }
568
569 print $em <<'END';
570 #endif
571 END
572
573 read_only_bottom_close_and_rename($em);
574
575 $em = open_print_header('embedvar.h');
576
577 print $em <<'END';
578 /* (Doing namespace management portably in C is really gross.) */
579
580 /*
581    The following combinations of MULTIPLICITY and PERL_IMPLICIT_CONTEXT
582    are supported:
583      1) none
584      2) MULTIPLICITY    # supported for compatibility
585      3) MULTIPLICITY && PERL_IMPLICIT_CONTEXT
586
587    All other combinations of these flags are errors.
588
589    only #3 is supported directly, while #2 is a special
590    case of #3 (supported by redefining vTHX appropriately).
591 */
592
593 #if defined(MULTIPLICITY)
594 /* cases 2 and 3 above */
595
596 #  if defined(PERL_IMPLICIT_CONTEXT)
597 #    define vTHX        aTHX
598 #  else
599 #    define vTHX        PERL_GET_INTERP
600 #  endif
601
602 END
603
604 for $sym (sort keys %intrp) {
605     print $em multon($sym,'I','vTHX->');
606 }
607
608 print $em <<'END';
609
610 #else   /* !MULTIPLICITY */
611
612 /* case 1 above */
613
614 END
615
616 for $sym (sort keys %intrp) {
617     print $em multoff($sym,'I');
618 }
619
620 print $em <<'END';
621
622 END
623
624 print $em <<'END';
625
626 #endif  /* MULTIPLICITY */
627
628 #if defined(PERL_GLOBAL_STRUCT)
629
630 END
631
632 for $sym (sort keys %globvar) {
633     print $em "#ifdef OS2\n" if $sym eq 'sh_path';
634     print $em multon($sym,   'G','my_vars->');
635     print $em multon("G$sym",'', 'my_vars->');
636     print $em "#endif\n" if $sym eq 'sh_path';
637 }
638
639 print $em <<'END';
640
641 #else /* !PERL_GLOBAL_STRUCT */
642
643 END
644
645 for $sym (sort keys %globvar) {
646     print $em "#ifdef OS2\n" if $sym eq 'sh_path';
647     print $em multoff($sym,'G');
648     print $em "#endif\n" if $sym eq 'sh_path';
649 }
650
651 print $em <<'END';
652
653 #endif /* PERL_GLOBAL_STRUCT */
654 END
655
656 read_only_bottom_close_and_rename($em);
657
658 my $capih = open_print_header('perlapi.h');
659
660 print $capih <<'EOT';
661 /* declare accessor functions for Perl variables */
662 #ifndef __perlapi_h__
663 #define __perlapi_h__
664
665 #if defined (MULTIPLICITY) && defined (PERL_GLOBAL_STRUCT)
666
667 START_EXTERN_C
668
669 #undef PERLVAR
670 #undef PERLVARA
671 #undef PERLVARI
672 #undef PERLVARIC
673 #define PERLVAR(v,t)    EXTERN_C t* Perl_##v##_ptr(pTHX);
674 #define PERLVARA(v,n,t) typedef t PL_##v##_t[n];                        \
675                         EXTERN_C PL_##v##_t* Perl_##v##_ptr(pTHX);
676 #define PERLVARI(v,t,i) PERLVAR(v,t)
677 #define PERLVARIC(v,t,i) PERLVAR(v, const t)
678
679 #include "perlvars.h"
680
681 #undef PERLVAR
682 #undef PERLVARA
683 #undef PERLVARI
684 #undef PERLVARIC
685
686 END_EXTERN_C
687
688 #if defined(PERL_CORE)
689
690 /* accessor functions for Perl "global" variables */
691
692 /* these need to be mentioned here, or most linkers won't put them in
693    the perl executable */
694
695 #ifndef PERL_NO_FORCE_LINK
696
697 START_EXTERN_C
698
699 #ifndef DOINIT
700 EXTCONST void * const PL_force_link_funcs[];
701 #else
702 EXTCONST void * const PL_force_link_funcs[] = {
703 #undef PERLVAR
704 #undef PERLVARA
705 #undef PERLVARI
706 #undef PERLVARIC
707 #define PERLVAR(v,t)    (void*)Perl_##v##_ptr,
708 #define PERLVARA(v,n,t) PERLVAR(v,t)
709 #define PERLVARI(v,t,i) PERLVAR(v,t)
710 #define PERLVARIC(v,t,i) PERLVAR(v,t)
711
712 /* In Tru64 (__DEC && __osf__) the cc option -std1 causes that one
713  * cannot cast between void pointers and function pointers without
714  * info level warnings.  The PL_force_link_funcs[] would cause a few
715  * hundred of those warnings.  In code one can circumnavigate this by using
716  * unions that overlay the different pointers, but in declarations one
717  * cannot use this trick.  Therefore we just disable the warning here
718  * for the duration of the PL_force_link_funcs[] declaration. */
719
720 #if defined(__DECC) && defined(__osf__)
721 #pragma message save
722 #pragma message disable (nonstandcast)
723 #endif
724
725 #include "perlvars.h"
726
727 #if defined(__DECC) && defined(__osf__)
728 #pragma message restore
729 #endif
730
731 #undef PERLVAR
732 #undef PERLVARA
733 #undef PERLVARI
734 #undef PERLVARIC
735 };
736 #endif  /* DOINIT */
737
738 END_EXTERN_C
739
740 #endif  /* PERL_NO_FORCE_LINK */
741
742 #else   /* !PERL_CORE */
743
744 EOT
745
746 foreach $sym (sort keys %globvar) {
747     print $capih bincompat_var('G',$sym);
748 }
749
750 print $capih <<'EOT';
751
752 #endif /* !PERL_CORE */
753 #endif /* MULTIPLICITY && PERL_GLOBAL_STRUCT */
754
755 #endif /* __perlapi_h__ */
756 EOT
757
758 read_only_bottom_close_and_rename($capih);
759
760 my $capi = open_print_header('perlapi.c', <<'EOQ');
761  *
762  *
763  * Up to the threshold of the door there mounted a flight of twenty-seven
764  * broad stairs, hewn by some unknown art of the same black stone.  This
765  * was the only entrance to the tower; ...
766  *
767  *     [p.577 of _The Lord of the Rings_, III/x: "The Voice of Saruman"]
768  *
769  */
770 EOQ
771
772 print $capi <<'EOT';
773 #include "EXTERN.h"
774 #include "perl.h"
775 #include "perlapi.h"
776
777 #if defined (MULTIPLICITY) && defined (PERL_GLOBAL_STRUCT)
778
779 /* accessor functions for Perl "global" variables */
780 START_EXTERN_C
781
782 #undef PERLVARI
783 #define PERLVARI(v,t,i) PERLVAR(v,t)
784
785 #undef PERLVAR
786 #undef PERLVARA
787 #define PERLVAR(v,t)    t* Perl_##v##_ptr(pTHX)                         \
788                         { dVAR; PERL_UNUSED_CONTEXT; return &(PL_##v); }
789 #define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX)                \
790                         { dVAR; PERL_UNUSED_CONTEXT; return &(PL_##v); }
791 #undef PERLVARIC
792 #define PERLVARIC(v,t,i)        \
793                         const t* Perl_##v##_ptr(pTHX)           \
794                         { PERL_UNUSED_CONTEXT; return (const t *)&(PL_##v); }
795 #include "perlvars.h"
796
797 #undef PERLVAR
798 #undef PERLVARA
799 #undef PERLVARI
800 #undef PERLVARIC
801
802 END_EXTERN_C
803
804 #endif /* MULTIPLICITY && PERL_GLOBAL_STRUCT */
805 EOT
806
807 read_only_bottom_close_and_rename($capi);
808
809 # ex: set ts=8 sts=4 sw=4 noet: