Commits

mattip committed d2fa62b Merge

merge win32-fixes4, which fixes some tests on win32

Comments (0)

Files changed (12)

lib-python/2.7/test/test_genericpath.py

         unicwd = u'\xe7w\xf0'
         try:
             fsencoding = test_support.TESTFN_ENCODING or "ascii"
-            unicwd.encode(fsencoding)
+            asciival = unicwd.encode(fsencoding)
+            v = asciival.find('?')
+            if v >= 0:
+                raise UnicodeEncodeError(fsencoding, unicwd, v, v, asciival)
    1. mattip author

      This test behaves identically in cpython, fails in vanilla 2.7.6 and passes with this fix. As it causes divergence with cpython, this justifies a bug report to cpython, but I am doubtful it will be accepted.

      1. Brian Kearns

        Well, if we must diverge here, can we condition the possible test skip on a certain platform (win32)? Ie only raise UnicodeEncodeError by hand in case of win32 and find('?')?

        Out of curiousity, what is fsencoding where you are experiencing the error?

        1. mattip author

          cp1255 - hebrew. I specifically test for this in pypy/module/_codecs/test/test_codecs.py below. The issues dissapears when I change the system locale to english (control panel->Region and Language->Administrative tab->Change system locale, then reboot), I ran the tests both ways to make sure, with both cpython and pypy

         except (AttributeError, UnicodeEncodeError):
-            # FS encoding is probably ASCII
+            # FS encoding is probably ASCII or windows and codepage is non-Latin1
             pass
         else:
             with test_support.temp_cwd(unicwd):

pypy/doc/whatsnew-head.rst

 
 .. branch: refactor_PyErr_SetFromErrnoWithFilename
 Add support for PyErr_SetFromErrnoWithFilenameObject to cpyext
+
+.. branch: win32-fixes4
+fix more tests for win32

pypy/module/_codecs/test/test_codecs.py

+import sys
+
 class AppTestCodecs:
     spaceconfig = {
         "usemodules": ['unicodedata', 'struct', 'binascii'],
 
 
 class AppTestPartialEvaluation:
-    spaceconfig = dict(usemodules=('array',))
+    spaceconfig = dict(usemodules=['array',])
+    if sys.platform == 'win32':
+        spaceconfig['usemodules'].append('_winreg')
 
     def test_partial_utf8(self):
         import _codecs
         import sys
         if sys.platform != 'win32':
             return
+        toencode = u'caf\xe9', 'caf\xe9'
+        try:
+            #test for non-latin1 codepage, more general test needed
+            import _winreg
+            key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 
+                        r'System\CurrentControlSet\Control\Nls\CodePage')
+            if _winreg.QueryValueEx(key, 'ACP')[0] == u'1255': #non-latin1
+                toencode = u'caf\xbf','caf\xbf'
+        except:
+            assert False, 'cannot test mbcs on this windows system, check code page'
         assert u'test'.encode('mbcs') == 'test'
-        assert u'caf\xe9'.encode('mbcs') == 'caf\xe9'
+        assert toencode[0].encode('mbcs') == toencode[1]
         assert u'\u040a'.encode('mbcs') == '?' # some cyrillic letter
         assert 'cafx\e9'.decode('mbcs') == u'cafx\e9'
 

pypy/module/cpyext/test/test_eval.py

             ("get_flags", "METH_NOARGS",
              """
                 PyCompilerFlags flags;
+                int result;
                 flags.cf_flags = 0;
-                int result = PyEval_MergeCompilerFlags(&flags);
+                result = PyEval_MergeCompilerFlags(&flags);
                 return Py_BuildValue("ii", result, flags.cf_flags);
              """),
             ])

rpython/jit/backend/detect_cpu.py

 
 def detect_model_from_c_compiler():
     # based on http://sourceforge.net/p/predef/wiki/Architectures/
+    # and http://msdn.microsoft.com/en-us/library/b0084kay.aspx
     mapping = {
-        MODEL_X86_64: ['__amd64__', '__amd64', '__x86_64__', '__x86_64'],
-        MODEL_ARM:    ['__arm__', '__thumb__'],
-        MODEL_X86:    ['i386', '__i386', '__i386__', '__i686__'],
+        MODEL_X86_64: ['__amd64__', '__amd64', '__x86_64__', '__x86_64', '_M_X64', '_M_AMD64'],
+        MODEL_ARM:    ['__arm__', '__thumb__','_M_ARM_EP'],
+        MODEL_X86:    ['i386', '__i386', '__i386__', '__i686__','_M_IX86'],
         MODEL_PPC_64: ['__powerpc64__'],
     }
     for k, v in mapping.iteritems():

rpython/jit/backend/llgraph/runner.py

         self.args = args
 
 class CallDescr(AbstractDescr):
-    def __init__(self, RESULT, ARGS, extrainfo):
+    from rpython.rlib.clibffi import FFI_DEFAULT_ABI
+    def __init__(self, RESULT, ARGS, extrainfo, ABI=FFI_DEFAULT_ABI):
         self.RESULT = RESULT
         self.ARGS = ARGS
+        self.ABI = ABI
         self.extrainfo = extrainfo
 
     def __repr__(self):
         try:
             return self.descrs[key]
         except KeyError:
-            descr = CallDescr(RESULT, ARGS, extrainfo)
+            descr = CallDescr(RESULT, ARGS, extrainfo, ABI=cif_description.abi)
             self.descrs[key] = descr
             return descr
 
             # graph, not to directly execute the python function
             result = self.cpu.maybe_on_top_of_llinterp(func, call_args, descr.RESULT)
         else:
-            FUNC = lltype.FuncType(descr.ARGS, descr.RESULT)
+            FUNC = lltype.FuncType(descr.ARGS, descr.RESULT, descr.ABI)
             func_to_call = rffi.cast(lltype.Ptr(FUNC), func)
             result = func_to_call(*call_args)
         del self.force_guard_op

rpython/jit/backend/llsupport/test/test_rewrite.py

File contents unchanged.

rpython/jit/metainterp/test/test_ajit.py

 from rpython.rlib.longlong2float import float2longlong, longlong2float
 from rpython.rlib.rarithmetic import ovfcheck, is_valid_int
 from rpython.rtyper.lltypesystem import lltype, rffi
+from rpython.translator.tool.cbuild import ExternalCompilationInfo
 
 
 class BasicTests:
         self.check_resops(arraylen_gc=2)
 
     def test_release_gil_flush_heap_cache(self):
+        eci = ExternalCompilationInfo()
         if sys.platform == "win32":
-            py.test.skip("needs 'time'")
+            eci = ExternalCompilationInfo(libraries=["msvcrt"])
         T = rffi.CArrayPtr(rffi.TIME_T)
 
-        external = rffi.llexternal("time", [T], rffi.TIME_T, releasegil=True)
+        external = rffi.llexternal("time", [T], rffi.TIME_T, releasegil=True, compilation_info=eci)
         # Not a real lock, has all the same properties with respect to GIL
         # release though, so good for this test.
         class Lock(object):
         self.interp_operations(f, [])
 
     def test_external_call(self):
+        eci = ExternalCompilationInfo()
+        if sys.platform == "win32":
+            eci = ExternalCompilationInfo(libraries=["msvcrt"])
         from rpython.rlib.objectmodel import invoke_around_extcall
 
         T = rffi.CArrayPtr(rffi.TIME_T)
-        external = rffi.llexternal("time", [T], rffi.TIME_T)
+        external = rffi.llexternal("time", [T], rffi.TIME_T, compilation_info=eci)
 
         class Oups(Exception):
             pass

rpython/rlib/test/test_clibffi.py

     def setup_class(cls):
         if sys.platform != 'win32':
             py.test.skip("Handle to libc library, Win-only test")
-        BaseFfiTest.setup_class(cls)
+        BaseFfiTest.setup_class()
     
     def test_get_libc_handle(self):
         handle = get_libc_handle()
         print get_libc_name()
-        print hex(handle)
-        assert handle != 0
-        assert handle % 0x1000 == 0
+        print dir(handle)
+        addr = rffi.cast(rffi.INT, handle)
+        assert addr != 0
+        assert addr % 0x1000 == 0

rpython/rlib/test/test_rposix.py

     def as_unicode(self):
         return self.unistr
 
-class BasePosixUnicode:
+class BasePosixUnicodeOrAscii:
     def setup_method(self, method):
         self.ufilename = self._get_filename()
         try:
             py.test.skip("encoding not good enough")
         f.write("test")
         f.close()
-
-        self.path  = UnicodeWithEncoding(self.ufilename)
-        self.path2 = UnicodeWithEncoding(self.ufilename + ".new")
+        if sys.platform == 'win32' and isinstance(self.ufilename, str):
+            self.path = self.ufilename
+            self.path2 = self.ufilename + ".new"
+        else:
+            self.path  = UnicodeWithEncoding(self.ufilename)
+            self.path2 = UnicodeWithEncoding(self.ufilename + ".new")
 
     def test_open(self):
         def f():
     def test_stat(self):
         def f():
             return rposix.stat(self.path).st_mtime
-
-        assert interpret(f, []) == os.stat(self.ufilename).st_mtime
+        if sys.platform == 'win32':
+            #double vs. float, be satisfied with sub-millisec resolution
+            assert abs(interpret(f, []) - os.stat(self.ufilename).st_mtime) < 1e-4
+        else:    
+            assert interpret(f, []) == os.stat(self.ufilename).st_mtime
 
     def test_access(self):
         def f():
 
         if sys.platform == 'win32':
             def f():
-                return u', '.join(rposix.listdir(udir))
+                if isinstance(udir.as_unicode(), str):
+                    _udir = udir.as_unicode()
+                else:
+                    _udir = udir
+                return u', '.join(rposix.listdir(_udir))
             result = interpret(f, [])
             assert os.path.basename(self.ufilename) in ll_to_string(result)
         else:
         interpret(f, []) # does not crash
 
 
-class TestPosixAscii(BasePosixUnicode):
+class TestPosixAscii(BasePosixUnicodeOrAscii):
     def _get_filename(self):
         return str(udir.join('test_open_ascii'))
 
-class TestPosixUnicode(BasePosixUnicode):
+class TestPosixUnicode(BasePosixUnicodeOrAscii):
     def _get_filename(self):
         return (unicode(udir.join('test_open')) +
                 u'\u65e5\u672c.txt') # "Japan"

rpython/rtyper/lltypesystem/ll2ctypes.py

 
     if isinstance(T, lltype.Ptr):
         if isinstance(T.TO, lltype.FuncType):
+            
+            functype = ctypes.CFUNCTYPE
+            if sys.platform == 'win32':
+                from rpython.rlib.clibffi import FFI_STDCALL, FFI_DEFAULT_ABI
+                if getattr(T.TO, 'ABI', FFI_DEFAULT_ABI) == FFI_STDCALL:
+                    # for win32 system call
+                    functype = ctypes.WINFUNCTYPE
             argtypes = [get_ctypes_type(ARG) for ARG in T.TO.ARGS
                         if ARG is not lltype.Void]
             if T.TO.RESULT is lltype.Void:
                 restype = get_ctypes_type(T.TO.RESULT)
             try:
                 kwds = {'use_errno': True}
-                return ctypes.CFUNCTYPE(restype, *argtypes, **kwds)
+                return functype(restype, *argtypes, **kwds)
             except TypeError:
                 # unexpected 'use_errno' argument, old ctypes version
-                return ctypes.CFUNCTYPE(restype, *argtypes)
+                return functype(restype, *argtypes)
         elif isinstance(T.TO, lltype.OpaqueType):
             return ctypes.c_void_p
         else:

rpython/rtyper/lltypesystem/lltype.py

 class FuncType(ContainerType):
     _gckind = 'raw'
     __name__ = 'func'
-    def __init__(self, args, result):
+    def __init__(self, args, result, abi='FFI_DEFAULT_ABI'):
         for arg in args:
             assert isinstance(arg, LowLevelType)
             # There are external C functions eating raw structures, not
         if isinstance(result, ContainerType):
             raise TypeError, "function result can only be primitive or pointer"
         self.RESULT = result
+        self.ABI = abi
 
     def __str__(self):
         args = ', '.join(map(str, self.ARGS))