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