Skip to content

Commit 7c2467c

Browse files
khwilliamsonLeont
authored andcommitted
vutil.c: Don't use perl macros that assume perl control
Because 'version' can be called from anywhere anytime, it can't assume that the macros that perl uses to toggle the locale for LC_NUMERIC actually will work. This commit removes that assumption.
1 parent 9e67fa1 commit 7c2467c

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

vutil/vutil.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@
77

88
#define VERSION_MAX 0x7FFFFFFF
99

10+
#ifndef POSIX_SETLOCALE_LOCK
11+
# ifdef gwLOCALE_LOCK
12+
# define POSIX_SETLOCALE_LOCK gwLOCALE_LOCK
13+
# define POSIX_SETLOCALE_UNLOCK gwLOCALE_UNLOCK
14+
# else
15+
# define POSIX_SETLOCALE_LOCK NOOP
16+
# define POSIX_SETLOCALE_UNLOCK NOOP
17+
# endif
18+
#endif
19+
#ifndef DISABLE_LC_NUMERIC_CHANGES
20+
# ifdef LOCK_LC_NUMERIC_STANDARD
21+
# define DISABLE_LC_NUMERIC_CHANGES() LOCK_LC_NUMERIC_STANDARD()
22+
# define REENABLE_LC_NUMERIC_CHANGES() UNLOCK_LC_NUMERIC_STANDARD()
23+
# else
24+
# define DISABLE_LC_NUMERIC_CHANGES() NOOP
25+
# define REENABLE_LC_NUMERIC_CHANGES() NOOP
26+
# endif
27+
#endif
28+
1029
/*
1130
=for apidoc prescan_version
1231
@@ -569,6 +588,9 @@ to force this SV to be interpreted as an "extended" version.
569588
#define GET_NUMERIC_VERSION(ver, sv, tbuf, buf, len) \
570589
STMT_START { \
571590
\
591+
/* Prevent callees from trying to change the locale */ \
592+
DISABLE_LC_NUMERIC_CHANGES(); \
593+
\
572594
/* We earlier created 'sv' for very large version numbers, to rely \
573595
* on the specialized algorithms SV code has built-in for such \
574596
* values */ \
@@ -582,6 +604,7 @@ to force this SV to be interpreted as an "extended" version.
582604
buf = tbuf; \
583605
} \
584606
\
607+
REENABLE_LC_NUMERIC_CHANGES(); \
585608
} STMT_END
586609

587610
SV *
@@ -659,7 +682,7 @@ Perl_upg_version(pTHX_ SV *ver, bool qv)
659682
/* In windows, or not threaded, or not thread-safe, if it isn't C,
660683
* set it to C. */
661684

662-
LC_NUMERIC_LOCK(0); /* Start critical section */
685+
POSIX_SETLOCALE_LOCK; /* Start critical section */
663686

664687
locale_name_on_entry = setlocale(LC_NUMERIC, NULL);
665688
if ( strNE(locale_name_on_entry, "C")
@@ -674,19 +697,14 @@ Perl_upg_version(pTHX_ SV *ver, bool qv)
674697
locale_name_on_entry = NULL;
675698
}
676699

677-
/* Prevent recursed calls from trying to change back */
678-
LOCK_LC_NUMERIC_STANDARD();
679-
680700
GET_NUMERIC_VERSION(ver, sv, tbuf, buf, len);
681701

682-
UNLOCK_LC_NUMERIC_STANDARD();
683-
684702
if (locale_name_on_entry) {
685703
setlocale(LC_NUMERIC, locale_name_on_entry);
686704
Safefree(locale_name_on_entry);
687705
}
688706

689-
LC_NUMERIC_UNLOCK; /* End critical section */
707+
POSIX_SETLOCALE_UNLOCK; /* End critical section */
690708
# endif
691709

692710
}

0 commit comments

Comments
 (0)