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