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