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