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