Skip to content

Commit 0614b1e

Browse files
committed
perl.h - rename PERL_DEB() to a more intuitive name
This patch renames PERL_DEB() to PERL_IF_DEBUGGING() and renames PERL_DEB2() to PERL_IF_DEBUGGING_ELSE(). It also documents them, along with PERL_DEBUG() and DEBUG_r() and friends. I have switched the existing PERL_DEB() or PERL_DEB2() calls to use the new names, but kept aliases for the old names just in case they are used out in the wild (eg CPAN). Thanks to mauke for the name suggestions!
1 parent 59755da commit 0614b1e

File tree

3 files changed

+92
-8
lines changed

3 files changed

+92
-8
lines changed

perl.h

+89-5
Original file line numberDiff line numberDiff line change
@@ -4922,8 +4922,8 @@ Gid_t getegid (void);
49224922
# define DEBUG_Lv_TEST DEBUG_Lv_TEST_
49234923
# define DEBUG_yv_TEST DEBUG_yv_TEST_
49244924

4925-
# define PERL_DEB(a) a
4926-
# define PERL_DEB2(a,b) a
4925+
# define PERL_IF_DEBUGGING(a) a
4926+
# define PERL_IF_DEBUGGING_ELSE(a,b) a
49274927
# define PERL_DEBUG(a) if (PL_debug) a
49284928
# define DEBUG_p(a) if (DEBUG_p_TEST) a
49294929
# define DEBUG_s(a) if (DEBUG_s_TEST) a
@@ -5051,8 +5051,8 @@ Gid_t getegid (void);
50515051
# define DEBUG_Lv_TEST (0)
50525052
# define DEBUG_yv_TEST (0)
50535053

5054-
# define PERL_DEB(a)
5055-
# define PERL_DEB2(a,b) b
5054+
# define PERL_IF_DEBUGGING(a)
5055+
# define PERL_IF_DEBUGGING_ELSE(a,b) b
50565056
# define PERL_DEBUG(a)
50575057
# define DEBUG_p(a)
50585058
# define DEBUG_s(a)
@@ -5088,6 +5088,90 @@ Gid_t getegid (void);
50885088
#endif /* DEBUGGING */
50895089

50905090

5091+
/*
5092+
=for apidoc_section $debugging
5093+
=for apidoc mu||PERL_IF_DEBUGGING|code
5094+
5095+
A macro which is executed only when DEBUGGING is enabled.
5096+
Functionally identical to
5097+
5098+
#ifdef DEBUGGING
5099+
code
5100+
#endif
5101+
5102+
but prettier. This macro is useful for declaring variables that are
5103+
only used on DEBUGGING builds. Note that what this macro does is
5104+
determined at compile time, if you want a run time equivalent then
5105+
use C<PERL_DEBUG()> instead.
5106+
5107+
=for apidoc mu||PERL_IF_DEBUGGING_ELSE|code_debugging|code_nondebugging
5108+
5109+
A macro way of expressing different code that should be compiled
5110+
depending on whether DEBUGGING is enabled. Functionally identical
5111+
to
5112+
5113+
#ifdef DEBUGGING
5114+
code_debugging
5115+
#else
5116+
code_nondebugging
5117+
#end
5118+
5119+
but prettier.
5120+
5121+
=for apidoc mu||PERL_DEBUG|code
5122+
A macro way of expressing code that will only be executed when the run
5123+
time internal variable PL_debug is non-zero.
5124+
5125+
=for apidoc mu||DEBUG_A|code
5126+
=for apidoc_item mu||DEBUG_B|code
5127+
=for apidoc_item mu||DEBUG_C|code
5128+
=for apidoc_item mu||DEBUG_c|code
5129+
=for apidoc_item mu||DEBUG_D|code
5130+
=for apidoc_item mu||DEBUG_f|code
5131+
=for apidoc_item mu||DEBUG_i|code
5132+
=for apidoc_item mu||DEBUG_L|code
5133+
=for apidoc_item mu||DEBUG_l|code
5134+
=for apidoc_item mu||DEBUG_Lv|code
5135+
=for apidoc_item mu||DEBUG_m|code
5136+
=for apidoc_item mu||DEBUG_o|code
5137+
=for apidoc_item mu||DEBUG_P|code
5138+
=for apidoc_item mu||DEBUG_p|code
5139+
=for apidoc_item mu||DEBUG_Pv|code
5140+
=for apidoc_item mu||DEBUG_q|code
5141+
=for apidoc_item mu||DEBUG_R|code
5142+
=for apidoc_item mu||DEBUG_r|code
5143+
=for apidoc_item mu||DEBUG_S|code
5144+
=for apidoc_item mu||DEBUG_s|code
5145+
=for apidoc_item mu||DEBUG_T|code
5146+
=for apidoc_item mu||DEBUG_t|code
5147+
=for apidoc_item mu||DEBUG_U|code
5148+
=for apidoc_item mu||DEBUG_u|code
5149+
=for apidoc_item mu||DEBUG_Uv|code
5150+
=for apidoc_item mu||DEBUG_V|code
5151+
=for apidoc_item mu||DEBUG_X|code
5152+
=for apidoc_item mu||DEBUG_x|code
5153+
=for apidoc_item mu||DEBUG_Xv|code
5154+
=for apidoc_item mu||DEBUG_y|code
5155+
=for apidoc_item mu||DEBUG_yv|code
5156+
5157+
These are debugging macros similar to PERL_DEBUG() but which test
5158+
which flags in PL_debug have been set. Each letter corresponds to
5159+
a mode exposed by the -D option to perl. These macros only execute
5160+
when DEBUGGING is enabled, and when the appropriate debug mode
5161+
has been enabled on the command line.
5162+
5163+
See L<perlrun> for details on the meaning of the different
5164+
switches.
5165+
5166+
=cut
5167+
*/
5168+
5169+
/* these are for backwards compatibility, just in case anything out
5170+
* in the wild (eg CPAN) is using them. */
5171+
#define PERL_DEB(a) PERL_IF_DEBUGGING(a)
5172+
#define PERL_DEB2(a,b) PERL_IF_DEBUGGING_ELSE(a,b)
5173+
5174+
50915175
#define DEBUG_SCOPE(where) \
50925176
DEBUG_l( \
50935177
Perl_deb(aTHX_ "%s scope %ld (savestack=%ld) at %s:%d\n", \
@@ -5097,7 +5181,7 @@ Gid_t getegid (void);
50975181
/* Keep the old croak based assert for those who want it, and as a fallback if
50985182
the platform is so heretically non-ANSI that it can't assert. */
50995183

5100-
#define Perl_assert(what) PERL_DEB2( \
5184+
#define Perl_assert(what) PERL_IF_DEBUGGING_ELSE( \
51015185
((what) ? ((void) 0) : \
51025186
(Perl_croak_nocontext("Assertion %s failed: file \"" __FILE__ \
51035187
"\", line %d", STRINGIFY(what), __LINE__), \

util.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ Perl_safesysrealloc(Malloc_t where,MEM_SIZE size)
257257
}
258258
else {
259259
dSAVE_ERRNO;
260-
PERL_DEB(UV was_where = PTR2UV(where)); /* used in diags below */
260+
PERL_IF_DEBUGGING(UV was_where = PTR2UV(where)); /* used in diags below */
261261
#ifdef USE_MDH
262262
where = (Malloc_t)((char*)where-PERL_MEMORY_DEBUG_HEADER_SIZE);
263263
if (size + PERL_MEMORY_DEBUG_HEADER_SIZE < size)

win32/win32.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -3493,7 +3493,7 @@ win32_tmpfd_mode(int mode)
34933493
if (fh != INVALID_HANDLE_VALUE) {
34943494
int fd = win32_open_osfhandle((intptr_t)fh, mode);
34953495
if (fd >= 0) {
3496-
PERL_DEB(dTHX;)
3496+
PERL_IF_DEBUGGING(dTHX;)
34973497
DEBUG_p(PerlIO_printf(Perl_debug_log,
34983498
"Created tmpfile=%s\n",filename));
34993499
return fd;
@@ -4194,7 +4194,7 @@ win32_chmod(const char *path, int mode)
41944194
static char *
41954195
create_command_line(char *cname, STRLEN clen, const char * const *args)
41964196
{
4197-
PERL_DEB(dTHX;)
4197+
PERL_IF_DEBUGGING(dTHX;)
41984198
int index;
41994199
char *cmd, *ptr;
42004200
const char *arg;

0 commit comments

Comments
 (0)