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