diff options
author | Karl Williamson <khw@cpan.org> | 2017-12-31 07:53:32 -0700 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2018-01-01 12:37:49 -0700 |
commit | b09aaf4024bc971d2edc73f59eabad0ed6b5f85c (patch) | |
tree | bed9905b918b4c8ac35b3bf97d5ed12c67df3ed2 | |
parent | 6a6f44b87d17378de192eee3aaef77977237dad6 (diff) | |
download | perl-b09aaf4024bc971d2edc73f59eabad0ed6b5f85c.tar.gz |
locale.c: Improve debugging output
This extracts some debugging output code into a function (so that it can
be called from more than one place) and add some detail to the output.
-rw-r--r-- | embed.fnc | 1 | ||||
-rw-r--r-- | embed.h | 1 | ||||
-rw-r--r-- | locale.c | 71 | ||||
-rw-r--r-- | proto.h | 1 |
4 files changed, 48 insertions, 26 deletions
@@ -2758,6 +2758,7 @@ s |bool |isa_lookup |NN HV *stash|NN const char * const name \ #endif #if defined(PERL_IN_LOCALE_C) +sn |const char*|category_name |const int category # ifdef HAS_NL_LANGINFO sn |const char*|my_nl_langinfo|const nl_item item|bool toggle # else @@ -1620,6 +1620,7 @@ #define unshare_hek_or_pvn(a,b,c,d) S_unshare_hek_or_pvn(aTHX_ a,b,c,d) # endif # if defined(PERL_IN_LOCALE_C) +#define category_name S_category_name #define save_to_buffer S_save_to_buffer # if defined(USE_LOCALE) #define new_collate(a) S_new_collate(aTHX_ a) @@ -201,6 +201,50 @@ const char * category_names[] = { * checked for at compile time by using the #define LC_ALL_INDEX which is only * defined if we do have LC_ALL. */ +STATIC const char * +S_category_name(const int category) +{ + unsigned int i; + +#ifdef LC_ALL + + if (category == LC_ALL) { + return "LC_ALL"; + } + +#endif + + for (i = 0; i < NOMINAL_LC_ALL_INDEX; i++) { + if (category == categories[i]) { + return category_names[i]; + } + } + + { + const char suffix[] = " (unknown)"; + int temp = category; + Size_t length = sizeof(suffix) + 1; + char * unknown; + dTHX; + + if (temp < 0) { + length++; + temp = - temp; + } + + /* Calculate the number of digits */ + while (temp >= 10) { + temp /= 10; + length++; + } + + Newx(unknown, length, char); + my_snprintf(unknown, length, "%d%s", category, suffix); + SAVEFREEPV(unknown); + return unknown; + } +} + /* Now create LC_foo_INDEX #defines for just those categories on this system */ # ifdef USE_LOCALE_NUMERIC # define LC_NUMERIC_INDEX 0 @@ -3614,34 +3658,9 @@ S_setlocale_debug_string(const int category, /* category number, static char ret[128] = "If you can read this, thank your buggy C" " library strlcpy(), and change your hints file" " to undef it"; - unsigned int i; - -# ifdef LC_ALL - - const unsigned int highest_index = LC_ALL_INDEX; - -# else - - const unsigned int highest_index = NOMINAL_LC_ALL_INDEX - 1; - -#endif - my_strlcpy(ret, "setlocale(", sizeof(ret)); - - /* Look for category in our list, and if found, add its name */ - for (i = 0; i <= highest_index; i++) { - if (category == categories[i]) { - my_strlcat(ret, category_names[i], sizeof(ret)); - goto found_category; - } - } - - /* Unknown category to us */ - my_snprintf(ret, sizeof(ret), "%s? %d", ret, category); - - found_category: - + my_strlcat(ret, category_name(category), sizeof(ret)); my_strlcat(ret, ", ", sizeof(ret)); if (locale) { @@ -4679,6 +4679,7 @@ PERL_CALLCONV SV* Perl_hfree_next_entry(pTHX_ HV *hv, STRLEN *indexp); assert(hv); assert(indexp) #endif #if defined(PERL_IN_LOCALE_C) +STATIC const char* S_category_name(const int category); #ifndef PERL_NO_INLINE_FUNCTIONS PERL_STATIC_INLINE const char * S_save_to_buffer(const char * string, char **buf, Size_t *buf_size, const Size_t offset); #define PERL_ARGS_ASSERT_SAVE_TO_BUFFER \ |