Commits

Alex Gaynor committed 74cf1f2 Merge

merged default in.

Comments (0)

Files changed (10)

     try:
         res = greenlet.run(*args)
     finally:
-        if greenlet.parent is not _tls.main:
-            _continuation.permute(greenlet, greenlet.parent)
+        _continuation.permute(greenlet, greenlet.parent)
     return (res,)
 
 def _greenlet_throw(greenlet, exc, value, tb):
     try:
         raise exc, value, tb
     finally:
-        if greenlet.parent is not _tls.main:
-            _continuation.permute(greenlet, greenlet.parent)
+        _continuation.permute(greenlet, greenlet.parent)

pypy/module/_continuation/interp_continuation.py

     def check_sthread(self):
         ec = self.space.getexecutioncontext()
         if ec.stacklet_thread is not self.sthread:
-            start_state.clear()
+            global_state.clear()
             raise geterror(self.space, "inter-thread support is missing")
         return ec
 
     def descr_init(self, w_callable, __args__):
         if self.sthread is not None:
             raise geterror(self.space, "continulet already __init__ialized")
-        start_state.origin = self
-        start_state.w_callable = w_callable
-        start_state.args = __args__
+        global_state.origin = self
+        global_state.w_callable = w_callable
+        global_state.args = __args__
         self.bottomframe = make_fresh_frame(self.space)
         self.sthread = build_sthread(self.space)
         try:
                 raise MemoryError
         except MemoryError:
             self.sthread = None
-            start_state.clear()
+            global_state.clear()
             raise getmemoryerror(self.space)
 
     def switch(self, w_to):
         sthread = self.sthread
         if sthread is not None and sthread.is_empty_handle(self.h):
-            start_state.clear()
+            global_state.clear()
             raise geterror(self.space, "continulet already finished")
         to = self.space.interp_w(W_Continulet, w_to, can_be_None=True)
         if to is not None and to.sthread is None:
                 return get_result()  # else: no-op
         if to is not None:
             if to.sthread is not sthread:
-                start_state.clear()
+                global_state.clear()
                 raise geterror(self.space, "cross-thread double switch")
             if self is to:    # double-switch to myself: no-op
                 return get_result()
             if sthread.is_empty_handle(to.h):
-                start_state.clear()
+                global_state.clear()
                 raise geterror(self.space, "continulet already finished")
         ec = self.check_sthread()
         #
-        start_state.origin = self
+        global_state.origin = self
         if to is None:
             # simple switch: going to self.h
-            start_state.destination = self
+            global_state.destination = self
         else:
             # double switch: the final destination is to.h
-            start_state.destination = to
+            global_state.destination = to
         #
         try:
-            do_switch(sthread, start_state.destination.h)
+            do_switch(sthread, global_state.destination.h)
         except MemoryError:
-            start_state.clear()
+            global_state.clear()
             raise getmemoryerror(self.space)
         #
         return get_result()
 
     def descr_switch(self, w_value=None, w_to=None):
-        start_state.w_value = w_value
+        global_state.w_value = w_value
         return self.switch(w_to)
 
     def descr_throw(self, w_type, w_val=None, w_tb=None, w_to=None):
         #
         operr = OperationError(w_type, w_val, tb)
         operr.normalize_exception(space)
-        start_state.w_value = None
-        start_state.propagate_exception = operr
+        global_state.w_value = None
+        global_state.propagate_exception = operr
         return self.switch(w_to)
 
     def descr_is_pending(self):
 # ____________________________________________________________
 
 
-class StartState:   # xxx a single global to pass around the function to start
+class GlobalState:
     def clear(self):
         self.origin = None
         self.destination = None
         self.args = None
         self.w_value = None
         self.propagate_exception = None
-start_state = StartState()
-start_state.clear()
+global_state = GlobalState()
+global_state.clear()
 
 
 def new_stacklet_callback(h, arg):
-    self       = start_state.origin
-    w_callable = start_state.w_callable
-    args       = start_state.args
-    start_state.clear()
+    self       = global_state.origin
+    w_callable = global_state.w_callable
+    args       = global_state.args
+    global_state.clear()
     try:
         do_switch(self.sthread, h)
     except MemoryError:
     try:
         assert self.sthread.ec.topframeref() is None
         self.sthread.ec.topframeref = jit.non_virtual_ref(self.bottomframe)
-        if start_state.propagate_exception is not None:
-            raise start_state.propagate_exception   # just propagate it further
-        if start_state.w_value is not space.w_None:
+        if global_state.propagate_exception is not None:
+            raise global_state.propagate_exception  # just propagate it further
+        if global_state.w_value is not space.w_None:
             raise OperationError(space.w_TypeError, space.wrap(
                 "can't send non-None value to a just-started continulet"))
 
         args = args.prepend(self.space.wrap(self))
         w_result = space.call_args(w_callable, args)
     except Exception, e:
-        start_state.propagate_exception = e
+        global_state.propagate_exception = e
     else:
-        start_state.w_value = w_result
+        global_state.w_value = w_result
     self.sthread.ec.topframeref = jit.vref_None
-    start_state.origin = self
-    start_state.destination = self
+    global_state.origin = self
+    global_state.destination = self
     return self.h
 
 
 def do_switch(sthread, h):
     h = sthread.switch(h)
-    origin = start_state.origin
-    self = start_state.destination
-    start_state.origin = None
-    start_state.destination = None
+    origin = global_state.origin
+    self = global_state.destination
+    global_state.origin = None
+    global_state.destination = None
     self.h, origin.h = origin.h, h
     #
     current = sthread.ec.topframeref
     origin.bottomframe.f_backref = current
 
 def get_result():
-    if start_state.propagate_exception:
-        e = start_state.propagate_exception
-        start_state.propagate_exception = None
+    if global_state.propagate_exception:
+        e = global_state.propagate_exception
+        global_state.propagate_exception = None
         raise e
-    w_value = start_state.w_value
-    start_state.w_value = None
+    w_value = global_state.w_value
+    global_state.w_value = None
     return w_value
 
 def build_sthread(space):
         cont = space.interp_w(W_Continulet, w_cont)
         if cont.sthread is not sthread:
             if cont.sthread is None:
-                raise geterror(space, "got a non-initialized continulet")
+                continue   # ignore non-initialized continulets
             else:
                 raise geterror(space, "inter-thread support is missing")
         elif sthread.is_empty_handle(cont.h):

pypy/module/_continuation/test/test_stacklet.py

             assert res == "done"
         main()
 
+    def test_permute_noninitialized(self):
+        from _continuation import continulet, permute
+        permute(continulet.__new__(continulet))    # ignored
+        permute(continulet.__new__(continulet),    # ignored
+                continulet.__new__(continulet))
+
     def test_bug_finish_with_already_finished_stacklet(self):
         from _continuation import continulet, error
         # make an already-finished continulet

pypy/module/pyexpat/interp_pyexpat.py

         if XML_ParserFree: # careful with CPython interpreter shutdown
             XML_ParserFree(self.itself)
         if global_storage:
-            global_storage.free_nonmoving_id(
-                rffi.cast(lltype.Signed, self.itself))
+            global_storage.free_nonmoving_id(self.id)
 
     @unwrap_spec(flag=int)
     def SetParamEntityParsing(self, space, flag):

pypy/objspace/std/stringobject.py

File contents unchanged.
 class JitHintError(Exception):
     """Inconsistency in the JIT hints."""
 
-PARAMETERS = {'threshold': 1032, # just above 1024
-              'function_threshold': 1617, # slightly more than one above
+PARAMETERS = {'threshold': 1039, # just above 1024, prime
+              'function_threshold': 1619, # slightly more than one above, also prime
               'trace_eagerness': 200,
-              'trace_limit': 12000,
+              'trace_limit': 6000,
               'inlining': 1,
               'loop_longevity': 1000,
               'retrace_limit': 5,

pypy/rpython/memory/gctransform/asmgcroot.py

                          QSORT_CALLBACK_PTR],
                         lltype.Void,
                         sandboxsafe=True,
+                        random_effects_on_gcobjs=False,  # but has a callback
                         _nowrapper=True)

pypy/rpython/memory/gctransform/framework.py

         func = getattr(graph, 'func', None)
         if func and getattr(func, '_gc_no_collect_', False):
             if self.collect_analyzer.analyze_direct_call(graph):
-                raise Exception("no_collect function can trigger collection: %s"
-                                % func.__name__)
+                raise Exception("'no_collect' function can trigger collection:"
+                                " %s" % func)
             
         if self.write_barrier_ptr:
             self.clean_sets = (

pypy/rpython/test/test_rlist.py

     def test_hints(self):
         from pypy.rlib.objectmodel import newlist
         from pypy.rpython.annlowlevel import hlstr
-        
-        def f(z):
-            z = hlstr(z)
+
+        strings = ['abc', 'def']
+        def f(i):
+            z = strings[i]
             x = newlist(sizehint=13)
             x += z
             return ''.join(x)
 
-        res = self.interpret(f, [self.string_to_ll('abc')])
+        res = self.interpret(f, [0])
         assert self.ll_to_string(res) == 'abc'
 
 class TestLLtype(BaseTestRlist, LLRtypeMixin):

pypy/translator/backendopt/graphanalyze.py

 from pypy.rpython.lltypesystem import lltype
 
 class GraphAnalyzer(object):
+    verbose = False
+
     def __init__(self, translator):
         self.translator = translator
         self.analyzed_calls = {}
         if op.opname == "direct_call":
             graph = get_graph(op.args[0], self.translator)
             if graph is None:
-                return self.analyze_external_call(op, seen)
-            return self.analyze_direct_call(graph, seen)
+                x = self.analyze_external_call(op, seen)
+                if self.verbose and x:
+                    print '\tanalyze_external_call %s: %r' % (op, x)
+                return x
+            x = self.analyze_direct_call(graph, seen)
+            if self.verbose and x:
+                print '\tanalyze_direct_call(%s): %r' % (graph, x)
+            return x
         elif op.opname == "indirect_call":
-            if op.args[-1].value is None:
+            graphs = op.args[-1].value
+            if graphs is None:
+                if self.verbose:
+                    print '\t%s to unknown' % (op,)
                 return self.top_result()
-            return self.analyze_indirect_call(op.args[-1].value, seen)
+            x = self.analyze_indirect_call(graphs, seen)
+            if self.verbose and x:
+                print '\tanalyze_indirect_call(%s): %r' % (graphs, x)
+            return x
         elif op.opname == "oosend":
             name = op.args[0].value
             TYPE = op.args[1].concretetype
             if graph is None:
                 return self.analyze_external_method(op, TYPE, meth)
             return self.analyze_oosend(TYPE, name, seen)
-        return self.analyze_simple_operation(op, graphinfo)
+        x = self.analyze_simple_operation(op, graphinfo)
+        if self.verbose and x:
+            print '\t%s: %r' % (op, x)
+        return x
 
     def analyze_direct_call(self, graph, seen=None):
         if graph in self.analyzed_calls: