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