From f028d9f71a5367df6062388166ebddfa2fe4e5e1 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Sat, 10 Sep 2016 11:52:18 -0700 Subject: Issue #27932: Backs out change --- Lib/platform.py | 62 +++++++++++++++++++++++++++------------------------------ Misc/NEWS | 2 -- 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/Lib/platform.py b/Lib/platform.py index e219326..e7eaa32 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -498,61 +498,57 @@ _WIN32_SERVER_RELEASES = { (6, None): "post2012ServerR2", } -if sys.platform == 'win32': - import ctypes - import ctypes.wintypes +def _get_real_winver(maj, min, build): + if maj < 6 or (maj == 6 and min < 2): + return maj, min, build + + from ctypes import (c_buffer, POINTER, byref, create_unicode_buffer, + Structure, WinDLL) + from ctypes.wintypes import DWORD, HANDLE - class VS_FIXEDFILEINFO(ctypes.Structure): + class VS_FIXEDFILEINFO(Structure): _fields_ = [ - ("dwSignature", ctypes.wintypes.DWORD), - ("dwStrucVersion", ctypes.wintypes.DWORD), - ("dwFileVersionMS", ctypes.wintypes.DWORD), - ("dwFileVersionLS", ctypes.wintypes.DWORD), - ("dwProductVersionMS", ctypes.wintypes.DWORD), - ("dwProductVersionLS", ctypes.wintypes.DWORD), - ("dwFileFlagsMask", ctypes.wintypes.DWORD), - ("dwFileFlags", ctypes.wintypes.DWORD), - ("dwFileOS", ctypes.wintypes.DWORD), - ("dwFileType", ctypes.wintypes.DWORD), - ("dwFileSubtype", ctypes.wintypes.DWORD), - ("dwFileDateMS", ctypes.wintypes.DWORD), - ("dwFileDateLS", ctypes.wintypes.DWORD), + ("dwSignature", DWORD), + ("dwStrucVersion", DWORD), + ("dwFileVersionMS", DWORD), + ("dwFileVersionLS", DWORD), + ("dwProductVersionMS", DWORD), + ("dwProductVersionLS", DWORD), + ("dwFileFlagsMask", DWORD), + ("dwFileFlags", DWORD), + ("dwFileOS", DWORD), + ("dwFileType", DWORD), + ("dwFileSubtype", DWORD), + ("dwFileDateMS", DWORD), + ("dwFileDateLS", DWORD), ] - P_VS_FIXEDFILEINFO = ctypes.POINTER(VS_FIXEDFILEINFO) - -def _get_real_winver(maj, min, build): - if maj < 6 or (maj == 6 and min < 2): - return maj, min, build + kernel32 = WinDLL('kernel32') + version = WinDLL('version') - kernel32 = ctypes.WinDLL('kernel32') # We will immediately double the length up to MAX_PATH, but the # path may be longer, so we retry until the returned string is # shorter than our buffer. name_len = actual_len = 130 while actual_len == name_len: name_len *= 2 - name = ctypes.create_unicode_buffer(name_len) - actual_len = kernel32.GetModuleFileNameW( - ctypes.wintypes.HANDLE(kernel32._handle), - name, len(name) - ) + name = create_unicode_buffer(name_len) + actual_len = kernel32.GetModuleFileNameW(HANDLE(kernel32._handle), + name, len(name)) if not actual_len: return maj, min, build - version = ctypes.WinDLL('version') size = version.GetFileVersionInfoSizeW(name, None) if not size: return maj, min, build - ver_block = ctypes.c_buffer(size) + ver_block = c_buffer(size) if (not version.GetFileVersionInfoW(name, None, size, ver_block) or not ver_block): return maj, min, build - pvi = P_VS_FIXEDFILEINFO() - if not version.VerQueryValueW(ver_block, "", - ctypes.byref(pvi), ctypes.byref(ctypes.wintypes.DWORD())): + pvi = POINTER(VS_FIXEDFILEINFO)() + if not version.VerQueryValueW(ver_block, "", byref(pvi), byref(DWORD())): return maj, min, build maj = pvi.contents.dwProductVersionMS >> 16 diff --git a/Misc/NEWS b/Misc/NEWS index 04c9fab..13b448c 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -71,8 +71,6 @@ Library - Issue #25969: Update the lib2to3 grammar to handle the unpacking generalizations added in 3.5. -- Issue #27932: Fixes memory leak in platform.win32_ver() - - Issue #14977: mailcap now respects the order of the lines in the mailcap files ("first match"), as required by RFC 1542. Patch by Michael Lazar. -- cgit v0.12 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
#include "Python.h"

#ifdef X87_DOUBLE_ROUNDING
/* On x86 platforms using an x87 FPU, this function is called from the
   Py_FORCE_DOUBLE macro (defined in pymath.h) to force a floating-point
   number out of an 80-bit x87 FPU register and into a 64-bit memory location,
   thus rounding from extended precision to double precision. */
double _Py_force_double(double x)
{
    volatile double y;
    y = x;
    return y;
}
#endif

#ifdef HAVE_GCC_ASM_FOR_X87

/* inline assembly for getting and setting the 387 FPU control word on
   gcc/x86 */

unsigned short _Py_get_387controlword(void) {
    unsigned short cw;
    __asm__ __volatile__ ("fnstcw %0" : "=m" (cw));
    return cw;
}

void _Py_set_387controlword(unsigned short cw) {
    __asm__ __volatile__ ("fldcw %0" : : "m" (cw));
}

#endif


#ifndef HAVE_HYPOT
double hypot(double x, double y)
{
    double yx;

    x = fabs(x);
    y = fabs(y);
    if (x < y) {
        double temp = x;
        x = y;
        y = temp;
    }
    if (x == 0.)
        return 0.;
    else {
        yx = y/x;
        return x*sqrt(1.+yx*yx);
    }
}
#endif /* HAVE_HYPOT */

#ifndef HAVE_COPYSIGN
double
copysign(double x, double y)
{
    /* use atan2 to distinguish -0. from 0. */
    if (y > 0. || (y == 0. && atan2(y, -1.) > 0.)) {
        return fabs(x);
    } else {
        return -fabs(x);
    }
}
#endif /* HAVE_COPYSIGN */

#ifndef HAVE_ROUND
double
round(double x)
{
    double absx, y;
    absx = fabs(x);
    y = floor(absx);
    if (absx - y >= 0.5)
    y += 1.0;
    return copysign(y, x);
}
#endif /* HAVE_ROUND */