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