]> granicus.if.org Git - python/commitdiff
Issue #13889: On MSVC builds, set FPU control word at runtime for all string <->...
authorMark Dickinson <mdickinson@enthought.com>
Sun, 15 Apr 2012 14:19:06 +0000 (15:19 +0100)
committerMark Dickinson <mdickinson@enthought.com>
Sun, 15 Apr 2012 14:19:06 +0000 (15:19 +0100)
Include/pyport.h
Misc/NEWS

index 1abc14c5af894315f4df8087be964763e323f6f6..9bc5f1369046a0ddcb15393baa5db80f1768f8e0 100644 (file)
@@ -549,6 +549,30 @@ extern "C" {
         _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
index ce44ca801368aff2a028a4189f79d6a195a50ac9..85bea30b3ecf6b12145793cce739d867f9d1f031 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,10 @@ What's New in Python 2.7.4
 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 #14505: Fix file descriptor leak when deallocating file objects
   created with PyFile_FromString().