This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #52740] [PATCH-tests] crash when localizing a symtab entry
[perl5.git] / embed.pl
CommitLineData
5f05dabc 1#!/usr/bin/perl -w
e50aee73 2
954c1994
GS
3require 5.003; # keep this compatible, an old perl is all we may have before
4 # we build the new one
5f05dabc 5
88e01c9d
AL
6use strict;
7
36bb303b
NC
8BEGIN {
9 # Get function prototypes
9ad884cb 10 require 'regen_lib.pl';
36bb303b
NC
11}
12
88e01c9d
AL
13my $SPLINT = 0; # Turn true for experimental splint support http://www.splint.org
14
cea2e8a9 15#
346f75ff 16# See database of global and static function prototypes in embed.fnc
cea2e8a9
GS
17# This is used to generate prototype headers under various configurations,
18# export symbols lists for different platforms, and macros to provide an
19# implicit interpreter context argument.
20#
21
7f1be197
MB
22sub do_not_edit ($)
23{
24 my $file = shift;
4373e329 25
7272f7c1 26 my $years = '1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007';
4bb101f2
JH
27
28 $years =~ s/1999,/1999,\n / if length $years > 40;
29
7f1be197 30 my $warning = <<EOW;
37442d52 31 -*- buffer-read-only: t -*-
7f1be197
MB
32
33 $file
34
4bb101f2 35 Copyright (C) $years, by Larry Wall and others
7f1be197
MB
36
37 You may distribute under the terms of either the GNU General Public
38 License or the Artistic License, as specified in the README file.
39
40!!!!!!! DO NOT EDIT THIS FILE !!!!!!!
41This file is built by embed.pl from data in embed.fnc, embed.pl,
907b3e23 42pp.sym, intrpvar.h, and perlvars.h.
7f1be197
MB
43Any changes made here will be lost!
44
45Edit those files and run 'make regen_headers' to effect changes.
46
47EOW
48
cfa0b873
AT
49 $warning .= <<EOW if $file eq 'perlapi.c';
50
51Up to the threshold of the door there mounted a flight of twenty-seven
52broad stairs, hewn by some unknown art of the same black stone. This
53was the only entrance to the tower.
54
55
56EOW
57
7f1be197 58 if ($file =~ m:\.[ch]$:) {
0ea9712b
MB
59 $warning =~ s:^: * :gm;
60 $warning =~ s: +$::gm;
61 $warning =~ s: :/:;
62 $warning =~ s:$:/:;
7f1be197
MB
63 }
64 else {
0ea9712b
MB
65 $warning =~ s:^:# :gm;
66 $warning =~ s: +$::gm;
7f1be197
MB
67 }
68 $warning;
69} # do_not_edit
70
94bdecf9 71open IN, "embed.fnc" or die $!;
cea2e8a9
GS
72
73# walk table providing an array of components in each line to
74# subroutine, printing the result
75sub walk_table (&@) {
76 my $function = shift;
77 my $filename = shift || '-';
0ea9712b
MB
78 my $leader = shift;
79 defined $leader or $leader = do_not_edit ($filename);
cea2e8a9
GS
80 my $trailer = shift;
81 my $F;
cea2e8a9
GS
82 if (ref $filename) { # filehandle
83 $F = $filename;
84 }
85 else {
b6b9a099 86 # safer_unlink $filename if $filename ne '/dev/null';
424a4936 87 $F = safer_open("$filename-new");
cea2e8a9
GS
88 }
89 print $F $leader if $leader;
94bdecf9
JH
90 seek IN, 0, 0; # so we may restart
91 while (<IN>) {
cea2e8a9 92 chomp;
1d7c1841 93 next if /^:/;
cea2e8a9 94 while (s|\\$||) {
94bdecf9 95 $_ .= <IN>;
cea2e8a9
GS
96 chomp;
97 }
23f1b5c3 98 s/\s+$//;
cea2e8a9
GS
99 my @args;
100 if (/^\s*(#|$)/) {
101 @args = $_;
102 }
103 else {
104 @args = split /\s*\|\s*/, $_;
105 }
4373e329
AL
106 my @outs = &{$function}(@args);
107 print $F @outs; # $function->(@args) is not 5.003
cea2e8a9
GS
108 }
109 print $F $trailer if $trailer;
36bb303b 110 unless (ref $filename) {
08858ed2 111 safer_close($F);
424a4936 112 rename_if_different("$filename-new", $filename);
36bb303b 113 }
cea2e8a9
GS
114}
115
116sub munge_c_files () {
117 my $functions = {};
118 unless (@ARGV) {
4373e329 119 warn "\@ARGV empty, nothing to do\n";
cea2e8a9
GS
120 return;
121 }
122 walk_table {
123 if (@_ > 1) {
124 $functions->{$_[2]} = \@_ if $_[@_-1] =~ /\.\.\./;
125 }
37442d52 126 } '/dev/null', '', '';
cea2e8a9
GS
127 local $^I = '.bak';
128 while (<>) {
cea2e8a9
GS
129 s{(\b(\w+)[ \t]*\([ \t]*(?!aTHX))}
130 {
131 my $repl = $1;
132 my $f = $2;
133 if (exists $functions->{$f}) {
134 $repl .= "aTHX_ ";
135 warn("$ARGV:$.:$`#$repl#$'");
136 }
137 $repl;
138 }eg;
139 print;
140 close ARGV if eof; # restart $.
141 }
142 exit;
143}
144
145#munge_c_files();
146
147# generate proto.h
0cb96387
GS
148my $wrote_protected = 0;
149
cea2e8a9
GS
150sub write_protos {
151 my $ret = "";
152 if (@_ == 1) {
153 my $arg = shift;
1d7c1841 154 $ret .= "$arg\n";
cea2e8a9
GS
155 }
156 else {
7918f24d 157 my ($flags,$retval,$plain_func,@args) = @_;
4373e329
AL
158 my @nonnull;
159 my $has_context = ( $flags !~ /n/ );
88e01c9d
AL
160 my $never_returns = ( $flags =~ /r/ );
161 my $commented_out = ( $flags =~ /m/ );
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
GS
186 }
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";
197 our $unflagged_pointers;
198 ++$unflagged_pointers;
199 }
88e01c9d
AL
200 my $nn = ( $arg =~ s/\s*\bNN\b\s+// );
201 push( @nonnull, $n ) if $nn;
202
203 my $nullok = ( $arg =~ s/\s*\bNULLOK\b\s+// ); # strip NULLOK with no effect
c48640ec
AL
204
205 # Make sure each arg has at least a type and a var name.
206 # An arg of "int" is valid C, but want it to be "int foo".
207 my $temp_arg = $arg;
208 $temp_arg =~ s/\*//g;
209 $temp_arg =~ s/\s*\bstruct\b\s*/ /g;
7918f24d
NC
210 if ( ($temp_arg ne "...")
211 && ($temp_arg !~ /\w+\s+(\w+)(?:\[\d+\])?\s*$/) ) {
212 warn "$func: $arg ($n) doesn't have a name\n";
c48640ec 213 }
88e01c9d
AL
214 if ( $SPLINT && $nullok && !$commented_out ) {
215 $arg = '/*@null@*/ ' . $arg;
216 }
7918f24d
NC
217 if (defined $1 && $nn) {
218 push @names_of_nn, $1;
219 }
4373e329 220 }
cea2e8a9
GS
221 $ret .= join ", ", @args;
222 }
223 else {
4373e329 224 $ret .= "void" if !$has_context;
cea2e8a9
GS
225 }
226 $ret .= ")";
f54cb97a
AL
227 my @attrs;
228 if ( $flags =~ /r/ ) {
abb2c242 229 push @attrs, "__attribute__noreturn__";
f54cb97a 230 }
88e01c9d 231 if ( $is_malloc ) {
abb2c242 232 push @attrs, "__attribute__malloc__";
f54cb97a 233 }
88e01c9d 234 if ( !$can_ignore ) {
abb2c242 235 push @attrs, "__attribute__warn_unused_result__";
f54cb97a
AL
236 }
237 if ( $flags =~ /P/ ) {
abb2c242 238 push @attrs, "__attribute__pure__";
f54cb97a 239 }
1c846c1f 240 if( $flags =~ /f/ ) {
cdfeb707
RB
241 my $prefix = $has_context ? 'pTHX_' : '';
242 my $args = scalar @args;
243 my $pat = $args - 1;
244 my $macro = @nonnull && $nonnull[-1] == $pat
245 ? '__attribute__format__'
246 : '__attribute__format__null_ok__';
247 push @attrs, sprintf "%s(__printf__,%s%d,%s%d)", $macro,
248 $prefix, $pat, $prefix, $args;
894356b3 249 }
4373e329 250 if ( @nonnull ) {
3d42dc86 251 my @pos = map { $has_context ? "pTHX_$_" : $_ } @nonnull;
abb2c242 252 push @attrs, map { sprintf( "__attribute__nonnull__(%s)", $_ ) } @pos;
f54cb97a
AL
253 }
254 if ( @attrs ) {
255 $ret .= "\n";
256 $ret .= join( "\n", map { "\t\t\t$_" } @attrs );
4373e329 257 }
af3c7592 258 $ret .= ";";
88e01c9d 259 $ret = "/* $ret */" if $commented_out;
7918f24d
NC
260 if (@names_of_nn) {
261 $ret .= "\n#define PERL_ARGS_ASSERT_\U$plain_func\E\t\\\n\t"
262 . join '; ', map "assert($_)", @names_of_nn;
263 }
f54cb97a 264 $ret .= @attrs ? "\n\n" : "\n";
cea2e8a9
GS
265 }
266 $ret;
267}
268
2b10efc6
NC
269# generates global.sym (API export list)
270{
271 my %seen;
272 sub write_global_sym {
273 my $ret = "";
274 if (@_ > 1) {
275 my ($flags,$retval,$func,@args) = @_;
276 # If a function is defined twice, for example before and after an
277 # #else, only process the flags on the first instance for global.sym
278 return $ret if $seen{$func}++;
279 if ($flags =~ /[AX]/ && $flags !~ /[xm]/
280 || $flags =~ /b/) { # public API, so export
281 $func = "Perl_$func" if $flags =~ /[pbX]/;
282 $ret = "$func\n";
283 }
284 }
285 $ret;
286 }
cea2e8a9
GS
287}
288
2b10efc6 289
7827dc65 290our $unflagged_pointers;
37442d52 291walk_table(\&write_protos, "proto.h", undef, "/* ex: set ro: */\n");
7827dc65 292warn "$unflagged_pointers pointer arguments to clean up\n" if $unflagged_pointers;
37442d52 293walk_table(\&write_global_sym, "global.sym", undef, "# ex: set ro:\n");
cea2e8a9 294
709f4e38
GS
295# XXX others that may need adding
296# warnhook
297# hints
298# copline
84fee439 299my @extvars = qw(sv_undef sv_yes sv_no na dowarn
4373e329
AL
300 curcop compiling
301 tainting tainted stack_base stack_sp sv_arenaroot
256a4781 302 no_modify
4373e329
AL
303 curstash DBsub DBsingle DBassertion debstash
304 rsfp
305 stdingv
6b88bc9c
GS
306 defgv
307 errgv
3070f6ec
GS
308 rsfp_filters
309 perldb
709f4e38
GS
310 diehook
311 dirty
312 perl_destruct_level
ac634a9a 313 ppaddr
84fee439
NIS
314 );
315
5f05dabc 316sub readsyms (\%$) {
317 my ($syms, $file) = @_;
5f05dabc 318 local (*FILE, $_);
319 open(FILE, "< $file")
320 or die "embed.pl: Can't open $file: $!\n";
321 while (<FILE>) {
322 s/[ \t]*#.*//; # Delete comments.
323 if (/^\s*(\S+)\s*$/) {
22c35a8c 324 my $sym = $1;
d1594dd0 325 warn "duplicate symbol $sym while processing $file line $.\n"
22c35a8c
GS
326 if exists $$syms{$sym};
327 $$syms{$sym} = 1;
5f05dabc 328 }
329 }
330 close(FILE);
331}
332
cea2e8a9
GS
333# Perl_pp_* and Perl_ck_* are in pp.sym
334readsyms my %ppsym, 'pp.sym';
5f05dabc 335
c6af7a1a
GS
336sub readvars(\%$$@) {
337 my ($syms, $file,$pre,$keep_pre) = @_;
d4cce5f1
NIS
338 local (*FILE, $_);
339 open(FILE, "< $file")
340 or die "embed.pl: Can't open $file: $!\n";
341 while (<FILE>) {
342 s/[ \t]*#.*//; # Delete comments.
27da23d5 343 if (/PERLVARA?I?S?C?\($pre(\w+)/) {
22c35a8c 344 my $sym = $1;
c6af7a1a 345 $sym = $pre . $sym if $keep_pre;
d1594dd0 346 warn "duplicate symbol $sym while processing $file line $.\n"
22c35a8c 347 if exists $$syms{$sym};
51371543 348 $$syms{$sym} = $pre || 1;
d4cce5f1
NIS
349 }
350 }
351 close(FILE);
352}
353
354my %intrp;
88e01c9d 355my %globvar;
d4cce5f1
NIS
356
357readvars %intrp, 'intrpvar.h','I';
22239a37 358readvars %globvar, 'perlvars.h','G';
d4cce5f1 359
4543f4c0 360my $sym;
d4cce5f1 361
c6af7a1a
GS
362sub undefine ($) {
363 my ($sym) = @_;
364 "#undef $sym\n";
365}
366
5f05dabc 367sub hide ($$) {
368 my ($from, $to) = @_;
369 my $t = int(length($from) / 8);
370 "#define $from" . "\t" x ($t < 3 ? 3 - $t : 1) . "$to\n";
371}
c6af7a1a 372
6f4183fe 373sub bincompat_var ($$) {
51371543 374 my ($pfx, $sym) = @_;
acfe0abc 375 my $arg = ($pfx eq 'G' ? 'NULL' : 'aTHX');
c5be433b 376 undefine("PL_$sym") . hide("PL_$sym", "(*Perl_${pfx}${sym}_ptr($arg))");
c6af7a1a
GS
377}
378
d4cce5f1
NIS
379sub multon ($$$) {
380 my ($sym,$pre,$ptr) = @_;
3280af22 381 hide("PL_$sym", "($ptr$pre$sym)");
5f05dabc 382}
54aff467 383
d4cce5f1
NIS
384sub multoff ($$) {
385 my ($sym,$pre) = @_;
533c011a 386 return hide("PL_$pre$sym", "PL_$sym");
5f05dabc 387}
388
424a4936 389my $em = safer_open('embed.h-new');
e50aee73 390
424a4936 391print $em do_not_edit ("embed.h"), <<'END';
e50aee73
AD
392
393/* (Doing namespace management portably in C is really gross.) */
394
d51482e4
JH
395/* By defining PERL_NO_SHORT_NAMES (not done by default) the short forms
396 * (like warn instead of Perl_warn) for the API are not defined.
397 * Not defining the short forms is a good thing for cleaner embedding. */
398
399#ifndef PERL_NO_SHORT_NAMES
820c3be9 400
22c35a8c 401/* Hide global symbols */
5f05dabc 402
cea2e8a9 403#if !defined(PERL_IMPLICIT_CONTEXT)
e50aee73 404
e50aee73
AD
405END
406
da4ddda1
NC
407# Try to elimiate lots of repeated
408# #ifdef PERL_CORE
409# foo
410# #endif
411# #ifdef PERL_CORE
412# bar
413# #endif
414# by tracking state and merging foo and bar into one block.
415my $ifdef_state = '';
416
cea2e8a9
GS
417walk_table {
418 my $ret = "";
da4ddda1 419 my $new_ifdef_state = '';
cea2e8a9
GS
420 if (@_ == 1) {
421 my $arg = shift;
12a98ad5 422 $ret .= "$arg\n" if $arg =~ /^#\s*(if|ifn?def|else|endif)\b/;
cea2e8a9
GS
423 }
424 else {
425 my ($flags,$retval,$func,@args) = @_;
af3c7592 426 unless ($flags =~ /[om]/) {
cea2e8a9
GS
427 if ($flags =~ /s/) {
428 $ret .= hide($func,"S_$func");
429 }
430 elsif ($flags =~ /p/) {
431 $ret .= hide($func,"Perl_$func");
432 }
433 }
47e67c64 434 if ($ret ne '' && $flags !~ /A/) {
de37762f 435 if ($flags =~ /E/) {
da4ddda1
NC
436 $new_ifdef_state
437 = "#if defined(PERL_CORE) || defined(PERL_EXT)\n";
438 }
439 else {
440 $new_ifdef_state = "#ifdef PERL_CORE\n";
441 }
442
443 if ($new_ifdef_state ne $ifdef_state) {
444 $ret = $new_ifdef_state . $ret;
de37762f
HS
445 }
446 }
cea2e8a9 447 }
da4ddda1
NC
448 if ($ifdef_state && $new_ifdef_state ne $ifdef_state) {
449 # Close the old one ahead of opening the new one.
450 $ret = "#endif\n$ret";
451 }
452 # Remember the new state.
453 $ifdef_state = $new_ifdef_state;
cea2e8a9 454 $ret;
424a4936 455} $em, "";
cea2e8a9 456
da4ddda1 457if ($ifdef_state) {
424a4936 458 print $em "#endif\n";
da4ddda1
NC
459}
460
cea2e8a9
GS
461for $sym (sort keys %ppsym) {
462 $sym =~ s/^Perl_//;
424a4936 463 print $em hide($sym, "Perl_$sym");
cea2e8a9
GS
464}
465
424a4936 466print $em <<'END';
cea2e8a9
GS
467
468#else /* PERL_IMPLICIT_CONTEXT */
469
470END
471
472my @az = ('a'..'z');
473
da4ddda1 474$ifdef_state = '';
cea2e8a9
GS
475walk_table {
476 my $ret = "";
da4ddda1 477 my $new_ifdef_state = '';
cea2e8a9
GS
478 if (@_ == 1) {
479 my $arg = shift;
12a98ad5 480 $ret .= "$arg\n" if $arg =~ /^#\s*(if|ifn?def|else|endif)\b/;
cea2e8a9
GS
481 }
482 else {
483 my ($flags,$retval,$func,@args) = @_;
af3c7592 484 unless ($flags =~ /[om]/) {
cea2e8a9
GS
485 my $args = scalar @args;
486 if ($args and $args[$args-1] =~ /\.\.\./) {
487 # we're out of luck for varargs functions under CPP
488 }
489 elsif ($flags =~ /n/) {
490 if ($flags =~ /s/) {
491 $ret .= hide($func,"S_$func");
492 }
493 elsif ($flags =~ /p/) {
494 $ret .= hide($func,"Perl_$func");
495 }
496 }
497 else {
498 my $alist = join(",", @az[0..$args-1]);
499 $ret = "#define $func($alist)";
500 my $t = int(length($ret) / 8);
501 $ret .= "\t" x ($t < 4 ? 4 - $t : 1);
502 if ($flags =~ /s/) {
503 $ret .= "S_$func(aTHX";
504 }
505 elsif ($flags =~ /p/) {
506 $ret .= "Perl_$func(aTHX";
507 }
508 $ret .= "_ " if $alist;
509 $ret .= $alist . ")\n";
510 }
511 }
da4ddda1 512 unless ($flags =~ /A/) {
de37762f 513 if ($flags =~ /E/) {
da4ddda1
NC
514 $new_ifdef_state
515 = "#if defined(PERL_CORE) || defined(PERL_EXT)\n";
516 }
517 else {
518 $new_ifdef_state = "#ifdef PERL_CORE\n";
519 }
520
521 if ($new_ifdef_state ne $ifdef_state) {
522 $ret = $new_ifdef_state . $ret;
de37762f
HS
523 }
524 }
cea2e8a9 525 }
da4ddda1
NC
526 if ($ifdef_state && $new_ifdef_state ne $ifdef_state) {
527 # Close the old one ahead of opening the new one.
528 $ret = "#endif\n$ret";
529 }
530 # Remember the new state.
531 $ifdef_state = $new_ifdef_state;
cea2e8a9 532 $ret;
424a4936 533} $em, "";
cea2e8a9 534
da4ddda1 535if ($ifdef_state) {
424a4936 536 print $em "#endif\n";
da4ddda1
NC
537}
538
cea2e8a9
GS
539for $sym (sort keys %ppsym) {
540 $sym =~ s/^Perl_//;
541 if ($sym =~ /^ck_/) {
424a4936 542 print $em hide("$sym(a)", "Perl_$sym(aTHX_ a)");
cea2e8a9
GS
543 }
544 elsif ($sym =~ /^pp_/) {
424a4936 545 print $em hide("$sym()", "Perl_$sym(aTHX)");
cea2e8a9
GS
546 }
547 else {
548 warn "Illegal symbol '$sym' in pp.sym";
549 }
e50aee73
AD
550}
551
424a4936 552print $em <<'END';
e50aee73 553
cea2e8a9 554#endif /* PERL_IMPLICIT_CONTEXT */
22c35a8c 555
d51482e4 556#endif /* #ifndef PERL_NO_SHORT_NAMES */
35209cc8 557
22c35a8c
GS
558END
559
424a4936 560print $em <<'END';
22c35a8c 561
cea2e8a9
GS
562/* Compatibility stubs. Compile extensions with -DPERL_NOCOMPAT to
563 disable them.
564 */
565
538feb02 566#if !defined(PERL_CORE)
5bc28da9 567# define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,PTR2IV(ptr))
a0714e2c 568# define sv_setptrref(rv,ptr) sv_setref_iv(rv,NULL,PTR2IV(ptr))
538feb02 569#endif
cea2e8a9 570
08e5223a 571#if !defined(PERL_CORE) && !defined(PERL_NOCOMPAT)
cea2e8a9
GS
572
573/* Compatibility for various misnamed functions. All functions
574 in the API that begin with "perl_" (not "Perl_") take an explicit
575 interpreter context pointer.
576 The following are not like that, but since they had a "perl_"
577 prefix in previous versions, we provide compatibility macros.
578 */
65cec589
GS
579# define perl_atexit(a,b) call_atexit(a,b)
580# define perl_call_argv(a,b,c) call_argv(a,b,c)
581# define perl_call_pv(a,b) call_pv(a,b)
582# define perl_call_method(a,b) call_method(a,b)
583# define perl_call_sv(a,b) call_sv(a,b)
584# define perl_eval_sv(a,b) eval_sv(a,b)
585# define perl_eval_pv(a,b) eval_pv(a,b)
586# define perl_require_pv(a) require_pv(a)
587# define perl_get_sv(a,b) get_sv(a,b)
588# define perl_get_av(a,b) get_av(a,b)
589# define perl_get_hv(a,b) get_hv(a,b)
590# define perl_get_cv(a,b) get_cv(a,b)
591# define perl_init_i18nl10n(a) init_i18nl10n(a)
592# define perl_init_i18nl14n(a) init_i18nl14n(a)
593# define perl_new_ctype(a) new_ctype(a)
594# define perl_new_collate(a) new_collate(a)
595# define perl_new_numeric(a) new_numeric(a)
cea2e8a9
GS
596
597/* varargs functions can't be handled with CPP macros. :-(
598 This provides a set of compatibility functions that don't take
599 an extra argument but grab the context pointer using the macro
600 dTHX.
601 */
d51482e4 602#if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_NO_SHORT_NAMES)
cea2e8a9 603# define croak Perl_croak_nocontext
c5be433b 604# define deb Perl_deb_nocontext
cea2e8a9
GS
605# define die Perl_die_nocontext
606# define form Perl_form_nocontext
e4783991 607# define load_module Perl_load_module_nocontext
5a844595 608# define mess Perl_mess_nocontext
cea2e8a9
GS
609# define newSVpvf Perl_newSVpvf_nocontext
610# define sv_catpvf Perl_sv_catpvf_nocontext
611# define sv_setpvf Perl_sv_setpvf_nocontext
612# define warn Perl_warn_nocontext
c5be433b 613# define warner Perl_warner_nocontext
cea2e8a9
GS
614# define sv_catpvf_mg Perl_sv_catpvf_mg_nocontext
615# define sv_setpvf_mg Perl_sv_setpvf_mg_nocontext
616#endif
617
618#endif /* !defined(PERL_CORE) && !defined(PERL_NOCOMPAT) */
619
620#if !defined(PERL_IMPLICIT_CONTEXT)
621/* undefined symbols, point them back at the usual ones */
622# define Perl_croak_nocontext Perl_croak
623# define Perl_die_nocontext Perl_die
c5be433b 624# define Perl_deb_nocontext Perl_deb
cea2e8a9 625# define Perl_form_nocontext Perl_form
e4783991 626# define Perl_load_module_nocontext Perl_load_module
5a844595 627# define Perl_mess_nocontext Perl_mess
c5be433b
GS
628# define Perl_newSVpvf_nocontext Perl_newSVpvf
629# define Perl_sv_catpvf_nocontext Perl_sv_catpvf
630# define Perl_sv_setpvf_nocontext Perl_sv_setpvf
cea2e8a9 631# define Perl_warn_nocontext Perl_warn
c5be433b 632# define Perl_warner_nocontext Perl_warner
cea2e8a9
GS
633# define Perl_sv_catpvf_mg_nocontext Perl_sv_catpvf_mg
634# define Perl_sv_setpvf_mg_nocontext Perl_sv_setpvf_mg
635#endif
db5cf5a9 636
37442d52 637/* ex: set ro: */
d4cce5f1
NIS
638END
639
08858ed2 640safer_close($em);
424a4936 641rename_if_different('embed.h-new', 'embed.h');
d4cce5f1 642
424a4936 643$em = safer_open('embedvar.h-new');
d4cce5f1 644
424a4936 645print $em do_not_edit ("embedvar.h"), <<'END';
d4cce5f1
NIS
646
647/* (Doing namespace management portably in C is really gross.) */
648
54aff467 649/*
3db8f154
MB
650 The following combinations of MULTIPLICITY and PERL_IMPLICIT_CONTEXT
651 are supported:
54aff467
GS
652 1) none
653 2) MULTIPLICITY # supported for compatibility
654 3) MULTIPLICITY && PERL_IMPLICIT_CONTEXT
54aff467
GS
655
656 All other combinations of these flags are errors.
657
3db8f154 658 only #3 is supported directly, while #2 is a special
54aff467
GS
659 case of #3 (supported by redefining vTHX appropriately).
660*/
cea2e8a9 661
54aff467 662#if defined(MULTIPLICITY)
3db8f154 663/* cases 2 and 3 above */
cea2e8a9 664
54aff467
GS
665# if defined(PERL_IMPLICIT_CONTEXT)
666# define vTHX aTHX
667# else
668# define vTHX PERL_GET_INTERP
669# endif
cea2e8a9 670
e50aee73
AD
671END
672
d4cce5f1 673for $sym (sort keys %intrp) {
424a4936 674 print $em multon($sym,'I','vTHX->');
d4cce5f1
NIS
675}
676
424a4936 677print $em <<'END';
d4cce5f1 678
54aff467 679#else /* !MULTIPLICITY */
1d7c1841 680
3db8f154 681/* case 1 above */
5f05dabc 682
56d28764 683END
e50aee73 684
d4cce5f1 685for $sym (sort keys %intrp) {
424a4936 686 print $em multoff($sym,'I');
d4cce5f1
NIS
687}
688
424a4936 689print $em <<'END';
d4cce5f1 690
d4cce5f1
NIS
691END
692
424a4936 693print $em <<'END';
d4cce5f1 694
54aff467 695#endif /* MULTIPLICITY */
d4cce5f1 696
54aff467 697#if defined(PERL_GLOBAL_STRUCT)
22239a37
NIS
698
699END
700
701for $sym (sort keys %globvar) {
424a4936
NC
702 print $em multon($sym, 'G','my_vars->');
703 print $em multon("G$sym",'', 'my_vars->');
22239a37
NIS
704}
705
424a4936 706print $em <<'END';
22239a37
NIS
707
708#else /* !PERL_GLOBAL_STRUCT */
709
710END
711
712for $sym (sort keys %globvar) {
424a4936 713 print $em multoff($sym,'G');
22239a37
NIS
714}
715
424a4936 716print $em <<'END';
22239a37 717
22239a37
NIS
718#endif /* PERL_GLOBAL_STRUCT */
719
85add8c2 720#ifdef PERL_POLLUTE /* disabled by default in 5.6.0 */
84fee439
NIS
721
722END
723
724for $sym (sort @extvars) {
424a4936 725 print $em hide($sym,"PL_$sym");
84fee439
NIS
726}
727
424a4936 728print $em <<'END';
84fee439 729
db5cf5a9 730#endif /* PERL_POLLUTE */
37442d52
RGS
731
732/* ex: set ro: */
84fee439
NIS
733END
734
08858ed2 735safer_close($em);
424a4936 736rename_if_different('embedvar.h-new', 'embedvar.h');
c6af7a1a 737
424a4936
NC
738my $capi = safer_open('perlapi.c-new');
739my $capih = safer_open('perlapi.h-new');
51371543 740
424a4936 741print $capih do_not_edit ("perlapi.h"), <<'EOT';
51371543 742
51371543 743/* declare accessor functions for Perl variables */
6f4183fe
GS
744#ifndef __perlapi_h__
745#define __perlapi_h__
51371543 746
acfe0abc 747#if defined (MULTIPLICITY)
c5be433b 748
51371543
GS
749START_EXTERN_C
750
751#undef PERLVAR
752#undef PERLVARA
753#undef PERLVARI
754#undef PERLVARIC
27da23d5 755#undef PERLVARISC
acfe0abc 756#define PERLVAR(v,t) EXTERN_C t* Perl_##v##_ptr(pTHX);
51371543 757#define PERLVARA(v,n,t) typedef t PL_##v##_t[n]; \
acfe0abc 758 EXTERN_C PL_##v##_t* Perl_##v##_ptr(pTHX);
51371543 759#define PERLVARI(v,t,i) PERLVAR(v,t)
c5be433b 760#define PERLVARIC(v,t,i) PERLVAR(v, const t)
27da23d5
JH
761#define PERLVARISC(v,i) typedef const char PL_##v##_t[sizeof(i)]; \
762 EXTERN_C PL_##v##_t* Perl_##v##_ptr(pTHX);
51371543 763
51371543
GS
764#include "intrpvar.h"
765#include "perlvars.h"
766
767#undef PERLVAR
768#undef PERLVARA
769#undef PERLVARI
770#undef PERLVARIC
27da23d5
JH
771#undef PERLVARISC
772
773#ifndef PERL_GLOBAL_STRUCT
774EXTERN_C Perl_ppaddr_t** Perl_Gppaddr_ptr(pTHX);
775EXTERN_C Perl_check_t** Perl_Gcheck_ptr(pTHX);
776EXTERN_C unsigned char** Perl_Gfold_locale_ptr(pTHX);
777#define Perl_ppaddr_ptr Perl_Gppaddr_ptr
778#define Perl_check_ptr Perl_Gcheck_ptr
779#define Perl_fold_locale_ptr Perl_Gfold_locale_ptr
780#endif
51371543
GS
781
782END_EXTERN_C
783
682fc664 784#if defined(PERL_CORE)
6f4183fe 785
682fc664
GS
786/* accessor functions for Perl variables (provide binary compatibility) */
787
788/* these need to be mentioned here, or most linkers won't put them in
789 the perl executable */
790
791#ifndef PERL_NO_FORCE_LINK
792
793START_EXTERN_C
794
795#ifndef DOINIT
27da23d5 796EXTCONST void * const PL_force_link_funcs[];
682fc664 797#else
27da23d5 798EXTCONST void * const PL_force_link_funcs[] = {
682fc664
GS
799#undef PERLVAR
800#undef PERLVARA
801#undef PERLVARI
802#undef PERLVARIC
ea1f607c 803#define PERLVAR(v,t) (void*)Perl_##v##_ptr,
682fc664
GS
804#define PERLVARA(v,n,t) PERLVAR(v,t)
805#define PERLVARI(v,t,i) PERLVAR(v,t)
806#define PERLVARIC(v,t,i) PERLVAR(v,t)
27da23d5 807#define PERLVARISC(v,i) PERLVAR(v,char)
682fc664 808
3c0f78ca
JH
809/* In Tru64 (__DEC && __osf__) the cc option -std1 causes that one
810 * cannot cast between void pointers and function pointers without
811 * info level warnings. The PL_force_link_funcs[] would cause a few
812 * hundred of those warnings. In code one can circumnavigate this by using
813 * unions that overlay the different pointers, but in declarations one
814 * cannot use this trick. Therefore we just disable the warning here
815 * for the duration of the PL_force_link_funcs[] declaration. */
816
817#if defined(__DECC) && defined(__osf__)
818#pragma message save
819#pragma message disable (nonstandcast)
820#endif
821
682fc664
GS
822#include "intrpvar.h"
823#include "perlvars.h"
824
3c0f78ca
JH
825#if defined(__DECC) && defined(__osf__)
826#pragma message restore
827#endif
828
682fc664
GS
829#undef PERLVAR
830#undef PERLVARA
831#undef PERLVARI
832#undef PERLVARIC
27da23d5 833#undef PERLVARISC
682fc664
GS
834};
835#endif /* DOINIT */
836
acfe0abc 837END_EXTERN_C
682fc664
GS
838
839#endif /* PERL_NO_FORCE_LINK */
840
841#else /* !PERL_CORE */
51371543
GS
842
843EOT
844
4543f4c0 845foreach $sym (sort keys %intrp) {
424a4936 846 print $capih bincompat_var('I',$sym);
6f4183fe
GS
847}
848
4543f4c0 849foreach $sym (sort keys %globvar) {
424a4936 850 print $capih bincompat_var('G',$sym);
6f4183fe
GS
851}
852
424a4936 853print $capih <<'EOT';
6f4183fe
GS
854
855#endif /* !PERL_CORE */
acfe0abc 856#endif /* MULTIPLICITY */
6f4183fe
GS
857
858#endif /* __perlapi_h__ */
859
37442d52 860/* ex: set ro: */
6f4183fe 861EOT
08858ed2 862safer_close($capih);
424a4936 863rename_if_different('perlapi.h-new', 'perlapi.h');
51371543 864
424a4936 865print $capi do_not_edit ("perlapi.c"), <<'EOT';
51371543
GS
866
867#include "EXTERN.h"
868#include "perl.h"
869#include "perlapi.h"
870
acfe0abc 871#if defined (MULTIPLICITY)
51371543
GS
872
873/* accessor functions for Perl variables (provides binary compatibility) */
874START_EXTERN_C
875
876#undef PERLVAR
877#undef PERLVARA
878#undef PERLVARI
879#undef PERLVARIC
27da23d5 880#undef PERLVARISC
6f4183fe 881
6f4183fe 882#define PERLVAR(v,t) t* Perl_##v##_ptr(pTHX) \
96a5add6 883 { dVAR; PERL_UNUSED_CONTEXT; return &(aTHX->v); }
6f4183fe 884#define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX) \
96a5add6 885 { dVAR; PERL_UNUSED_CONTEXT; return &(aTHX->v); }
6f4183fe 886
51371543 887#define PERLVARI(v,t,i) PERLVAR(v,t)
c5be433b 888#define PERLVARIC(v,t,i) PERLVAR(v, const t)
27da23d5 889#define PERLVARISC(v,i) PL_##v##_t* Perl_##v##_ptr(pTHX) \
96a5add6 890 { dVAR; PERL_UNUSED_CONTEXT; return &(aTHX->v); }
51371543 891
51371543 892#include "intrpvar.h"
c5be433b
GS
893
894#undef PERLVAR
895#undef PERLVARA
acfe0abc 896#define PERLVAR(v,t) t* Perl_##v##_ptr(pTHX) \
96a5add6 897 { dVAR; PERL_UNUSED_CONTEXT; return &(PL_##v); }
acfe0abc 898#define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX) \
96a5add6 899 { dVAR; PERL_UNUSED_CONTEXT; return &(PL_##v); }
34f7a5fe 900#undef PERLVARIC
27da23d5
JH
901#undef PERLVARISC
902#define PERLVARIC(v,t,i) \
903 const t* Perl_##v##_ptr(pTHX) \
96a5add6 904 { PERL_UNUSED_CONTEXT; return (const t *)&(PL_##v); }
27da23d5 905#define PERLVARISC(v,i) PL_##v##_t* Perl_##v##_ptr(pTHX) \
96a5add6 906 { dVAR; PERL_UNUSED_CONTEXT; return &(PL_##v); }
51371543
GS
907#include "perlvars.h"
908
909#undef PERLVAR
910#undef PERLVARA
911#undef PERLVARI
912#undef PERLVARIC
27da23d5
JH
913#undef PERLVARISC
914
915#ifndef PERL_GLOBAL_STRUCT
916/* A few evil special cases. Could probably macrofy this. */
917#undef PL_ppaddr
918#undef PL_check
919#undef PL_fold_locale
920Perl_ppaddr_t** Perl_Gppaddr_ptr(pTHX) {
88e01c9d 921 static Perl_ppaddr_t* const ppaddr_ptr = PL_ppaddr;
96a5add6 922 PERL_UNUSED_CONTEXT;
27da23d5
JH
923 return (Perl_ppaddr_t**)&ppaddr_ptr;
924}
925Perl_check_t** Perl_Gcheck_ptr(pTHX) {
88e01c9d 926 static Perl_check_t* const check_ptr = PL_check;
96a5add6 927 PERL_UNUSED_CONTEXT;
27da23d5
JH
928 return (Perl_check_t**)&check_ptr;
929}
930unsigned char** Perl_Gfold_locale_ptr(pTHX) {
88e01c9d 931 static unsigned char* const fold_locale_ptr = PL_fold_locale;
96a5add6 932 PERL_UNUSED_CONTEXT;
27da23d5
JH
933 return (unsigned char**)&fold_locale_ptr;
934}
935#endif
51371543 936
acfe0abc 937END_EXTERN_C
6f4183fe 938
acfe0abc 939#endif /* MULTIPLICITY */
37442d52
RGS
940
941/* ex: set ro: */
51371543
GS
942EOT
943
08858ed2 944safer_close($capi);
424a4936 945rename_if_different('perlapi.c-new', 'perlapi.c');
acfe0abc 946
c5be433b 947# functions that take va_list* for implementing vararg functions
08cd8952 948# NOTE: makedef.pl must be updated if you add symbols to %vfuncs
acfe0abc 949# XXX %vfuncs currently unused
c5be433b
GS
950my %vfuncs = qw(
951 Perl_croak Perl_vcroak
952 Perl_warn Perl_vwarn
953 Perl_warner Perl_vwarner
954 Perl_die Perl_vdie
955 Perl_form Perl_vform
e4783991 956 Perl_load_module Perl_vload_module
5a844595 957 Perl_mess Perl_vmess
c5be433b
GS
958 Perl_deb Perl_vdeb
959 Perl_newSVpvf Perl_vnewSVpvf
960 Perl_sv_setpvf Perl_sv_vsetpvf
961 Perl_sv_setpvf_mg Perl_sv_vsetpvf_mg
962 Perl_sv_catpvf Perl_sv_vcatpvf
963 Perl_sv_catpvf_mg Perl_sv_vcatpvf_mg
964 Perl_dump_indent Perl_dump_vindent
965 Perl_default_protect Perl_vdefault_protect
966);
1b6737cc
AL
967
968# ex: set ts=8 sts=4 sw=4 noet: