Commits

Philip Jenvey committed f1b5863 Merge

merge default

Comments (0)

Files changed (15)

lib_pypy/cffi/api.py

     backend = ffi._backend
     try:
         if '.' not in name and '/' not in name:
-            raise OSError
+            raise OSError("library not found: %r" % (name,))
         backendlib = backend.load_library(name, flags)
     except OSError:
         import ctypes.util
         path = ctypes.util.find_library(name)
         if path is None:
-            raise OSError("library not found: %r" % (name,))
+            raise     # propagate the original OSError
         backendlib = backend.load_library(path, flags)
     copied_enums = []
     #

pypy/interpreter/baseobjspace.py

File contents unchanged.

pypy/interpreter/mixedmodule.py

File contents unchanged.

pypy/module/_cffi_backend/ctypefunc.py

                "with verify() (see pypy/module/_cffi_backend/ctypefunc.py "
                "for details)"))
 
-        if USE_C_LIBFFI_MSVC and is_result_type:
-            # MSVC returns small structures in registers.  Pretend int32 or
-            # int64 return type.  This is needed as a workaround for what
-            # is really a bug of libffi_msvc seen as an independent library
-            # (ctypes has a similar workaround).
-            if ctype.size <= 4:
-                return clibffi.ffi_type_sint32
-            if ctype.size <= 8:
-                return clibffi.ffi_type_sint64
-
         # walk the fields, expanding arrays into repetitions; first,
         # only count how many flattened fields there are
         nflat = 0
                                "a struct with a zero-length array"))
             nflat += flat
 
+        if USE_C_LIBFFI_MSVC and is_result_type:
+            # MSVC returns small structures in registers.  Pretend int32 or
+            # int64 return type.  This is needed as a workaround for what
+            # is really a bug of libffi_msvc seen as an independent library
+            # (ctypes has a similar workaround).
+            if ctype.size <= 4:
+                return clibffi.ffi_type_sint32
+            if ctype.size <= 8:
+                return clibffi.ffi_type_sint64
+
         # allocate an array of (nflat + 1) ffi_types
         elements = self.fb_alloc(rffi.sizeof(FFI_TYPE_P) * (nflat + 1))
         elements = rffi.cast(FFI_TYPE_PP, elements)

pypy/module/imp/importing.py

File contents unchanged.

pypy/module/imp/test/test_app.py

                     pass
             rmtree(dir_name, True)
 
+    def test_builtin_reimport(self):
+        # from https://bugs.pypy.org/issue1514
+        skip("fix me")
+        import sys, marshal
+
+        old = marshal.loads
+        marshal.loads = 42
+
+        # save, re-import, restore.
+        saved = sys.modules.pop('marshal')
+        __import__('marshal')
+        sys.modules['marshal'] = saved
+
+        assert marshal.loads == 42
+        import marshal
+        assert marshal.loads == 42
+        marshal.loads = old
+
+    def test_builtin_reimport_mess(self):
+        # taken from https://bugs.pypy.org/issue1514, with extra cases
+        # that show a difference with CPython: we can get on CPython
+        # several module objects for the same built-in module :-(
+        skip("several built-in module objects: not supported by pypy")
+        import sys, marshal
+
+        old = marshal.loads
+        marshal.loads = 42
+
+        # save, re-import, restore.
+        saved = sys.modules.pop('marshal')
+        marshal2 = __import__('marshal')
+        assert marshal2 is not marshal
+        assert marshal2.loads is old
+        assert marshal2 is sys.modules['marshal']
+        assert marshal is saved
+        assert marshal.loads == 42
+
+        import marshal
+        assert marshal.loads is old
+
+        sys.modules['marshal'] = saved
+        import marshal
+        assert marshal.loads == 42
+
+        marshal.loads = old
+
     def test_get_tag(self):
         import imp
         import sys

pypy/module/imp/test/test_import.py

         assert sys.path is oldpath
         assert 'settrace' in dir(sys)
 
+    def test_reload_builtin_doesnt_clear(self):
+        import sys
+        sys.foobar = "baz"
+        reload(sys)
+        assert sys.foobar == "baz"
+
+    def test_reimport_builtin_simple_case_1(self):
+        import sys, time
+        del time.tzset
+        del sys.modules['time']
+        import time
+        assert hasattr(time, 'tzset')
+
+    def test_reimport_builtin_simple_case_2(self):
+        skip("fix me")
+        import sys, time
+        time.foo = "bar"
+        del sys.modules['time']
+        import time
+        assert not hasattr(time, 'foo')
+
+    def test_reimport_builtin(self):
+        skip("fix me")
+        import sys, time
+        oldpath = sys.path
+        time.tzset = "<test_reimport_builtin removed this>"
+
+        del sys.modules['time']
+        import time as time1
+        assert sys.modules['time'] is time1
+
+        assert time.tzset == "<test_reimport_builtin removed this>"
+
+        reload(time1)   # don't leave a broken time.tzset behind
+        import time
+        assert time.tzset != "<test_reimport_builtin removed this>"
+
     def test_reload_infinite(self):
         import infinite_reload
 

pypy/module/sys/__init__.py

         '_xoptions'             : 'app.null__xoptions',
     }
 
-    def setbuiltinmodule(self, w_module, name):
-        w_name = self.space.wrap(name)
-        w_modules = self.get('modules')
-        self.space.setitem(w_modules, w_name, w_module)
-
     def startup(self, space):
         if space.config.translating and not we_are_translated():
             # don't get the filesystemencoding at translation time

pypy/module/sys/app.py

     try:
         # first try to print the exception's class name
         stderr = sys.stderr
-        stderr.write(getattr(exctype, '__name__', exctype))
+        stderr.write(str(getattr(exctype, '__name__', exctype)))
         # then attempt to get the str() of the exception
         try:
             s = str(value)
         except:
             s = '<failure of str() on the exception instance>'
-        # then print it, and don't worry too much about the extra space
-        # between the exception class and the ':'
+        # then print it
         if s:
             stderr.write(': %s\n' % (s,))
         else:

pypy/module/test_lib_pypy/cffi_tests/test_ffi_backend.py

 
 class TestBitfield:
     def check(self, source, expected_ofs_y, expected_align, expected_size):
+        # NOTE: 'expected_*' is the numbers expected from GCC.
+        # The numbers expected from MSVC are not explicitly written
+        # in this file, and will just be taken from the compiler.
         ffi = FFI()
         ffi.cdef("struct s1 { %s };" % source)
         ctype = ffi.typeof("struct s1")
         # verify the information with gcc
-        if sys.platform != "win32":
-            ffi1 = FFI()
-            ffi1.cdef("""
-                static const int Gofs_y, Galign, Gsize;
-                struct s1 *try_with_value(int fieldnum, long long value);
-            """)
-            fnames = [name for name, cfield in ctype.fields
-                           if name and cfield.bitsize > 0]
-            setters = ['case %d: s.%s = value; break;' % iname
-                       for iname in enumerate(fnames)]
-            lib = ffi1.verify("""
-                struct s1 { %s };
-                struct sa { char a; struct s1 b; };
-                #define Gofs_y  offsetof(struct s1, y)
-                #define Galign  offsetof(struct sa, b)
-                #define Gsize   sizeof(struct s1)
-                struct s1 *try_with_value(int fieldnum, long long value)
-                {
-                    static struct s1 s;
-                    memset(&s, 0, sizeof(s));
-                    switch (fieldnum) { %s }
-                    return &s;
-                }
-            """ % (source, ' '.join(setters)))
-            assert lib.Gofs_y == expected_ofs_y
-            assert lib.Galign == expected_align
-            assert lib.Gsize  == expected_size
+        ffi1 = FFI()
+        ffi1.cdef("""
+            static const int Gofs_y, Galign, Gsize;
+            struct s1 *try_with_value(int fieldnum, long long value);
+        """)
+        fnames = [name for name, cfield in ctype.fields
+                       if name and cfield.bitsize > 0]
+        setters = ['case %d: s.%s = value; break;' % iname
+                   for iname in enumerate(fnames)]
+        lib = ffi1.verify("""
+            struct s1 { %s };
+            struct sa { char a; struct s1 b; };
+            #define Gofs_y  offsetof(struct s1, y)
+            #define Galign  offsetof(struct sa, b)
+            #define Gsize   sizeof(struct s1)
+            struct s1 *try_with_value(int fieldnum, long long value)
+            {
+                static struct s1 s;
+                memset(&s, 0, sizeof(s));
+                switch (fieldnum) { %s }
+                return &s;
+            }
+        """ % (source, ' '.join(setters)))
+        if sys.platform == 'win32':
+            expected_ofs_y = lib.Gofs_y
+            expected_align = lib.Galign
+            expected_size  = lib.Gsize
         else:
-            lib = None
-            fnames = None
+            assert (lib.Gofs_y, lib.Galign, lib.Gsize) == (
+                expected_ofs_y, expected_align, expected_size)
         # the real test follows
         assert ffi.offsetof("struct s1", "y") == expected_ofs_y
         assert ffi.alignof("struct s1") == expected_align
         setattr(s, name, value)
         assert getattr(s, name) == value
         raw1 = ffi.buffer(s)[:]
-        if lib is not None:
-            t = lib.try_with_value(fnames.index(name), value)
-            raw2 = ffi.buffer(t, len(raw1))[:]
-            assert raw1 == raw2
+        t = lib.try_with_value(fnames.index(name), value)
+        raw2 = ffi.buffer(t, len(raw1))[:]
+        assert raw1 == raw2
 
     def test_bitfield_basic(self):
         self.check("int a; int b:9; int c:20; int y;", 8, 4, 12)
         L = FFI().alignof("long long")
         self.check("char y; int :0;", 0, 1, 4)
         self.check("char x; int :0; char y;", 4, 1, 5)
+        self.check("char x; int :0; int :0; char y;", 4, 1, 5)
         self.check("char x; long long :0; char y;", L, 1, L + 1)
         self.check("short x, y; int :0; int :0;", 2, 2, 4)
         self.check("char x; int :0; short b:1; char y;", 5, 2, 6)
+        self.check("int a:1; int :0; int b:1; char y;", 5, 4, 8)
 
     def test_error_cases(self):
         ffi = FFI()

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

 import weakref
 from rpython.rlib.jit import JitDriver, dont_look_inside
 from rpython.jit.backend.llsupport.test.zrpy_gc_test import run, get_entry, compile
-from rpython.jit.backend.llsupport.test.ztranslation_test import fix_annotator_for_vrawbuffer
 
 class X(object):
     def __init__(self, x=0):
     g._dont_inline_ = True
     return g
 
-def compile_boehm_test(monkeypatch):
-    fix_annotator_for_vrawbuffer(monkeypatch)
+def compile_boehm_test():
     myjitdriver = JitDriver(greens = [], reds = ['n', 'x'])
     @dont_look_inside
     def see(lst, n):

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

 from rpython.jit.codewriter.policy import StopAtXPolicy
 
 
-def fix_annotator_for_vrawbuffer(monkeypatch):
-    from rpython.rlib.nonconst import NonConstant
-    from rpython.jit.metainterp.optimizeopt.virtualize import VRawBufferValue
-    from rpython.jit.metainterp import warmspot
-
-    def my_hook_for_tests(cpu):
-        # this is needed so that the annotator can see it
-        if NonConstant(False):
-            v = VRawBufferValue(cpu, None, -1, None, None)
-    monkeypatch.setattr(warmspot, 'hook_for_tests', my_hook_for_tests)
-
-
 class TranslationTest(CCompiledMixin):
     CPUClass = getcpuclass()
 
-    def test_stuff_translates(self, monkeypatch):
-        fix_annotator_for_vrawbuffer(monkeypatch)
+    def test_stuff_translates(self):
         # this is a basic test that tries to hit a number of features and their
         # translation:
         # - jitting of loops and bridges
 class TranslationTestCallAssembler(CCompiledMixin):
     CPUClass = getcpuclass()
 
-    def test_direct_assembler_call_translates(self, monkeypatch):
+    def test_direct_assembler_call_translates(self):
         """Test CALL_ASSEMBLER and the recursion limit"""
         from rpython.rlib.rstackovf import StackOverflow
-        fix_annotator_for_vrawbuffer(monkeypatch)
 
         class Thing(object):
             def __init__(self, val):
 class TranslationTestJITStats(CCompiledMixin):
     CPUClass = getcpuclass()
 
-    def test_jit_get_stats(self, monkeypatch):
-        fix_annotator_for_vrawbuffer(monkeypatch)
+    def test_jit_get_stats(self):
         driver = JitDriver(greens = [], reds = ['i'])
 
         def f():
 class TranslationRemoveTypePtrTest(CCompiledMixin):
     CPUClass = getcpuclass()
 
-    def test_external_exception_handling_translates(self, monkeypatch):
-        fix_annotator_for_vrawbuffer(monkeypatch)
+    def test_external_exception_handling_translates(self):
         jitdriver = JitDriver(greens = [], reds = ['n', 'total'])
 
         class ImDone(Exception):

rpython/jit/metainterp/optimizeopt/virtualize.py

     _attrs_ = ('keybox', 'source_op', '_cached_vinfo')
     box = None
     level = optimizer.LEVEL_NONNULL
+    is_about_raw = False
     _cached_vinfo = None
 
     def __init__(self, keybox, source_op=None):
 
 
 class VRawBufferValue(AbstractVArrayValue):
+    is_about_raw = True
 
     def __init__(self, cpu, logops, size, keybox, source_op):
         AbstractVirtualValue.__init__(self, keybox, source_op)
 
 
 class VRawSliceValue(AbstractVirtualValue):
+    is_about_raw = True
 
     def __init__(self, rawbuffer_value, offset, keybox, source_op):
         AbstractVirtualValue.__init__(self, keybox, source_op)
         offsetbox = self.get_constant_box(op.getarg(1))
         if value.is_virtual() and offsetbox is not None:
             offset = offsetbox.getint()
-            if isinstance(value, VRawBufferValue):
-                self.make_virtual_raw_slice(value, offset, op.result, op)
-                return
-            elif isinstance(value, VRawSliceValue):
-                offset = offset + value.offset
-                self.make_virtual_raw_slice(value.rawbuffer_value, offset, op.result, op)
-                return
+            # the following check is constant-folded to False if the
+            # translation occurs without any VRawXxxValue instance around
+            if value.is_about_raw:
+                if isinstance(value, VRawBufferValue):
+                    self.make_virtual_raw_slice(value, offset, op.result, op)
+                    return
+                elif isinstance(value, VRawSliceValue):
+                    offset = offset + value.offset
+                    self.make_virtual_raw_slice(value.rawbuffer_value, offset,
+                                                op.result, op)
+                    return
         self.emit_operation(op)
 
     def optimize_ARRAYLEN_GC(self, op):

rpython/jit/metainterp/resume.py

 
 class AbstractVirtualInfo(object):
     kind = REF
+    is_about_raw = False
     #def allocate(self, decoder, index):
     #    raise NotImplementedError
     def equals(self, fieldnums):
 
     def debug_prints(self):
         raise NotImplementedError
-        
+
 
 class AbstractVirtualStructInfo(AbstractVirtualInfo):
     def __init__(self, fielddescrs):
 
 class VRawBufferStateInfo(AbstractVirtualInfo):
     kind = INT
+    is_about_raw = True
     
     def __init__(self, size, offsets, descrs):
         self.size = size
         assert self.virtuals_cache is not None
         v = self.virtuals_cache.get_int(index)
         if not v:
-            v = self.rd_virtuals[index].allocate_int(self, index)
+            v = self.rd_virtuals[index]
+            assert v.is_about_raw and isinstance(v, VRawBufferStateInfo)
+            v = v.allocate_int(self, index)
             ll_assert(v == self.virtuals_cache.get_int(index), "resume.py: bad cache")
         return v
 

rpython/jit/metainterp/warmspot.py

         cpu = jd.warmstate.cpu
 
         def ll_portal_runner(*args):
-            hook_for_tests(cpu) # usually it's empty, but tests can monkeypatch
-                                # it to fix the annotator
             start = True
             while 1:
                 try:
         graphs = self.translator.graphs
         for graph, block, i in find_force_quasi_immutable(graphs):
             self.replace_force_quasiimmut_with_direct_call(block.operations[i])
-
-def hook_for_tests(cpu):
-    """
-    This function is empty and does nothing. Its only role is to be
-    monkey-patched by tests to "fix" the annotator if needed (see
-    e.g. x86/test/test_ztranslation::test_external_exception_handling_translates
-    """