@@ -131,6 +131,7 @@ locale_is_ascii(const char *str)
131131static int
132132locale_decode_monetary (PyObject * dict , struct lconv * lc )
133133{
134+ #ifndef MS_WINDOWS
134135 int change_locale ;
135136 change_locale = (!locale_is_ascii (lc -> int_curr_symbol )
136137 || !locale_is_ascii (lc -> currency_symbol )
@@ -166,12 +167,18 @@ locale_decode_monetary(PyObject *dict, struct lconv *lc)
166167 }
167168 }
168169
170+ #define GET_LOCALE_STRING (ATTR ) PyUnicode_DecodeLocale(lc->ATTR, NULL)
171+ #else /* MS_WINDOWS */
172+ /* Use _W_* fields of Windows struct lconv */
173+ #define GET_LOCALE_STRING (ATTR ) PyUnicode_FromWideChar(lc->_W_ ## ATTR, -1)
174+ #endif /* MS_WINDOWS */
175+
169176 int res = -1 ;
170177
171178#define RESULT_STRING (ATTR ) \
172179 do { \
173180 PyObject *obj; \
174- obj = PyUnicode_DecodeLocale(lc-> ATTR, NULL ); \
181+ obj = GET_LOCALE_STRING( ATTR); \
175182 if (obj == NULL) { \
176183 goto done; \
177184 } \
@@ -187,14 +194,17 @@ locale_decode_monetary(PyObject *dict, struct lconv *lc)
187194 RESULT_STRING (mon_decimal_point );
188195 RESULT_STRING (mon_thousands_sep );
189196#undef RESULT_STRING
197+ #undef GET_LOCALE_STRING
190198
191199 res = 0 ;
192200
193201done :
202+ #ifndef MS_WINDOWS
194203 if (loc != NULL ) {
195204 setlocale (LC_CTYPE , oldloc );
196205 }
197206 PyMem_Free (oldloc );
207+ #endif
198208 return res ;
199209}
200210
@@ -230,9 +240,15 @@ PyLocale_localeconv(PyObject* self, PyObject *Py_UNUSED(ignored))
230240 Py_DECREF(obj); \
231241 } while (0)
232242
243+ #ifdef MS_WINDOWS
244+ /* Use _W_* fields of Windows struct lconv */
245+ #define GET_LOCALE_STRING (ATTR ) PyUnicode_FromWideChar(lc->_W_ ## ATTR, -1)
246+ #else
247+ #define GET_LOCALE_STRING (ATTR ) PyUnicode_DecodeLocale(lc->ATTR, NULL)
248+ #endif
233249#define RESULT_STRING (s )\
234250 do { \
235- x = PyUnicode_DecodeLocale(lc->s, NULL ); \
251+ x = GET_LOCALE_STRING(s ); \
236252 RESULT(#s, x); \
237253 } while (0)
238254
@@ -261,8 +277,10 @@ PyLocale_localeconv(PyObject* self, PyObject *Py_UNUSED(ignored))
261277 RESULT_INT (n_sign_posn );
262278
263279 /* Numeric information: LC_NUMERIC encoding */
264- PyObject * decimal_point , * thousands_sep ;
280+ PyObject * decimal_point = NULL , * thousands_sep = NULL ;
265281 if (_Py_GetLocaleconvNumeric (lc , & decimal_point , & thousands_sep ) < 0 ) {
282+ Py_XDECREF (decimal_point );
283+ Py_XDECREF (thousands_sep );
266284 goto failed ;
267285 }
268286
@@ -291,6 +309,7 @@ PyLocale_localeconv(PyObject* self, PyObject *Py_UNUSED(ignored))
291309#undef RESULT
292310#undef RESULT_STRING
293311#undef RESULT_INT
312+ #undef GET_LOCALE_STRING
294313}
295314
296315#if defined(HAVE_WCSCOLL )
0 commit comments