This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
locale.c: Move setting errno out of critical section
authorKarl Williamson <khw@cpan.org>
Fri, 7 Apr 2023 15:18:35 +0000 (09:18 -0600)
committerKarl Williamson <khw@cpan.org>
Sun, 16 Jul 2023 16:16:39 +0000 (10:16 -0600)
I doesn't matter much, but its better practice to make critical sections
as small as possible.

locale.c

index 1fe3a01..9f64119 100644 (file)
--- a/locale.c
+++ b/locale.c
@@ -3173,8 +3173,8 @@ Perl_mbtowc_(pTHX_ const wchar_t * pwc, const char * s, const Size_t len)
 
 #  else
 
-        MBTOWC_LOCK_;
         SETERRNO(0, 0);
+        MBTOWC_LOCK_;
         retval = mbtowc(NULL, NULL, 0);
         MBTOWC_UNLOCK_;
         return retval;
@@ -3192,8 +3192,8 @@ Perl_mbtowc_(pTHX_ const wchar_t * pwc, const char * s, const Size_t len)
 
     /* Locking prevents races, but locales can be switched out without locking,
      * so this isn't a cure all */
-    MBTOWC_LOCK_;
     SETERRNO(0, 0);
+    MBTOWC_LOCK_;
     retval = mbtowc((wchar_t *) pwc, s, len);
     MBTOWC_UNLOCK_;