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