Commit | Line | Data |
---|---|---|
5f05dabc | 1 | #!/usr/bin/perl -w |
6294c161 DM |
2 | # |
3 | # Regenerate (overwriting only if changed): | |
4 | # | |
5 | # embed.h | |
6 | # embedvar.h | |
7 | # global.sym | |
8 | # perlapi.c | |
9 | # perlapi.h | |
10 | # proto.h | |
11 | # | |
12 | # from information stored in | |
13 | # | |
14 | # embed.fnc | |
15 | # intrpvar.h | |
16 | # perlvars.h | |
897d3989 | 17 | # regen/opcodes |
6294c161 | 18 | # |
6294c161 DM |
19 | # Accepts the standard regen_lib -q and -v args. |
20 | # | |
21 | # This script is normally invoked from regen.pl. | |
e50aee73 | 22 | |
916e4025 | 23 | require 5.004; # keep this compatible, an old perl is all we may have before |
954c1994 | 24 | # we build the new one |
5f05dabc | 25 | |
88e01c9d AL |
26 | use strict; |
27 | ||
36bb303b NC |
28 | BEGIN { |
29 | # Get function prototypes | |
af001346 | 30 | require 'regen/regen_lib.pl'; |
36bb303b NC |
31 | } |
32 | ||
88e01c9d | 33 | my $SPLINT = 0; # Turn true for experimental splint support http://www.splint.org |
916e4025 | 34 | my $unflagged_pointers; |
88e01c9d | 35 | |
cea2e8a9 | 36 | # |
346f75ff | 37 | # See database of global and static function prototypes in embed.fnc |
cea2e8a9 GS |
38 | # This is used to generate prototype headers under various configurations, |
39 | # export symbols lists for different platforms, and macros to provide an | |
40 | # implicit interpreter context argument. | |
41 | # | |
42 | ||
5f8dc073 | 43 | sub open_print_header { |
56fd1190 | 44 | my ($file, $quote) = @_; |
4373e329 | 45 | |
5f8dc073 NC |
46 | return open_new($file, '>', |
47 | { file => $file, style => '*', by => 'regen/embed.pl', | |
48 | from => ['data in embed.fnc', 'regen/embed.pl', | |
49 | 'regen/opcodes', 'intrpvar.h', 'perlvars.h'], | |
50 | final => "\nEdit those files and run 'make regen_headers' to effect changes.\n", | |
51 | copyright => [1993 .. 2009], quote => $quote }); | |
52 | } | |
7f1be197 | 53 | |
94bdecf9 | 54 | open IN, "embed.fnc" or die $!; |
cea2e8a9 | 55 | |
881a2100 | 56 | my @embed; |
125218eb | 57 | my (%has_va, %has_nocontext); |
881a2100 NC |
58 | |
59 | while (<IN>) { | |
60 | chomp; | |
61 | next if /^:/; | |
24dd05fb | 62 | next if /^$/; |
881a2100 NC |
63 | while (s|\\$||) { |
64 | $_ .= <IN>; | |
65 | chomp; | |
66 | } | |
67 | s/\s+$//; | |
68 | my @args; | |
69 | if (/^\s*(#|$)/) { | |
70 | @args = $_; | |
71 | } | |
72 | else { | |
73 | @args = split /\s*\|\s*/, $_; | |
125218eb NC |
74 | my $func = $args[2]; |
75 | if ($func) { | |
76 | ++$has_va{$func} if $args[-1] =~ /\.\.\./; | |
77 | ++$has_nocontext{$1} if $func =~ /(.*)_nocontext/; | |
78 | } | |
881a2100 | 79 | } |
7c662e8a NC |
80 | if (@args == 1 && $args[0] !~ /^#\s*(?:if|ifdef|ifndef|else|endif)/) { |
81 | die "Illegal line $. '$args[0]' in embed.fnc"; | |
82 | } | |
881a2100 NC |
83 | push @embed, \@args; |
84 | } | |
85 | ||
146326cb NC |
86 | open IN, 'regen/opcodes' or die $!; |
87 | { | |
88 | my %syms; | |
89 | ||
90 | while (<IN>) { | |
91 | chop; | |
92 | next unless $_; | |
93 | next if /^#/; | |
94 | my (undef, undef, $check) = split /\t+/, $_; | |
95 | ++$syms{$check}; | |
96 | } | |
97 | ||
98 | foreach (keys %syms) { | |
99 | # These are all indirectly referenced by globals.c. | |
100 | push @embed, ['pR', 'OP *', $_, 'NN OP *o']; | |
101 | } | |
102 | } | |
103 | close IN; | |
104 | ||
e8a67806 | 105 | my (@core, @ext, @api); |
c527bc84 | 106 | { |
e8a67806 NC |
107 | # Cluster entries in embed.fnc that have the same #ifdef guards. |
108 | # Also, split out at the top level the three classes of functions. | |
109 | my @state; | |
110 | my %groups; | |
111 | my $current; | |
c527bc84 | 112 | foreach (@embed) { |
e8a67806 NC |
113 | if (@$_ > 1) { |
114 | push @$current, $_; | |
115 | next; | |
116 | } | |
c527bc84 NC |
117 | $_->[0] =~ s/^#\s+/#/; |
118 | $_->[0] =~ /^\S*/; | |
119 | $_->[0] =~ s/^#ifdef\s+(\S+)/#if defined($1)/; | |
120 | $_->[0] =~ s/^#ifndef\s+(\S+)/#if !defined($1)/; | |
e8a67806 NC |
121 | if ($_->[0] =~ /^#if\s*(.*)/) { |
122 | push @state, $1; | |
123 | } elsif ($_->[0] =~ /^#else\s*$/) { | |
124 | die "Unmatched #else in embed.fnc" unless @state; | |
125 | $state[-1] = "!($state[-1])"; | |
126 | } elsif ($_->[0] =~ m!^#endif\s*(?:/\*.*\*/)?$!) { | |
127 | die "Unmatched #endif in embed.fnc" unless @state; | |
128 | pop @state; | |
129 | } else { | |
130 | die "Unhandled pre-processor directive '$_->[0]' in embed.fnc"; | |
131 | } | |
132 | $current = \%groups; | |
133 | # Nested #if blocks are effectively &&ed together | |
134 | # For embed.fnc, ordering withing the && isn't relevant, so we can | |
135 | # sort them to try to group more functions together. | |
136 | my @sorted = sort @state; | |
137 | while (my $directive = shift @sorted) { | |
138 | $current->{$directive} ||= {}; | |
139 | $current = $current->{$directive}; | |
140 | } | |
141 | $current->{''} ||= []; | |
142 | $current = $current->{''}; | |
143 | } | |
144 | ||
145 | sub add_level { | |
146 | my ($level, $indent, $wanted) = @_; | |
147 | my $funcs = $level->{''}; | |
148 | my @entries; | |
149 | if ($funcs) { | |
150 | if (!defined $wanted) { | |
151 | @entries = @$funcs; | |
152 | } else { | |
153 | foreach (@$funcs) { | |
154 | if ($_->[0] =~ /A/) { | |
155 | push @entries, $_ if $wanted eq 'A'; | |
156 | } elsif ($_->[0] =~ /E/) { | |
157 | push @entries, $_ if $wanted eq 'E'; | |
158 | } else { | |
159 | push @entries, $_ if $wanted eq ''; | |
160 | } | |
161 | } | |
162 | } | |
163 | @entries = sort {$a->[2] cmp $b->[2]} @entries; | |
164 | } | |
165 | foreach (sort grep {length $_} keys %$level) { | |
166 | my @conditional = add_level($level->{$_}, $indent . ' ', $wanted); | |
167 | push @entries, | |
168 | ["#${indent}if $_"], @conditional, ["#${indent}endif"] | |
169 | if @conditional; | |
170 | } | |
171 | return @entries; | |
c527bc84 | 172 | } |
e8a67806 NC |
173 | @core = add_level(\%groups, '', ''); |
174 | @ext = add_level(\%groups, '', 'E'); | |
175 | @api = add_level(\%groups, '', 'A'); | |
176 | ||
177 | @embed = add_level(\%groups, ''); | |
c527bc84 NC |
178 | } |
179 | ||
cea2e8a9 GS |
180 | # walk table providing an array of components in each line to |
181 | # subroutine, printing the result | |
182 | sub walk_table (&@) { | |
ce716c52 | 183 | my ($function, $filename) = @_; |
cea2e8a9 | 184 | my $F; |
cea2e8a9 GS |
185 | if (ref $filename) { # filehandle |
186 | $F = $filename; | |
187 | } | |
d0ee0d3d | 188 | else { |
5f8dc073 | 189 | $F = open_print_header($filename); |
cea2e8a9 | 190 | } |
881a2100 NC |
191 | foreach (@embed) { |
192 | my @outs = &{$function}(@$_); | |
1028dc3c | 193 | # $function->(@args) is not 5.003 |
d0ee0d3d | 194 | print $F @outs; |
cea2e8a9 | 195 | } |
d0ee0d3d | 196 | unless (ref $filename) { |
ce716c52 | 197 | read_only_bottom_close_and_rename($F); |
36bb303b | 198 | } |
cea2e8a9 GS |
199 | } |
200 | ||
cea2e8a9 | 201 | # generate proto.h |
9516dc40 | 202 | { |
5f8dc073 NC |
203 | my $pr = open_print_header("proto.h"); |
204 | print $pr "START_EXTERN_C\n"; | |
f8394530 | 205 | my $ret; |
9516dc40 NC |
206 | |
207 | foreach (@embed) { | |
208 | if (@$_ == 1) { | |
209 | print $pr "$_->[0]\n"; | |
210 | next; | |
211 | } | |
212 | ||
213 | my ($flags,$retval,$plain_func,@args) = @$_; | |
4373e329 AL |
214 | my @nonnull; |
215 | my $has_context = ( $flags !~ /n/ ); | |
88e01c9d AL |
216 | my $never_returns = ( $flags =~ /r/ ); |
217 | my $commented_out = ( $flags =~ /m/ ); | |
aa4ca557 | 218 | my $binarycompat = ( $flags =~ /b/ ); |
88e01c9d AL |
219 | my $is_malloc = ( $flags =~ /a/ ); |
220 | my $can_ignore = ( $flags !~ /R/ ) && !$is_malloc; | |
7918f24d NC |
221 | my @names_of_nn; |
222 | my $func; | |
88e01c9d AL |
223 | |
224 | my $splint_flags = ""; | |
225 | if ( $SPLINT && !$commented_out ) { | |
226 | $splint_flags .= '/*@noreturn@*/ ' if $never_returns; | |
227 | if ($can_ignore && ($retval ne 'void') && ($retval !~ /\*/)) { | |
228 | $retval .= " /*\@alt void\@*/"; | |
229 | } | |
230 | } | |
231 | ||
71556506 KW |
232 | if ($flags =~ /([si])/) { |
233 | my $type = ($1 eq 's') ? "STATIC" : "PERL_STATIC_INLINE"; | |
234 | warn "$func: i and s flags are mutually exclusive" | |
235 | if $flags =~ /s/ && $flags =~ /i/; | |
236 | $retval = "$type $splint_flags$retval"; | |
7918f24d | 237 | $func = "S_$plain_func"; |
cea2e8a9 | 238 | } |
0cb96387 | 239 | else { |
88e01c9d | 240 | $retval = "PERL_CALLCONV $splint_flags$retval"; |
25b0f989 | 241 | if ($flags =~ /[bp]/) { |
7918f24d NC |
242 | $func = "Perl_$plain_func"; |
243 | } else { | |
244 | $func = $plain_func; | |
0cb96387 | 245 | } |
cea2e8a9 | 246 | } |
f8394530 | 247 | $ret = "$retval\t$func("; |
4373e329 AL |
248 | if ( $has_context ) { |
249 | $ret .= @args ? "pTHX_ " : "pTHX"; | |
cea2e8a9 GS |
250 | } |
251 | if (@args) { | |
4373e329 AL |
252 | my $n; |
253 | for my $arg ( @args ) { | |
254 | ++$n; | |
7827dc65 AL |
255 | if ( $arg =~ /\*/ && $arg !~ /\b(NN|NULLOK)\b/ ) { |
256 | warn "$func: $arg needs NN or NULLOK\n"; | |
7827dc65 AL |
257 | ++$unflagged_pointers; |
258 | } | |
88e01c9d AL |
259 | my $nn = ( $arg =~ s/\s*\bNN\b\s+// ); |
260 | push( @nonnull, $n ) if $nn; | |
261 | ||
262 | my $nullok = ( $arg =~ s/\s*\bNULLOK\b\s+// ); # strip NULLOK with no effect | |
c48640ec AL |
263 | |
264 | # Make sure each arg has at least a type and a var name. | |
265 | # An arg of "int" is valid C, but want it to be "int foo". | |
266 | my $temp_arg = $arg; | |
267 | $temp_arg =~ s/\*//g; | |
268 | $temp_arg =~ s/\s*\bstruct\b\s*/ /g; | |
7918f24d NC |
269 | if ( ($temp_arg ne "...") |
270 | && ($temp_arg !~ /\w+\s+(\w+)(?:\[\d+\])?\s*$/) ) { | |
271 | warn "$func: $arg ($n) doesn't have a name\n"; | |
c48640ec | 272 | } |
88e01c9d AL |
273 | if ( $SPLINT && $nullok && !$commented_out ) { |
274 | $arg = '/*@null@*/ ' . $arg; | |
275 | } | |
aa4ca557 | 276 | if (defined $1 && $nn && !($commented_out && !$binarycompat)) { |
7918f24d NC |
277 | push @names_of_nn, $1; |
278 | } | |
4373e329 | 279 | } |
cea2e8a9 GS |
280 | $ret .= join ", ", @args; |
281 | } | |
282 | else { | |
4373e329 | 283 | $ret .= "void" if !$has_context; |
cea2e8a9 GS |
284 | } |
285 | $ret .= ")"; | |
f54cb97a AL |
286 | my @attrs; |
287 | if ( $flags =~ /r/ ) { | |
abb2c242 | 288 | push @attrs, "__attribute__noreturn__"; |
f54cb97a | 289 | } |
a5c26493 RGS |
290 | if ( $flags =~ /D/ ) { |
291 | push @attrs, "__attribute__deprecated__"; | |
292 | } | |
88e01c9d | 293 | if ( $is_malloc ) { |
abb2c242 | 294 | push @attrs, "__attribute__malloc__"; |
f54cb97a | 295 | } |
88e01c9d | 296 | if ( !$can_ignore ) { |
abb2c242 | 297 | push @attrs, "__attribute__warn_unused_result__"; |
f54cb97a AL |
298 | } |
299 | if ( $flags =~ /P/ ) { | |
abb2c242 | 300 | push @attrs, "__attribute__pure__"; |
f54cb97a | 301 | } |
1c846c1f | 302 | if( $flags =~ /f/ ) { |
cdfeb707 RB |
303 | my $prefix = $has_context ? 'pTHX_' : ''; |
304 | my $args = scalar @args; | |
305 | my $pat = $args - 1; | |
306 | my $macro = @nonnull && $nonnull[-1] == $pat | |
307 | ? '__attribute__format__' | |
308 | : '__attribute__format__null_ok__'; | |
309 | push @attrs, sprintf "%s(__printf__,%s%d,%s%d)", $macro, | |
310 | $prefix, $pat, $prefix, $args; | |
894356b3 | 311 | } |
4373e329 | 312 | if ( @nonnull ) { |
3d42dc86 | 313 | my @pos = map { $has_context ? "pTHX_$_" : $_ } @nonnull; |
abb2c242 | 314 | push @attrs, map { sprintf( "__attribute__nonnull__(%s)", $_ ) } @pos; |
f54cb97a AL |
315 | } |
316 | if ( @attrs ) { | |
317 | $ret .= "\n"; | |
318 | $ret .= join( "\n", map { "\t\t\t$_" } @attrs ); | |
4373e329 | 319 | } |
af3c7592 | 320 | $ret .= ";"; |
88e01c9d | 321 | $ret = "/* $ret */" if $commented_out; |
7918f24d NC |
322 | if (@names_of_nn) { |
323 | $ret .= "\n#define PERL_ARGS_ASSERT_\U$plain_func\E\t\\\n\t" | |
324 | . join '; ', map "assert($_)", @names_of_nn; | |
325 | } | |
f54cb97a | 326 | $ret .= @attrs ? "\n\n" : "\n"; |
9516dc40 NC |
327 | |
328 | print $pr $ret; | |
cea2e8a9 | 329 | } |
9516dc40 | 330 | |
897d3989 NC |
331 | print $pr <<'EOF'; |
332 | #ifdef PERL_CORE | |
333 | # include "pp_proto.h" | |
334 | #endif | |
335 | END_EXTERN_C | |
897d3989 | 336 | EOF |
9516dc40 | 337 | |
ce716c52 | 338 | read_only_bottom_close_and_rename($pr); |
cea2e8a9 GS |
339 | } |
340 | ||
2b10efc6 NC |
341 | # generates global.sym (API export list) |
342 | { | |
343 | my %seen; | |
344 | sub write_global_sym { | |
2b10efc6 NC |
345 | if (@_ > 1) { |
346 | my ($flags,$retval,$func,@args) = @_; | |
2b10efc6 NC |
347 | if ($flags =~ /[AX]/ && $flags !~ /[xm]/ |
348 | || $flags =~ /b/) { # public API, so export | |
9be14afe NC |
349 | # If a function is defined twice, for example before and after |
350 | # an #else, only export its name once. | |
351 | return '' if $seen{$func}++; | |
2b10efc6 | 352 | $func = "Perl_$func" if $flags =~ /[pbX]/; |
f8394530 | 353 | return "$func\n"; |
2b10efc6 NC |
354 | } |
355 | } | |
f8394530 | 356 | return ''; |
2b10efc6 | 357 | } |
cea2e8a9 GS |
358 | } |
359 | ||
7827dc65 | 360 | warn "$unflagged_pointers pointer arguments to clean up\n" if $unflagged_pointers; |
ce716c52 | 361 | walk_table(\&write_global_sym, "global.sym"); |
cea2e8a9 | 362 | |
adf34b4b NC |
363 | sub readvars { |
364 | my ($file, $pre) = @_; | |
d4cce5f1 | 365 | local (*FILE, $_); |
adf34b4b | 366 | my %seen; |
d4cce5f1 NIS |
367 | open(FILE, "< $file") |
368 | or die "embed.pl: Can't open $file: $!\n"; | |
369 | while (<FILE>) { | |
370 | s/[ \t]*#.*//; # Delete comments. | |
58f645e2 | 371 | if (/PERLVARA?I?C?\($pre(\w+)/) { |
adf34b4b NC |
372 | warn "duplicate symbol $1 while processing $file line $.\n" |
373 | if $seen{$1}++; | |
d4cce5f1 NIS |
374 | } |
375 | } | |
376 | close(FILE); | |
adf34b4b | 377 | return sort keys %seen; |
d4cce5f1 NIS |
378 | } |
379 | ||
adf34b4b NC |
380 | my @intrp = readvars 'intrpvar.h','I'; |
381 | my @globvar = readvars 'perlvars.h','G'; | |
d4cce5f1 | 382 | |
125218eb NC |
383 | sub hide { |
384 | my ($from, $to, $indent) = @_; | |
385 | $indent = '' unless defined $indent; | |
386 | my $t = int(length("$indent$from") / 8); | |
387 | "#${indent}define $from" . "\t" x ($t < 3 ? 3 - $t : 1) . "$to\n"; | |
5f05dabc | 388 | } |
c6af7a1a | 389 | |
d4cce5f1 NIS |
390 | sub multon ($$$) { |
391 | my ($sym,$pre,$ptr) = @_; | |
3280af22 | 392 | hide("PL_$sym", "($ptr$pre$sym)"); |
5f05dabc | 393 | } |
54aff467 | 394 | |
d4cce5f1 NIS |
395 | sub multoff ($$) { |
396 | my ($sym,$pre) = @_; | |
533c011a | 397 | return hide("PL_$pre$sym", "PL_$sym"); |
5f05dabc | 398 | } |
399 | ||
5f8dc073 | 400 | my $em = open_print_header('embed.h'); |
e50aee73 | 401 | |
5f8dc073 | 402 | print $em <<'END'; |
e50aee73 AD |
403 | /* (Doing namespace management portably in C is really gross.) */ |
404 | ||
d51482e4 JH |
405 | /* By defining PERL_NO_SHORT_NAMES (not done by default) the short forms |
406 | * (like warn instead of Perl_warn) for the API are not defined. | |
407 | * Not defining the short forms is a good thing for cleaner embedding. */ | |
408 | ||
409 | #ifndef PERL_NO_SHORT_NAMES | |
820c3be9 | 410 | |
22c35a8c | 411 | /* Hide global symbols */ |
5f05dabc | 412 | |
e50aee73 AD |
413 | END |
414 | ||
cea2e8a9 GS |
415 | my @az = ('a'..'z'); |
416 | ||
e8a67806 NC |
417 | sub embed_h { |
418 | my ($guard, $funcs) = @_; | |
419 | print $em "$guard\n" if $guard; | |
420 | ||
2a4d8072 | 421 | my $lines; |
e8a67806 NC |
422 | foreach (@$funcs) { |
423 | if (@$_ == 1) { | |
424 | my $cond = $_->[0]; | |
425 | # Indent the conditionals if we are wrapped in an #if/#endif pair. | |
426 | $cond =~ s/#(.*)/# $1/ if $guard; | |
2a4d8072 | 427 | $lines .= "$cond\n"; |
e8a67806 NC |
428 | next; |
429 | } | |
430 | my $ret = ""; | |
431 | my ($flags,$retval,$func,@args) = @$_; | |
af3c7592 | 432 | unless ($flags =~ /[om]/) { |
cea2e8a9 | 433 | my $args = scalar @args; |
7a5a24f7 | 434 | if ($flags =~ /n/) { |
cea2e8a9 | 435 | if ($flags =~ /s/) { |
f8394530 | 436 | $ret = hide($func,"S_$func"); |
cea2e8a9 GS |
437 | } |
438 | elsif ($flags =~ /p/) { | |
f8394530 | 439 | $ret = hide($func,"Perl_$func"); |
cea2e8a9 GS |
440 | } |
441 | } | |
7a5a24f7 | 442 | elsif ($args and $args[$args-1] =~ /\.\.\./) { |
e64ca59f NC |
443 | if ($flags =~ /p/) { |
444 | # we're out of luck for varargs functions under CPP | |
445 | # So we can only do these macros for no implicit context: | |
446 | $ret = "#ifndef PERL_IMPLICIT_CONTEXT\n" | |
447 | . hide($func,"Perl_$func") . "#endif\n"; | |
448 | } | |
7a5a24f7 | 449 | } |
cea2e8a9 GS |
450 | else { |
451 | my $alist = join(",", @az[0..$args-1]); | |
452 | $ret = "#define $func($alist)"; | |
453 | my $t = int(length($ret) / 8); | |
454 | $ret .= "\t" x ($t < 4 ? 4 - $t : 1); | |
71556506 | 455 | if ($flags =~ /[si]/) { |
cea2e8a9 GS |
456 | $ret .= "S_$func(aTHX"; |
457 | } | |
458 | elsif ($flags =~ /p/) { | |
459 | $ret .= "Perl_$func(aTHX"; | |
460 | } | |
461 | $ret .= "_ " if $alist; | |
462 | $ret .= $alist . ")\n"; | |
463 | } | |
464 | } | |
2a4d8072 | 465 | $lines .= $ret; |
cea2e8a9 | 466 | } |
2a4d8072 NC |
467 | # Prune empty #if/#endif pairs. |
468 | while ($lines =~ s/#\s*if[^\n]+\n#\s*endif\n//) { | |
469 | } | |
b2e549c0 NC |
470 | # Merge adjacent blocks. |
471 | while ($lines =~ s/(#ifndef PERL_IMPLICIT_CONTEXT | |
472 | [^\n]+ | |
473 | )#endif | |
474 | #ifndef PERL_IMPLICIT_CONTEXT | |
475 | /$1/) { | |
476 | } | |
477 | ||
2a4d8072 | 478 | print $em $lines; |
e8a67806 | 479 | print $em "#endif\n" if $guard; |
da4ddda1 NC |
480 | } |
481 | ||
e8a67806 NC |
482 | embed_h('', \@api); |
483 | embed_h('#if defined(PERL_CORE) || defined(PERL_EXT)', \@ext); | |
484 | embed_h('#ifdef PERL_CORE', \@core); | |
485 | ||
424a4936 | 486 | print $em <<'END'; |
e50aee73 | 487 | |
d51482e4 | 488 | #endif /* #ifndef PERL_NO_SHORT_NAMES */ |
35209cc8 | 489 | |
cea2e8a9 GS |
490 | /* Compatibility stubs. Compile extensions with -DPERL_NOCOMPAT to |
491 | disable them. | |
492 | */ | |
493 | ||
538feb02 | 494 | #if !defined(PERL_CORE) |
5bc28da9 | 495 | # define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,PTR2IV(ptr)) |
a0714e2c | 496 | # define sv_setptrref(rv,ptr) sv_setref_iv(rv,NULL,PTR2IV(ptr)) |
538feb02 | 497 | #endif |
cea2e8a9 | 498 | |
08e5223a | 499 | #if !defined(PERL_CORE) && !defined(PERL_NOCOMPAT) |
cea2e8a9 GS |
500 | |
501 | /* Compatibility for various misnamed functions. All functions | |
502 | in the API that begin with "perl_" (not "Perl_") take an explicit | |
503 | interpreter context pointer. | |
504 | The following are not like that, but since they had a "perl_" | |
505 | prefix in previous versions, we provide compatibility macros. | |
506 | */ | |
65cec589 | 507 | # define perl_atexit(a,b) call_atexit(a,b) |
7b53c8ee NC |
508 | END |
509 | ||
510 | walk_table { | |
511 | my ($flags,$retval,$func,@args) = @_; | |
512 | return unless $func; | |
513 | return unless $flags =~ /O/; | |
514 | ||
515 | my $alist = join ",", @az[0..$#args]; | |
516 | my $ret = "# define perl_$func($alist)"; | |
517 | my $t = (length $ret) >> 3; | |
518 | $ret .= "\t" x ($t < 5 ? 5 - $t : 1); | |
519 | "$ret$func($alist)\n"; | |
1028dc3c | 520 | } $em; |
7b53c8ee NC |
521 | |
522 | print $em <<'END'; | |
cea2e8a9 GS |
523 | |
524 | /* varargs functions can't be handled with CPP macros. :-( | |
525 | This provides a set of compatibility functions that don't take | |
526 | an extra argument but grab the context pointer using the macro | |
527 | dTHX. | |
528 | */ | |
d51482e4 | 529 | #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_NO_SHORT_NAMES) |
125218eb NC |
530 | END |
531 | ||
532 | foreach (sort keys %has_va) { | |
533 | next unless $has_nocontext{$_}; | |
534 | next if /printf/; # Not clear to me why these are skipped but they are. | |
535 | print $em hide($_, "Perl_${_}_nocontext", " "); | |
536 | } | |
537 | ||
538 | print $em <<'END'; | |
cea2e8a9 GS |
539 | #endif |
540 | ||
541 | #endif /* !defined(PERL_CORE) && !defined(PERL_NOCOMPAT) */ | |
542 | ||
543 | #if !defined(PERL_IMPLICIT_CONTEXT) | |
544 | /* undefined symbols, point them back at the usual ones */ | |
125218eb NC |
545 | END |
546 | ||
547 | foreach (sort keys %has_va) { | |
548 | next unless $has_nocontext{$_}; | |
549 | next if /printf/; # Not clear to me why these are skipped but they are. | |
550 | print $em hide("Perl_${_}_nocontext", "Perl_$_", " "); | |
551 | } | |
552 | ||
553 | print $em <<'END'; | |
cea2e8a9 | 554 | #endif |
d4cce5f1 NIS |
555 | END |
556 | ||
ce716c52 | 557 | read_only_bottom_close_and_rename($em); |
d4cce5f1 | 558 | |
5f8dc073 | 559 | $em = open_print_header('embedvar.h'); |
d4cce5f1 | 560 | |
5f8dc073 | 561 | print $em <<'END'; |
d4cce5f1 NIS |
562 | /* (Doing namespace management portably in C is really gross.) */ |
563 | ||
54aff467 | 564 | /* |
3db8f154 MB |
565 | The following combinations of MULTIPLICITY and PERL_IMPLICIT_CONTEXT |
566 | are supported: | |
54aff467 GS |
567 | 1) none |
568 | 2) MULTIPLICITY # supported for compatibility | |
569 | 3) MULTIPLICITY && PERL_IMPLICIT_CONTEXT | |
54aff467 GS |
570 | |
571 | All other combinations of these flags are errors. | |
572 | ||
3db8f154 | 573 | only #3 is supported directly, while #2 is a special |
54aff467 GS |
574 | case of #3 (supported by redefining vTHX appropriately). |
575 | */ | |
cea2e8a9 | 576 | |
54aff467 | 577 | #if defined(MULTIPLICITY) |
3db8f154 | 578 | /* cases 2 and 3 above */ |
cea2e8a9 | 579 | |
54aff467 GS |
580 | # if defined(PERL_IMPLICIT_CONTEXT) |
581 | # define vTHX aTHX | |
582 | # else | |
583 | # define vTHX PERL_GET_INTERP | |
584 | # endif | |
cea2e8a9 | 585 | |
e50aee73 AD |
586 | END |
587 | ||
adf34b4b NC |
588 | my $sym; |
589 | ||
590 | for $sym (@intrp) { | |
424a4936 | 591 | print $em multon($sym,'I','vTHX->'); |
d4cce5f1 NIS |
592 | } |
593 | ||
424a4936 | 594 | print $em <<'END'; |
d4cce5f1 | 595 | |
54aff467 | 596 | #else /* !MULTIPLICITY */ |
1d7c1841 | 597 | |
3db8f154 | 598 | /* case 1 above */ |
5f05dabc | 599 | |
56d28764 | 600 | END |
e50aee73 | 601 | |
adf34b4b | 602 | for $sym (@intrp) { |
424a4936 | 603 | print $em multoff($sym,'I'); |
d4cce5f1 NIS |
604 | } |
605 | ||
424a4936 | 606 | print $em <<'END'; |
d4cce5f1 | 607 | |
d4cce5f1 NIS |
608 | END |
609 | ||
424a4936 | 610 | print $em <<'END'; |
d4cce5f1 | 611 | |
54aff467 | 612 | #endif /* MULTIPLICITY */ |
d4cce5f1 | 613 | |
54aff467 | 614 | #if defined(PERL_GLOBAL_STRUCT) |
22239a37 NIS |
615 | |
616 | END | |
617 | ||
adf34b4b | 618 | for $sym (@globvar) { |
0447859b | 619 | print $em "#ifdef OS2\n" if $sym eq 'sh_path'; |
424a4936 NC |
620 | print $em multon($sym, 'G','my_vars->'); |
621 | print $em multon("G$sym",'', 'my_vars->'); | |
0447859b | 622 | print $em "#endif\n" if $sym eq 'sh_path'; |
22239a37 NIS |
623 | } |
624 | ||
424a4936 | 625 | print $em <<'END'; |
22239a37 NIS |
626 | |
627 | #else /* !PERL_GLOBAL_STRUCT */ | |
628 | ||
629 | END | |
630 | ||
adf34b4b | 631 | for $sym (@globvar) { |
0447859b | 632 | print $em "#ifdef OS2\n" if $sym eq 'sh_path'; |
424a4936 | 633 | print $em multoff($sym,'G'); |
0447859b | 634 | print $em "#endif\n" if $sym eq 'sh_path'; |
22239a37 NIS |
635 | } |
636 | ||
424a4936 | 637 | print $em <<'END'; |
22239a37 | 638 | |
22239a37 | 639 | #endif /* PERL_GLOBAL_STRUCT */ |
84fee439 NIS |
640 | END |
641 | ||
ce716c52 | 642 | read_only_bottom_close_and_rename($em); |
c6af7a1a | 643 | |
5f8dc073 | 644 | my $capih = open_print_header('perlapi.h'); |
51371543 | 645 | |
5f8dc073 | 646 | print $capih <<'EOT'; |
51371543 | 647 | /* declare accessor functions for Perl variables */ |
6f4183fe GS |
648 | #ifndef __perlapi_h__ |
649 | #define __perlapi_h__ | |
51371543 | 650 | |
87b9e160 | 651 | #if defined (MULTIPLICITY) && defined (PERL_GLOBAL_STRUCT) |
c5be433b | 652 | |
51371543 GS |
653 | START_EXTERN_C |
654 | ||
655 | #undef PERLVAR | |
656 | #undef PERLVARA | |
657 | #undef PERLVARI | |
658 | #undef PERLVARIC | |
acfe0abc | 659 | #define PERLVAR(v,t) EXTERN_C t* Perl_##v##_ptr(pTHX); |
51371543 | 660 | #define PERLVARA(v,n,t) typedef t PL_##v##_t[n]; \ |
acfe0abc | 661 | EXTERN_C PL_##v##_t* Perl_##v##_ptr(pTHX); |
51371543 | 662 | #define PERLVARI(v,t,i) PERLVAR(v,t) |
c5be433b | 663 | #define PERLVARIC(v,t,i) PERLVAR(v, const t) |
51371543 | 664 | |
51371543 GS |
665 | #include "perlvars.h" |
666 | ||
667 | #undef PERLVAR | |
668 | #undef PERLVARA | |
669 | #undef PERLVARI | |
670 | #undef PERLVARIC | |
27da23d5 | 671 | |
51371543 GS |
672 | END_EXTERN_C |
673 | ||
682fc664 | 674 | #if defined(PERL_CORE) |
6f4183fe | 675 | |
87b9e160 | 676 | /* accessor functions for Perl "global" variables */ |
682fc664 GS |
677 | |
678 | /* these need to be mentioned here, or most linkers won't put them in | |
679 | the perl executable */ | |
680 | ||
681 | #ifndef PERL_NO_FORCE_LINK | |
682 | ||
683 | START_EXTERN_C | |
684 | ||
685 | #ifndef DOINIT | |
27da23d5 | 686 | EXTCONST void * const PL_force_link_funcs[]; |
682fc664 | 687 | #else |
27da23d5 | 688 | EXTCONST void * const PL_force_link_funcs[] = { |
682fc664 GS |
689 | #undef PERLVAR |
690 | #undef PERLVARA | |
691 | #undef PERLVARI | |
692 | #undef PERLVARIC | |
ea1f607c | 693 | #define PERLVAR(v,t) (void*)Perl_##v##_ptr, |
682fc664 GS |
694 | #define PERLVARA(v,n,t) PERLVAR(v,t) |
695 | #define PERLVARI(v,t,i) PERLVAR(v,t) | |
696 | #define PERLVARIC(v,t,i) PERLVAR(v,t) | |
697 | ||
3c0f78ca JH |
698 | /* In Tru64 (__DEC && __osf__) the cc option -std1 causes that one |
699 | * cannot cast between void pointers and function pointers without | |
700 | * info level warnings. The PL_force_link_funcs[] would cause a few | |
701 | * hundred of those warnings. In code one can circumnavigate this by using | |
702 | * unions that overlay the different pointers, but in declarations one | |
703 | * cannot use this trick. Therefore we just disable the warning here | |
704 | * for the duration of the PL_force_link_funcs[] declaration. */ | |
705 | ||
706 | #if defined(__DECC) && defined(__osf__) | |
707 | #pragma message save | |
708 | #pragma message disable (nonstandcast) | |
709 | #endif | |
710 | ||
682fc664 GS |
711 | #include "perlvars.h" |
712 | ||
3c0f78ca JH |
713 | #if defined(__DECC) && defined(__osf__) |
714 | #pragma message restore | |
715 | #endif | |
716 | ||
682fc664 GS |
717 | #undef PERLVAR |
718 | #undef PERLVARA | |
719 | #undef PERLVARI | |
720 | #undef PERLVARIC | |
721 | }; | |
722 | #endif /* DOINIT */ | |
723 | ||
acfe0abc | 724 | END_EXTERN_C |
682fc664 GS |
725 | |
726 | #endif /* PERL_NO_FORCE_LINK */ | |
727 | ||
728 | #else /* !PERL_CORE */ | |
51371543 GS |
729 | |
730 | EOT | |
731 | ||
adf34b4b | 732 | foreach $sym (@globvar) { |
5f9c6535 NC |
733 | print $capih |
734 | "#undef PL_$sym\n" . hide("PL_$sym", "(*Perl_G${sym}_ptr(NULL))"); | |
6f4183fe GS |
735 | } |
736 | ||
424a4936 | 737 | print $capih <<'EOT'; |
6f4183fe GS |
738 | |
739 | #endif /* !PERL_CORE */ | |
87b9e160 | 740 | #endif /* MULTIPLICITY && PERL_GLOBAL_STRUCT */ |
6f4183fe GS |
741 | |
742 | #endif /* __perlapi_h__ */ | |
6f4183fe | 743 | EOT |
ce716c52 NC |
744 | |
745 | read_only_bottom_close_and_rename($capih); | |
51371543 | 746 | |
5f8dc073 | 747 | my $capi = open_print_header('perlapi.c', <<'EOQ'); |
56fd1190 | 748 | * |
892eaa71 NC |
749 | * |
750 | * Up to the threshold of the door there mounted a flight of twenty-seven | |
751 | * broad stairs, hewn by some unknown art of the same black stone. This | |
752 | * was the only entrance to the tower; ... | |
753 | * | |
754 | * [p.577 of _The Lord of the Rings_, III/x: "The Voice of Saruman"] | |
755 | * | |
756 | */ | |
56fd1190 | 757 | EOQ |
892eaa71 | 758 | |
5f8dc073 | 759 | print $capi <<'EOT'; |
51371543 GS |
760 | #include "EXTERN.h" |
761 | #include "perl.h" | |
762 | #include "perlapi.h" | |
763 | ||
87b9e160 | 764 | #if defined (MULTIPLICITY) && defined (PERL_GLOBAL_STRUCT) |
51371543 | 765 | |
87b9e160 | 766 | /* accessor functions for Perl "global" variables */ |
51371543 GS |
767 | START_EXTERN_C |
768 | ||
51371543 | 769 | #undef PERLVARI |
87b9e160 | 770 | #define PERLVARI(v,t,i) PERLVAR(v,t) |
c5be433b GS |
771 | |
772 | #undef PERLVAR | |
773 | #undef PERLVARA | |
acfe0abc | 774 | #define PERLVAR(v,t) t* Perl_##v##_ptr(pTHX) \ |
96a5add6 | 775 | { dVAR; PERL_UNUSED_CONTEXT; return &(PL_##v); } |
acfe0abc | 776 | #define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX) \ |
96a5add6 | 777 | { dVAR; PERL_UNUSED_CONTEXT; return &(PL_##v); } |
34f7a5fe | 778 | #undef PERLVARIC |
27da23d5 JH |
779 | #define PERLVARIC(v,t,i) \ |
780 | const t* Perl_##v##_ptr(pTHX) \ | |
96a5add6 | 781 | { PERL_UNUSED_CONTEXT; return (const t *)&(PL_##v); } |
51371543 GS |
782 | #include "perlvars.h" |
783 | ||
784 | #undef PERLVAR | |
785 | #undef PERLVARA | |
786 | #undef PERLVARI | |
787 | #undef PERLVARIC | |
27da23d5 | 788 | |
acfe0abc | 789 | END_EXTERN_C |
6f4183fe | 790 | |
87b9e160 | 791 | #endif /* MULTIPLICITY && PERL_GLOBAL_STRUCT */ |
51371543 GS |
792 | EOT |
793 | ||
ce716c52 | 794 | read_only_bottom_close_and_rename($capi); |
acfe0abc | 795 | |
1b6737cc | 796 | # ex: set ts=8 sts=4 sw=4 noet: |