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