Skip to content
This repository

MinGW enhancements for datetime functionality. #156

Closed
wants to merge 11 commits into from

4 participants

Han Genuit Ralf Gommers Mark Charles Harris
Han Genuit

Hi, as a solution for ticket 1909 and the issues in pull request 118, I made some enhancements (or hacks) to the MinGW compiler class in the NumPy distutils.

Like for the Python runtime library, it will try to generate a custom version of the MSVC runtime library, which exposes all functionality, for versions of VS2005 and up.

I had to hack in a preprocessor statement (NPY_MINGW_USE_CUSTOM_MSVCR), to be able to use this functionality safely with a fallback on the conventional (non-threadsafe) functions. It is a bit messy, but hopefully it will fix the issues with MinGW.

Ralf Gommers
Owner

Hi Han, thanks for working on this. Unfortunately, it still ends the same way for me:

$ wine .wine/drive_c/Python26/python.exe 
Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.test('full')
Running unit tests for numpy
NumPy version 2.0.0.dev-Unknown
NumPy is installed in Z:\Users\rgommers\.wine\drive_c\Python26\lib\site-packages\numpy
Python version 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]
nose version 0.11.3
...............S....wine: Call from 0x7bc40cfa to unimplemented function msvcr90.dll.localtime, aborting
wine: Unimplemented function msvcr90.dll.localtime called at address 0x7bc40cfa (thread 0009), starting debugger...
Unhandled exception: unimplemented function msvcr90.dll.localtime called in 32-bit code (0x7bc40cfa).
Register dump:
 CS:0017 SS:001f DS:001f ES:001f FS:1007 GS:0037
 EIP:7bc40cfa ESP:0041bfa8 EBP:0041c00c EFLAGS:00200202(   - --  I   - - - )
 EAX:0041bfb4 EBX:00000000 ECX:00000000 EDX:50d44130
 ESI:0041c150 EDI:ffffffff
Stack dump:
0x0041bfa8:  00000064 00000000 00000000 80000100
0x0041bfb8:  00000001 00000000 7bc40cfa 00000002
0x0041bfc8:  69c80e74 69c7fb20 0000019b 00000000
0x0041bfd8:  00000190 00000000 1e0130bf 00c210d0
0x0041bfe8:  0000019b 00000000 1e1d816c 69c69950
0x0041bff8:  0000002b 00000000 1e01302e 0041c190
0200: sel=1007 base=7ffc0000 limit=00000fff 32-bit rw-
Backtrace:
=>0 0x7bc40cfa _stub_entry_point+0x3f() in ntdll (0x0041c00c)
  1 0x0042001e in <wine-loader> (+0x42001e) (0x0041c118)
  2 0x69b8b129 in multiarray.pyd (+0xb129) (0x0041c1d8)
  3 0x1e032726 in python26 (+0x32726) (0x00edba30)
  4 0x00d0b870 in <wine-loader> (+0xd0b870) (0x00497030)
0x7bc40cfa _stub_entry_point+0x3f in ntdll: subl    $4,%esp
Modules:
Module  Address         Debug info  Name (164 modules)
ELF        0- 6101000   Stabs           <wine-loader>
PE   2ac0000- 2acc000   Deferred        _socket.pyd
PE  10000000-100a2000   Deferred        _ssl.pyd
PE  1d000000-1d00a000   Deferred        python
PE  1d1a0000-1d1b5000   Deferred        _ctypes.pyd
PE  1e000000-1e218000   Export          python26
PE  40000000-40146000   Deferred        libwine.1.dylib
PE  40146000-40177000   Deferred        libgl.1.dylib
PE  40177000-401e8000   Deferred        libglu.1.dylib
PE  401e8000-401fd000   Deferred        libxplugin.1.dylib
PE  401fd000-4020d000   Deferred        libxext.6.dylib
PE  4020d000-40323000   Deferred        libx11.6.dylib
PE  40323000-4032a000   Deferred        libxdmcp.6.dylib
PE  4032a000-4032f000   Deferred        libxau.6.dylib
PE  41870000-41879000   Deferred        libsm.6.dylib
PE  41879000-4187d000   Deferred        libxinerama.1.dylib
PE  41882000-418c6000   Deferred        libfontconfig.1.dylib
PE  418cb000-418e3000   Deferred        libice.6.dylib
PE  418e3000-418e9000   Deferred        libxxf86vm.1.dylib
PE  418e9000-418f3000   Deferred        libxrender.1.dylib
PE  418f3000-418fc000   Deferred        libxrandr.2.dylib
ELF 4275b000-428d0000   Deferred        user32<elf>
  \-PE  42760000-4285c000   \               user32
ELF 428d0000-4299b000   Deferred        gdi32<elf>
  \-PE  428e0000-4295f000   \               gdi32
ELF 4299b000-42a1f000   Deferred        advapi32<elf>
  \-PE  429a0000-429f7000   \               advapi32
ELF 42a1f000-42ad3000   Deferred        rpcrt4<elf>
  \-PE  42a30000-42a96000   \               rpcrt4
ELF 42ad3000-42cd0000   Deferred        shell32<elf>
  \-PE  42ae0000-42c6d000   \               shell32
ELF 42cd0000-42d69000   Deferred        shlwapi<elf>
  \-PE  42ce0000-42d2e000   \               shlwapi
ELF 42d69000-42eab000   Deferred        comctl32<elf>
  \-PE  42d70000-42e51000   \               comctl32
PE  42eab000-42f5e000   Deferred        libfreetype.6.dylib
ELF 43021000-43107000   Deferred        winex11<elf>
  \-PE  43030000-430cc000   \               winex11
ELF 43107000-43130000   Deferred        imm32<elf>
  \-PE  43110000-43127000   \               imm32
PE  43130000-4313b000   Deferred        libxcursor.1.dylib
PE  4313b000-43142000   Deferred        libxfixes.3.dylib
ELF 43142000-43182000   Deferred        uxtheme<elf>
  \-PE  43150000-43175000   \               uxtheme
ELF 431ae000-43360000   Deferred        ole32<elf>
  \-PE  431b0000-432cf000   \               ole32
ELF 4338d000-43424000   Deferred        msvcrt<elf>
  \-PE  43390000-433e2000   \               msvcrt
ELF 43424000-435a2000   Deferred        oleaut32<elf>
  \-PE  43430000-43531000   \               oleaut32
ELF 435a2000-435e8000   Deferred        rsaenh<elf>
  \-PE  435b0000-435de000   \               rsaenh
ELF 435e8000-436bb000   Deferred        crypt32<elf>
  \-PE  435f0000-43685000   \               crypt32
ELF 436bb000-436f1000   Deferred        ws2_32<elf>
  \-PE  436c0000-436e5000   \               ws2_32
PE  63b00000-63b0b000   Deferred        _compiled_base.pyd
PE  69200000-69227000   Deferred        scalarmath.pyd
PE  69b80000-69c8b000   COFF            multiarray.pyd
PE  6b040000-6b04e000   Deferred        fftpack_lite.pyd
PE  6f0c0000-6f131000   Deferred        mtrand.pyd
PE  6fb00000-6fc1b000   Deferred        lapack_lite.pyd
PE  70c40000-70c91000   Deferred        umath.pyd
PE  78520000-785c3000   Deferred        msvcr90
ELF 7b800000-7b98e000   Deferred        kernel32<elf>
  \-PE  7b810000-7b93b000   \               kernel32
ELF 7bc00000-7bd09000   Stabs           ntdll<elf>
  \-PE  7bc10000-7bcaa000   \               ntdll
PE  90003000-9014b000   Deferred        libfontparser.dylib
PE  9023e000-9025c000   Deferred        langanalysis
PE  9023e000-9025c000   Deferred        langanalysis
PE  9023e000-9025c000   Deferred        langanalysis
PE  903d6000-9041d000   Deferred        libcups.2.dylib
PE  9063d000-90767000   Deferred        osservices
PE  90941000-90946000   Deferred        trustevaluationagent
PE  90941000-90946000   Deferred        trustevaluationagent
PE  91307000-91352000   Deferred        ae
PE  91429000-91432000   Deferred        libgfxshared.dylib
PE  91c02000-91c11000   Deferred        print
PE  91d38000-91d8c000   Deferred        libtiff.dylib
PE  91dbc000-91e28000   Deferred        navigationservices
PE  91eaa000-91ee0000   Deferred        corevideo
PE  9200d000-92040000   Deferred        libxslt.1.dylib
PE  92058000-9211a000   Deferred        ats
PE  920f4000-926af000   Deferred        liblapack.dylib
PE  9252b000-92533000   Deferred        help
PE  9252f000-926dc000   Deferred        audiotoolbox
PE  9252f000-926dc000   Deferred        audiotoolbox
PE  92707000-92733000   Deferred        openscripting
PE  9277b000-92788000   Deferred        commercecore
PE  9277b000-92788000   Deferred        commercecore
PE  92960000-92a85000   Deferred        desktopservicespriv
PE  92960000-92a85000   Deferred        desktopservicespriv
PE  92c48000-92d4a000   Deferred        libiconv.2.dylib
PE  93d39000-93d4c000   Deferred        libz.1.dylib
PE  93d49000-93d4c000   Deferred        carbon
PE  93d9a000-94130000   Deferred        carboncore
PE  94101000-94179000   Deferred        libvmisc.dylib
PE  94171000-945ac000   Deferred        quartzcore
PE  94171000-945ac000   Deferred        quartzcore
PE  94171000-945ac000   Deferred        quartzcore
PE  94171000-945ac000   Deferred        quartzcore
PE  945ea000-94623000   Deferred        libglimage.dylib
PE  945ea000-94623000   Deferred        libglimage.dylib
PE  9488e000-9489b000   Deferred        opendirectory
PE  9488e000-9489b000   Deferred        opendirectory
PE  94c05000-94cf8000   Deferred        colorsync
PE  94c05000-94cf8000   Deferred        colorsync
PE  94d04000-94d0a000   Deferred        audiounit
PE  94d71000-94d7a000   Deferred        libgif.dylib
PE  94db2000-94e5e000   Deferred        coreaudio
PE  94db2000-94e5e000   Deferred        coreaudio
PE  94edb000-94ee3000   Deferred        libcorevmclient.dylib
PE  94ee4000-94f37000   Deferred        libauto.dylib
PE  94ee4000-94f37000   Deferred        libauto.dylib
PE  9555e000-95617000   Deferred        securityfoundation
PE  95624000-95627000   Deferred        veclib
PE  956c3000-9571d000   Deferred        systemconfiguration
PE  95701000-95769000   Deferred        familycontrols
PE  95701000-95769000   Deferred        familycontrols
PE  9584a000-9584d000   Deferred        accelerate
PE  95972000-95980000   Deferred        commonpanels
PE  95979000-95990000   Deferred        libsasl2.2.dylib
PE  95a29000-95aaf000   Deferred        htmlrendering
PE  95a8e000-95ab7000   Deferred        cfopendirectory
PE  95a8e000-95ab7000   Deferred        cfopendirectory
PE  95acb000-95aee000   Deferred        libpng.dylib
PE  95b50000-95b7c000   Deferred        directoryservice
PE  95b8c000-95c51000   Deferred        printcore
PE  95c23000-95c2a000   Deferred        securityhi
PE  95c23000-95c2a000   Deferred        securityhi
PE  95c33000-95d89000   Deferred        libcrypto.0.9.8.dylib
PE  964a7000-964d1000   Deferred        libresolv.9.dylib
PE  965fe000-96941000   Deferred        security
PE  96865000-96a86000   Deferred        imageio
PE  96865000-96a86000   Deferred        imageio
PE  96a28000-96a4a000   Deferred        speechsynthesis
PE  96a4b000-96a51000   Deferred        libradiance.dylib
PE  96a56000-96b81000   Deferred        libglprogrammability.dylib
PE  96c6a000-96c95000   Deferred        imagecapture
PE  96cb4000-96cc7000   Deferred        speechrecognition
PE  9703d000-97104000   Deferred        libsqlite3.dylib
PE  970f7000-9721c000   Deferred        libxml2.2.dylib
PE  971f9000-9720b000   Deferred        carbonsound
PE  9723d000-9725a000   Deferred        libbsm.0.dylib
PE  97558000-975c3000   Deferred        metadata
PE  98669000-98683000   Deferred        libgl.dylib
PE  9869f000-9878d000   Deferred        vimage
PE  9869f000-9878d000   Deferred        vimage
PE  987f7000-9885a000   Deferred        coreui
PE  98f1b000-98fcf000   Deferred        searchkit
PE  990cd000-99531000   Deferred        hitoolbox
PE  990cd000-99531000   Deferred        hitoolbox
PE  99556000-99e0d000   Deferred        coregraphics
PE  99d9d000-99e1b000   Deferred        hiservices
PE  99d9d000-99e1b000   Deferred        hiservices
PE  9a1bd000-9a1e2000   Deferred        libexpat.1.dylib
PE  9a229000-9a681000   Deferred        libblas.dylib
PE  9a640000-9a6a9000   Deferred        passwordserver
PE  9a640000-9a6a9000   Deferred        passwordserver
PE  9a90c000-9a92b000   Deferred        multitouchsupport
PE  9a932000-9a95d000   Deferred        libjpeg.dylib
PE  9a9bd000-9a9e7000   Deferred        opencl
PE  9aa20000-9aa5c000   Deferred        dictionaryservices
Threads:
process  tid      prio (all id:s are in hex)
00000008 (D) Z:\Users\rgommers\.wine\drive_c\Python26\python.exe
        00000009    0 <==
0000000e services.exe
        00000014    0
        00000010    0
        0000000f    0
00000011 winedevice.exe
        00000018    0
        00000017    0
        00000013    0
        00000012    0
0000001b explorer.exe
        0000001c    0
Backtrace:
=>0 0x7bc40cfa _stub_entry_point+0x3f() in ntdll (0x0041c00c)
  1 0x0042001e in <wine-loader> (+0x42001e) (0x0041c118)
  2 0x69b8b129 in multiarray.pyd (+0xb129) (0x0041c1d8)
  3 0x1e032726 in python26 (+0x32726) (0x00edba30)
  4 0x00d0b870 in <wine-loader> (+0xd0b870) (0x00497030)
wine: Call from 0x7bc40cfa to unimplemented function msvcr90.dll.localtime, aborting
Ralf Gommers
Owner

Do I need to enable something in the build? I didn't look at what you did yet, just pulled and built.

Han Genuit

Ah, sorry, I had not tried it under wine yet.. I think it tries to fall back on the default localtime for some reason, but that one does not exist anymore in msvcrt90. I'll have to work on it some more..

Ralf Gommers
Owner

It's not the most common setup I know, but am important one for me. The numpy Windows binaries are always built under Wine.

Han Genuit

Are you using an official Python executable? I just installed and built it under wine and it worked for me..

I think with a Python distro built with MinGW, it might be using a different compiler class. Hmm, I also need to test that.

Han Genuit

Does your build log indicate that NPY_MINGW_USE_CUSTOM_MSVCR has been defined? You should be seeing it as compiler argument for each object.. (something which I would also like to change)

Han Genuit

(By the way, this is my command line: wine ~/.wine/drive_c/Python27/python.exe setup.py build --compiler=mingw32 bdist_wininst)

Ralf Gommers
Owner

Yes, Python 2.6.4 binary from python.org. Those are built with Visual Studio.

Ralf Gommers
Owner

No, that doesn't occur in the build log. I do see 5 occurrences of -DNPY_NEEDS_MINGW_TIME_WORKAROUND. Full build log at http://pastebin.com/SJPCCpk8

Ralf Gommers
Owner

I'll try with the exact same build command now.

Han Genuit

Ah, yeah, someone had encountered a similar problem before.. ;-)

I'll look into the paver build, thanks!

Han Genuit

'Cannot build msvcr library: "msvcr90.dll" not found' --> this seems to be the problem..

Ralf Gommers
Owner

Same segfault with your build command.

Ralf Gommers
Owner
$ locate msvcr.dll
Ralf-Gommerss-iMac:~ $ locate msvcr80.dll
Ralf-Gommerss-iMac:~ $ locate msvcr70.dll
Ralf-Gommerss-iMac:~ $ locate msvcr90.dll
/Users/rgommers/.wine/drive_c/windows/winsxs/x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_d08d0375/msvcr90.dll
/Users/rgommers/__wine/drive_c/windows/winsxs/x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_d08d0375/msvcr90.dll
Ralf-Gommerss-iMac:~ $ locate msvcr100.dll
Ralf-Gommerss-iMac:~ $
Han Genuit

Yeah, it cannot find the msvc runtime library.. It normally sits in the Python base directory, but the script also looks for it in PATH.

Ralf Gommers
Owner

So should I try adding that dir to the path with wine regedit?

Han Genuit

[snip]

(does not show the one in the Python directory, though.)

Well, it could be worth a try, but it should work without explicitly adding it to PATH. Does it exist in the Python directory?

What does sys.prefix say on your machine?

Ralf Gommers
Owner
 >>> >>> sys.prefix
'Z:\\Users\\rgommers\\.wine\\drive_c\\Python27'

No dll in Python dir.

$ ls /usr/local/lib/wine/msvcr*
/usr/local/lib/wine/msvcr71.dll.so  /usr/local/lib/wine/msvcrt20.dll.so /usr/local/lib/wine/msvcrtd.dll.so
/usr/local/lib/wine/msvcrt.dll.so   /usr/local/lib/wine/msvcrt40.dll.so

$ ls /usr/local/lib/wine/fakedlls/msvc*
/usr/local/lib/wine/fakedlls/msvcirt.dll    /usr/local/lib/wine/fakedlls/msvcrt20.dll
/usr/local/lib/wine/fakedlls/msvcr71.dll    /usr/local/lib/wine/fakedlls/msvcrt40.dll
/usr/local/lib/wine/fakedlls/msvcrt.dll     /usr/local/lib/wine/fakedlls/msvcrtd.dll
Ralf Gommers
Owner

Seem msvcr71.dll is the default for my wine:

$ locate msvcr71.dll
/Users/rgommers/.wine/drive_c/windows/system32/msvcr71.dll
/Users/rgommers/Code/wine/dlls/msvcr71/msvcr71.dll.fake
/Users/rgommers/Code/wine/dlls/msvcr71/msvcr71.dll.so
/Users/rgommers/__wine/drive_c/windows/system32/msvcr71.dll
/Users/rgommers/wine/build/wine-1.1.39/dlls/msvcr71/msvcr71.dll.fake
/Users/rgommers/wine/build/wine-1.1.39/dlls/msvcr71/msvcr71.dll.so
/Users/rgommers/wine/wine-1.1.39/lib/wine/fakedlls/msvcr71.dll
/Users/rgommers/wine/wine-1.1.39/lib/wine/msvcr71.dll.so
/usr/local/lib/wine/fakedlls/msvcr71.dll
/usr/local/lib/wine/msvcr71.dll.so
Han Genuit

That is interesting, on my machine under wine as well as under windows, the Python installer puts msvcr90.dll in C:\Python27. The msvcr71.dll should have the localtime symbol, I believe, so that is not the one Python uses.. I think I'll have to account for the SxS directories, but I wonder why the dll is not present in the base directory in your situation..

Ralf Gommers
Owner

I may have an older Wine, but installed Pythons recently. py3.2 looks the same, no dll. I could put it there by hand to test. But I'll have to do this tomorrow on my other machine, don't want to mess up this one too much and get problems right before a scipy release.

Han Genuit

Maybe you have to install vcrun2008 with winetricks, but for me that reports an error at the moment. I myself have wine-1.3.18. You have the dll in an SxS directory, though.. I will update the pull request in either case.

Han Genuit

Hi Ralf, I pushed a few changes. Now, the installer should be able to pick up the msvcr90.dll from the winsxs directory.

Could you please try again? There is still the issue for the fallback-mechanism, but hopefully you do not need to make any more changes to the system.

Han Genuit

I had to add another preprocessor statement to reliably fall back on the localtime functionality in the newer versions of MSVC. Now the build should not fail whether or not msvc90.dll is found..

Ralf Gommers
Owner

This works!

Ralf Gommers
Owner

Looking at your changes to mingw32ccompiler, that looks cleaner than I expected this solution to be. Learned something again, thanks.

Mark should probably review your datetime changes.

Ralf Gommers
Owner

Some py3k related issue still:

Building msvcr library: "C:\Python31\libs\libmsvcr90.a" (from C:\windows\winsxs\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_d08d0375\msvcr90.dll)
Traceback (most recent call last):
  File "setup.py", line 214, in <module>
    setup_package()
  File "setup.py", line 207, in setup_package
    configuration=configuration )
  File "Z:\Users\rgommers\Code\numpy\build\py3k\numpy\distutils\core.py", line 186, in setup
    return old_setup(**new_attr)
  File "C:\Python31\lib\distutils\core.py", line 149, in setup
    dist.run_commands()
  File "C:\Python31\lib\distutils\dist.py", line 919, in run_commands
    self.run_command(cmd)
  File "C:\Python31\lib\distutils\dist.py", line 938, in run_command
    cmd_obj.run()
  File "Z:\Users\rgommers\Code\numpy\build\py3k\numpy\distutils\command\build.py", line 37, in run
    old_build.run(self)
  File "C:\Python31\lib\distutils\command\build.py", line 128, in run
    self.run_command(cmd_name)
  File "C:\Python31\lib\distutils\cmd.py", line 315, in run_command
    self.distribution.run_command(command)
  File "C:\Python31\lib\distutils\dist.py", line 938, in run_command
    cmd_obj.run()
  File "Z:\Users\rgommers\Code\numpy\build\py3k\numpy\distutils\command\build_src.py", line 152, in run
    self.build_sources()
  File "Z:\Users\rgommers\Code\numpy\build\py3k\numpy\distutils\command\build_src.py", line 163, in build_sources
    self.build_library_sources(*libname_info)
  File "Z:\Users\rgommers\Code\numpy\build\py3k\numpy\distutils\command\build_src.py", line 298, in build_library_sources
    sources = self.generate_sources(sources, (lib_name, build_info))
  File "Z:\Users\rgommers\Code\numpy\build\py3k\numpy\distutils\command\build_src.py", line 385, in generate_sources
    source = func(extension, build_dir)
  File "numpy\core\setup.py", line 646, in get_mathlib_info
    st = config_cmd.try_link('int main(void) { return 0;}')
  File "C:\Python31\lib\distutils\command\config.py", line 245, in try_link
    self._check_compiler()
  File "Z:\Users\rgommers\Code\numpy\build\py3k\numpy\distutils\command\config.py", line 45, in _check_compiler
    old_config._check_compiler(self)
  File "C:\Python31\lib\distutils\command\config.py", line 100, in _check_compiler
    dry_run=self.dry_run, force=1)
  File "Z:\Users\rgommers\Code\numpy\build\py3k\numpy\distutils\ccompiler.py", line 560, in new_compiler
    compiler = klass(None, dry_run, force)
  File "Z:\Users\rgommers\Code\numpy\build\py3k\numpy\distutils\mingw32ccompiler.py", line 94, in __init__
    if build_msvcr_library() | build_msvcr_library(debug=True):
  File "Z:\Users\rgommers\Code\numpy\build\py3k\numpy\distutils\mingw32ccompiler.py", line 356, in build_msvcr_library
    generate_def(dll_file, def_file)
  File "Z:\Users\rgommers\Code\numpy\build\py3k\numpy\distutils\mingw32ccompiler.py", line 275, in generate_def
    if _START.match(dump[i]):
TypeError: can't use a string pattern on a bytes-like object
numpy/core/src/multiarray/datetime_strings.c
... ... @@ -12,6 +12,13 @@
12 12
13 13 #include <time.h>
14 14
  15 +#if defined(_WIN32) && \
  16 + defined(__GNUC__) && \
  17 + (defined(NPY_MINGW_USE_CUSTOM_MSVCR) | \
  18 + defined(NPY_MINGW_USE_64BIT_MSVCR))
  19 +#define time_t __time64_t
2
Mark Collaborator
mwiebe added a note

This should be a typedef, not a #define. In general type aliases should never be done with the preprocessor.

Han Genuit
87 added a note

Ah, thanks, I didn't know that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
numpy/core/src/multiarray/datetime_strings.c
((16 lines not shown))
  47 + func_name = "localtime_s";
  48 + goto fail;
  49 + }
  50 + #elif defined(__GNUC__) && defined(NPY_MINGW_USE_CUSTOM_MSVCR)
  51 + if (_localtime64_s(tms, ts) != 0) {
  52 + func_name = "_localtime64_s";
  53 + goto fail;
  54 + }
  55 + #elif defined(__GNUC__) && defined(NPY_MINGW_USE_64BIT_MSVCR)
  56 + struct tm *tms_tmp;
  57 + tms_tmp = _localtime64(ts);
  58 + if (tms_tmp == NULL) {
  59 + func_name = "_localtime64";
  60 + goto fail;
  61 + }
  62 + memcpy((void*)tms, (void*)tms_tmp, sizeof(struct tm));
2
Mark Collaborator
mwiebe added a note

I'd suggest removing the casts to (void*), any pointer can implicitly convert to void*, and I think casts should be used only where necessary.

Han Genuit
87 added a note

Ok, I agree with using casts only when necessary, didn't know about implicit void conversion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
numpy/core/src/multiarray/datetime_strings.c
((24 lines not shown))
  55 + #elif defined(__GNUC__) && defined(NPY_MINGW_USE_64BIT_MSVCR)
  56 + struct tm *tms_tmp;
  57 + tms_tmp = _localtime64(ts);
  58 + if (tms_tmp == NULL) {
  59 + func_name = "_localtime64";
  60 + goto fail;
  61 + }
  62 + memcpy((void*)tms, (void*)tms_tmp, sizeof(struct tm));
  63 + #else
  64 + struct tm *tms_tmp;
  65 + tms_tmp = localtime(ts);
  66 + if (tms_tmp == NULL) {
  67 + func_name = "localtime";
  68 + goto fail;
  69 + }
  70 + memcpy((void*)tms, (void*)tms_tmp, sizeof(struct tm));
1
Mark Collaborator
mwiebe added a note

ditto about the void* cast here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
numpy/core/tests/test_datetime.py
... ... @@ -506,14 +506,14 @@ class TestDateTime(TestCase):
506 506 assert_equal(str_a, str_b)
507 507
508 508 def test_datetime_array_str(self):
509   - a = np.array(['2011-03-16', '1920-01-01', '2013-05-19'], dtype='M')
510   - assert_equal(str(a), "['2011-03-16' '1920-01-01' '2013-05-19']")
  509 + a = np.array(['2011-03-16', '1970-01-01', '2013-05-19'], dtype='M')
  510 + assert_equal(str(a), "['2011-03-16' '1970-01-01' '2013-05-19']")
4
Mark Collaborator
mwiebe added a note

I think these should change back to 1920, I was explicitly wanting to test dates on both side of the 1970 epoch boundary, this removes important test cases. We should probably discuss what to do about any errors with localtime and gmtime for dates before 1970.

Han Genuit
87 added a note

That's fine by me, the errors also prevent the rest of the test from running, though..

Mark Collaborator
mwiebe added a note

Better to come up with a reasonable fix, though, than to ignore the error. ;)

Han Genuit
87 added a note

True, true.. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
numpy/distutils/mingw32ccompiler.py
... ... @@ -90,6 +90,15 @@ class Mingw32CCompiler(distutils.cygwinccompiler.CygwinCCompiler):
90 90
91 91 build_import_library()
92 92
  93 + # Check for custom msvc runtime library on Windows. Build if it doesn't exist.
  94 + if build_msvcr_library() | build_msvcr_library(debug=True):
4
Mark Collaborator
mwiebe added a note

Should this be "or" instead of "|" here?

Han Genuit
87 added a note

Actually, the 'or' statement only executes the second statement if the first one evaluates False -- I wanted to convert both libraries if possible.. the '|' makes sure that both statements are executed regardless of their value.

Mark Collaborator
mwiebe added a note

This kind of clever coding can make it harder to maintain, though. I think it's better to say "built_rel, built_deb = build_msvcr_library(), build_msvcr_library(debug=True)", then "if built_rel or built_deb". This is more explicit, and doesn't require people looking at the code to be aware of this kind of Python subtlety.

Han Genuit
87 added a note

Ah, ok, I'll do that. It is kind of subtle, yes..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Mark
Collaborator

Looks good to me, just a few tweaks needed to clean up the code and revert test changes.

Han Genuit

I'll take a look at the python3 issues, maybe also fix up python25 if possible.

Mark
Collaborator

I've already fixed some of the Python3 issues here: https://github.com/m-paradox/numpy/tree/datetime-cleanup

Locally, I just get a failure about %lld with the timedelta in that branch.

Han Genuit

I could not test python25, because nose is not compatible anymore.

Han Genuit

The test test_datetime_array_str may give errors that it cannot use the localtime function, but that should be fixed up elsewhere?

Han Genuit

Ralf, could you test it one last time (with a clean Python?) I think there should be no issues anymore, but I've made some changes to the dll finder and MinGW macros that might warrant an extra pair of eyes..

Ralf Gommers
Owner

Compiles fine with python 3.1 now. Some test failures still. May be fixed in Mark's branch already (I didn't check), but the OSError ones could also still be related to this fix.

======================================================================
ERROR: test_datetime_array_str (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\core\tests\test_datetime.py", line 510, in test_datetime_array_str
    assert_equal(str(a), "['2011-03-16' '1920-01-01' '2013-05-19']")
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\core\numeric.py", line 1517, in array_str
    return array2string(a, max_line_width, precision, suppress_small, ' ', "", str)
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\core\arrayprint.py", line 459, in array2string
    separator, prefix, formatter=formatter)
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\core\arrayprint.py", line 331, in _array2string
    _summaryEdgeItems, summary_insert)[:-1]
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\core\arrayprint.py", line 502, in _formatArray
    word = format_function(a[-i]) + separator
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\core\arrayprint.py", line 770, in __call__
    casting=self.casting)
OSError: Failed to use '_localtime64_s' to convert to a local time

======================================================================
ERROR: test_datetime_divide (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\core\tests\test_datetime.py", line 926, in test_datetime_divide
    assert_equal(tda / tdb, 6.0 / 9.0)
TypeError: ufunc 'true_divide' did not contain a loop with signature matching types dtype('<m8[h]') dtype('<m8[h]') dtype('float64')

======================================================================
ERROR: test_string_parser_variants (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\core\tests\test_datetime.py", line 1050, in test_string_parser_variants
    assert_equal(np.array(['1980-02-29T01:02:03'], np.dtype('M8[s]')),
OSError: Failed to use '_gmtime64_s' to convert to a UTC time

======================================================================
ERROR: test_timedelta_scalar_construction_units (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\core\tests\test_datetime.py", line 287, in test_timedelta_scalar_construction_units
    assert_equal(np.datetime64('2010-03-12T17').dtype,
OSError: Failed to use '_gmtime64_s' to convert to a UTC time

======================================================================
FAIL: test_datetime_as_string (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\core\tests\test_datetime.py", line 1166, in test_datetime_as_string
    '1959')
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\testing\utils.py", line 313, in assert_equal
    raise AssertionError(msg)
AssertionError: 
Items are not equal:
 ACTUAL: b'1959'
 DESIRED: '1959'

======================================================================
FAIL: test_datetime_as_string_timezone (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\core\tests\test_datetime.py", line 1277, in test_datetime_as_string_timezone
    '2010-03-15T06:30Z')
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\testing\utils.py", line 313, in assert_equal
    raise AssertionError(msg)
AssertionError: 
Items are not equal:
 ACTUAL: b'2010-03-15T06:30Z'
 DESIRED: '2010-03-15T06:30Z'

======================================================================
FAIL: test_timedelta_scalar_construction (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\core\tests\test_datetime.py", line 219, in test_timedelta_scalar_construction
    assert_equal(str(np.timedelta64(3, 's')), '3 seconds')
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\testing\utils.py", line 313, in assert_equal
    raise AssertionError(msg)
AssertionError: 
Items are not equal:
 ACTUAL: '%lld seconds'
 DESIRED: '3 seconds'


======================================================================
FAIL: test_datetime_as_string (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\core\tests\test_datetime.py", line 1166, in test_datetime_as_string
    '1959')
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\testing\utils.py", line 313, in assert_equal
    raise AssertionError(msg)
AssertionError: 
Items are not equal:
 ACTUAL: b'1959'
 DESIRED: '1959'

======================================================================
FAIL: test_datetime_as_string_timezone (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\core\tests\test_datetime.py", line 1277, in test_datetime_as_string_timezone
    '2010-03-15T06:30Z')
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\testing\utils.py", line 313, in assert_equal
    raise AssertionError(msg)
AssertionError: 
Items are not equal:
 ACTUAL: b'2010-03-15T06:30Z'
 DESIRED: '2010-03-15T06:30Z'

======================================================================
FAIL: test_timedelta_scalar_construction (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\core\tests\test_datetime.py", line 219, in test_timedelta_scalar_construction
    assert_equal(str(np.timedelta64(3, 's')), '3 seconds')
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\testing\utils.py", line 313, in assert_equal
    raise AssertionError(msg)
AssertionError: 
Items are not equal:
 ACTUAL: '%lld seconds'
 DESIRED: '3 seconds'
Ralf Gommers
Owner

WIth Python 2.5:

======================================================================
ERROR: test_datetime_array_str (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python25\Lib\site-packages\numpy\core\tests\test_datetime.py", line 514, in test_datetime_array_str
    formatter={'datetime': lambda x :
  File "C:\Python25\Lib\site-packages\numpy\core\arrayprint.py", line 459, in array2string
    separator, prefix, formatter=formatter)
  File "C:\Python25\Lib\site-packages\numpy\core\arrayprint.py", line 259, in _array2string
    'int' : IntegerFormat(data),
  File "C:\Python25\Lib\site-packages\numpy\core\arrayprint.py", line 658, in __init__
    len(str(minimum.reduce(data, skipna=True))))
OSError: Failed to use 'localtime' to convert to a local time
Han Genuit

Hmm, the errors in test_datetime_array_str were expected, they have something to do with the 1920 date, but I am not completely sure in this case. The errors from _gmtime64_s I did not expect.. I cannot reproduce them on my system, but I have seen them before when the time_t type was wrong.

Han Genuit

How old is the version of MinGW you use? It seems that only since 3.18 it has the 64-bit time_t defined in time.h.
(which was released march 2010)

Ralf Gommers
Owner

I installed it in Feb or Mar 2010. with the automated installer: http://sourceforge.net/projects/mingw/files/Automated%20MinGW%20Installer/

There are so many different version numbers that I don't know what to compare 3.18 with, but I'm pretty sure I have an earlier version. My MinGW is version 5.1.6, gcc 3.4.5.

Han Genuit

Ah.. I got the version number from C:\MinGW\include\ _mingw.h --> __MINGW32_VERSION.

Ralf Gommers
Owner

OK, that's 3.17 for me.

Han Genuit

Ah, that would explain that.. What is the best option? I could hack the time_t definition back in again, but it would be cleaner to bump the version of MinGW, I think.

Ralf Gommers
Owner

Sure, bumping the version is not unreasonable.

Mark
Collaborator

I've incorporated some of these code changes into #161, as I did some Y2038-related changes and tried to reduce the pain the forthcoming merge conflict will cause.

Han Genuit

I merged the conflicting file into my pull request, which hopefully negates the pain. ;-)

Charles Harris
Owner

There is still a merge conflict with Mark's changes. Could you rebase to current master, possibly with a new pull request?

Han Genuit
87 commented

Ok, I rebased and skipped the conflicting commit (which Mark had reimplemented).

Charles Harris
Owner

OK, as soon as Ralph sign off on this we can merge it.

Ralf Gommers
Owner

I'm fine with merging this.

It would be good to document that gcc 4.x is required for MinGW now. Not sure where best to put that info though - if there's no obvious place I'll add it to HOWTO_DOCUMENT

Han Genuit
87 commented

I spotted an error in the buildbot related to these changes:

creating build\temp.win32-2.5\Release\numpy\core\src\multiarray
compile options: '-Inumpy\core\include -Ibuild\src.win32-2.5\numpy\core\include/numpy -Inumpy\core\src\private -Inumpy\core\src -Inumpy\core -Inumpy\core\src\npymath -Inumpy\core\src\multiarray -Inumpy\core\src\umath -Inumpy\core\src\npysort -Inumpy\core\include -IC:\Python25\include -IC:\Python25\PC -Ibuild\src.win32-2.5\numpy\core\src\multiarray -Ibuild\src.win32-2.5\numpy\core\src\umath -c'
gcc -mno-cygwin -O2 -Wall -Wstrict-prototypes -Inumpy\core\include -Ibuild\src.win32-2.5\numpy\core\include/numpy -Inumpy\core\src\private -Inumpy\core\src -Inumpy\core -Inumpy\core\src\npymath -Inumpy\core\src\multiarray -Inumpy\core\src\umath -Inumpy\core\src\npysort -Inumpy\core\include -IC:\Python25\include -IC:\Python25\PC -Ibuild\src.win32-2.5\numpy\core\src\multiarray -Ibuild\src.win32-2.5\numpy\core\src\umath -c numpy\core\src\multiarray\multiarraymodule_onefile.c -o build\temp.win32-2.5\Release\numpy\core\src\multiarray\multiarraymodule_onefile.o
g++ -mno-cygwin -shared build\temp.win32-2.5\Release\numpy\core\src\multiarray\multiarraymodule_onefile.o -LC:\Python25\libs -LC:\Python25\PCBuild -Lbuild\temp.win32-2.5 -lnpymath -lnpysort -lpython25 -lmsvcr71 -o build\lib.win32-2.5\numpy\core\multiarray.pyd
build\temp.win32-2.5\Release\numpy\core\src\multiarray\multiarraymodule_onefile.o:multiarraymodule_onefile.c:(.text+0x7cd5): undefined reference to `localtime_s'
build\temp.win32-2.5\Release\numpy\core\src\multiarray\multiarraymodule_onefile.o:multiarraymodule_onefile.c:(.text+0x82f9): undefined reference to `gmtime_s'
build\temp.win32-2.5\Release\numpy\core\src\multiarray\multiarraymodule_onefile.o:multiarraymodule_onefile.c:(.text+0x9b31): undefined reference to `localtime_s'
collect2: ld returned 1 exit status
error: Command "g++ -mno-cygwin -shared build\temp.win32-2.5\Release\numpy\core\src\multiarray\multiarraymodule_onefile.o -LC:\Python25\libs -LC:\Python25\PCBuild -Lbuild\temp.win32-2.5 -lnpymath -lnpysort -lpython25 -lmsvcr71 -o build\lib.win32-2.5\numpy\core\multiarray.pyd" failed with exit status 1

It seems that the VC compiler check #if defined(_MSC_VER) && (_MSC_VER >= 1400) is not robust enough, because in this situation it gets through on gcc.

Han Genuit
87 commented

Sorry, I had to rebase again. I committed a fix for Python 2.5 (and gcc 4.x) to test if I could reproduce the buildbot error, but I cannot...

Charles Harris
Owner

I pushed this in 2e899dd..909010a, but please keep an eye on it in case issues arise later on.

Han Genuit
87 commented

Okeydokey, will do, thanks! :-)

Han Genuit
87 commented

Ah.. I see now that the build was from July 31st -- long before these changes went in. Anyway, I'll keep an eye out.

Ralf Gommers
Owner

This is still failing with MSVC, see recent thread on numpy-discussion titled "Numpy-dev and scipy-0.10.1 test errors".

This is a release blocker. Does anyone have time to investigate?

Because the transition to gcc 4.x is stuck for now, I wouldn't be unhappy if there is any way to still make this work with MinGW 3.4.5 too.

Ralf Gommers
Owner

Sorry, that's on the scipy-dev list.

Han Genuit
87 commented

Oww.. I can reproduce them on WIN7.. I'll take a look at it.. sorry!

Han Genuit
87 commented

The errors are from the issue that windows will not parse timestamps from before 1970. The localtime_s function can parse dates up to the year 3000 for the 64-bits version, and 2038 for the 32-bits version.

See also: http://msdn.microsoft.com/en-us/library/a442x3ye.aspx.

I am not sure about the best solution, because you might lose functionality when dates from before 1970 are not accepted.

Han Genuit
87 commented

For an older version of MinGW, it might be possible to use the plain localtime fallback.

Does it give compile errors on MinGW 3.4.5? Or only in tests? Does it try to use the localtime function, or the localtime_s function?

Ralf Gommers
Owner

I've tested 2.5 and 2.7 with current master and MinGW 3.4.5 again just now. It builds, but tests give the following errors:

Python 2.5 test errors:

======================================================================
ERROR: test_datetime_array_str (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python25\Lib\site-packages\numpy\core\tests\test_datetime.py", line 514, in test_datetime_array_str
    formatter={'datetime': lambda x :
  File "C:\Python25\Lib\site-packages\numpy\core\arrayprint.py", line 459, in array2string
    separator, prefix, formatter=formatter)
  File "C:\Python25\Lib\site-packages\numpy\core\arrayprint.py", line 259, in _array2string
    'int' : IntegerFormat(data),
  File "C:\Python25\Lib\site-packages\numpy\core\arrayprint.py", line 658, in __init__
    len(str(minimum.reduce(data, skipna=True))))
OSError: Failed to use 'localtime' to convert to a local time

======================================================================
ERROR: test_combinations (test_multiarray.TestArgmax)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python25\Lib\site-packages\numpy\core\tests\test_multiarray.py", line 979, in test_combinations
    assert_equal(np.argmax(arr), pos, err_msg="%r"%arr)
OSError: Failed to use 'localtime' to convert to a local time

======================================================================
ERROR: test_combinations (test_multiarray.TestArgmin)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python25\Lib\site-packages\numpy\core\tests\test_multiarray.py", line 1047, in test_combinations
    assert_equal(np.argmin(arr), pos, err_msg="%r"%arr)
OSError: Failed to use 'localtime' to convert to a local time

Python 2.7 test errors:

======================================================================
ERROR: test_datetime_arange (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python27\lib\site-packages\numpy\core\tests\test_datetime.py", line 1351, in test_datetime_arange
    assert_raises(ValueError, np.arange, np.datetime64('today'),
OSError: Failed to use '_localtime64_s' to convert to a local time

======================================================================
ERROR: test_datetime_y2038 (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python27\lib\site-packages\numpy\core\tests\test_datetime.py", line 1706, in test_datetime_y2038
    a = np.datetime64('2038-01-20T13:21:14')
OSError: Failed to use '_gmtime64_s' to convert to a UTC time

======================================================================
ERROR: test_pydatetime_creation (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python27\lib\site-packages\numpy\core\tests\test_datetime.py", line 467, in test_pydatetime_creation
    a = np.array(['today', datetime.date.today()], dtype='M8[D]')
OSError: Failed to use '_localtime64_s' to convert to a local time

======================================================================
ERROR: test_string_parser_variants (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python27\lib\site-packages\numpy\core\tests\test_datetime.py", line 1054, in test_string_parser_variants
    assert_equal(np.array(['1980-02-29T01:02:03'], np.dtype('M8[s]')),
OSError: Failed to use '_gmtime64_s' to convert to a UTC time

======================================================================
ERROR: test_timedelta_scalar_construction_units (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python27\lib\site-packages\numpy\core\tests\test_datetime.py", line 287, in test_timedelta_scalar_construction_units
    assert_equal(np.datetime64('2010-03-12T17').dtype,
OSError: Failed to use '_gmtime64_s' to convert to a UTC time

======================================================================
ERROR: Failure: OSError (Failed to use '_gmtime64_s' to convert to a UTC time)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python27\lib\site-packages\nose-0.11.4-py2.7.egg\nose\loader.py", line 382, in loadTestsFromName
    addr.filename, addr.module)
  File "Z:\Users\rgommers\.wine\drive_c\Python27\lib\site-packages\nose-0.11.4-py2.7.egg\nose\importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "Z:\Users\rgommers\.wine\drive_c\Python27\lib\site-packages\nose-0.11.4-py2.7.egg\nose\importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "Z:\Users\rgommers\.wine\drive_c\Python27\lib\site-packages\numpy\core\tests\test_multiarray.py", line 915, in <module>
    class TestArgmax(TestCase):
  File "Z:\Users\rgommers\.wine\drive_c\Python27\lib\site-packages\numpy\core\tests\test_multiarray.py", line 937, in TestArgmax
    np.datetime64('1994-06-21T14:43:15'),
OSError: Failed to use '_gmtime64_s' to convert to a UTC time
Ralf Gommers
Owner

And Python 3.1:

======================================================================
ERROR: test_datetime_y2038 (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\core\tests\test_datetime.py", line 1706, in test_datetime_y2038
    a = np.datetime64('2038-01-20T13:21:14')
OSError: Failed to use '_gmtime64_s' to convert to a UTC time

======================================================================
ERROR: test_string_parser_variants (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\core\tests\test_datetime.py", line 1054, in test_string_parser_variants
    assert_equal(np.array(['1980-02-29T01:02:03'], np.dtype('M8[s]')),
OSError: Failed to use '_gmtime64_s' to convert to a UTC time

======================================================================
ERROR: test_timedelta_scalar_construction_units (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\core\tests\test_datetime.py", line 287, in test_timedelta_scalar_construction_units
    assert_equal(np.datetime64('2010-03-12T17').dtype,
OSError: Failed to use '_gmtime64_s' to convert to a UTC time

======================================================================
ERROR: test_maskna.test_array_maskna_astype
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\nose-3.0.0.dev-py3.1.egg\nose\case.py", line 178, in runTest
    self.test(*self.arg)
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\core\tests\test_maskna.py", line 212, in test_array_maskna_astype
    b = a.astype(dt2)
TypeError: complex() argument must be a string or a number

======================================================================
ERROR: Failure: OSError (Failed to use '_gmtime64_s' to convert to a UTC time)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\nose-3.0.0.dev-py3.1.egg\nose\failure.py", line 37, in runTest
    reraise(self.exc_class, self.exc_val, self.tb)
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\nose-3.0.0.dev-py3.1.egg\nose\_3.py", line 7, in reraise
    raise exc_class(exc_val).with_traceback(tb)
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\nose-3.0.0.dev-py3.1.egg\nose\loader.py", line 389, in loadTestsFromName
    addr.filename, addr.module)
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\nose-3.0.0.dev-py3.1.egg\nose\importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\nose-3.0.0.dev-py3.1.egg\nose\importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\core\tests\test_multiarray.py", line 915, in <module>
    class TestArgmax(TestCase):
  File "Z:\Users\rgommers\.wine\drive_c\Python31\lib\site-packages\numpy\core\tests\test_multiarray.py", line 937, in TestArgmax
    np.datetime64('1994-06-21T14:43:15'),
OSError: Failed to use '_gmtime64_s' to convert to a UTC time
Mark
Collaborator

The situation looks even worse for me, built in 64-bit windows with Visual Studio 2008:

======================================================================
ERROR: test_datetime_array_str (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\numpy\core\tests\test_datetime.py", line 514, in test_datetime_array_str
    formatter={'datetime': lambda x :
  File "C:\Python27\lib\site-packages\numpy\core\arrayprint.py", line 459, in array2string
    separator, prefix, formatter=formatter)
  File "C:\Python27\lib\site-packages\numpy\core\arrayprint.py", line 259, in _array2string
    'int' : IntegerFormat(data),
  File "C:\Python27\lib\site-packages\numpy\core\arrayprint.py", line 658, in __init__
    len(str(minimum.reduce(data, skipna=True))))
OSError: Failed to use 'localtime_s' to convert to a local time

======================================================================
ERROR: test_combinations (test_multiarray.TestArgmax)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\numpy\core\tests\test_multiarray.py", line 979, in test_combinations
    assert_equal(np.argmax(arr), pos, err_msg="%r"%arr)
OSError: Failed to use 'localtime_s' to convert to a local time

======================================================================
ERROR: test_combinations (test_multiarray.TestArgmin)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\numpy\core\tests\test_multiarray.py", line 1047, in test_combinations
    assert_equal(np.argmin(arr), pos, err_msg="%r"%arr)
OSError: Failed to use 'localtime_s' to convert to a local time

======================================================================
ERROR: Parametric test factory.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\nose-1.1.2-py2.7.egg\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "C:\Python27\lib\site-packages\numpy\core\tests\test_numeric.py", line 1166, in tst_not_allclose
    assert_(not allclose(x,y), "%s and %s shouldn't be close" % (x,y))
  File "C:\Python27\lib\site-packages\numpy\core\numeric.py", line 2020, in allclose
    return all(less_equal(absolute(x-y), atol + rtol * absolute(y)))
RuntimeWarning: invalid value encountered in absolute

======================================================================
ERROR: Ticket 794.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\numpy\core\tests\test_regression.py", line 1007, in test_sign_for_complex_nan
    have = np.sign(C)
RuntimeWarning: invalid value encountered in sign

======================================================================
ERROR: test_complex_nans (test_umath.TestFmax)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\numpy\core\tests\test_umath.py", line 568, in test_complex_nans
    assert_equal(np.fmax(arg1, arg2), out)
RuntimeWarning: invalid value encountered in fmax

======================================================================
ERROR: test_float_nans (test_umath.TestFmax)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\numpy\core\tests\test_umath.py", line 560, in test_float_nans
    assert_equal(np.fmax(arg1, arg2), out)
RuntimeWarning: invalid value encountered in fmax

======================================================================
ERROR: test_complex_nans (test_umath.TestFmin)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\numpy\core\tests\test_umath.py", line 610, in test_complex_nans
    assert_equal(np.fmin(arg1, arg2), out)
RuntimeWarning: invalid value encountered in fmin

======================================================================
ERROR: test_float_nans (test_umath.TestFmin)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\numpy\core\tests\test_umath.py", line 602, in test_float_nans
    assert_equal(np.fmin(arg1, arg2), out)
RuntimeWarning: invalid value encountered in fmin

======================================================================
ERROR: test_umath.TestLogAddExp.test_nan
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\nose-1.1.2-py2.7.egg\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "C:\Python27\lib\site-packages\numpy\core\tests\test_umath.py", line 259, in test_nan
    assert_(np.isnan(np.logaddexp(np.nan, np.inf)))
RuntimeWarning: invalid value encountered in logaddexp

======================================================================
ERROR: test_umath.TestLogAddExp2.test_nan
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\nose-1.1.2-py2.7.egg\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "C:\Python27\lib\site-packages\numpy\core\tests\test_umath.py", line 193, in test_nan
    assert_(np.isnan(np.logaddexp2(np.nan, np.inf)))
RuntimeWarning: invalid value encountered in logaddexp2

======================================================================
ERROR: test_complex_nans (test_umath.TestMaximum)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\numpy\core\tests\test_umath.py", line 474, in test_complex_nans
    assert_equal(np.maximum(arg1, arg2), out)
RuntimeWarning: invalid value encountered in maximum

======================================================================
ERROR: test_float_nans (test_umath.TestMaximum)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\numpy\core\tests\test_umath.py", line 466, in test_float_nans
    assert_equal(np.maximum(arg1, arg2), out)
RuntimeWarning: invalid value encountered in maximum

======================================================================
ERROR: test_complex_nans (test_umath.TestMinimum)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\numpy\core\tests\test_umath.py", line 521, in test_complex_nans
    assert_equal(np.minimum(arg1, arg2), out)
RuntimeWarning: invalid value encountered in minimum

======================================================================
ERROR: test_float_nans (test_umath.TestMinimum)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\numpy\core\tests\test_umath.py", line 513, in test_float_nans
    assert_equal(np.minimum(arg1, arg2), out)
RuntimeWarning: invalid value encountered in minimum

======================================================================
ERROR: test_umath.test_complex_nan_comparisons
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\nose-1.1.2-py2.7.egg\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "C:\Python27\lib\site-packages\numpy\core\tests\test_umath.py", line 1228, in test_complex_nan_comparisons
    assert_equal(x < y, False, err_msg="%r < %r" % (x, y))
RuntimeWarning: invalid value encountered in less

======================================================================
ERROR: test_umath_complex.TestCabs.test_fabs
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\nose-1.1.2-py2.7.egg\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "C:\Python27\lib\site-packages\numpy\core\tests\test_umath_complex.py", line 446, in test_fabs
    assert_array_equal(np.abs(x), np.real(x))
RuntimeWarning: invalid value encountered in absolute

======================================================================
ERROR: test_umath_complex.TestCabs.test_simple
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\nose-1.1.2-py2.7.egg\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "C:\Python27\lib\site-packages\numpy\core\tests\test_umath_complex.py", line 433, in test_simple
    y = np.abs(x)
RuntimeWarning: invalid value encountered in absolute

======================================================================
ERROR: Test using +/-inf bin edges works. See #1788.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\numpy\lib\tests\test_function_base.py", line 791, in test_inf_edges
    h, e = np.histogramdd(x, bins=[3, np.array([-1, 2, np.inf])])
  File "C:\Python27\lib\site-packages\numpy\lib\function_base.py", line 361, in histogramdd
    decimal))[0]
  File "C:\Python27\lib\site-packages\numpy\core\fromnumeric.py", line 2376, in around
    return round(decimals, out)
RuntimeWarning: invalid value encountered in rint

======================================================================
ERROR: Test a special case for var
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\numpy\ma\tests\test_core.py", line 2723, in test_varstd_specialcases
    _ = method(out=nout)
  File "C:\Python27\lib\site-packages\numpy\ma\core.py", line 4776, in std
    dvar = sqrt(dvar)
  File "C:\Python27\lib\site-packages\numpy\ma\core.py", line 848, in __call__
    m |= self.domain(d)
  File "C:\Python27\lib\site-packages\numpy\ma\core.py", line 800, in __call__
    return umath.less(x, self.critical_value)
RuntimeWarning: invalid value encountered in less

----------------------------------------------------------------------
Ran 3047 tests in 13.616s

FAILED (KNOWNFAIL=8, SKIP=7, errors=20)
Ralf Gommers
Owner

Doesn't look any worse. Note that I didn't post any failures other than the datetime ones, even though there are a few. The datetime ones are the only release blockers though, the other ones are easily fixed or skipped.

Han Genuit
87 commented

Could it be possible that the 64-bits functions are called with a 32-bits time type? The time_t definition in datetime_strings comes from time.h and this can be 32-bits or 64-bits depending on the version of MinGW.. (?)

There is also the issue with dates before 1970. (Which are the failures for me on Win7.)

Han Genuit
87 commented

Ralf, could you, just for testing purposes, replace time_t on line 28 with __time64_t in datetime_strings.c to see if that solves the problems with gmtime? (I think that some problems with localtime might still persist, because of the date issue.)

I don't have a windows machine at hand, at the moment..

Han Genuit
87 commented

I think the best way to deal with the pre-1970 issue is to throw a ValueError, like it is done here, when the time conversion fails.

Ralf Gommers
Owner

Doing that replacement on line 28 results in the following test failures for Python 2.7. There's less failures and not the same ones:

======================================================================
ERROR: test_datetime_array_str (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python27\lib\site-packages\numpy\core\tests\test_datetime.py", line 514, in test_datetime_array_str
    formatter={'datetime': lambda x :
  File "Z:\Users\rgommers\.wine\drive_c\Python27\lib\site-packages\numpy\core\arrayprint.py", line 459, in array2string
    separator, prefix, formatter=formatter)
  File "Z:\Users\rgommers\.wine\drive_c\Python27\lib\site-packages\numpy\core\arrayprint.py", line 259, in _array2string
    'int' : IntegerFormat(data),
  File "Z:\Users\rgommers\.wine\drive_c\Python27\lib\site-packages\numpy\core\arrayprint.py", line 658, in __init__
    len(str(minimum.reduce(data, skipna=True))))
OSError: Failed to use '_localtime64_s' to convert to a local time

======================================================================
ERROR: test_datetime_y2038 (test_datetime.TestDateTime)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python27\lib\site-packages\numpy\core\tests\test_datetime.py", line 1706, in test_datetime_y2038
    a = np.datetime64('2038-01-20T13:21:14')
OSError: Failed to use mktime to convert local time to UTC

======================================================================
ERROR: Failure: OSError (Failed to use mktime to convert local time to UTC)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Z:\Users\rgommers\.wine\drive_c\Python27\lib\site-packages\nose-0.11.4-py2.7.egg\nose\loader.py", line 382, in loadTestsFromName
    addr.filename, addr.module)
  File "Z:\Users\rgommers\.wine\drive_c\Python27\lib\site-packages\nose-0.11.4-py2.7.egg\nose\importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "Z:\Users\rgommers\.wine\drive_c\Python27\lib\site-packages\nose-0.11.4-py2.7.egg\nose\importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "Z:\Users\rgommers\.wine\drive_c\Python27\lib\site-packages\numpy\core\tests\test_multiarray.py", line 915, in <module>
    class TestArgmax(TestCase):
  File "Z:\Users\rgommers\.wine\drive_c\Python27\lib\site-packages\numpy\core\tests\test_multiarray.py", line 941, in TestArgmax
    np.datetime64('2041-12-03T14:05:03')], 5),
OSError: Failed to use mktime to convert local time to UTC
Han Genuit
87 commented

Thanks! That was what I suspected.

I think we need to solve two issues here:

  • The time_t type has to be 64-bits when the 64-bits functions are available and 32-bits when only the 32-bits functions are available. The windows time.h does this correctly, but the MinGW (old) time.h does not. So we need to correct for the MinGW time.h definitions, but only when using MinGW.

  • The acceptable date-ranges for datetime64 differ from platform to platform, but this is only noticed (at the moment) when using one of the platform-specific conversion functions. I find it strange that linux does not give the same errors as windows, because according to the man-pages, the time_t on linux also represents the EPOCH time from 1970.

What is the complete range for the numpy datetime64 specification/implementation? How are times handled that are out of the platform-supported time range?

Ralf Gommers
Owner

time.h may vary between MinGW versions. Would that be doable, or become a maintenance headache?

Not sure about out-of-range dates, @mwiebe should be able to answer that.

Han Genuit
87 commented

I think it could be a simple solution to define NPY_TIME_T as __time64_t when #if defined(__GNUC__) && defined(NPY_MINGW_USE_CUSTOM_MSVCR) [Then we are sure that MinGW is used and that it can access the 64-bits functions], though it might not look so nice in the code..

Han Genuit
87 commented

Ah, I think we might not need the __GNUC__ check.

Ralf Gommers
Owner

Would the user have to define NPY_MINGW_USE_CUSTOM_MSVCR, or can you figure that out automatically?

Han Genuit
87 commented

Yeah, it is defined automatically in mingw32ccompiler.

Mark
Collaborator

I've made a pull request for the test errors on Windows.

Regarding the 1970 epoch, datetime64 and time_t are signed integers, so datetimes before that are just fine.

Mark
Collaborator

That leaves just the MinGW-related issues. What I think is important is that the default builds of NumPy not include a Y2038 bug, which is what using the 32-bit time_t will give. Hopefully the issues can be resolved reasonably!

Han Genuit
87 commented

Hi Mark, are you sure that the localtime functions on Windows will accept a negative integer? According to their documentation, they do not.

The 64bit time range on windows is defined from the year 1970 to 3000: http://msdn.microsoft.com/en-us/library/a442x3ye.aspx.

Have you checked the validity of the datetime64 functionality on linux? Because the linux localtime might behave differently. (Although I still think there is a boundary on linux as well.)

Han Genuit
87 commented

Ah, I see what you mean. For the NumPy implementation, negative integers work perfectly fine.

Han Genuit
87 commented

I think if we force a 64-bits time_t for MinGW, the only thing left that could go wrong is when the 64-bits functionality is not available (e.g. on older platforms, like msvcr < 7).

Han Genuit
87 commented

I made a pull request that should fix the time type on (older versions of) MinGW. Together with the pull request from Mark, this will hopefully fix all the issues with datetime64.. (when available.)

Thouis (Ray) Jones thouis referenced this pull request in thouis/numpy-trac-migration
Closed

Datetime related build error on Windows (migrated from Trac #1909) #3457

numpy-gitbot numpy-gitbot referenced this pull request in thouis/numpy-trac-migration
Closed

Datetime related build error on Windows (Trac #1909) #5707

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 84 additions and 6 deletions. Show diff stats Hide diff stats

  1. +84 6 numpy/distutils/mingw32ccompiler.py
90 numpy/distutils/mingw32ccompiler.py
@@ -90,6 +90,17 @@ def __init__ (self,
90 90
91 91 build_import_library()
92 92
  93 + # Check for custom msvc runtime library on Windows. Build if it doesn't exist.
  94 + msvcr_success = build_msvcr_library()
  95 + msvcr_dbg_success = build_msvcr_library(debug=True)
  96 + if msvcr_success or msvcr_dbg_success:
  97 + # add preprocessor statement for using customized msvcr lib
  98 + self.define_macro('NPY_MINGW_USE_CUSTOM_MSVCR')
  99 +
  100 + # Define the MSVC version as hint for MinGW
  101 + msvcr_version = '0x%03i0' % int(msvc_runtime_library().lstrip('msvcr'))
  102 + self.define_macro('__MSVCRT_VERSION__', msvcr_version)
  103 +
93 104 # **changes: eric jones 4/11/01
94 105 # 2. increased optimization and turned off all warnings
95 106 # 3. also added --driver-name g++
@@ -104,7 +115,7 @@ def __init__ (self,
104 115 # bad consequences, like using Py_ModuleInit4 instead of
105 116 # Py_ModuleInit4_64, etc... So we add it here
106 117 if get_build_architecture() == 'AMD64':
107   - if self.gcc_version < "4.":
  118 + if self.gcc_version < "4.0":
108 119 self.set_executables(
109 120 compiler='gcc -g -DDEBUG -DMS_WIN64 -mno-cygwin -O0 -Wall',
110 121 compiler_so='gcc -g -DDEBUG -DMS_WIN64 -mno-cygwin -O0 -Wall -Wstrict-prototypes',
@@ -124,7 +135,7 @@ def __init__ (self,
124 135 linker_exe='g++ -mno-cygwin',
125 136 linker_so='%s -mno-cygwin -mdll -static %s'
126 137 % (self.linker, entry_point))
127   - elif self.gcc_version < "4.":
  138 + elif self.gcc_version < "4.0":
128 139 self.set_executables(compiler='gcc -mno-cygwin -O2 -Wall',
129 140 compiler_so='gcc -mno-cygwin -O2 -Wall -Wstrict-prototypes',
130 141 linker_exe='g++ -mno-cygwin',
@@ -263,15 +274,14 @@ def generate_def(dll, dfile):
263 274 The .def file will be overwritten"""
264 275 dump = dump_table(dll)
265 276 for i in range(len(dump)):
266   - if _START.match(dump[i]):
  277 + if _START.match(dump[i].decode()):
267 278 break
268   -
269   - if i == len(dump):
  279 + else:
270 280 raise ValueError("Symbol table not found")
271 281
272 282 syms = []
273 283 for j in range(i+1, len(dump)):
274   - m = _TABLE.match(dump[j])
  284 + m = _TABLE.match(dump[j].decode())
275 285 if m:
276 286 syms.append((int(m.group(1).strip()), m.group(2)))
277 287 else:
@@ -290,6 +300,74 @@ def generate_def(dll, dfile):
290 300 d.write('%s\n' % s[1])
291 301 d.close()
292 302
  303 +def find_dll(dll_name):
  304 +
  305 + def _find_dll_in_winsxs(dll_name):
  306 + # Walk through the WinSxS directory to find the dll.
  307 + winsxs_path = os.path.join(os.environ['WINDIR'], 'winsxs')
  308 + if not os.path.exists(winsxs_path):
  309 + return None
  310 + for root, dirs, files in os.walk(winsxs_path):
  311 + if dll_name in files:
  312 + return os.path.join(root, dll_name)
  313 + return None
  314 +
  315 + def _find_dll_in_path(dll_name):
  316 + # First, look in the Python directory, then scan PATH for
  317 + # the given dll name.
  318 + for path in [sys.prefix] + os.environ['PATH'].split(';'):
  319 + filepath = os.path.join(path, dll_name)
  320 + if os.path.exists(filepath):
  321 + return os.path.abspath(filepath)
  322 +
  323 + return _find_dll_in_winsxs(dll_name) or _find_dll_in_path(dll_name)
  324 +
  325 +def build_msvcr_library(debug=False):
  326 + if os.name != 'nt':
  327 + return False
  328 +
  329 + msvcr_name = msvc_runtime_library()
  330 +
  331 + # Skip using a custom library for versions < MSVC 8.0
  332 + if int(msvcr_name.lstrip('msvcr')) < 80:
  333 + log.debug('Skip building msvcr library: custom functionality not present')
  334 + return False
  335 +
  336 + if debug:
  337 + msvcr_name += 'd'
  338 +
  339 + # Skip if custom library already exists
  340 + out_name = "lib%s.a" % msvcr_name
  341 + out_file = os.path.join(sys.prefix, 'libs', out_name)
  342 + if os.path.isfile(out_file):
  343 + log.debug('Skip building msvcr library: "%s" exists' % (out_file))
  344 + return True
  345 +
  346 + # Find the msvcr dll
  347 + msvcr_dll_name = msvcr_name + '.dll'
  348 + dll_file = find_dll(msvcr_dll_name)
  349 + if not dll_file:
  350 + log.warn('Cannot build msvcr library: "%s" not found' % msvcr_dll_name)
  351 + return False
  352 +
  353 + def_name = "lib%s.def" % msvcr_name
  354 + def_file = os.path.join(sys.prefix, 'libs', def_name)
  355 +
  356 + log.info('Building msvcr library: "%s" (from %s)' \
  357 + % (out_file, dll_file))
  358 +
  359 + # Generate a symbol definition file from the msvcr dll
  360 + generate_def(dll_file, def_file)
  361 +
  362 + # Create a custom mingw library for the given symbol definitions
  363 + cmd = ['dlltool', '-d', def_file, '-l', out_file]
  364 + retcode = subprocess.call(cmd)
  365 +
  366 + # Clean up symbol definitions
  367 + os.remove(def_file)
  368 +
  369 + return (not retcode)
  370 +
293 371 def build_import_library():
294 372 if os.name != 'nt':
295 373 return

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.