Author: Maciej Fijalkowski <fij...@gmail.com> Branch: kill-someobject Changeset: r57863:9f74be6a89fd Date: 2012-10-07 20:59 +0200 http://bitbucket.org/pypy/pypy/changeset/9f74be6a89fd/
Log: merge diff --git a/pypy/rpython/llinterp.py b/pypy/rpython/llinterp.py --- a/pypy/rpython/llinterp.py +++ b/pypy/rpython/llinterp.py @@ -846,12 +846,6 @@ def op_gc_deallocate(self, TYPE, addr): raise NotImplementedError("gc_deallocate") - def op_gc_push_alive_pyobj(self, pyobj): - raise NotImplementedError("gc_push_alive_pyobj") - - def op_gc_pop_alive_pyobj(self, pyobj): - raise NotImplementedError("gc_pop_alive_pyobj") - def op_gc_reload_possibly_moved(self, v_newaddr, v_ptr): assert v_newaddr.concretetype is llmemory.Address assert isinstance(v_ptr.concretetype, lltype.Ptr) @@ -938,28 +932,6 @@ def op_stack_current(self): return 0 - # operations on pyobjects! - for opname in lloperation.opimpls.keys(): - exec py.code.Source(""" - def op_%(opname)s(self, *pyobjs): - for pyo in pyobjs: - assert lltype.typeOf(pyo) == lltype.Ptr(lltype.PyObject) - func = lloperation.opimpls[%(opname)r] - try: - pyo = func(*[pyo._obj.value for pyo in pyobjs]) - except Exception: - self.make_llexception() - return self.heap.pyobjectptr(pyo) - """ % locals()).compile() - del opname - - def op_simple_call(self, f, *args): - assert lltype.typeOf(f) == lltype.Ptr(lltype.PyObject) - for pyo in args: - assert lltype.typeOf(pyo) == lltype.Ptr(lltype.PyObject) - res = f._obj.value(*[pyo._obj.value for pyo in args]) - return self.heap.pyobjectptr(res) - # __________________________________________________________ # operations on addresses @@ -980,7 +952,7 @@ return llmemory.raw_malloc_usage(size) def op_raw_free(self, addr): - checkadr(addr) + checkadr(addr) llmemory.raw_free(addr) def op_raw_memclear(self, addr, size): diff --git a/pypy/rpython/lltypesystem/lloperation.py b/pypy/rpython/lltypesystem/lloperation.py --- a/pypy/rpython/lltypesystem/lloperation.py +++ b/pypy/rpython/lltypesystem/lloperation.py @@ -8,7 +8,7 @@ class LLOp(object): def __init__(self, sideeffects=True, canfold=False, canraise=(), - pyobj=False, canmallocgc=False, canrun=False, oo=False, + canmallocgc=False, canrun=False, oo=False, tryfold=False): # self.opname = ... (set afterwards) @@ -32,9 +32,6 @@ assert not canraise or not canfold - # The operation manipulates PyObjects - self.pyobj = pyobj - # The operation can go a GC malloc self.canmallocgc = canmallocgc if canmallocgc: @@ -476,8 +473,6 @@ 'gc_restore_exception': LLOp(), 'gc_call_rtti_destructor': LLOp(), 'gc_deallocate': LLOp(), - 'gc_push_alive_pyobj': LLOp(), - 'gc_pop_alive_pyobj': LLOp(), 'gc_reload_possibly_moved': LLOp(), # see rlib/objectmodel for gc_identityhash and gc_id 'gc_identityhash': LLOp(sideeffects=False, canmallocgc=True), @@ -602,17 +597,6 @@ } # ***** Run test_lloperation after changes. ***** - - # __________ operations on PyObjects __________ - -from pypy.objspace.flow.operation import FunctionByName -opimpls = FunctionByName.copy() -opimpls['is_true'] = bool -for opname in opimpls: - LL_OPERATIONS[opname] = LLOp(canraise=(Exception,), pyobj=True) -LL_OPERATIONS['simple_call'] = LLOp(canraise=(Exception,), pyobj=True) -del opname, FunctionByName - # ____________________________________________________________ # Post-processing diff --git a/pypy/rpython/memory/gctransform/boehm.py b/pypy/rpython/memory/gctransform/boehm.py --- a/pypy/rpython/memory/gctransform/boehm.py +++ b/pypy/rpython/memory/gctransform/boehm.py @@ -1,12 +1,12 @@ from pypy.rpython.memory.gctransform.transform import GCTransformer, mallocHelpers -from pypy.rpython.memory.gctransform.support import type_contains_pyobjs, \ - get_rtti, _static_deallocator_body_for_type, LLTransformerOp, ll_call_destructor +from pypy.rpython.memory.gctransform.support import (get_rtti, + _static_deallocator_body_for_type, LLTransformerOp, ll_call_destructor) from pypy.rpython.lltypesystem import lltype, llmemory from pypy.objspace.flow.model import Constant from pypy.rpython.lltypesystem.lloperation import llop -from pypy.rpython.lltypesystem import rffi from pypy.rpython import rmodel + class BoehmGCTransformer(GCTransformer): malloc_zero_filled = True FINALIZER_PTR = lltype.Ptr(lltype.FuncType([llmemory.Address], lltype.Void)) @@ -99,20 +99,7 @@ destrptr = None DESTR_ARG = None - if type_contains_pyobjs(TYPE): - if destrptr: - raise Exception("can't mix PyObjects and __del__ with Boehm") - - static_body = '\n'.join(_static_deallocator_body_for_type('v', TYPE)) - d = {'pop_alive': LLTransformerOp(self.pop_alive), - 'PTR_TYPE':lltype.Ptr(TYPE), - 'cast_adr_to_ptr': llmemory.cast_adr_to_ptr} - src = ("def ll_finalizer(addr):\n" - " v = cast_adr_to_ptr(addr, PTR_TYPE)\n" - "%s\n")%(static_body,) - exec src in d - fptr = self.annotate_finalizer(d['ll_finalizer'], [llmemory.Address], lltype.Void) - elif destrptr: + if destrptr: EXC_INSTANCE_TYPE = self.translator.rtyper.exceptiondata.lltype_of_exception_value typename = TYPE.__name__ def ll_finalizer(addr): diff --git a/pypy/rpython/memory/gctransform/refcounting.py b/pypy/rpython/memory/gctransform/refcounting.py --- a/pypy/rpython/memory/gctransform/refcounting.py +++ b/pypy/rpython/memory/gctransform/refcounting.py @@ -201,9 +201,7 @@ return self.static_deallocator_funcptrs[TYPE] #print_call_chain(self) - if TYPE._gckind == 'cpy': - return # you don't really have an RPython deallocator for PyObjects - rtti = get_rtti(TYPE) + rtti = get_rtti(TYPE) if rtti is not None and hasattr(rtti._obj, 'destructor_funcptr'): destrptr = rtti._obj.destructor_funcptr DESTR_ARG = lltype.typeOf(destrptr).TO.ARGS[0] @@ -266,7 +264,6 @@ return fptr def dynamic_deallocation_funcptr_for_type(self, TYPE): - assert TYPE._gckind != 'cpy' if TYPE in self.dynamic_deallocator_funcptrs: return self.dynamic_deallocator_funcptrs[TYPE] #print_call_chain(self) diff --git a/pypy/rpython/memory/gctransform/test/test_boehm.py b/pypy/rpython/memory/gctransform/test/test_boehm.py --- a/pypy/rpython/memory/gctransform/test/test_boehm.py +++ b/pypy/rpython/memory/gctransform/test/test_boehm.py @@ -5,8 +5,7 @@ from pypy.translator.translator import graphof from pypy.translator.c.gc import BoehmGcPolicy from pypy.rpython.memory.gctransform.test.test_transform import LLInterpedTranformerTests -from pypy import conftest -import py + class TestLLInterpedBoehm(LLInterpedTranformerTests): gcpolicy = BoehmGcPolicy @@ -34,11 +33,6 @@ f, t = make_boehm_finalizer(S) assert f is None -def test_boehm_finalizer_pyobj(): - S = lltype.GcStruct("S", ('x', lltype.Ptr(lltype.PyObject))) - f, t = make_boehm_finalizer(S) - assert f is not None - def test_boehm_finalizer___del__(): S = lltype.GcStruct("S", ('x', lltype.Signed), rtti=True) def f(s): @@ -53,24 +47,6 @@ lltype.Void), "destructor_funcptr", _callable=f) - pinf = lltype.attachRuntimeTypeInfo(S, qp, destrptr=dp) + lltype.attachRuntimeTypeInfo(S, qp, destrptr=dp) f, t = make_boehm_finalizer(S) assert f is not None - -def test_boehm_finalizer_nomix___del___and_pyobj(): - S = lltype.GcStruct("S", ('x', lltype.Signed), - ('y', lltype.Ptr(lltype.PyObject)), rtti=True) - def f(s): - s.x = 1 - def type_info_S(p): - return lltype.getRuntimeTypeInfo(S) - qp = lltype.functionptr(lltype.FuncType([lltype.Ptr(S)], - lltype.Ptr(lltype.RuntimeTypeInfo)), - "type_info_S", - _callable=type_info_S) - dp = lltype.functionptr(lltype.FuncType([lltype.Ptr(S)], - lltype.Void), - "destructor_funcptr", - _callable=f) - pinf = lltype.attachRuntimeTypeInfo(S, qp, destrptr=dp) - py.test.raises(Exception, "make_boehm_finalizer(S)") diff --git a/pypy/rpython/memory/gctransform/test/test_transform.py b/pypy/rpython/memory/gctransform/test/test_transform.py --- a/pypy/rpython/memory/gctransform/test/test_transform.py +++ b/pypy/rpython/memory/gctransform/test/test_transform.py @@ -1,6 +1,5 @@ from pypy.rpython.memory.gctransform.transform import BaseGCTransformer from pypy.objspace.flow.model import c_last_exception, Variable -from pypy.rpython.memory.gctransform.support import var_ispyobj from pypy.translator.backendopt.support import var_needsgc from pypy.translator.translator import TranslationContext, graphof from pypy.translator.exceptiontransform import ExceptionTransformer @@ -110,22 +109,13 @@ and not is_borrowed(v)]) push_alives = len([op for op in block.operations if op.opname == 'gc_push_alive']) - pyobj_push_alives = len([op for op in block.operations - if op.opname == 'gc_push_alive_pyobj']) - # implicit_pyobj_pushalives included calls to things that return pyobject* - implicit_pyobj_pushalives = len([op for op in block.operations - if var_ispyobj(op.result) - and op.opname not in ('getfield', 'getarrayitem', 'same_as')]) - nonpyobj_gc_returning_calls = len([op for op in block.operations - if op.opname in ('direct_call', 'indirect_call') - and var_needsgc(op.result) - and not var_ispyobj(op.result)]) + gc_returning_calls = len([op for op in block.operations + if op.opname in ('direct_call', 'indirect_call') + and var_needsgc(op.result)]) pop_alives = len([op for op in block.operations if op.opname == 'gc_pop_alive']) - pyobj_pop_alives = len([op for op in block.operations - if op.opname == 'gc_pop_alive_pyobj']) if pop_alives == len(block.operations): # it's a block we inserted return @@ -135,9 +125,8 @@ for v2 in link.target.inputargs: if var_needsgc(v2) and not is_borrowed(v2): refs_out += 1 - pyobj_pushes = pyobj_push_alives + implicit_pyobj_pushalives - nonpyobj_pushes = push_alives + nonpyobj_gc_returning_calls - assert refs_in + pyobj_pushes + nonpyobj_pushes == pop_alives + pyobj_pop_alives + refs_out + pushes = push_alives + gc_returning_calls + assert refs_in + pushes == pop_alives + refs_out def rtype(func, inputtypes, specialize=True): t = TranslationContext() @@ -229,55 +218,6 @@ return a.x + b.x t, transformer = rtype_and_transform(f, [int], _TestGCTransformer) -def test_pyobj(): - def f(x): - if x: - a = 1 - else: - a = "1" - return int(a) - t, transformer = rtype_and_transform(f, [int], _TestGCTransformer) - fgraph = graphof(t, f) - gcops = [op for op in fgraph.startblock.exits[0].target.operations - if op.opname.startswith("gc_")] - for op in gcops: - assert op.opname.endswith("_pyobj") - -def test_call_return_pyobj(): - def g(factory): - return factory() - def f(factory): - g(factory) - t, transformer = rtype_and_transform(f, [object], _TestGCTransformer) - fgraph = graphof(t, f) - ops = getops(fgraph) - calls = ops['direct_call'] - for call in calls: - if call.result.concretetype is not lltype.Bool: #RPyExceptionOccurred() - assert var_ispyobj(call.result) - -def test_getfield_pyobj(): - class S: - pass - def f(thing): - s = S() - s.x = thing - return s.x - t, transformer = rtype_and_transform(f, [object], _TestGCTransformer) - fgraph = graphof(t, f) - pyobj_getfields = 0 - pyobj_setfields = 0 - for b in fgraph.iterblocks(): - for op in b.operations: - if op.opname == 'getfield' and var_ispyobj(op.result): - pyobj_getfields += 1 - elif op.opname == 'bare_setfield' and var_ispyobj(op.args[2]): - pyobj_setfields += 1 - # although there's only one explicit getfield in the code, a - # setfield on a pyobj must get the old value out and decref it - assert pyobj_getfields >= 2 - assert pyobj_setfields >= 1 - def test_pass_gc_pointer(): S = lltype.GcStruct("S", ('x', lltype.Signed)) def f(s): diff --git a/pypy/rpython/memory/gctransform/transform.py b/pypy/rpython/memory/gctransform/transform.py --- a/pypy/rpython/memory/gctransform/transform.py +++ b/pypy/rpython/memory/gctransform/transform.py @@ -505,7 +505,6 @@ if add_flags: flags.update(add_flags) flavor = flags['flavor'] - assert flavor != 'cpy', "cannot malloc CPython objects directly" meth = getattr(self, 'gct_fv_%s_malloc_varsize' % flavor, None) assert meth, "%s has no support for malloc_varsize with flavor %r" % (self, flavor) return self.varsize_malloc_helper(hop, flags, meth, []) @@ -583,7 +582,6 @@ flags = op.args[1].value flavor = flags['flavor'] v = op.args[0] - assert flavor != 'cpy', "cannot free CPython objects directly" if flavor == 'raw': v = hop.genop("cast_ptr_to_adr", [v], resulttype=llmemory.Address) if flags.get('track_allocation', True): diff --git a/pypy/rpython/rmodel.py b/pypy/rpython/rmodel.py --- a/pypy/rpython/rmodel.py +++ b/pypy/rpython/rmodel.py @@ -172,16 +172,15 @@ isinstance(T.TO, (lltype.Struct, lltype.Array, lltype.ForwardReference))): - assert T.TO._gckind != 'cpy' return DummyValueBuilder(rtyper, T.TO) else: return None def rtype_bltn_list(self, hop): - raise TyperError, 'no list() support for %r' % self + raise TyperError('no list() support for %r' % self) def rtype_unichr(self, hop): - raise TyperError, 'no unichr() support for %r' % self + raise TyperError('no unichr() support for %r' % self) # default implementation of some operations diff --git a/pypy/rpython/test/test_rbool.py b/pypy/rpython/test/test_rbool.py --- a/pypy/rpython/test/test_rbool.py +++ b/pypy/rpython/test/test_rbool.py @@ -1,11 +1,10 @@ from pypy.translator.translator import TranslationContext -from pypy.rpython.lltypesystem.lltype import pyobjectptr from pypy.annotation import model as annmodel from pypy.rpython.test import snippet from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin + class TestSnippet(object): - def _test(self, func, types): t = TranslationContext() t.buildannotator().build_types(func, types) diff --git a/pypy/rpython/test/test_rbuiltin.py b/pypy/rpython/test/test_rbuiltin.py --- a/pypy/rpython/test/test_rbuiltin.py +++ b/pypy/rpython/test/test_rbuiltin.py @@ -562,31 +562,6 @@ class TestLLtype(BaseTestRbuiltin, LLRtypeMixin): - - def test_isinstance_obj(self): - _1 = lltype.pyobjectptr(1) - def f(x): - return isinstance(x, int) - res = self.interpret(f, [_1], someobjects=True) - assert res is True - _1_0 = lltype.pyobjectptr(1.0) - res = self.interpret(f, [_1_0], someobjects=True) - assert res is False - - def test_hasattr(self): - class A(object): - def __init__(self): - self.x = 42 - def f(i): - a = A() - if i==0: return int(hasattr(A, '__init__')) - if i==1: return int(hasattr(A, 'y')) - if i==2: return int(hasattr(42, 'x')) - for x, y in zip(range(3), (1, 0, 0)): - res = self.interpret(f, [x], someobjects=True) - assert res._obj.value == y - # hmm, would like to test against PyObj, is this the wrong place/way? - def test_cast(self): def llfn(v): return rffi.cast(rffi.VOIDP, v) @@ -607,7 +582,8 @@ res = self.interpret(llfn, [lltype.nullptr(rffi.VOIDP.TO)]) assert res == 0 assert isinstance(res, r_ulonglong) - + + class TestOOtype(BaseTestRbuiltin, OORtypeMixin): def test_instantiate_multiple_meta(self): diff --git a/pypy/translator/c/test/test_boehm.py b/pypy/translator/c/test/test_boehm.py --- a/pypy/translator/c/test/test_boehm.py +++ b/pypy/translator/c/test/test_boehm.py @@ -2,11 +2,11 @@ from pypy.translator.translator import TranslationContext from pypy.rpython.lltypesystem import lltype, llmemory from pypy.rpython.lltypesystem.lloperation import llop -from pypy.rpython.memory.test import snippet from pypy.translator.c.genc import CExtModuleBuilder from pypy.rlib.objectmodel import keepalive_until_here from pypy import conftest + def setup_module(mod): from pypy.rpython.tool.rffi_platform import configure_boehm from pypy.translator.platform import CompilationError @@ -69,7 +69,6 @@ fn() def test__del__(self): - from pypy.rpython.lltypesystem.lloperation import llop class State: pass s = State() @@ -105,7 +104,6 @@ def test_id_is_weak(self): # test that compute_unique_id(obj) does not keep obj alive - from pypy.rpython.lltypesystem.lloperation import llop from pypy.rlib.objectmodel import compute_unique_id class State: pass @@ -155,7 +153,6 @@ assert 0 < res2 <= 5 def test_del_raises(self): - from pypy.rpython.lltypesystem.lloperation import llop class A(object): def __del__(self): s.dels += 1 @@ -199,31 +196,6 @@ fn = self.getcompiled(f) res = fn() assert res == 10 - - # this test shows if we have a problem with refcounting PyObject - def test_refcount_pyobj(self): - from pypy.rpython.lltypesystem.lloperation import llop - def prob_with_pyobj(b): - return 3, b - def collect(): - llop.gc__collect(lltype.Void) - f = self.getcompiled(prob_with_pyobj, [object]) - c = self.getcompiled(collect, []) - from sys import getrefcount as g - obj = None - before = g(obj) - f(obj) - f(obj) - f(obj) - f(obj) - f(obj) - c() - c() - c() - c() - c() - after = g(obj) - assert abs(before - after) < 5 def test_zero_malloc(self): T = lltype.GcStruct("C", ('x', lltype.Signed)) diff --git a/pypy/translator/c/test/test_genc.py b/pypy/translator/c/test/test_genc.py --- a/pypy/translator/c/test/test_genc.py +++ b/pypy/translator/c/test/test_genc.py @@ -1,10 +1,7 @@ -import sys - import py import ctypes from pypy.rpython.lltypesystem.lltype import * -from pypy.annotation import model as annmodel from pypy.translator.translator import TranslationContext from pypy.translator.c import genc from pypy.translator.interactive import Translation @@ -94,16 +91,6 @@ assert f1(-5) == -42 -def test_rptr_array(): - A = GcArray(Ptr(PyObject)) - def f(i, x): - p = malloc(A, i) - p[1] = x - return p[1] - f1 = compile(f, [int, annmodel.SomePtr(Ptr(PyObject))]) - assert f1(5, 123) == 123 - assert f1(12, "hello") == "hello" - def test_empty_string(): A = Array(Char, hints={'nolength': True}) p = malloc(A, 1, immortal=True) @@ -304,61 +291,12 @@ def f(): x = [1] y = ['b'] - objectmodel.keepalive_until_here(x,y) + objectmodel.keepalive_until_here(x, y) return 1 f1 = compile(f, []) assert f1() == 1 -def test_refcount_pyobj(): - def prob_with_pyobj(b): - return 3, b - - f = compile(prob_with_pyobj, [object]) - from sys import getrefcount as g - obj = None - import gc; gc.collect() - before = g(obj) - f(obj) - after = g(obj) - assert before == after - -def test_refcount_pyobj_setfield(): - import weakref, gc - class S(object): - def __init__(self): - self.p = None - def foo(wref, objfact): - s = S() - b = objfact() - s.p = b - wr = wref(b) - s.p = None - return wr - f = compile(foo, [object, object], backendopt=False) - class C(object): - pass - wref = f(weakref.ref, C) - gc.collect() - assert not wref() - -def test_refcount_pyobj_setfield_increfs(): - class S(object): - def __init__(self): - self.p = None - def goo(objfact): - s = S() - b = objfact() - s.p = b - return s - def foo(objfact): - s = goo(objfact) - return s.p - f = compile(foo, [object], backendopt=False) - class C(object): - pass - print f(C) - def test_print(): def f(): for i in range(10): @@ -375,7 +313,7 @@ t = Translation(f, [], backend="c") t.annotate() - compiled_fn = t.compile_c() + t.compile_c() if py.test.config.option.view: t.view() assert 'pypy_xyz_f' in t.driver.cbuilder.c_source_filename.read() @@ -391,7 +329,7 @@ t = Translation(f, [], backend="c", secondaryentrypoints="test_entrypoints42") t.annotate() - compiled_fn = t.compile_c() + t.compile_c() if py.test.config.option.view: t.view() assert 'foobar' in t.driver.cbuilder.c_source_filename.read() @@ -406,7 +344,7 @@ export_struct("BarStruct", foo._obj) t = Translation(f, [], backend="c") t.annotate() - compiled_fn = t.compile_c() + t.compile_c() if py.test.config.option.view: t.view() assert ' BarStruct ' in t.driver.cbuilder.c_source_filename.read() @@ -416,7 +354,6 @@ from pypy.rpython.annlowlevel import llhelper from pypy.rpython.lltypesystem import lltype from pypy.rlib.objectmodel import specialize - from pypy.rlib.nonconst import NonConstant FT = lltype.ForwardReference() FTPTR = lltype.Ptr(FT) STRUCT = lltype.Struct("foo", ("bar", FTPTR)) @@ -464,7 +401,6 @@ assert fn(True) def test_inhibit_tail_call(): - from pypy.rpython.lltypesystem import lltype def foobar_fn(n): return 42 foobar_fn._dont_inline_ = True _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit