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 | |
6294c161 DM |
7 | # perlapi.c |
8 | # perlapi.h | |
9 | # proto.h | |
10 | # | |
11 | # from information stored in | |
12 | # | |
13 | # embed.fnc | |
14 | # intrpvar.h | |
15 | # perlvars.h | |
897d3989 | 16 | # regen/opcodes |
6294c161 | 17 | # |
6294c161 DM |
18 | # Accepts the standard regen_lib -q and -v args. |
19 | # | |
20 | # This script is normally invoked from regen.pl. | |
e50aee73 | 21 | |
916e4025 | 22 | require 5.004; # keep this compatible, an old perl is all we may have before |
954c1994 | 23 | # we build the new one |
5f05dabc | 24 | |
88e01c9d AL |
25 | use strict; |
26 | ||
36bb303b NC |
27 | BEGIN { |
28 | # Get function prototypes | |
3d7c117d MB |
29 | require './regen/regen_lib.pl'; |
30 | require './regen/embed_lib.pl'; | |
36bb303b NC |
31 | } |
32 | ||
916e4025 | 33 | my $unflagged_pointers; |
88e01c9d | 34 | |
cea2e8a9 | 35 | # |
346f75ff | 36 | # See database of global and static function prototypes in embed.fnc |
cea2e8a9 GS |
37 | # This is used to generate prototype headers under various configurations, |
38 | # export symbols lists for different platforms, and macros to provide an | |
39 | # implicit interpreter context argument. | |
40 | # | |
41 | ||
eeec122d KW |
42 | my $error_count = 0; |
43 | sub die_at_end ($) { # Keeps going for now, but makes sure the regen doesn't | |
44 | # succeed. | |
45 | warn shift; | |
46 | $error_count++; | |
47 | } | |
48 | ||
03b6588a KW |
49 | sub full_name ($$) { # Returns the function name with potentially the |
50 | # prefixes 'S_' or 'Perl_' | |
51 | my ($func, $flags) = @_; | |
52 | ||
5ff52e3c | 53 | return "Perl_$func" if $flags =~ /p/; |
4d2e4fbc | 54 | return "S_$func" if $flags =~ /[si]/; |
03b6588a KW |
55 | return $func; |
56 | } | |
57 | ||
5f8dc073 | 58 | sub open_print_header { |
56fd1190 | 59 | my ($file, $quote) = @_; |
4373e329 | 60 | |
5f8dc073 NC |
61 | return open_new($file, '>', |
62 | { file => $file, style => '*', by => 'regen/embed.pl', | |
63 | from => ['data in embed.fnc', 'regen/embed.pl', | |
64 | 'regen/opcodes', 'intrpvar.h', 'perlvars.h'], | |
65 | final => "\nEdit those files and run 'make regen_headers' to effect changes.\n", | |
66 | copyright => [1993 .. 2009], quote => $quote }); | |
67 | } | |
7f1be197 | 68 | |
5ccbf88e NC |
69 | my ($embed, $core, $ext, $api) = setup_embed(); |
70 | ||
cea2e8a9 | 71 | # generate proto.h |
9516dc40 | 72 | { |
5f8dc073 NC |
73 | my $pr = open_print_header("proto.h"); |
74 | print $pr "START_EXTERN_C\n"; | |
f8394530 | 75 | my $ret; |
9516dc40 | 76 | |
5ccbf88e | 77 | foreach (@$embed) { |
9516dc40 NC |
78 | if (@$_ == 1) { |
79 | print $pr "$_->[0]\n"; | |
80 | next; | |
81 | } | |
82 | ||
83 | my ($flags,$retval,$plain_func,@args) = @$_; | |
21553840 | 84 | if ($flags =~ / ( [^AabDdEfiMmnOoPpRrsUWXx] ) /x) { |
eeec122d | 85 | die_at_end "flag $1 is not legal (for function $plain_func)"; |
556343f1 | 86 | } |
4373e329 | 87 | my @nonnull; |
21553840 | 88 | my $has_depth = ( $flags =~ /W/ ); |
4373e329 | 89 | my $has_context = ( $flags !~ /n/ ); |
88e01c9d | 90 | my $never_returns = ( $flags =~ /r/ ); |
aa4ca557 | 91 | my $binarycompat = ( $flags =~ /b/ ); |
3f1866a8 | 92 | my $commented_out = ( ! $binarycompat && $flags =~ /m/ ); |
88e01c9d | 93 | my $is_malloc = ( $flags =~ /a/ ); |
b289a0bd | 94 | my $can_ignore = ( $flags !~ /R/ ) && ( $flags !~ /P/ ) && !$is_malloc; |
7918f24d NC |
95 | my @names_of_nn; |
96 | my $func; | |
88e01c9d | 97 | |
9f68b0f7 KW |
98 | if (! $can_ignore && $retval eq 'void') { |
99 | warn "It is nonsensical to require the return value of a void function ($plain_func) to be checked"; | |
100 | } | |
82728c33 | 101 | |
eeec122d | 102 | die_at_end "$plain_func: s flag is mutually exclusive from the i and p plags" |
4d2e4fbc | 103 | if $flags =~ /s/ && $flags =~ /[ip]/; |
88e01c9d | 104 | |
71556506 | 105 | if ($flags =~ /([si])/) { |
98c015b7 DD |
106 | my $type; |
107 | if ($never_returns) { | |
108 | $type = $1 eq 's' ? "PERL_STATIC_NO_RET" : "PERL_STATIC_INLINE_NO_RET"; | |
109 | } | |
110 | else { | |
111 | $type = $1 eq 's' ? "STATIC" : "PERL_STATIC_INLINE"; | |
112 | } | |
c707756e | 113 | $retval = "$type $retval"; |
2391bfdf | 114 | die_at_end "Don't declare static function '$plain_func' pure" if $flags =~ /P/; |
cea2e8a9 | 115 | } |
0cb96387 | 116 | else { |
718fae11 | 117 | if ($never_returns) { |
c707756e | 118 | $retval = "PERL_CALLCONV_NO_RET $retval"; |
718fae11 JD |
119 | } |
120 | else { | |
c707756e | 121 | $retval = "PERL_CALLCONV $retval"; |
718fae11 | 122 | } |
cea2e8a9 | 123 | } |
03b6588a | 124 | $func = full_name($plain_func, $flags); |
3f1866a8 KW |
125 | $ret = ""; |
126 | $ret .= "#ifndef NO_MATHOMS\n" if $binarycompat; | |
127 | $ret .= "$retval\t$func("; | |
4373e329 AL |
128 | if ( $has_context ) { |
129 | $ret .= @args ? "pTHX_ " : "pTHX"; | |
cea2e8a9 GS |
130 | } |
131 | if (@args) { | |
4373e329 AL |
132 | my $n; |
133 | for my $arg ( @args ) { | |
134 | ++$n; | |
7827dc65 AL |
135 | if ( $arg =~ /\*/ && $arg !~ /\b(NN|NULLOK)\b/ ) { |
136 | warn "$func: $arg needs NN or NULLOK\n"; | |
7827dc65 AL |
137 | ++$unflagged_pointers; |
138 | } | |
88e01c9d AL |
139 | my $nn = ( $arg =~ s/\s*\bNN\b\s+// ); |
140 | push( @nonnull, $n ) if $nn; | |
141 | ||
142 | my $nullok = ( $arg =~ s/\s*\bNULLOK\b\s+// ); # strip NULLOK with no effect | |
c48640ec AL |
143 | |
144 | # Make sure each arg has at least a type and a var name. | |
145 | # An arg of "int" is valid C, but want it to be "int foo". | |
146 | my $temp_arg = $arg; | |
147 | $temp_arg =~ s/\*//g; | |
148 | $temp_arg =~ s/\s*\bstruct\b\s*/ /g; | |
7918f24d NC |
149 | if ( ($temp_arg ne "...") |
150 | && ($temp_arg !~ /\w+\s+(\w+)(?:\[\d+\])?\s*$/) ) { | |
eeec122d | 151 | die_at_end "$func: $arg ($n) doesn't have a name\n"; |
c48640ec | 152 | } |
aa4ca557 | 153 | if (defined $1 && $nn && !($commented_out && !$binarycompat)) { |
7918f24d NC |
154 | push @names_of_nn, $1; |
155 | } | |
4373e329 | 156 | } |
cea2e8a9 GS |
157 | $ret .= join ", ", @args; |
158 | } | |
159 | else { | |
4373e329 | 160 | $ret .= "void" if !$has_context; |
cea2e8a9 | 161 | } |
21553840 | 162 | $ret .= " _pDEPTH" if $has_depth; |
cea2e8a9 | 163 | $ret .= ")"; |
f54cb97a AL |
164 | my @attrs; |
165 | if ( $flags =~ /r/ ) { | |
abb2c242 | 166 | push @attrs, "__attribute__noreturn__"; |
f54cb97a | 167 | } |
a5c26493 RGS |
168 | if ( $flags =~ /D/ ) { |
169 | push @attrs, "__attribute__deprecated__"; | |
170 | } | |
88e01c9d | 171 | if ( $is_malloc ) { |
abb2c242 | 172 | push @attrs, "__attribute__malloc__"; |
f54cb97a | 173 | } |
88e01c9d | 174 | if ( !$can_ignore ) { |
abb2c242 | 175 | push @attrs, "__attribute__warn_unused_result__"; |
f54cb97a AL |
176 | } |
177 | if ( $flags =~ /P/ ) { | |
abb2c242 | 178 | push @attrs, "__attribute__pure__"; |
f54cb97a | 179 | } |
1c846c1f | 180 | if( $flags =~ /f/ ) { |
cdfeb707 | 181 | my $prefix = $has_context ? 'pTHX_' : ''; |
5d37acd6 DM |
182 | my ($args, $pat); |
183 | if ($args[-1] eq '...') { | |
184 | $args = scalar @args; | |
185 | $pat = $args - 1; | |
186 | $args = $prefix . $args; | |
187 | } | |
188 | else { | |
189 | # don't check args, and guess which arg is the pattern | |
190 | # (one of 'fmt', 'pat', 'f'), | |
191 | $args = 0; | |
192 | my @fmts = grep $args[$_] =~ /\b(f|pat|fmt)$/, 0..$#args; | |
193 | if (@fmts != 1) { | |
194 | die "embed.pl: '$plain_func': can't determine pattern arg\n"; | |
195 | } | |
196 | $pat = $fmts[0] + 1; | |
197 | } | |
198 | my $macro = grep($_ == $pat, @nonnull) | |
cdfeb707 RB |
199 | ? '__attribute__format__' |
200 | : '__attribute__format__null_ok__'; | |
531b2663 DM |
201 | if ($plain_func =~ /strftime/) { |
202 | push @attrs, sprintf "%s(__strftime__,%s1,0)", $macro, $prefix; | |
203 | } | |
204 | else { | |
5d37acd6 DM |
205 | push @attrs, sprintf "%s(__printf__,%s%d,%s)", $macro, |
206 | $prefix, $pat, $args; | |
531b2663 | 207 | } |
894356b3 | 208 | } |
f54cb97a AL |
209 | if ( @attrs ) { |
210 | $ret .= "\n"; | |
211 | $ret .= join( "\n", map { "\t\t\t$_" } @attrs ); | |
4373e329 | 212 | } |
af3c7592 | 213 | $ret .= ";"; |
88e01c9d | 214 | $ret = "/* $ret */" if $commented_out; |
7918f24d NC |
215 | if (@names_of_nn) { |
216 | $ret .= "\n#define PERL_ARGS_ASSERT_\U$plain_func\E\t\\\n\t" | |
217 | . join '; ', map "assert($_)", @names_of_nn; | |
218 | } | |
3f1866a8 | 219 | $ret .= "\n#endif" if $binarycompat; |
f54cb97a | 220 | $ret .= @attrs ? "\n\n" : "\n"; |
9516dc40 NC |
221 | |
222 | print $pr $ret; | |
cea2e8a9 | 223 | } |
9516dc40 | 224 | |
897d3989 NC |
225 | print $pr <<'EOF'; |
226 | #ifdef PERL_CORE | |
227 | # include "pp_proto.h" | |
228 | #endif | |
229 | END_EXTERN_C | |
897d3989 | 230 | EOF |
9516dc40 | 231 | |
eeec122d | 232 | read_only_bottom_close_and_rename($pr) if ! $error_count; |
cea2e8a9 GS |
233 | } |
234 | ||
eeec122d | 235 | die_at_end "$unflagged_pointers pointer arguments to clean up\n" if $unflagged_pointers; |
cea2e8a9 | 236 | |
adf34b4b NC |
237 | sub readvars { |
238 | my ($file, $pre) = @_; | |
d4cce5f1 | 239 | local (*FILE, $_); |
adf34b4b | 240 | my %seen; |
d4cce5f1 NIS |
241 | open(FILE, "< $file") |
242 | or die "embed.pl: Can't open $file: $!\n"; | |
243 | while (<FILE>) { | |
244 | s/[ \t]*#.*//; # Delete comments. | |
115ff745 | 245 | if (/PERLVARA?I?C?\($pre,\s*(\w+)/) { |
eeec122d | 246 | die_at_end "duplicate symbol $1 while processing $file line $.\n" |
adf34b4b | 247 | if $seen{$1}++; |
d4cce5f1 NIS |
248 | } |
249 | } | |
250 | close(FILE); | |
adf34b4b | 251 | return sort keys %seen; |
d4cce5f1 NIS |
252 | } |
253 | ||
adf34b4b NC |
254 | my @intrp = readvars 'intrpvar.h','I'; |
255 | my @globvar = readvars 'perlvars.h','G'; | |
d4cce5f1 | 256 | |
125218eb NC |
257 | sub hide { |
258 | my ($from, $to, $indent) = @_; | |
259 | $indent = '' unless defined $indent; | |
260 | my $t = int(length("$indent$from") / 8); | |
261 | "#${indent}define $from" . "\t" x ($t < 3 ? 3 - $t : 1) . "$to\n"; | |
5f05dabc | 262 | } |
c6af7a1a | 263 | |
d4cce5f1 NIS |
264 | sub multon ($$$) { |
265 | my ($sym,$pre,$ptr) = @_; | |
3280af22 | 266 | hide("PL_$sym", "($ptr$pre$sym)"); |
5f05dabc | 267 | } |
54aff467 | 268 | |
5f8dc073 | 269 | my $em = open_print_header('embed.h'); |
e50aee73 | 270 | |
5f8dc073 | 271 | print $em <<'END'; |
e50aee73 AD |
272 | /* (Doing namespace management portably in C is really gross.) */ |
273 | ||
d51482e4 JH |
274 | /* By defining PERL_NO_SHORT_NAMES (not done by default) the short forms |
275 | * (like warn instead of Perl_warn) for the API are not defined. | |
276 | * Not defining the short forms is a good thing for cleaner embedding. */ | |
277 | ||
278 | #ifndef PERL_NO_SHORT_NAMES | |
820c3be9 | 279 | |
22c35a8c | 280 | /* Hide global symbols */ |
5f05dabc | 281 | |
e50aee73 AD |
282 | END |
283 | ||
cea2e8a9 GS |
284 | my @az = ('a'..'z'); |
285 | ||
e8a67806 NC |
286 | sub embed_h { |
287 | my ($guard, $funcs) = @_; | |
288 | print $em "$guard\n" if $guard; | |
289 | ||
2a4d8072 | 290 | my $lines; |
e8a67806 NC |
291 | foreach (@$funcs) { |
292 | if (@$_ == 1) { | |
293 | my $cond = $_->[0]; | |
294 | # Indent the conditionals if we are wrapped in an #if/#endif pair. | |
295 | $cond =~ s/#(.*)/# $1/ if $guard; | |
2a4d8072 | 296 | $lines .= "$cond\n"; |
e8a67806 NC |
297 | next; |
298 | } | |
299 | my $ret = ""; | |
300 | my ($flags,$retval,$func,@args) = @$_; | |
af3c7592 | 301 | unless ($flags =~ /[om]/) { |
cea2e8a9 | 302 | my $args = scalar @args; |
7a5a24f7 | 303 | if ($flags =~ /n/) { |
da8a4494 KW |
304 | my $full_name = full_name($func, $flags); |
305 | next if $full_name eq $func; # Don't output a no-op. | |
306 | $ret = hide($func, $full_name); | |
cea2e8a9 | 307 | } |
7a5a24f7 | 308 | elsif ($args and $args[$args-1] =~ /\.\.\./) { |
e64ca59f NC |
309 | if ($flags =~ /p/) { |
310 | # we're out of luck for varargs functions under CPP | |
311 | # So we can only do these macros for no implicit context: | |
312 | $ret = "#ifndef PERL_IMPLICIT_CONTEXT\n" | |
03b6588a | 313 | . hide($func, full_name($func, $flags)) . "#endif\n"; |
e64ca59f | 314 | } |
7a5a24f7 | 315 | } |
cea2e8a9 GS |
316 | else { |
317 | my $alist = join(",", @az[0..$args-1]); | |
318 | $ret = "#define $func($alist)"; | |
319 | my $t = int(length($ret) / 8); | |
320 | $ret .= "\t" x ($t < 4 ? 4 - $t : 1); | |
03b6588a | 321 | $ret .= full_name($func, $flags) . "(aTHX"; |
cea2e8a9 | 322 | $ret .= "_ " if $alist; |
21553840 YO |
323 | $ret .= $alist; |
324 | if ($flags =~ /W/) { | |
325 | if ($alist) { | |
326 | $ret .= " _aDEPTH"; | |
327 | } else { | |
328 | die "Can't use W without other args (currently)"; | |
329 | } | |
330 | } | |
331 | $ret .= ")\n"; | |
cea2e8a9 | 332 | } |
3f1866a8 | 333 | $ret = "#ifndef NO_MATHOMS\n$ret#endif\n" if $flags =~ /b/; |
cea2e8a9 | 334 | } |
2a4d8072 | 335 | $lines .= $ret; |
cea2e8a9 | 336 | } |
2a4d8072 NC |
337 | # Prune empty #if/#endif pairs. |
338 | while ($lines =~ s/#\s*if[^\n]+\n#\s*endif\n//) { | |
339 | } | |
b2e549c0 NC |
340 | # Merge adjacent blocks. |
341 | while ($lines =~ s/(#ifndef PERL_IMPLICIT_CONTEXT | |
342 | [^\n]+ | |
343 | )#endif | |
344 | #ifndef PERL_IMPLICIT_CONTEXT | |
345 | /$1/) { | |
346 | } | |
347 | ||
2a4d8072 | 348 | print $em $lines; |
e8a67806 | 349 | print $em "#endif\n" if $guard; |
da4ddda1 NC |
350 | } |
351 | ||
5ccbf88e NC |
352 | embed_h('', $api); |
353 | embed_h('#if defined(PERL_CORE) || defined(PERL_EXT)', $ext); | |
354 | embed_h('#ifdef PERL_CORE', $core); | |
e8a67806 | 355 | |
424a4936 | 356 | print $em <<'END'; |
e50aee73 | 357 | |
d51482e4 | 358 | #endif /* #ifndef PERL_NO_SHORT_NAMES */ |
35209cc8 | 359 | |
cea2e8a9 GS |
360 | /* Compatibility stubs. Compile extensions with -DPERL_NOCOMPAT to |
361 | disable them. | |
362 | */ | |
363 | ||
538feb02 | 364 | #if !defined(PERL_CORE) |
5bc28da9 | 365 | # define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,PTR2IV(ptr)) |
a0714e2c | 366 | # define sv_setptrref(rv,ptr) sv_setref_iv(rv,NULL,PTR2IV(ptr)) |
538feb02 | 367 | #endif |
cea2e8a9 | 368 | |
08e5223a | 369 | #if !defined(PERL_CORE) && !defined(PERL_NOCOMPAT) |
cea2e8a9 GS |
370 | |
371 | /* Compatibility for various misnamed functions. All functions | |
372 | in the API that begin with "perl_" (not "Perl_") take an explicit | |
373 | interpreter context pointer. | |
374 | The following are not like that, but since they had a "perl_" | |
375 | prefix in previous versions, we provide compatibility macros. | |
376 | */ | |
65cec589 | 377 | # define perl_atexit(a,b) call_atexit(a,b) |
7b53c8ee NC |
378 | END |
379 | ||
3a54c8e7 NC |
380 | foreach (@$embed) { |
381 | my ($flags, $retval, $func, @args) = @$_; | |
382 | next unless $func; | |
383 | next unless $flags =~ /O/; | |
7b53c8ee NC |
384 | |
385 | my $alist = join ",", @az[0..$#args]; | |
386 | my $ret = "# define perl_$func($alist)"; | |
387 | my $t = (length $ret) >> 3; | |
388 | $ret .= "\t" x ($t < 5 ? 5 - $t : 1); | |
3a54c8e7 NC |
389 | print $em "$ret$func($alist)\n"; |
390 | } | |
7b53c8ee | 391 | |
eacd26c2 NC |
392 | my @nocontext; |
393 | { | |
394 | my (%has_va, %has_nocontext); | |
5ccbf88e | 395 | foreach (@$embed) { |
eacd26c2 NC |
396 | next unless @$_ > 1; |
397 | ++$has_va{$_->[2]} if $_->[-1] =~ /\.\.\./; | |
398 | ++$has_nocontext{$1} if $_->[2] =~ /(.*)_nocontext/; | |
399 | } | |
400 | ||
401 | @nocontext = sort grep { | |
402 | $has_nocontext{$_} | |
403 | && !/printf/ # Not clear to me why these are skipped but they are. | |
404 | } keys %has_va; | |
405 | } | |
406 | ||
7b53c8ee | 407 | print $em <<'END'; |
cea2e8a9 GS |
408 | |
409 | /* varargs functions can't be handled with CPP macros. :-( | |
410 | This provides a set of compatibility functions that don't take | |
411 | an extra argument but grab the context pointer using the macro | |
412 | dTHX. | |
413 | */ | |
d51482e4 | 414 | #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_NO_SHORT_NAMES) |
125218eb NC |
415 | END |
416 | ||
eacd26c2 | 417 | foreach (@nocontext) { |
125218eb NC |
418 | print $em hide($_, "Perl_${_}_nocontext", " "); |
419 | } | |
420 | ||
421 | print $em <<'END'; | |
cea2e8a9 GS |
422 | #endif |
423 | ||
424 | #endif /* !defined(PERL_CORE) && !defined(PERL_NOCOMPAT) */ | |
425 | ||
426 | #if !defined(PERL_IMPLICIT_CONTEXT) | |
427 | /* undefined symbols, point them back at the usual ones */ | |
125218eb NC |
428 | END |
429 | ||
eacd26c2 | 430 | foreach (@nocontext) { |
125218eb NC |
431 | print $em hide("Perl_${_}_nocontext", "Perl_$_", " "); |
432 | } | |
433 | ||
434 | print $em <<'END'; | |
cea2e8a9 | 435 | #endif |
d4cce5f1 NIS |
436 | END |
437 | ||
eeec122d | 438 | read_only_bottom_close_and_rename($em) if ! $error_count; |
d4cce5f1 | 439 | |
5f8dc073 | 440 | $em = open_print_header('embedvar.h'); |
d4cce5f1 | 441 | |
5f8dc073 | 442 | print $em <<'END'; |
d4cce5f1 NIS |
443 | /* (Doing namespace management portably in C is really gross.) */ |
444 | ||
54aff467 | 445 | /* |
3db8f154 MB |
446 | The following combinations of MULTIPLICITY and PERL_IMPLICIT_CONTEXT |
447 | are supported: | |
54aff467 GS |
448 | 1) none |
449 | 2) MULTIPLICITY # supported for compatibility | |
450 | 3) MULTIPLICITY && PERL_IMPLICIT_CONTEXT | |
54aff467 GS |
451 | |
452 | All other combinations of these flags are errors. | |
453 | ||
3db8f154 | 454 | only #3 is supported directly, while #2 is a special |
54aff467 GS |
455 | case of #3 (supported by redefining vTHX appropriately). |
456 | */ | |
cea2e8a9 | 457 | |
54aff467 | 458 | #if defined(MULTIPLICITY) |
3db8f154 | 459 | /* cases 2 and 3 above */ |
cea2e8a9 | 460 | |
54aff467 GS |
461 | # if defined(PERL_IMPLICIT_CONTEXT) |
462 | # define vTHX aTHX | |
463 | # else | |
464 | # define vTHX PERL_GET_INTERP | |
465 | # endif | |
cea2e8a9 | 466 | |
e50aee73 AD |
467 | END |
468 | ||
adf34b4b NC |
469 | my $sym; |
470 | ||
471 | for $sym (@intrp) { | |
1a904fc8 FC |
472 | if ($sym eq 'sawampersand') { |
473 | print $em "#ifndef PL_sawampersand\n"; | |
474 | } | |
424a4936 | 475 | print $em multon($sym,'I','vTHX->'); |
1a904fc8 FC |
476 | if ($sym eq 'sawampersand') { |
477 | print $em "#endif\n"; | |
478 | } | |
d4cce5f1 NIS |
479 | } |
480 | ||
424a4936 | 481 | print $em <<'END'; |
d4cce5f1 | 482 | |
54aff467 | 483 | #endif /* MULTIPLICITY */ |
d4cce5f1 | 484 | |
54aff467 | 485 | #if defined(PERL_GLOBAL_STRUCT) |
22239a37 NIS |
486 | |
487 | END | |
488 | ||
adf34b4b | 489 | for $sym (@globvar) { |
0447859b | 490 | print $em "#ifdef OS2\n" if $sym eq 'sh_path'; |
483efd0a | 491 | print $em "#ifdef __VMS\n" if $sym eq 'perllib_sep'; |
424a4936 NC |
492 | print $em multon($sym, 'G','my_vars->'); |
493 | print $em multon("G$sym",'', 'my_vars->'); | |
0447859b | 494 | print $em "#endif\n" if $sym eq 'sh_path'; |
483efd0a | 495 | print $em "#endif\n" if $sym eq 'perllib_sep'; |
22239a37 NIS |
496 | } |
497 | ||
424a4936 | 498 | print $em <<'END'; |
22239a37 | 499 | |
22239a37 | 500 | #endif /* PERL_GLOBAL_STRUCT */ |
84fee439 NIS |
501 | END |
502 | ||
eeec122d | 503 | read_only_bottom_close_and_rename($em) if ! $error_count; |
c6af7a1a | 504 | |
5f8dc073 | 505 | my $capih = open_print_header('perlapi.h'); |
51371543 | 506 | |
5f8dc073 | 507 | print $capih <<'EOT'; |
51371543 | 508 | /* declare accessor functions for Perl variables */ |
6f4183fe GS |
509 | #ifndef __perlapi_h__ |
510 | #define __perlapi_h__ | |
51371543 | 511 | |
87b9e160 | 512 | #if defined (MULTIPLICITY) && defined (PERL_GLOBAL_STRUCT) |
c5be433b | 513 | |
51371543 GS |
514 | START_EXTERN_C |
515 | ||
516 | #undef PERLVAR | |
517 | #undef PERLVARA | |
518 | #undef PERLVARI | |
519 | #undef PERLVARIC | |
115ff745 NC |
520 | #define PERLVAR(p,v,t) EXTERN_C t* Perl_##p##v##_ptr(pTHX); |
521 | #define PERLVARA(p,v,n,t) typedef t PL_##v##_t[n]; \ | |
522 | EXTERN_C PL_##v##_t* Perl_##p##v##_ptr(pTHX); | |
523 | #define PERLVARI(p,v,t,i) PERLVAR(p,v,t) | |
524 | #define PERLVARIC(p,v,t,i) PERLVAR(p,v, const t) | |
51371543 | 525 | |
51371543 GS |
526 | #include "perlvars.h" |
527 | ||
528 | #undef PERLVAR | |
529 | #undef PERLVARA | |
530 | #undef PERLVARI | |
531 | #undef PERLVARIC | |
27da23d5 | 532 | |
51371543 GS |
533 | END_EXTERN_C |
534 | ||
682fc664 | 535 | #if defined(PERL_CORE) |
6f4183fe | 536 | |
87b9e160 | 537 | /* accessor functions for Perl "global" variables */ |
682fc664 GS |
538 | |
539 | /* these need to be mentioned here, or most linkers won't put them in | |
540 | the perl executable */ | |
541 | ||
542 | #ifndef PERL_NO_FORCE_LINK | |
543 | ||
544 | START_EXTERN_C | |
545 | ||
546 | #ifndef DOINIT | |
27da23d5 | 547 | EXTCONST void * const PL_force_link_funcs[]; |
682fc664 | 548 | #else |
27da23d5 | 549 | EXTCONST void * const PL_force_link_funcs[] = { |
682fc664 GS |
550 | #undef PERLVAR |
551 | #undef PERLVARA | |
552 | #undef PERLVARI | |
553 | #undef PERLVARIC | |
115ff745 NC |
554 | #define PERLVAR(p,v,t) (void*)Perl_##p##v##_ptr, |
555 | #define PERLVARA(p,v,n,t) PERLVAR(p,v,t) | |
556 | #define PERLVARI(p,v,t,i) PERLVAR(p,v,t) | |
557 | #define PERLVARIC(p,v,t,i) PERLVAR(p,v,t) | |
682fc664 | 558 | |
3c0f78ca JH |
559 | /* In Tru64 (__DEC && __osf__) the cc option -std1 causes that one |
560 | * cannot cast between void pointers and function pointers without | |
561 | * info level warnings. The PL_force_link_funcs[] would cause a few | |
562 | * hundred of those warnings. In code one can circumnavigate this by using | |
563 | * unions that overlay the different pointers, but in declarations one | |
564 | * cannot use this trick. Therefore we just disable the warning here | |
565 | * for the duration of the PL_force_link_funcs[] declaration. */ | |
566 | ||
567 | #if defined(__DECC) && defined(__osf__) | |
568 | #pragma message save | |
569 | #pragma message disable (nonstandcast) | |
570 | #endif | |
571 | ||
682fc664 GS |
572 | #include "perlvars.h" |
573 | ||
3c0f78ca JH |
574 | #if defined(__DECC) && defined(__osf__) |
575 | #pragma message restore | |
576 | #endif | |
577 | ||
682fc664 GS |
578 | #undef PERLVAR |
579 | #undef PERLVARA | |
580 | #undef PERLVARI | |
581 | #undef PERLVARIC | |
582 | }; | |
583 | #endif /* DOINIT */ | |
584 | ||
acfe0abc | 585 | END_EXTERN_C |
682fc664 GS |
586 | |
587 | #endif /* PERL_NO_FORCE_LINK */ | |
588 | ||
589 | #else /* !PERL_CORE */ | |
51371543 GS |
590 | |
591 | EOT | |
592 | ||
adf34b4b | 593 | foreach $sym (@globvar) { |
5f9c6535 NC |
594 | print $capih |
595 | "#undef PL_$sym\n" . hide("PL_$sym", "(*Perl_G${sym}_ptr(NULL))"); | |
6f4183fe GS |
596 | } |
597 | ||
424a4936 | 598 | print $capih <<'EOT'; |
6f4183fe GS |
599 | |
600 | #endif /* !PERL_CORE */ | |
87b9e160 | 601 | #endif /* MULTIPLICITY && PERL_GLOBAL_STRUCT */ |
6f4183fe GS |
602 | |
603 | #endif /* __perlapi_h__ */ | |
6f4183fe | 604 | EOT |
ce716c52 | 605 | |
eeec122d | 606 | read_only_bottom_close_and_rename($capih) if ! $error_count; |
51371543 | 607 | |
5f8dc073 | 608 | my $capi = open_print_header('perlapi.c', <<'EOQ'); |
56fd1190 | 609 | * |
892eaa71 NC |
610 | * |
611 | * Up to the threshold of the door there mounted a flight of twenty-seven | |
612 | * broad stairs, hewn by some unknown art of the same black stone. This | |
613 | * was the only entrance to the tower; ... | |
614 | * | |
615 | * [p.577 of _The Lord of the Rings_, III/x: "The Voice of Saruman"] | |
616 | * | |
617 | */ | |
56fd1190 | 618 | EOQ |
892eaa71 | 619 | |
5f8dc073 | 620 | print $capi <<'EOT'; |
51371543 GS |
621 | #include "EXTERN.h" |
622 | #include "perl.h" | |
623 | #include "perlapi.h" | |
624 | ||
87b9e160 | 625 | #if defined (MULTIPLICITY) && defined (PERL_GLOBAL_STRUCT) |
51371543 | 626 | |
87b9e160 | 627 | /* accessor functions for Perl "global" variables */ |
51371543 GS |
628 | START_EXTERN_C |
629 | ||
51371543 | 630 | #undef PERLVARI |
115ff745 | 631 | #define PERLVARI(p,v,t,i) PERLVAR(p,v,t) |
c5be433b GS |
632 | |
633 | #undef PERLVAR | |
634 | #undef PERLVARA | |
115ff745 | 635 | #define PERLVAR(p,v,t) t* Perl_##p##v##_ptr(pTHX) \ |
96a5add6 | 636 | { dVAR; PERL_UNUSED_CONTEXT; return &(PL_##v); } |
115ff745 | 637 | #define PERLVARA(p,v,n,t) PL_##v##_t* Perl_##p##v##_ptr(pTHX) \ |
96a5add6 | 638 | { dVAR; PERL_UNUSED_CONTEXT; return &(PL_##v); } |
34f7a5fe | 639 | #undef PERLVARIC |
115ff745 NC |
640 | #define PERLVARIC(p,v,t,i) \ |
641 | const t* Perl_##p##v##_ptr(pTHX) \ | |
96a5add6 | 642 | { PERL_UNUSED_CONTEXT; return (const t *)&(PL_##v); } |
51371543 GS |
643 | #include "perlvars.h" |
644 | ||
645 | #undef PERLVAR | |
646 | #undef PERLVARA | |
647 | #undef PERLVARI | |
648 | #undef PERLVARIC | |
27da23d5 | 649 | |
acfe0abc | 650 | END_EXTERN_C |
6f4183fe | 651 | |
87b9e160 | 652 | #endif /* MULTIPLICITY && PERL_GLOBAL_STRUCT */ |
51371543 GS |
653 | EOT |
654 | ||
eeec122d KW |
655 | read_only_bottom_close_and_rename($capi) if ! $error_count; |
656 | ||
657 | die "$error_count errors found" if $error_count; | |
acfe0abc | 658 | |
1b6737cc | 659 | # ex: set ts=8 sts=4 sw=4 noet: |