Skip to content

MinGW enhancements for datetime functionality. #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed

Conversation

87
Copy link
Contributor

@87 87 commented Sep 14, 2011

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.

@rgommers
Copy link
Member

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

@rgommers
Copy link
Member

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

@87
Copy link
Contributor Author

87 commented Sep 14, 2011

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..

@rgommers
Copy link
Member

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

@87
Copy link
Contributor Author

87 commented Sep 14, 2011

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.

@87
Copy link
Contributor Author

87 commented Sep 14, 2011

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)

@87
Copy link
Contributor Author

87 commented Sep 14, 2011

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

@rgommers
Copy link
Member

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

@rgommers
Copy link
Member

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

@rgommers
Copy link
Member

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

@87
Copy link
Contributor Author

87 commented Sep 14, 2011

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

I'll look into the paver build, thanks!

@87
Copy link
Contributor Author

87 commented Sep 14, 2011

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

@rgommers
Copy link
Member

Same segfault with your build command.

@rgommers
Copy link
Member

$ 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:~ $

@87
Copy link
Contributor Author

87 commented Sep 14, 2011

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.

@rgommers
Copy link
Member

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

@87
Copy link
Contributor Author

87 commented Sep 14, 2011

[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?

@rgommers
Copy link
Member

 >>> >>> 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

@rgommers
Copy link
Member

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

@87
Copy link
Contributor Author

87 commented Sep 14, 2011

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..

@rgommers
Copy link
Member

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.

@87
Copy link
Contributor Author

87 commented Sep 14, 2011

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.

@87
Copy link
Contributor Author

87 commented Sep 14, 2011

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.

@87
Copy link
Contributor Author

87 commented Sep 15, 2011

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..

@rgommers
Copy link
Member

This works!

@rgommers
Copy link
Member

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.

@rgommers
Copy link
Member

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

defined(__GNUC__) && \
(defined(NPY_MINGW_USE_CUSTOM_MSVCR) | \
defined(NPY_MINGW_USE_64BIT_MSVCR))
#define time_t __time64_t
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks, I didn't know that!

@87
Copy link
Contributor Author

87 commented Feb 17, 2012

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

@87
Copy link
Contributor Author

87 commented Feb 17, 2012

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.

@87
Copy link
Contributor Author

87 commented Feb 17, 2012

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?

@rgommers
Copy link
Member

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

@rgommers
Copy link
Member

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

@mwiebe
Copy link
Member

mwiebe commented Feb 17, 2012

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)

@rgommers
Copy link
Member

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.

@87
Copy link
Contributor Author

87 commented Feb 18, 2012

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.)

@87
Copy link
Contributor Author

87 commented Feb 18, 2012

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..

@87
Copy link
Contributor Author

87 commented Feb 18, 2012

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.

@rgommers
Copy link
Member

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

@87
Copy link
Contributor Author

87 commented Feb 18, 2012

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?

@rgommers
Copy link
Member

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.

@87
Copy link
Contributor Author

87 commented Feb 19, 2012

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..

@87
Copy link
Contributor Author

87 commented Feb 19, 2012

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

@rgommers
Copy link
Member

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

@87
Copy link
Contributor Author

87 commented Feb 19, 2012

Yeah, it is defined automatically in mingw32ccompiler.

@mwiebe
Copy link
Member

mwiebe commented Feb 19, 2012

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.

@mwiebe
Copy link
Member

mwiebe commented Feb 19, 2012

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!

@87
Copy link
Contributor Author

87 commented Feb 20, 2012

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.)

@87
Copy link
Contributor Author

87 commented Feb 20, 2012

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

@87
Copy link
Contributor Author

87 commented Feb 20, 2012

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).

@87
Copy link
Contributor Author

87 commented Feb 20, 2012

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants