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