[Python-checkins] cpython (3.2): Issue #13889: On MSVC builds, set FPU control word at runtime for all string
mark.dickinson
python-checkins at python.org
Sun Apr 15 16:14:43 CEST 2012
http://hg.python.org/cpython/rev/dfc9a98a5fef
changeset: 76320:dfc9a98a5fef
branch: 3.2
parent: 76317:1cce16c79de2
user: Mark Dickinson <mdickinson at enthought.com>
date: Sun Apr 15 15:10:56 2012 +0100
summary:
Issue #13889: On MSVC builds, set FPU control word at runtime for all string <-> float conversions. Patch by Samuel Iseli and Stefan Krah.
files:
Include/pyport.h | 24 ++++++++++++++++++++++++
Misc/NEWS | 4 ++++
2 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/Include/pyport.h b/Include/pyport.h
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -557,6 +557,30 @@
_Py_set_387controlword(old_387controlword)
#endif
+/* get and set x87 control word for VisualStudio/x86 */
+#if defined(_MSC_VER) && !defined(_WIN64) /* x87 not supported in 64-bit */
+#define HAVE_PY_SET_53BIT_PRECISION 1
+#define _Py_SET_53BIT_PRECISION_HEADER \
+ unsigned int old_387controlword, new_387controlword, out_387controlword
+/* We use the __control87_2 function to set only the x87 control word.
+ The SSE control word is unaffected. */
+#define _Py_SET_53BIT_PRECISION_START \
+ do { \
+ __control87_2(0, 0, &old_387controlword, NULL); \
+ new_387controlword = \
+ (old_387controlword & ~(_MCW_PC | _MCW_RC)) | (_PC_53 | _RC_NEAR); \
+ if (new_387controlword != old_387controlword) \
+ __control87_2(new_387controlword, _MCW_PC | _MCW_RC, \
+ &out_387controlword, NULL); \
+ } while (0)
+#define _Py_SET_53BIT_PRECISION_END \
+ do { \
+ if (new_387controlword != old_387controlword) \
+ __control87_2(old_387controlword, _MCW_PC | _MCW_RC, \
+ &out_387controlword, NULL); \
+ } while (0)
+#endif
+
/* default definitions are empty */
#ifndef HAVE_PY_SET_53BIT_PRECISION
#define _Py_SET_53BIT_PRECISION_HEADER
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@
Core and Builtins
-----------------
+- Issue #13889: Check and (if necessary) set FPU control word before calling
+ any of the dtoa.c string <-> float conversion functions, on MSVC builds of
+ Python. This fixes issues when embedding Python in a Delphi app.
+
- Issue #14474: Save and restore exception state in thread.start_new_thread()
while writing error message if the thread leaves a unhandled exception.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list