From: Fredrik Lundh Date: Thu, 29 Dec 2005 20:35:52 +0000 (+0000) Subject: SF#1391872 X-Git-Tag: v2.5a0~930 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=24f0fa97c5ed31397f20b094a166de325036e3c2;p=python SF#1391872 Floating point literals don't work in non-US locale in 2.5. Patch and new locale tests by Hye-Shik Chang. --- diff --git a/Lib/test/test__locale.py b/Lib/test/test__locale.py index ef4fe8d717..abdb87e068 100644 --- a/Lib/test/test__locale.py +++ b/Lib/test/test__locale.py @@ -97,6 +97,18 @@ class _LocaleTests(unittest.TestCase): loc, set_locale)) + def test_float_parsing(self): + # Bug #1391872: Test whether float parsing is okay on European + # locales. + for loc in candidate_locales: + try: + setlocale(LC_NUMERIC, loc) + except Error: + continue + self.assertEquals(int(eval('3.14') * 100), 314) + self.assertEquals(int(float('3.14') * 100), 314) + + def test_main(): run_unittest(_LocaleTests) diff --git a/Python/ast.c b/Python/ast.c index 93334dc18e..745cda28c0 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -2773,7 +2773,7 @@ parsenumber(const char *s) if (imflag) { c.real = 0.; PyFPE_START_PROTECT("atof", return 0) - c.imag = atof(s); + c.imag = PyOS_ascii_atof(s); PyFPE_END_PROTECT(c) return PyComplex_FromCComplex(c); } @@ -2781,7 +2781,7 @@ parsenumber(const char *s) #endif { PyFPE_START_PROTECT("atof", return 0) - dx = atof(s); + dx = PyOS_ascii_atof(s); PyFPE_END_PROTECT(dx) return PyFloat_FromDouble(dx); }