Author: Armin Rigo <ar...@tunes.org> Branch: gc-del Changeset: r62751:5082b68711e3 Date: 2013-03-25 19:33 +0100 http://bitbucket.org/pypy/pypy/changeset/5082b68711e3/
Log: Next test. diff --git a/rpython/memory/gc/minimark.py b/rpython/memory/gc/minimark.py --- a/rpython/memory/gc/minimark.py +++ b/rpython/memory/gc/minimark.py @@ -573,10 +573,13 @@ def collect(self, gen=1): - """Do a minor (gen=0) or major (gen>0) collection.""" - self.minor_collection() - if gen > 0: - self.major_collection() + """Do a minor (gen=0) or major (gen>0) collection, + or merely executes pending finalizers (gen<0). + """ + if gen >= 0: + self.minor_collection() + if gen > 0: + self.major_collection() self.execute_finalizers() def collect_and_reserve(self, totalsize): diff --git a/rpython/memory/gcwrapper.py b/rpython/memory/gcwrapper.py --- a/rpython/memory/gcwrapper.py +++ b/rpython/memory/gcwrapper.py @@ -245,7 +245,9 @@ try: self.llinterp.eval_graph(finalizer.ptr._obj.graph, [obj], recursive=True) - except llinterp.LLException: + except llinterp.LLException, e: + if ''.join(e.args[0].name) == 'FinalizeLater\x00': + return False raise RuntimeError( "a finalizer raised an exception, shouldn't happen") return True diff --git a/rpython/memory/test/test_gc.py b/rpython/memory/test/test_gc.py --- a/rpython/memory/test/test_gc.py +++ b/rpython/memory/test/test_gc.py @@ -262,6 +262,7 @@ b.nextid += 1 def finalizer(self): b.num_finalized += 1 + debug_print("call to finalizer() number", b.num_finalized) if (b.num_finalized % 3) == 0: raise rgc.FinalizeLater def f(x): @@ -271,6 +272,8 @@ while i < x: i += 1 a = A() + rgc.register_finalizer(a.finalizer) + a = None llop.gc__collect(lltype.Void) if b.num_finalized == 0: llop.gc__collect(lltype.Void) @@ -282,7 +285,6 @@ rgc.progress_through_finalizer_queue() assert b.num_finalized == 8 res = self.interpret(f, [5]) - assert res == 606 def test_custom_trace(self): from rpython.rtyper.annlowlevel import llhelper diff --git a/rpython/rlib/rgc.py b/rpython/rlib/rgc.py --- a/rpython/rlib/rgc.py +++ b/rpython/rlib/rgc.py @@ -377,6 +377,18 @@ return hop.genop('gc_register_finalizer', [v_self, v_llfn], resulttype=lltype.Void) +class ProgressThroughFinalizerQueueEntry(ExtRegistryEntry): + _about_ = progress_through_finalizer_queue + + def compute_result_annotation(self): + from rpython.annotator import model as annmodel + return annmodel.s_None + + def specialize_call(self, hop): + hop.exception_cannot_occur() + args_v = [hop.inputconst(lltype.Signed, -1)] + return hop.genop('gc__collect', args_v, resulttype=hop.r_result) + # ____________________________________________________________ _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit