Permalink
Browse files

POSIX.xs: Prefer mbrlen() over mblen()

mbrlen is reentrant, so use it on threaded perls if available when
POSIX::mblen() is called.
  • Loading branch information...
khwilliamson committed Jan 11, 2018
1 parent 37a0630 commit dfdb9dbeb4d223527aa090c082f4bafc66bb8057
Showing with 17 additions and 0 deletions.
  1. +17 −0 ext/POSIX/POSIX.xs
View
@@ -3252,10 +3252,27 @@ write(fd, buffer, nbytes)
void
abort()
#ifdef I_WCHAR
# include <wchar.h>
#endif
int
mblen(s, n)
char * s
size_t n
PREINIT:
#if defined(USE_ITHREADS) && defined(HAS_MBRLEN)
mbstate_t ps;
#endif
CODE:
#if defined(USE_ITHREADS) && defined(HAS_MBRLEN)
PERL_UNUSED_RESULT(mbrlen(NULL, 0, &ps)); /* Initialize state */
RETVAL = mbrlen(s, n, &ps); /* Prefer reentrant version */
#else
RETVAL = mblen(s, n);
#endif
OUTPUT:
RETVAL
size_t
mbstowcs(s, pwcs, n)

0 comments on commit dfdb9db

Please sign in to comment.