Skip to content

Commit

Permalink
Mark certain mutex lock macros as private
Browse files Browse the repository at this point in the history
mbtowc() mblen(), and wctomb() should not be directly used by XS
writers; instead use the POSIX versions.  Don't encourage the direct use
by having public macros to aid in their use.
  • Loading branch information
khwilliamson committed May 5, 2021
1 parent 278b83f commit 4e3a599
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
16 changes: 8 additions & 8 deletions ext/POSIX/POSIX.xs
Expand Up @@ -3163,9 +3163,9 @@ mblen(s, n = ~0)
memzero(&PL_mbrlen_ps, sizeof(PL_mbrlen_ps));
RETVAL = 0;
#else
MBLEN_LOCK;
MBLEN_LOCK_;
RETVAL = mblen(NULL, 0);
MBLEN_UNLOCK;
MBLEN_UNLOCK_;
#endif
}
else { /* Not resetting state */
Expand All @@ -3185,9 +3185,9 @@ mblen(s, n = ~0)
#else
/* Locking prevents races, but locales can be switched out
* without locking, so this isn't a cure all */
MBLEN_LOCK;
MBLEN_LOCK_;
RETVAL = mblen(string, len);
MBLEN_UNLOCK;
MBLEN_UNLOCK_;
#endif
}
}
Expand Down Expand Up @@ -3250,9 +3250,9 @@ wctomb(s, wchar)
* But probably memzero would too */
RETVAL = wcrtomb(NULL, L'\0', &PL_wcrtomb_ps);
#else
WCTOMB_LOCK;
WCTOMB_LOCK_;
RETVAL = wctomb(NULL, L'\0');
WCTOMB_UNLOCK;
WCTOMB_UNLOCK_;
#endif
}
else { /* Not resetting state */
Expand All @@ -3262,9 +3262,9 @@ wctomb(s, wchar)
#else
/* Locking prevents races, but locales can be switched out without
* locking, so this isn't a cure all */
WCTOMB_LOCK;
WCTOMB_LOCK_;
RETVAL = wctomb(buffer, wchar);
WCTOMB_UNLOCK;
WCTOMB_UNLOCK_;
#endif
if (RETVAL >= 0) {
sv_setpvn_mg(s, buffer, RETVAL);
Expand Down
8 changes: 4 additions & 4 deletions locale.c
Expand Up @@ -2883,10 +2883,10 @@ Perl_mbtowc_(pTHX_ const wchar_t * pwc, const char * s, const Size_t len)

# else

MBTOWC_LOCK;
MBTOWC_LOCK_;
SETERRNO(0, 0);
retval = mbtowc(NULL, NULL, 0);
MBTOWC_UNLOCK;
MBTOWC_UNLOCK_;
return retval;

# endif
Expand All @@ -2902,10 +2902,10 @@ 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;
MBTOWC_LOCK_;
SETERRNO(0, 0);
retval = mbtowc((wchar_t *) pwc, s, len);
MBTOWC_UNLOCK;
MBTOWC_UNLOCK_;

# endif

Expand Down
20 changes: 10 additions & 10 deletions perl.h
Expand Up @@ -6676,14 +6676,14 @@ the plain locale pragma without a parameter (S<C<use locale>>) is in effect.
# define LOCALE_READ_UNLOCK NOOP
# define MBLEN_LOCK NOOP
# define MBLEN_UNLOCK NOOP
# define MBTOWC_LOCK NOOP
# define MBTOWC_UNLOCK NOOP
# define MBTOWC_LOCK_ NOOP
# define MBTOWC_UNLOCK_ NOOP
# define NL_LANGINFO_LOCK NOOP
# define NL_LANGINFO_UNLOCK NOOP
# define SETLOCALE_LOCK NOOP
# define SETLOCALE_UNLOCK NOOP
# define WCTOMB_LOCK NOOP
# define WCTOMB_UNLOCK NOOP
# define WCTOMB_LOCK_ NOOP
# define WCTOMB_UNLOCK_ NOOP
#else

/* Here, we will need critical sections in locale handling, because one or
Expand Down Expand Up @@ -6743,16 +6743,16 @@ the plain locale pragma without a parameter (S<C<use locale>>) is in effect.
# define NL_LANGINFO_UNLOCK LOCALE_UNLOCK_
# endif
# if defined(HAS_MBLEN) && ! defined(HAS_MBRLEN)
# define MBLEN_LOCK LOCALE_LOCK_
# define MBLEN_UNLOCK LOCALE_UNLOCK_
# define MBLEN_LOCK_ LOCALE_LOCK_
# define MBLEN_UNLOCK_ LOCALE_UNLOCK_
# endif
# if defined(HAS_MBTOWC) && ! defined(HAS_MBRTOWC)
# define MBTOWC_LOCK LOCALE_LOCK_
# define MBTOWC_UNLOCK LOCALE_UNLOCK_
# define MBTOWC_LOCK_ LOCALE_LOCK_
# define MBTOWC_UNLOCK_ LOCALE_UNLOCK_
# endif
# if defined(HAS_WCTOMB) && ! defined(HAS_WCRTOMB)
# define WCTOMB_LOCK LOCALE_LOCK_
# define WCTOMB_UNLOCK LOCALE_UNLOCK_
# define WCTOMB_LOCK_ LOCALE_LOCK_
# define WCTOMB_UNLOCK_ LOCALE_UNLOCK_
# endif
# if defined(USE_THREAD_SAFE_LOCALE)
/* On locale thread-safe systems, we don't need these workarounds */
Expand Down

0 comments on commit 4e3a599

Please sign in to comment.