Skip to content

Commit

Permalink
locale.c: Improve debugging for mem_collxfrm()
Browse files Browse the repository at this point in the history
This prints out more information, better organized.

It also moves up the info from -DLv to plain -DL
  • Loading branch information
khwilliamson committed May 5, 2021
1 parent f50e77e commit a54687a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 26 deletions.
7 changes: 4 additions & 3 deletions embed.fnc
Expand Up @@ -3318,9 +3318,10 @@ pTC |char * |Win_wstring_to_utf8_string|NULLOK const wchar_t * wstring
# endif
# ifdef DEBUGGING
S |void |print_collxfrm_input_and_return \
|NN const char * const s \
|NN const char * const e \
|NULLOK const STRLEN * const xlen \
|NN const char * s \
|NN const char * e \
|NULLOK const char * xbuf \
|const STRLEN xlen \
|const bool is_utf8
STR |char * |setlocale_debug_string_i|const unsigned cat_index \
|NULLOK const char* const locale \
Expand Down
2 changes: 1 addition & 1 deletion embed.h
Expand Up @@ -1605,7 +1605,7 @@
# if defined(PERL_IN_LOCALE_C)
#define print_bytes_for_locale(a,b,c) S_print_bytes_for_locale(aTHX_ a,b,c)
# if defined(USE_LOCALE)
#define print_collxfrm_input_and_return(a,b,c,d) S_print_collxfrm_input_and_return(aTHX_ a,b,c,d)
#define print_collxfrm_input_and_return(a,b,c,d,e) S_print_collxfrm_input_and_return(aTHX_ a,b,c,d,e)
#define setlocale_debug_string_i S_setlocale_debug_string_i
# endif
# endif
Expand Down
36 changes: 15 additions & 21 deletions locale.c
Expand Up @@ -5617,11 +5617,7 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string,

CLEANUP_STRXFRM;

DEBUG_Lv((print_collxfrm_input_and_return(s, s + len, xlen, utf8),
PerlIO_printf(Perl_debug_log, "Its xfrm is:"),
PerlIO_printf(Perl_debug_log, "%s\n",
_byte_dump_string((U8 *) xbuf + COLLXFRM_HDR_LEN,
*xlen, 1))));
DEBUG_L(print_collxfrm_input_and_return(s, s + len, xbuf, *xlen, utf8));

/* Free up unneeded space; retain enough for trailing NUL */
Renew(xbuf, COLLXFRM_HDR_LEN + *xlen + 1, char);
Expand All @@ -5635,7 +5631,7 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string,
bad:

CLEANUP_STRXFRM;
DEBUG_Lv(print_collxfrm_input_and_return(s, s + len, NULL, utf8));
DEBUG_L(print_collxfrm_input_and_return(s, s + len, NULL, 0, utf8));

Safefree(xbuf);
if (s != input_string) {
Expand All @@ -5650,27 +5646,25 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string,

STATIC void
S_print_collxfrm_input_and_return(pTHX_
const char * const s,
const char * const e,
const STRLEN * const xlen,
const char * s,
const char * e,
const char * xbuf,
const STRLEN xlen,
const bool is_utf8)
{

PERL_ARGS_ASSERT_PRINT_COLLXFRM_INPUT_AND_RETURN;

PerlIO_printf(Perl_debug_log, "mem_collxfrm_[%" UVuf "]: returning ",
(UV)PL_collation_ix);
if (xlen) {
PerlIO_printf(Perl_debug_log, "%zu", *xlen);
}
else {
PerlIO_printf(Perl_debug_log, "NULL");
}
PerlIO_printf(Perl_debug_log, " for locale '%s', string='",
PL_collation_name);
PerlIO_printf(Perl_debug_log,
"mem_collxfrm_[ix %" UVuf "] for locale '%s':\n",
(UV) PL_collation_ix, PL_collation_name);
PerlIO_printf(Perl_debug_log, " input=");
print_bytes_for_locale(s, e, is_utf8);

PerlIO_printf(Perl_debug_log, "'\n");
PerlIO_printf(Perl_debug_log, "\n return=%s\n return len=%zu\n",
((xbuf == NULL)
? "(null)"
: _byte_dump_string((U8 *) xbuf + COLLXFRM_HDR_LEN, xlen, 1)),
xlen);
}

# endif /* DEBUGGING */
Expand Down
2 changes: 1 addition & 1 deletion proto.h
Expand Up @@ -4620,7 +4620,7 @@ STATIC void S_print_bytes_for_locale(pTHX_ const char * const s, const char * co
#define PERL_ARGS_ASSERT_PRINT_BYTES_FOR_LOCALE \
assert(s); assert(e)
# if defined(USE_LOCALE)
STATIC void S_print_collxfrm_input_and_return(pTHX_ const char * const s, const char * const e, const STRLEN * const xlen, const bool is_utf8);
STATIC void S_print_collxfrm_input_and_return(pTHX_ const char * s, const char * e, const char * xbuf, const STRLEN xlen, const bool is_utf8);
#define PERL_ARGS_ASSERT_PRINT_COLLXFRM_INPUT_AND_RETURN \
assert(s); assert(e)
STATIC char * S_setlocale_debug_string_i(const unsigned cat_index, const char* const locale, const char* const retval)
Expand Down

0 comments on commit a54687a

Please sign in to comment.