Skip to content

Commit

Permalink
locale.c: Use new mechanism to save/restore errno
Browse files Browse the repository at this point in the history
Instead of explicitly saving the errno around debugging statements, the
new more general mechanism is used.
  • Loading branch information
khwilliamson committed Apr 29, 2021
1 parent 36a4af3 commit bf31e1c
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions locale.c
Expand Up @@ -101,6 +101,9 @@ static int debug_initialization = 0;
# define DEBUG_INITIALIZATION_set(v)
#endif

#define DEBUG_PRE_STMTS dSAVE_ERRNO;
#define DEBUG_POST_STMTS RESTORE_ERRNO;

#include "EXTERN.h"
#define PERL_IN_LOCALE_C
#include "perl_langinfo.h"
Expand Down Expand Up @@ -1054,12 +1057,9 @@ S_emulate_setlocale_i(pTHX_
__FILE__, __LINE__, line, old_obj));

if (! old_obj) {
dSAVE_ERRNO;
DEBUG_L(PerlIO_printf(Perl_debug_log,
"%s:%d:(%d): emulate_setlocale_i switching to C"
" failed: %d\n", __FILE__, __LINE__, line, GET_ERRNO));
RESTORE_ERRNO;

return NULL;
}

Expand Down Expand Up @@ -1117,8 +1117,6 @@ S_emulate_setlocale_i(pTHX_
new_obj = newlocale(mask, new_locale, old_obj);

if (! new_obj) {
dSAVE_ERRNO;

DEBUG_L(PerlIO_printf(Perl_debug_log,
"%s:%d:(%d): emulate_setlocale_i creating new object"
" failed: %d\n", __FILE__, __LINE__, line, GET_ERRNO));
Expand All @@ -1128,7 +1126,7 @@ S_emulate_setlocale_i(pTHX_
"%s:%d: switching back failed: %d\n",
__FILE__, __LINE__, GET_ERRNO));
}
RESTORE_ERRNO;

return NULL;
}

Expand All @@ -1143,21 +1141,17 @@ S_emulate_setlocale_i(pTHX_

/* And switch into it */
if (! uselocale(new_obj)) {
dSAVE_ERRNO;

DEBUG_L(PerlIO_printf(Perl_debug_log,
"%s:%d:(%d): emulate_setlocale_i switching to new object"
" failed\n", __FILE__, __LINE__, line));

if (! uselocale(old_obj)) {

DEBUG_L(PerlIO_printf(Perl_debug_log,
"%s:%d: switching back failed: %d\n",
__FILE__, __LINE__, GET_ERRNO));

}

freelocale(new_obj);
RESTORE_ERRNO;
return NULL;
}
}
Expand Down Expand Up @@ -2481,10 +2475,8 @@ S_win32_setlocale(pTHX_ int category, const char* locale)
result = setlocale(category, locale);
#endif
DEBUG_L(STMT_START {
dSAVE_ERRNO;
PerlIO_printf(Perl_debug_log, "%s:%d: %s\n", __FILE__, __LINE__,
setlocale_debug_string_r(category, locale, result));
RESTORE_ERRNO;
} STMT_END);

if (! override_LC_ALL) {
Expand Down Expand Up @@ -2513,11 +2505,9 @@ S_win32_setlocale(pTHX_ int category, const char* locale)

result = setlocale(LC_ALL, NULL);
DEBUG_L(STMT_START {
dSAVE_ERRNO;
PerlIO_printf(Perl_debug_log, "%s:%d: %s\n",
__FILE__, __LINE__,
setlocale_debug_string_c(LC_ALL, NULL, result));
RESTORE_ERRNO;
} STMT_END);

return result;
Expand Down

0 comments on commit bf31e1c

Please sign in to comment.