Skip to content

Commit 21ee7d4

Browse files
committed
Document things in EXTERN.h, INTERN.h
1 parent e45cc9e commit 21ee7d4

File tree

3 files changed

+72
-11
lines changed

3 files changed

+72
-11
lines changed

EXTERN.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,8 @@
88
*
99
*/
1010

11-
/*
12-
* EXT: designates a global var which is defined in perl.h
13-
*
14-
* dEXT: designates a global var which is defined in another
15-
* file, so we can't count on finding it in perl.h
16-
* (this practice should be avoided).
17-
*/
11+
/* These are documented in INTERN.h */
12+
1813
#undef EXT
1914
#undef dEXT
2015
#undef EXTCONST

INTERN.h

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,32 @@
99
*/
1010

1111
/*
12-
* EXT designates a global var which is defined in perl.h
13-
* dEXT designates a global var which is defined in another
14-
* file, so we can't count on finding it in perl.h
15-
* (this practice should be avoided).
12+
13+
=for apidoc CmU||EXT
14+
=for apidoc_item EXTCONST
15+
=for apidoc_item dEXT
16+
=for apidoc_item dEXTCONST
17+
18+
These each designate a global variable. The C<CONST> forms indicate that it is
19+
constant.
20+
21+
The designation in F<EXTERN.h> indicates that it is defined in some other file.
22+
The designation in F<INTERN.h> indicates that it is defined in the including file.
23+
24+
Use C<EXT> and C<EXTCONST> for variables which will become defined by
25+
#including F<perl.h>.
26+
27+
Use C<dEXT> and C<dEXTCONST> for variables that we can't count on finding in
28+
F<perl.h>. (This practice should be avoided).
29+
30+
Examples:
31+
32+
EXT char PL_WARN_ALL INIT(0);
33+
EXTCONST U8 PL_revision INIT(PERL_REVISION);
34+
35+
=cut
1636
*/
37+
1738
#undef EXT
1839
#undef dEXT
1940
#undef EXTCONST
@@ -45,7 +66,28 @@
4566
# endif
4667
# endif
4768

69+
/*
70+
=for apidoc Cm||INIT|const_expr
71+
72+
Macro to initialize something, used like so:
73+
74+
EXTCONST char PL_memory_wrap[] INIT("panic: memory wrap");
75+
76+
It expands to nothing in F<EXTERN.h>.
77+
78+
=cut
79+
*/
4880
#undef INIT
4981
#define INIT(...) = __VA_ARGS__
5082

83+
/*
84+
=for apidoc C#||DOINIT
85+
86+
When #defined, it means the code should be defining and initializing things,
87+
instead of declaring them to be globals external to the file.
88+
89+
Defined in F<INTERN.h>, undefined in F<EXTERN.h>
90+
91+
=cut
92+
*/
5193
#define DOINIT

autodoc.pl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204
my $filters_scn = 'Source Filters';
205205
my $floating_scn = 'Floating point';
206206
my $genconfig_scn = 'General Configuration';
207+
my $global_definitions_scn = 'Declaration and Initialization of Globals';
207208
my $globals_scn = 'Global Variables';
208209
my $GV_scn = 'GV Handling and Stashes';
209210
my $hook_scn = 'Hook manipulation';
@@ -379,6 +380,28 @@
379380
=back
380381
EOT
381382
},
383+
$global_definitions_scn => {
384+
header => <<~'EOT',
385+
Global variables are defined and initialized in one place, but
386+
referred to from multiple files. They need to be declared and any
387+
initialization done in that one place, but declarations made for
388+
them in each file that may refer to them. Note that there is no
389+
harm in declaring a global and not using it.
390+
391+
Perl has a mechanism that allows both purposes to be served while
392+
minimizing code duplication. Most files will include the file
393+
F<EXTERN.h>; the few files that do the actual definitions instead
394+
include the file F<INTERN.h>. These header files #define the same
395+
macros, but with different definitions. In F<EXTERN.h>, the
396+
macros expand to declarations of the globals as external to the
397+
file. In F<INTERN.h> they actually cause the space to be
398+
allocated and possibly initialized.
399+
400+
This section documents these macros. F<perl.h> has many uses that
401+
can serve as paradigms for you.
402+
EOT
403+
may_be_empty_in_perlapi => 1,
404+
},
382405
$globals_scn => {},
383406
$GV_scn => {},
384407
$hook_scn => {},
@@ -481,6 +504,7 @@
481504
'gv.c' => $GV_scn,
482505
'gv.h' => $GV_scn,
483506
'hv.h' => $HV_scn,
507+
'INTERN.h' => $global_definitions_scn,
484508
'locale.c' => $locale_scn,
485509
'malloc.c' => $memory_scn,
486510
'numeric.c' => $numeric_scn,

0 commit comments

Comments
 (0)