This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Correct code-like snippet in documentation
[perl5.git] / perlvars.h
1 /*    perlvars.h
2  *
3  *    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4  *    by Larry Wall and others
5  *
6  *    You may distribute under the terms of either the GNU General Public
7  *    License or the Artistic License, as specified in the README file.
8  *
9  */
10
11 /*
12 =head1 Global Variables
13 These variables are global to an entire process.  They are shared between
14 all interpreters and all threads in a process.  Any variables not documented
15 here may be changed or removed without notice, so don't use them!
16 If you feel you really do need to use an unlisted variable, first send email to
17 L<perl5-porters@perl.org|mailto:perl5-porters@perl.org>.  It may be that
18 someone there will point out a way to accomplish what you need without using an
19 internal variable.  But if not, you should get a go-ahead to document and then
20 use the variable.
21
22 =cut
23 */
24
25 /* Don't forget to re-run regen/embed.pl to propagate changes! */
26
27 /* This file describes the "global" variables used by perl
28  * This used to be in perl.h directly but we want to abstract out into
29  * distinct files which are per-thread, per-interpreter or really global,
30  * and how they're initialized.
31  *
32  * The 'G' prefix is only needed for vars that need appropriate #defines
33  * generated in embed*.h.  Such symbols are also used to generate
34  * the appropriate export list for win32. */
35
36 /* global state */
37 #if defined(USE_ITHREADS)
38 PERLVAR(G, op_mutex,    perl_mutex)     /* Mutex for op refcounting */
39 #endif
40 PERLVARI(G, curinterp,  PerlInterpreter *, NULL)
41                                         /* currently running interpreter
42                                          * (initial parent interpreter under
43                                          * useithreads) */
44 #if defined(USE_ITHREADS)
45 PERLVAR(G, thr_key,     perl_key)       /* key to retrieve per-thread struct */
46 #endif
47
48 /* XXX does anyone even use this? */
49 PERLVARI(G, do_undump,  bool,   FALSE)  /* -u or dump seen? */
50
51 #if defined(FAKE_PERSISTENT_SIGNAL_HANDLERS)||defined(FAKE_DEFAULT_SIGNAL_HANDLERS)
52 PERLVARI(G, sig_handlers_initted, int, 0)
53 #endif
54 #ifdef FAKE_PERSISTENT_SIGNAL_HANDLERS
55 PERLVARA(G, sig_ignoring, SIG_SIZE, int)
56                                         /* which signals we are ignoring */
57 #endif
58 #ifdef FAKE_DEFAULT_SIGNAL_HANDLERS
59 PERLVARA(G, sig_defaulting, SIG_SIZE, int)
60 #endif
61
62 /* XXX signals are process-wide anyway, so we
63  * ignore the implications of this for threading */
64 #ifndef HAS_SIGACTION
65 PERLVARI(G, sig_trapped, int,   0)
66 #endif
67
68 #ifndef PERL_MICRO
69 /* If Perl has to ignore SIGPFE, this is its saved state.
70  * See perl.h macros PERL_FPU_INIT and PERL_FPU_{PRE,POST}_EXEC. */
71 PERLVAR(G, sigfpe_saved, Sighandler_t)
72
73 /* these ptrs to functions are to avoid linkage problems; see
74  * perl-5.8.0-2193-g5c1546dc48
75  */
76 PERLVARI(G, csighandlerp,  Sighandler_t,  Perl_csighandler)
77 PERLVARI(G, csighandler1p, Sighandler1_t, Perl_csighandler1)
78 PERLVARI(G, csighandler3p, Sighandler3_t, Perl_csighandler3)
79 #endif
80
81 /* This is constant on most architectures, a global on OS/2 */
82 #ifdef OS2
83 PERLVARI(G, sh_path,    char *, SH_PATH) /* full path of shell */
84 #endif
85
86 #ifdef USE_PERLIO
87
88 #  if defined(USE_ITHREADS)
89 PERLVAR(G, perlio_mutex, perl_mutex)    /* Mutex for perlio fd refcounts */
90 #  endif
91
92 PERLVARI(G, perlio_fd_refcnt, int *, 0) /* Pointer to array of fd refcounts.  */
93 PERLVARI(G, perlio_fd_refcnt_size, int, 0) /* Size of the array */
94 PERLVARI(G, perlio_debug_fd, int, 0)    /* the fd to write perlio debug into, 0 means not set yet */
95 #endif
96
97 #ifdef HAS_MMAP
98 PERLVARI(G, mmap_page_size, IV, 0)
99 #endif
100
101 #if defined(USE_ITHREADS)
102 PERLVAR(G, hints_mutex, perl_mutex)    /* Mutex for refcounted he refcounting */
103 PERLVAR(G, env_mutex, perl_RnW1_mutex_t)      /* Mutex for accessing ENV */
104 PERLVAR(G, locale_mutex, perl_mutex)   /* Mutex related to locale handling */
105 #endif
106
107 #ifdef USE_POSIX_2008_LOCALE
108 PERLVARI(G, C_locale_obj, locale_t, NULL)
109 #endif
110
111 PERLVARI(G, watch_pvx,  char *, NULL)
112
113 /*
114 =for apidoc AmnU|Perl_check_t *|PL_check
115
116 Array, indexed by opcode, of functions that will be called for the "check"
117 phase of optree building during compilation of Perl code.  For most (but
118 not all) types of op, once the op has been initially built and populated
119 with child ops it will be filtered through the check function referenced
120 by the appropriate element of this array.  The new op is passed in as the
121 sole argument to the check function, and the check function returns the
122 completed op.  The check function may (as the name suggests) check the op
123 for validity and signal errors.  It may also initialise or modify parts of
124 the ops, or perform more radical surgery such as adding or removing child
125 ops, or even throw the op away and return a different op in its place.
126
127 This array of function pointers is a convenient place to hook into the
128 compilation process.  An XS module can put its own custom check function
129 in place of any of the standard ones, to influence the compilation of a
130 particular type of op.  However, a custom check function must never fully
131 replace a standard check function (or even a custom check function from
132 another module).  A module modifying checking must instead B<wrap> the
133 preexisting check function.  A custom check function must be selective
134 about when to apply its custom behaviour.  In the usual case where
135 it decides not to do anything special with an op, it must chain the
136 preexisting op function.  Check functions are thus linked in a chain,
137 with the core's base checker at the end.
138
139 For thread safety, modules should not write directly to this array.
140 Instead, use the function L</wrap_op_checker>.
141
142 =for apidoc Amn|enum perl_phase|PL_phase
143
144 A value that indicates the current Perl interpreter's phase. Possible values
145 include C<PERL_PHASE_CONSTRUCT>, C<PERL_PHASE_START>, C<PERL_PHASE_CHECK>,
146 C<PERL_PHASE_INIT>, C<PERL_PHASE_RUN>, C<PERL_PHASE_END>, and
147 C<PERL_PHASE_DESTRUCT>.
148
149 For example, the following determines whether the interpreter is in
150 global destruction:
151
152     if (PL_phase == PERL_PHASE_DESTRUCT) {
153         // we are in global destruction
154     }
155
156 C<PL_phase> was introduced in Perl 5.14; in prior perls you can use
157 C<PL_dirty> (boolean) to determine whether the interpreter is in global
158 destruction. (Use of C<PL_dirty> is discouraged since 5.14.)
159
160 =cut
161 */
162
163 #if defined(USE_ITHREADS)
164 PERLVAR(G, check_mutex, perl_mutex)     /* Mutex for PL_check */
165 #endif
166
167 /* allocate a unique index to every module that calls MY_CXT_INIT */
168
169 #ifdef MULTIPLICITY
170 # ifdef USE_ITHREADS
171 PERLVAR(G, my_ctx_mutex, perl_mutex)
172 PERLVARI(G, veto_switch_non_tTHX_context, int, FALSE)
173 # endif
174 PERLVARI(G, my_cxt_index, int,  0)
175 #endif
176
177 /* this is currently set without MUTEX protection, so keep it a type which
178  * can be set atomically (ie not a bit field) */
179 PERLVARI(G, veto_cleanup, int, FALSE)   /* exit without cleanup */
180
181 /*
182 =for apidoc AmnUx|Perl_keyword_plugin_t|PL_keyword_plugin
183
184 Function pointer, pointing at a function used to handle extended keywords.
185 The function should be declared as
186
187         int keyword_plugin_function(pTHX_
188                 char *keyword_ptr, STRLEN keyword_len,
189                 OP **op_ptr)
190
191 The function is called from the tokeniser, whenever a possible keyword
192 is seen.  C<keyword_ptr> points at the word in the parser's input
193 buffer, and C<keyword_len> gives its length; it is not null-terminated.
194 The function is expected to examine the word, and possibly other state
195 such as L<%^H|perlvar/%^H>, to decide whether it wants to handle it
196 as an extended keyword.  If it does not, the function should return
197 C<KEYWORD_PLUGIN_DECLINE>, and the normal parser process will continue.
198
199 If the function wants to handle the keyword, it first must
200 parse anything following the keyword that is part of the syntax
201 introduced by the keyword.  See L</Lexer interface> for details.
202
203 When a keyword is being handled, the plugin function must build
204 a tree of C<OP> structures, representing the code that was parsed.
205 The root of the tree must be stored in C<*op_ptr>.  The function then
206 returns a constant indicating the syntactic role of the construct that
207 it has parsed: C<KEYWORD_PLUGIN_STMT> if it is a complete statement, or
208 C<KEYWORD_PLUGIN_EXPR> if it is an expression.  Note that a statement
209 construct cannot be used inside an expression (except via C<do BLOCK>
210 and similar), and an expression is not a complete statement (it requires
211 at least a terminating semicolon).
212
213 When a keyword is handled, the plugin function may also have
214 (compile-time) side effects.  It may modify C<%^H>, define functions, and
215 so on.  Typically, if side effects are the main purpose of a handler,
216 it does not wish to generate any ops to be included in the normal
217 compilation.  In this case it is still required to supply an op tree,
218 but it suffices to generate a single null op.
219
220 That's how the C<*PL_keyword_plugin> function needs to behave overall.
221 Conventionally, however, one does not completely replace the existing
222 handler function.  Instead, take a copy of C<PL_keyword_plugin> before
223 assigning your own function pointer to it.  Your handler function should
224 look for keywords that it is interested in and handle those.  Where it
225 is not interested, it should call the saved plugin function, passing on
226 the arguments it received.  Thus C<PL_keyword_plugin> actually points
227 at a chain of handler functions, all of which have an opportunity to
228 handle keywords, and only the last function in the chain (built into
229 the Perl core) will normally return C<KEYWORD_PLUGIN_DECLINE>.
230
231 For thread safety, modules should not set this variable directly.
232 Instead, use the function L</wrap_keyword_plugin>.
233
234 =cut
235 */
236
237 #if defined(USE_ITHREADS)
238 PERLVAR(G, keyword_plugin_mutex, perl_mutex)   /* Mutex for PL_keyword_plugin and PL_infix_plugin */
239 #endif
240 PERLVARI(G, keyword_plugin, Perl_keyword_plugin_t, Perl_keyword_plugin_standard)
241
242 /*
243 =for apidoc AmnUx|Perl_infix_plugin_t|PL_infix_plugin
244
245 B<NOTE:> This API exists entirely for the purpose of making the CPAN module
246 C<XS::Parse::Infix> work. It is not expected that additional modules will make
247 use of it; rather, that they should use C<XS::Parse::Infix> to provide parsing
248 of new infix operators.
249
250 Function pointer, pointing at a function used to handle extended infix
251 operators. The function should be declared as
252
253         int infix_plugin_function(pTHX_
254                 char *opname, STRLEN oplen,
255                 struct Perl_custom_infix **infix_ptr)
256
257 The function is called from the tokenizer whenever a possible infix operator
258 is seen. C<opname> points to the operator name in the parser's input buffer,
259 and C<oplen> gives the I<maximum> number of bytes of it that should be
260 consumed; it is not null-terminated. The function is expected to examine the
261 operator name and possibly other state such as L<%^H|perlvar/%^H>, to
262 determine whether it wants to handle the operator name.
263
264 As compared to the single stage of C<PL_keyword_plugin>, parsing of additional
265 infix operators occurs in three separate stages. This is because of the more
266 complex interactions it has with the parser, to ensure that operator
267 precedence rules work correctly. These stages are co-ordinated by the use of
268 an additional information structure.
269
270 If the function wants to handle the infix operator, it must set the variable
271 pointed to by C<infix_ptr> to the address of a structure that provides this
272 additional information about the subsequent parsing stages. If it does not,
273 it should make a call to the next function in the chain.
274
275 This structure has the following definition:
276
277         struct Perl_custom_infix {
278             enum Perl_custom_infix_precedence prec;
279             void (*parse)(pTHX_ SV **opdata,
280                 struct Perl_custom_infix *);
281             OP *(*build_op)(pTHX_ SV **opdata, OP *lhs, OP *rhs,
282                 struct Perl_custom_infix *);
283         };
284
285 The function must then return an integer giving the number of bytes consumed
286 by the name of this operator. In the case of an operator whose name is
287 composed of identifier characters, this must be equal to C<oplen>. In the case
288 of an operator named by non-identifier characters, this is permitted to be
289 shorter than C<oplen>, and any additional characters after it will not be
290 claimed by the infix operator but instead will be consumed by the tokenizer
291 and parser as normal.
292
293 If the optional C<parse> function is provided, it is called immediately by the
294 parser to let the operator's definition consume any additional syntax from the
295 source code. This should I<not> be used for normal operand parsing, but it may
296 be useful when implementing things like parametric operators or meta-operators
297 that consume more syntax themselves. This function may use the variable
298 pointed to by C<opdata> to provide an SV containing additional data to be
299 passed into the C<build_op> function later on.
300
301 The information structure gives the operator precedence level in the C<prec>
302 field. This is used to tell the parser how much of the surrounding syntax
303 before and after should be considered as operands to the operator.
304
305 The tokenizer and parser will then continue to operate as normal until enough
306 additional input has been parsed to form both the left- and right-hand side
307 operands to the operator, according to the precedence level. At this point the
308 C<build_op> function is called, being passed the left- and right-hand operands
309 as optree fragments. It is expected to combine them into the resulting optree
310 fragment, which it should return.
311
312 After the C<build_op> function has returned, if the variable pointed to by
313 C<opdata> was set to a non-C<NULL> value, it will then be destroyed by calling
314 C<SvREFCNT_dec()>.
315
316 For thread safety, modules should not set this variable directly.
317 Instead, use the function L</wrap_infix_plugin>.
318
319 However, that all said, the introductory note above still applies. This
320 variable is provided in core perl only for the benefit of the
321 C<XS::Parse::Infix> module. That module acts as a central registry for infix
322 operators, automatically handling things like deparse support and
323 discovery/reflection, and these abilities only work because it knows all the
324 registered operators. Other modules should not use this interpreter variable
325 directly to implement them because then those central features would no longer
326 work properly.
327
328 Furthermore, it is likely that this (experimental) API will be replaced in a
329 future Perl version by a more complete API that fully implements the central
330 registry and other semantics currently provided by C<XS::Parse::Infix>, once
331 the module has had sufficient experimental testing time. This current
332 mechanism exists only as an interim measure to get to that stage.
333
334 =cut
335 */
336
337 PERLVARI(G, infix_plugin, Perl_infix_plugin_t, Perl_infix_plugin_standard)
338
339 PERLVARI(G, op_sequence, HV *, NULL)    /* dump.c */
340 PERLVARI(G, op_seq,     UV,     0)      /* dump.c */
341
342 #ifdef USE_ITHREADS
343 PERLVAR(G, dollarzero_mutex, perl_mutex) /* Modifying $0 */
344 #endif
345
346 /* Restricted hashes placeholder value.
347    In theory, the contents are never used, only the address.
348    In practice, &PL_sv_placeholder is returned by some APIs, and the calling
349    code is checking SvOK().  */
350
351 PERLVAR(G, sv_placeholder, SV)
352
353 #if defined(MYMALLOC) && defined(USE_ITHREADS)
354 PERLVAR(G, malloc_mutex, perl_mutex)    /* Mutex for malloc */
355 #endif
356
357 PERLVARI(G, hash_seed_set, bool, FALSE) /* perl.c */
358 PERLVARA(G, hash_seed_w, PERL_HASH_SEED_WORDS, PVT__PERL_HASH_WORD_TYPE) /* perl.c and hv.h */
359 #if defined(PERL_HASH_STATE_BYTES)
360 PERLVARA(G, hash_state_w, PERL_HASH_STATE_WORDS, PVT__PERL_HASH_WORD_TYPE) /* perl.c and hv.h */
361 #endif
362 #if defined(PERL_USE_SINGLE_CHAR_HASH_CACHE)
363 #define PERL_SINGLE_CHAR_HASH_CACHE_ELEMS ((1+256) * sizeof(U32))
364 PERLVARA(G, hash_chars, PERL_SINGLE_CHAR_HASH_CACHE_ELEMS, unsigned char) /* perl.c and hv.h */
365 #endif
366
367 /* The path separator can vary depending on whether we're running under DCL or
368  * a Unix shell.
369  */
370 #ifdef __VMS
371 PERLVAR(G, perllib_sep, char)
372 #endif
373
374 /* Definitions of user-defined \p{} properties, as the subs that define them
375  * are only called once */
376 PERLVARI(G, user_def_props,     HV *, NULL)
377
378 #if defined(USE_ITHREADS)
379 PERLVAR(G, user_def_props_aTHX, PerlInterpreter *)  /* aTHX that user_def_props
380                                                        was defined in */
381 PERLVAR(G, user_prop_mutex, perl_mutex)    /* Mutex for manipulating
382                                               PL_user_defined_properties */
383 #endif
384
385 /* these record the best way to perform certain IO operations while
386  * atomically setting FD_CLOEXEC. On the first call, a probe is done
387  * and the result recorded for use by subsequent calls.
388  * In theory these variables aren't thread-safe, but the worst that can
389  * happen is that two treads will both do an initial probe
390  */
391 PERLVARI(G, strategy_dup,        int, 0)        /* doio.c */
392 PERLVARI(G, strategy_dup2,       int, 0)        /* doio.c */
393 PERLVARI(G, strategy_open,       int, 0)        /* doio.c */
394 PERLVARI(G, strategy_open3,      int, 0)        /* doio.c */
395 PERLVARI(G, strategy_mkstemp,    int, 0)        /* doio.c */
396 PERLVARI(G, strategy_socket,     int, 0)        /* doio.c */
397 PERLVARI(G, strategy_accept,     int, 0)        /* doio.c */
398 PERLVARI(G, strategy_pipe,       int, 0)        /* doio.c */
399 PERLVARI(G, strategy_socketpair, int, 0)        /* doio.c */
400
401 PERLVARI(G, my_environ, char **, NULL)
402 PERLVARI(G, origenviron, char **, NULL)