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