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