Skip to content

Commit b0f0047

Browse files
committed
Issue #13889: Merge fix from 3.2.
2 parents 69c6352 + 18e3d81 commit b0f0047

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Include/pyport.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,30 @@ extern "C" {
557557
_Py_set_387controlword(old_387controlword)
558558
#endif
559559

560+
/* get and set x87 control word for VisualStudio/x86 */
561+
#if defined(_MSC_VER) && !defined(_WIN64) /* x87 not supported in 64-bit */
562+
#define HAVE_PY_SET_53BIT_PRECISION 1
563+
#define _Py_SET_53BIT_PRECISION_HEADER \
564+
unsigned int old_387controlword, new_387controlword, out_387controlword
565+
/* We use the __control87_2 function to set only the x87 control word.
566+
The SSE control word is unaffected. */
567+
#define _Py_SET_53BIT_PRECISION_START \
568+
do { \
569+
__control87_2(0, 0, &old_387controlword, NULL); \
570+
new_387controlword = \
571+
(old_387controlword & ~(_MCW_PC | _MCW_RC)) | (_PC_53 | _RC_NEAR); \
572+
if (new_387controlword != old_387controlword) \
573+
__control87_2(new_387controlword, _MCW_PC | _MCW_RC, \
574+
&out_387controlword, NULL); \
575+
} while (0)
576+
#define _Py_SET_53BIT_PRECISION_END \
577+
do { \
578+
if (new_387controlword != old_387controlword) \
579+
__control87_2(old_387controlword, _MCW_PC | _MCW_RC, \
580+
&out_387controlword, NULL); \
581+
} while (0)
582+
#endif
583+
560584
/* default definitions are empty */
561585
#ifndef HAVE_PY_SET_53BIT_PRECISION
562586
#define _Py_SET_53BIT_PRECISION_HEADER

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ What's New in Python 3.3.0 Alpha 3?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #13889: Check and (if necessary) set FPU control word before calling
14+
any of the dtoa.c string <-> float conversion functions, on MSVC builds of
15+
Python. This fixes issues when embedding Python in a Delphi app.
16+
1317
- Issue #2377: Make importlib the implementation of __import__().
1418

1519
- Issue #1559549: ImportError now has 'name' and 'path' attributes that are set

0 commit comments

Comments
 (0)