Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r76052:ce0ca1b30216
Date: 2015-02-22 17:23 +0100
http://bitbucket.org/pypy/pypy/changeset/ce0ca1b30216/

Log:    merge heads

diff --git a/pypy/module/zipimport/interp_zipimport.py 
b/pypy/module/zipimport/interp_zipimport.py
--- a/pypy/module/zipimport/interp_zipimport.py
+++ b/pypy/module/zipimport/interp_zipimport.py
@@ -199,8 +199,7 @@
         magic = importing._get_long(buf[:4])
         timestamp = importing._get_long(buf[4:8])
         if not self.can_use_pyc(space, filename, magic, timestamp):
-            return self.import_py_file(space, modname, filename[:-1], buf,
-                                       pkgpath)
+            return None
         buf = buf[8:] # XXX ugly copy, should use sequential read instead
         w_mod = w(Module(space, w(modname)))
         real_name = self.filename + os.path.sep + self.corr_zname(filename)
@@ -249,7 +248,6 @@
     def load_module(self, space, fullname):
         w = space.wrap
         filename = self.make_filename(fullname)
-        last_exc = None
         for compiled, is_package, ext in ENUMERATE_EXTS:
             fname = filename + ext
             try:
@@ -268,19 +266,18 @@
                     pkgpath = None
                 try:
                     if compiled:
-                        return self.import_pyc_file(space, fullname, fname,
-                                                    buf, pkgpath)
+                        w_result = self.import_pyc_file(space, fullname, fname,
+                                                        buf, pkgpath)
+                        if w_result is not None:
+                            return w_result
                     else:
                         return self.import_py_file(space, fullname, fname,
                                                    buf, pkgpath)
-                except OperationError, e:
-                    last_exc = e
+                except:
                     w_mods = space.sys.get('modules')
-                space.call_method(w_mods, 'pop', w(fullname), space.w_None)
-        if last_exc:
-            raise OperationError(get_error(space), last_exc.get_w_value(space))
-        # should never happen I think
-        return space.w_None
+                    space.call_method(w_mods, 'pop', w(fullname), space.w_None)
+                    raise
+        raise oefmt(get_error(space), "can't find module '%s'", fullname)
 
     @unwrap_spec(filename=str)
     def get_data(self, space, filename):
diff --git a/pypy/module/zipimport/test/test_zipimport.py 
b/pypy/module/zipimport/test/test_zipimport.py
--- a/pypy/module/zipimport/test/test_zipimport.py
+++ b/pypy/module/zipimport/test/test_zipimport.py
@@ -195,7 +195,8 @@
         m0 ^= 0x04
         test_pyc = chr(m0) + self.test_pyc[1:]
         self.writefile("uu.pyc", test_pyc)
-        raises(ImportError, "__import__('uu', globals(), locals(), [])")
+        raises(zipimport.ZipImportError,
+               "__import__('uu', globals(), locals(), [])")
         assert 'uu' not in sys.modules
 
     def test_force_py(self):
@@ -360,6 +361,11 @@
         co_filename = code.co_filename
         assert co_filename == expected
 
+    def test_import_exception(self):
+        self.writefile('x1test.py', '1/0')
+        self.writefile('x1test/__init__.py', 'raise ValueError')
+        raises(ValueError, __import__, 'x1test', None, None, [])
+
 
 if os.sep != '/':
     class AppTestNativePathSep(AppTestZipimport):
diff --git a/rpython/jit/backend/arm/arch.py b/rpython/jit/backend/arm/arch.py
--- a/rpython/jit/backend/arm/arch.py
+++ b/rpython/jit/backend/arm/arch.py
@@ -1,4 +1,3 @@
-FUNC_ALIGN = 8
 WORD = 4
 DOUBLE_WORD = 8
 
diff --git a/rpython/jit/backend/arm/assembler.py 
b/rpython/jit/backend/arm/assembler.py
--- a/rpython/jit/backend/arm/assembler.py
+++ b/rpython/jit/backend/arm/assembler.py
@@ -4,7 +4,7 @@
 
 from rpython.jit.backend.arm import conditions as c, registers as r
 from rpython.jit.backend.arm import shift
-from rpython.jit.backend.arm.arch import (WORD, DOUBLE_WORD, FUNC_ALIGN,
+from rpython.jit.backend.arm.arch import (WORD, DOUBLE_WORD,
     JITFRAME_FIXED_SIZE)
 from rpython.jit.backend.arm.codebuilder import InstrBuilder, 
OverwritingBuilder
 from rpython.jit.backend.arm.locations import imm, StackLocation, get_fp_offset
@@ -484,10 +484,6 @@
         self.mc.BL(target)
         return startpos
 
-    def align(self):
-        while(self.mc.currpos() % FUNC_ALIGN != 0):
-            self.mc.writechar(chr(0))
-
     def gen_func_epilog(self, mc=None, cond=c.AL):
         gcrootmap = self.cpu.gc_ll_descr.gcrootmap
         if mc is None:
@@ -557,7 +553,7 @@
         debug_stop('jit-backend-ops')
 
     def _call_header(self):
-        self.align()
+        assert self.currpos() == 0
         self.gen_func_prolog()
 
     def _call_header_with_stack_check(self):
diff --git a/rpython/jit/backend/arm/codebuilder.py 
b/rpython/jit/backend/arm/codebuilder.py
--- a/rpython/jit/backend/arm/codebuilder.py
+++ b/rpython/jit/backend/arm/codebuilder.py
@@ -1,7 +1,7 @@
 from rpython.jit.backend.arm import conditions as cond
 from rpython.jit.backend.arm import registers as reg
 from rpython.jit.backend.arm import support
-from rpython.jit.backend.arm.arch import (WORD, FUNC_ALIGN, PC_OFFSET)
+from rpython.jit.backend.arm.arch import WORD, PC_OFFSET
 from rpython.jit.backend.arm.instruction_builder import define_instructions
 from rpython.jit.backend.llsupport.asmmemmgr import BlockBuilderMixin
 from rpython.rlib.objectmodel import we_are_translated
@@ -29,14 +29,9 @@
 
 
 class AbstractARMBuilder(object):
-
     def __init__(self, arch_version=7):
         self.arch_version = arch_version
 
-    def align(self):
-        while(self.currpos() % FUNC_ALIGN != 0):
-            self.writechar(chr(0))
-
     def NOP(self):
         self.MOV_rr(0, 0)
 
@@ -467,21 +462,6 @@
                 f.write(data[i])
             f.close()
 
-    # XXX remove and setup aligning in llsupport
-    def materialize(self, asmmemmgr, allblocks, gcrootmap=None):
-        size = self.get_relative_pos() + WORD
-        malloced = asmmemmgr.malloc(size, size + 7)
-        allblocks.append(malloced)
-        rawstart = malloced[0]
-        while(rawstart % FUNC_ALIGN != 0):
-            rawstart += 1
-        self.copy_to_raw_memory(rawstart)
-        if self.gcroot_markers is not None:
-            assert gcrootmap is not None
-            for pos, mark in self.gcroot_markers:
-                gcrootmap.put(rawstart + pos, mark)
-        return rawstart
-
     def clear_cache(self, addr):
         if we_are_translated():
             startaddr = rffi.cast(llmemory.Address, addr)
diff --git a/rpython/jit/backend/llsupport/asmmemmgr.py 
b/rpython/jit/backend/llsupport/asmmemmgr.py
--- a/rpython/jit/backend/llsupport/asmmemmgr.py
+++ b/rpython/jit/backend/llsupport/asmmemmgr.py
@@ -208,6 +208,8 @@
                    ('data', lltype.FixedSizeArray(lltype.Char, SUBBLOCK_SIZE)))
     SUBBLOCK_PTR.TO.become(SUBBLOCK)
 
+    ALIGN_MATERIALIZE = 16
+
     gcroot_markers = None
 
     def __init__(self, translated=None):
@@ -303,9 +305,12 @@
 
     def materialize(self, asmmemmgr, allblocks, gcrootmap=None):
         size = self.get_relative_pos()
+        align = self.ALIGN_MATERIALIZE
+        size += align - 1
         malloced = asmmemmgr.malloc(size, size)
         allblocks.append(malloced)
         rawstart = malloced[0]
+        rawstart = (rawstart + align - 1) & (-align)
         self.copy_to_raw_memory(rawstart)
         if self.gcroot_markers is not None:
             assert gcrootmap is not None
diff --git a/rpython/rlib/ropenssl.py b/rpython/rlib/ropenssl.py
--- a/rpython/rlib/ropenssl.py
+++ b/rpython/rlib/ropenssl.py
@@ -56,9 +56,9 @@
 ASN1_OBJECT = rffi.COpaquePtr('ASN1_OBJECT')
 X509_NAME = rffi.COpaquePtr('X509_NAME')
 X509_VERIFY_PARAM = rffi.COpaquePtr('X509_VERIFY_PARAM')
-stack_st_X509_OBJECT = rffi.COpaquePtr('struct stack_st_X509_OBJECT')
+stack_st_X509_OBJECT = rffi.COpaquePtr('STACK_OF(X509_OBJECT)')
 DIST_POINT = rffi.COpaquePtr('DIST_POINT')
-stack_st_DIST_POINT = rffi.COpaquePtr('struct stack_st_DIST_POINT')
+stack_st_DIST_POINT = rffi.COpaquePtr('STACK_OF(X509_OBJECT)')
 DH = rffi.COpaquePtr('DH')
 EC_KEY = rffi.COpaquePtr('EC_KEY')
 AUTHORITY_INFO_ACCESS = rffi.COpaquePtr('AUTHORITY_INFO_ACCESS')
diff --git a/rpython/tool/ansi_mandelbrot.py b/rpython/tool/ansi_mandelbrot.py
--- a/rpython/tool/ansi_mandelbrot.py
+++ b/rpython/tool/ansi_mandelbrot.py
@@ -21,22 +21,15 @@
 else:
     palette = [39, 34, 35, 36, 31, 33, 32, 37]
 
-colour_range = None # used for debugging
-
-
-def print_pixel(colour, value_range, invert=1):
-    global colour_range
-    chars = [".", ".", "+", "*", "%", "#"]
-    idx = lambda chars: (colour+1) * (len(chars) - 1) / value_range
-    if invert:
-        idx = lambda chars, idx=idx:len(chars) - 1 - idx(chars)
-    char = chars[idx(chars)]
-    ansi_colour = palette[idx(palette)]
-    ansi_print(char, ansi_colour, newline=False, flush=True)
-    #if colour_range is None:
-    #    colour_range = [colour, colour]
-    #else:
-    #    colour_range = [min(colour_range[0], colour), max(colour_range[1], 
colour)]
+# used for debugging/finding new coordinates
+# How to:
+#   1. Set DEBUG to True
+#   2. Add a new coordinate to coordinates with a high distance and high max 
colour (e.g. 300)
+#   3. Run, pick an interesting coordinate from the shown list and replace the 
newly added
+#      coordinate by it.
+#   4. Rerun to see the max colour, insert this max colour where you put the 
high max colour.
+#   5. Set DEBUG to False
+DEBUG = False
 
 
 class Mandelbrot:
@@ -58,9 +51,6 @@
         ymin = self.ypos - self.yscale * self.y / 2
         self.x_range = [xmin + self.xscale * ix for ix in range(self.x)]
         self.y_range = [ymin + self.yscale * iy for iy in range(self.y)]
-        
-        #print "x", self.x_range[0], self.x_range[-1]
-        #print "y", self.y_range[0], self.y_range[-1]
 
     def reset(self, cnt):
         self.reset_lines = cnt
@@ -100,8 +90,11 @@
 
 class Driver(object):
     zoom_locations = [
-        # x, y, "distance", range
+        # x, y, "distance", max color range
         (0.37865401, 0.669227668, 0.04, 111),
+        (-1.2693, -0.4145, 0.2, 105),
+        (-1.2693, -0.4145, 0.05, 97),
+        (-1.2642, -0.4185, 0.01, 95),
         (-1.15, -0.28, 0.9, 94),
         (-1.15, -0.28, 0.3, 58),
         (-1.15, -0.28, 0.05, 26),
@@ -109,8 +102,10 @@
     def __init__(self, **kwargs):
         self.kwargs = kwargs
         self.zoom_location = -1
-        self.colour_range = 256
+        self.max_colour = 256
+        self.colour_range = None
         self.invert = True
+        self.interesting_coordinates = []
         self.init()
 
     def init(self):
@@ -123,14 +118,6 @@
         """ Resets to the beginning of the line and drops cnt lines 
internally. """
         self.mandelbrot.reset(cnt)
 
-    def catchup(self):
-        """ Fills the current line. """
-        x = 0
-        while x != self.width - 1:
-            x, y, c = self.gen.next()
-            print_pixel(c, self.colour_range, self.invert)
-        print >>sys.stderr
-
     def restart(self):
         """ Restarts the current generator. """
         print >>sys.stderr
@@ -146,36 +133,54 @@
                 if width != self.width:
                     self.init()
         except StopIteration:
+            if DEBUG and self.interesting_coordinates:
+                print >>sys.stderr, "Interesting coordinates:", 
self.interesting_coordinates
+                self.interesting_coordinates = []
             kwargs = self.kwargs
             self.zoom_location += 1
             self.zoom_location %= len(self.zoom_locations)
             loc = self.zoom_locations[self.zoom_location]
             kwargs.update({"x_pos": loc[0], "y_pos": loc[1], "distance": 
loc[2]})
-            self.colour_range = loc[3]
-            #global colour_range
-            #print colour_range, loc[2]
-            #colour_range = None
-            return self.restart()
-        print_pixel(c, self.colour_range, self.invert)
+            self.max_colour = loc[3]
+            if DEBUG:
+                # Only used for debugging new locations:
+                print "Colour range", self.colour_range
+            self.colour_range = None
+            self.restart()
+            return
+        if self.print_pixel(c, self.invert):
+            self.interesting_coordinates.append(dict(x=(x, 
self.mandelbrot.x_range[x]),
+                                                     y=(y, 
self.mandelbrot.y_range[y])))
         if x == self.width - 1:
             print >>sys.stderr
 
+    def print_pixel(self, colour, invert=1):
+        chars = [".", ".", "+", "*", "%", "#"]
+        idx = lambda chars: (colour+1) * (len(chars) - 1) / self.max_colour
+        if invert:
+            idx = lambda chars, idx=idx:len(chars) - 1 - idx(chars)
+        char = chars[idx(chars)]
+        ansi_colour = palette[idx(palette)]
+        ansi_print(char, ansi_colour, newline=False, flush=True)
+        if DEBUG:
+            if self.colour_range is None:
+                self.colour_range = [colour, colour]
+            else:
+                old_colour_range = self.colour_range
+                self.colour_range = [min(self.colour_range[0], colour), 
max(self.colour_range[1], colour)]
+                if old_colour_range[0] - colour > 3 or colour - 
old_colour_range[1] > 3:
+                    return True
+
 
 if __name__ == '__main__':
     import random
     from time import sleep
 
     d = Driver()
-    for x in xrange(15000):
-        sleep(random.random() / 300)
+    while True:
+        sleep(random.random() / 800)
         d.dot()
         if 0 and random.random() < 0.01:
-            d.catchup()
-            print "WARNING! " * 3
-            d.reset(1)
-        #    print "R",
-        if 0 and random.random() < 0.01:
             string = "WARNING! " * 3
             d.jump(len(string))
             print string,
-
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to