This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
dac4d450898b8d0c92524af237e06c5eed2e3b46
[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,$keep_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             $sym = $pre . $sym if $keep_pre;
373             warn "duplicate symbol $sym while processing $file line $.\n"
374                 if exists $$syms{$sym};
375             $$syms{$sym} = $pre || 1;
376         }
377     }
378     close(FILE);
379 }
380
381 my %intrp;
382 my %globvar;
383
384 readvars %intrp,  'intrpvar.h','I';
385 readvars %globvar, 'perlvars.h','G';
386
387 my $sym;
388
389 sub undefine ($) {
390     my ($sym) = @_;
391     "#undef  $sym\n";
392 }
393
394 sub hide {
395     my ($from, $to, $indent) = @_;
396     $indent = '' unless defined $indent;
397     my $t = int(length("$indent$from") / 8);
398     "#${indent}define $from" . "\t" x ($t < 3 ? 3 - $t : 1) . "$to\n";
399 }
400
401 sub bincompat_var ($$) {
402     my ($pfx, $sym) = @_;
403     my $arg = ($pfx eq 'G' ? 'NULL' : 'aTHX');
404     undefine("PL_$sym") . hide("PL_$sym", "(*Perl_${pfx}${sym}_ptr($arg))");
405 }
406
407 sub multon ($$$) {
408     my ($sym,$pre,$ptr) = @_;
409     hide("PL_$sym", "($ptr$pre$sym)");
410 }
411
412 sub multoff ($$) {
413     my ($sym,$pre) = @_;
414     return hide("PL_$pre$sym", "PL_$sym");
415 }
416
417 my $em = open_print_header('embed.h');
418
419 print $em <<'END';
420 /* (Doing namespace management portably in C is really gross.) */
421
422 /* By defining PERL_NO_SHORT_NAMES (not done by default) the short forms
423  * (like warn instead of Perl_warn) for the API are not defined.
424  * Not defining the short forms is a good thing for cleaner embedding. */
425
426 #ifndef PERL_NO_SHORT_NAMES
427
428 /* Hide global symbols */
429
430 END
431
432 my @az = ('a'..'z');
433
434 sub embed_h {
435     my ($guard, $funcs) = @_;
436     print $em "$guard\n" if $guard;
437
438     my $lines;
439     foreach (@$funcs) {
440         if (@$_ == 1) {
441             my $cond = $_->[0];
442             # Indent the conditionals if we are wrapped in an #if/#endif pair.
443             $cond =~ s/#(.*)/#  $1/ if $guard;
444             $lines .= "$cond\n";
445             next;
446         }
447         my $ret = "";
448         my ($flags,$retval,$func,@args) = @$_;
449         unless ($flags =~ /[om]/) {
450             my $args = scalar @args;
451             if ($flags =~ /n/) {
452                 if ($flags =~ /s/) {
453                     $ret = hide($func,"S_$func");
454                 }
455                 elsif ($flags =~ /p/) {
456                     $ret = hide($func,"Perl_$func");
457                 }
458             }
459             elsif ($args and $args[$args-1] =~ /\.\.\./) {
460                 if ($flags =~ /p/) {
461                     # we're out of luck for varargs functions under CPP
462                     # So we can only do these macros for no implicit context:
463                     $ret = "#ifndef PERL_IMPLICIT_CONTEXT\n"
464                         . hide($func,"Perl_$func") . "#endif\n";
465                 }
466             }
467             else {
468                 my $alist = join(",", @az[0..$args-1]);
469                 $ret = "#define $func($alist)";
470                 my $t = int(length($ret) / 8);
471                 $ret .=  "\t" x ($t < 4 ? 4 - $t : 1);
472                 if ($flags =~ /[si]/) {
473                     $ret .= "S_$func(aTHX";
474                 }
475                 elsif ($flags =~ /p/) {
476                     $ret .= "Perl_$func(aTHX";
477                 }
478                 $ret .= "_ " if $alist;
479                 $ret .= $alist . ")\n";
480             }
481         }
482         $lines .= $ret;
483     }
484     # Prune empty #if/#endif pairs.
485     while ($lines =~ s/#\s*if[^\n]+\n#\s*endif\n//) {
486     }
487     # Merge adjacent blocks.
488     while ($lines =~ s/(#ifndef PERL_IMPLICIT_CONTEXT
489 [^\n]+
490 )#endif
491 #ifndef PERL_IMPLICIT_CONTEXT
492 /$1/) {
493     }
494
495     print $em $lines;
496     print $em "#endif\n" if $guard;
497 }
498
499 embed_h('', \@api);
500 embed_h('#if defined(PERL_CORE) || defined(PERL_EXT)', \@ext);
501 embed_h('#ifdef PERL_CORE', \@core);
502
503 print $em <<'END';
504
505 #endif  /* #ifndef PERL_NO_SHORT_NAMES */
506
507 /* Compatibility stubs.  Compile extensions with -DPERL_NOCOMPAT to
508    disable them.
509  */
510
511 #if !defined(PERL_CORE)
512 #  define sv_setptrobj(rv,ptr,name)     sv_setref_iv(rv,name,PTR2IV(ptr))
513 #  define sv_setptrref(rv,ptr)          sv_setref_iv(rv,NULL,PTR2IV(ptr))
514 #endif
515
516 #if !defined(PERL_CORE) && !defined(PERL_NOCOMPAT)
517
518 /* Compatibility for various misnamed functions.  All functions
519    in the API that begin with "perl_" (not "Perl_") take an explicit
520    interpreter context pointer.
521    The following are not like that, but since they had a "perl_"
522    prefix in previous versions, we provide compatibility macros.
523  */
524 #  define perl_atexit(a,b)              call_atexit(a,b)
525 END
526
527 walk_table {
528     my ($flags,$retval,$func,@args) = @_;
529     return unless $func;
530     return unless $flags =~ /O/;
531
532     my $alist = join ",", @az[0..$#args];
533     my $ret = "#  define perl_$func($alist)";
534     my $t = (length $ret) >> 3;
535     $ret .=  "\t" x ($t < 5 ? 5 - $t : 1);
536     "$ret$func($alist)\n";
537 } $em;
538
539 print $em <<'END';
540
541 /* varargs functions can't be handled with CPP macros. :-(
542    This provides a set of compatibility functions that don't take
543    an extra argument but grab the context pointer using the macro
544    dTHX.
545  */
546 #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_NO_SHORT_NAMES)
547 END
548
549 foreach (sort keys %has_va) {
550     next unless $has_nocontext{$_};
551     next if /printf/; # Not clear to me why these are skipped but they are.
552     print $em hide($_, "Perl_${_}_nocontext", "  ");
553 }
554
555 print $em <<'END';
556 #endif
557
558 #endif /* !defined(PERL_CORE) && !defined(PERL_NOCOMPAT) */
559
560 #if !defined(PERL_IMPLICIT_CONTEXT)
561 /* undefined symbols, point them back at the usual ones */
562 END
563
564 foreach (sort keys %has_va) {
565     next unless $has_nocontext{$_};
566     next if /printf/; # Not clear to me why these are skipped but they are.
567     print $em hide("Perl_${_}_nocontext", "Perl_$_", "  ");
568 }
569
570 print $em <<'END';
571 #endif
572 END
573
574 read_only_bottom_close_and_rename($em);
575
576 $em = open_print_header('embedvar.h');
577
578 print $em <<'END';
579 /* (Doing namespace management portably in C is really gross.) */
580
581 /*
582    The following combinations of MULTIPLICITY and PERL_IMPLICIT_CONTEXT
583    are supported:
584      1) none
585      2) MULTIPLICITY    # supported for compatibility
586      3) MULTIPLICITY && PERL_IMPLICIT_CONTEXT
587
588    All other combinations of these flags are errors.
589
590    only #3 is supported directly, while #2 is a special
591    case of #3 (supported by redefining vTHX appropriately).
592 */
593
594 #if defined(MULTIPLICITY)
595 /* cases 2 and 3 above */
596
597 #  if defined(PERL_IMPLICIT_CONTEXT)
598 #    define vTHX        aTHX
599 #  else
600 #    define vTHX        PERL_GET_INTERP
601 #  endif
602
603 END
604
605 for $sym (sort keys %intrp) {
606     print $em multon($sym,'I','vTHX->');
607 }
608
609 print $em <<'END';
610
611 #else   /* !MULTIPLICITY */
612
613 /* case 1 above */
614
615 END
616
617 for $sym (sort keys %intrp) {
618     print $em multoff($sym,'I');
619 }
620
621 print $em <<'END';
622
623 END
624
625 print $em <<'END';
626
627 #endif  /* MULTIPLICITY */
628
629 #if defined(PERL_GLOBAL_STRUCT)
630
631 END
632
633 for $sym (sort keys %globvar) {
634     print $em "#ifdef OS2\n" if $sym eq 'sh_path';
635     print $em multon($sym,   'G','my_vars->');
636     print $em multon("G$sym",'', 'my_vars->');
637     print $em "#endif\n" if $sym eq 'sh_path';
638 }
639
640 print $em <<'END';
641
642 #else /* !PERL_GLOBAL_STRUCT */
643
644 END
645
646 for $sym (sort keys %globvar) {
647     print $em "#ifdef OS2\n" if $sym eq 'sh_path';
648     print $em multoff($sym,'G');
649     print $em "#endif\n" if $sym eq 'sh_path';
650 }
651
652 print $em <<'END';
653
654 #endif /* PERL_GLOBAL_STRUCT */
655 END
656
657 read_only_bottom_close_and_rename($em);
658
659 my $capih = open_print_header('perlapi.h');
660
661 print $capih <<'EOT';
662 /* declare accessor functions for Perl variables */
663 #ifndef __perlapi_h__
664 #define __perlapi_h__
665
666 #if defined (MULTIPLICITY) && defined (PERL_GLOBAL_STRUCT)
667
668 START_EXTERN_C
669
670 #undef PERLVAR
671 #undef PERLVARA
672 #undef PERLVARI
673 #undef PERLVARIC
674 #define PERLVAR(v,t)    EXTERN_C t* Perl_##v##_ptr(pTHX);
675 #define PERLVARA(v,n,t) typedef t PL_##v##_t[n];                        \
676                         EXTERN_C PL_##v##_t* Perl_##v##_ptr(pTHX);
677 #define PERLVARI(v,t,i) PERLVAR(v,t)
678 #define PERLVARIC(v,t,i) PERLVAR(v, const t)
679
680 #include "perlvars.h"
681
682 #undef PERLVAR
683 #undef PERLVARA
684 #undef PERLVARI
685 #undef PERLVARIC
686
687 END_EXTERN_C
688
689 #if defined(PERL_CORE)
690
691 /* accessor functions for Perl "global" variables */
692
693 /* these need to be mentioned here, or most linkers won't put them in
694    the perl executable */
695
696 #ifndef PERL_NO_FORCE_LINK
697
698 START_EXTERN_C
699
700 #ifndef DOINIT
701 EXTCONST void * const PL_force_link_funcs[];
702 #else
703 EXTCONST void * const PL_force_link_funcs[] = {
704 #undef PERLVAR
705 #undef PERLVARA
706 #undef PERLVARI
707 #undef PERLVARIC
708 #define PERLVAR(v,t)    (void*)Perl_##v##_ptr,
709 #define PERLVARA(v,n,t) PERLVAR(v,t)
710 #define PERLVARI(v,t,i) PERLVAR(v,t)
711 #define PERLVARIC(v,t,i) PERLVAR(v,t)
712
713 /* In Tru64 (__DEC && __osf__) the cc option -std1 causes that one
714  * cannot cast between void pointers and function pointers without
715  * info level warnings.  The PL_force_link_funcs[] would cause a few
716  * hundred of those warnings.  In code one can circumnavigate this by using
717  * unions that overlay the different pointers, but in declarations one
718  * cannot use this trick.  Therefore we just disable the warning here
719  * for the duration of the PL_force_link_funcs[] declaration. */
720
721 #if defined(__DECC) && defined(__osf__)
722 #pragma message save
723 #pragma message disable (nonstandcast)
724 #endif
725
726 #include "perlvars.h"
727
728 #if defined(__DECC) && defined(__osf__)
729 #pragma message restore
730 #endif
731
732 #undef PERLVAR
733 #undef PERLVARA
734 #undef PERLVARI
735 #undef PERLVARIC
736 };
737 #endif  /* DOINIT */
738
739 END_EXTERN_C
740
741 #endif  /* PERL_NO_FORCE_LINK */
742
743 #else   /* !PERL_CORE */
744
745 EOT
746
747 foreach $sym (sort keys %globvar) {
748     print $capih bincompat_var('G',$sym);
749 }
750
751 print $capih <<'EOT';
752
753 #endif /* !PERL_CORE */
754 #endif /* MULTIPLICITY && PERL_GLOBAL_STRUCT */
755
756 #endif /* __perlapi_h__ */
757 EOT
758
759 read_only_bottom_close_and_rename($capih);
760
761 my $capi = open_print_header('perlapi.c', <<'EOQ');
762  *
763  *
764  * Up to the threshold of the door there mounted a flight of twenty-seven
765  * broad stairs, hewn by some unknown art of the same black stone.  This
766  * was the only entrance to the tower; ...
767  *
768  *     [p.577 of _The Lord of the Rings_, III/x: "The Voice of Saruman"]
769  *
770  */
771 EOQ
772
773 print $capi <<'EOT';
774 #include "EXTERN.h"
775 #include "perl.h"
776 #include "perlapi.h"
777
778 #if defined (MULTIPLICITY) && defined (PERL_GLOBAL_STRUCT)
779
780 /* accessor functions for Perl "global" variables */
781 START_EXTERN_C
782
783 #undef PERLVARI
784 #define PERLVARI(v,t,i) PERLVAR(v,t)
785
786 #undef PERLVAR
787 #undef PERLVARA
788 #define PERLVAR(v,t)    t* Perl_##v##_ptr(pTHX)                         \
789                         { dVAR; PERL_UNUSED_CONTEXT; return &(PL_##v); }
790 #define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX)                \
791                         { dVAR; PERL_UNUSED_CONTEXT; return &(PL_##v); }
792 #undef PERLVARIC
793 #define PERLVARIC(v,t,i)        \
794                         const t* Perl_##v##_ptr(pTHX)           \
795                         { PERL_UNUSED_CONTEXT; return (const t *)&(PL_##v); }
796 #include "perlvars.h"
797
798 #undef PERLVAR
799 #undef PERLVARA
800 #undef PERLVARI
801 #undef PERLVARIC
802
803 END_EXTERN_C
804
805 #endif /* MULTIPLICITY && PERL_GLOBAL_STRUCT */
806 EOT
807
808 read_only_bottom_close_and_rename($capi);
809
810 # ex: set ts=8 sts=4 sw=4 noet: