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