Skip to content

Commit

Permalink
Add a phase_name() macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
FGasper committed Aug 12, 2021
1 parent 0992730 commit cd584da
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions embed.fnc
Expand Up @@ -3699,4 +3699,6 @@ XEop |STRLEN*|dup_warnings |NULLOK STRLEN* warnings
Amd |void |CopFILEGV_set |NN COP * c|NN GV * gv
#endif

Amd|char *const|phase_name|enum perl_phase

: ex: set ts=8 sts=4 sw=4 noet:
18 changes: 18 additions & 0 deletions perl.h
Expand Up @@ -5431,6 +5431,24 @@ EXTCONST char *const PL_phase_names[] = {
EXTCONST char *const PL_phase_names[];
#endif

/*
=for apidoc_section $utility
=for apidoc Amd|char *const|phase_name|enum perl_phase
Returns the given phase's name as a NUL-terminated string.
For example, to print a stack trace that includes the current
interpreter phase you might do:
const char* phase_name = phase_name(PL_phase);
mess("This is weird. (Perl phase: %s)", phase_name);
=cut
*/

#define phase_name(phase) (PL_phase_names[phase])

#ifndef PERL_CORE
/* Do not use this macro. It only exists for extensions that rely on PL_dirty
* instead of using the newer PL_phase, which provides everything PL_dirty
Expand Down
5 changes: 2 additions & 3 deletions pod/perldelta.pod
Expand Up @@ -346,9 +346,8 @@ well.

=over 4

=item *

XXX
=item * A new phase_name() interface provides access to the name
for each interpreter phase (i.e., PL_phase value).

=back

Expand Down

0 comments on commit cd584da

Please sign in to comment.