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