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