[pypy-svn] r16160 - in pypy/dist/pypy/rpython: . memory memory/test test
cfbolz at codespeak.net
cfbolz at codespeak.net
Fri Aug 19 14:13:32 CEST 2005
Author: cfbolz
Date: Fri Aug 19 14:13:27 2005
New Revision: 16160
Added:
pypy/dist/pypy/rpython/test/test_nongc.py
Modified:
pypy/dist/pypy/rpython/memory/gc.py
pypy/dist/pypy/rpython/memory/test/test_gc.py
pypy/dist/pypy/rpython/memory/test/test_support.py
pypy/dist/pypy/rpython/objectmodel.py
Log:
moved free_non_gc_object to objectmodel.py
Modified: pypy/dist/pypy/rpython/memory/gc.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gc.py (original)
+++ pypy/dist/pypy/rpython/memory/gc.py Fri Aug 19 14:13:27 2005
@@ -1,24 +1,14 @@
from pypy.rpython.memory.lladdress import raw_malloc, raw_free, NULL
from pypy.rpython.memory.support import AddressLinkedList
-from pypy.rpython import lltype
from pypy.rpython.memory import lltypesimulation
+from pypy.rpython import lltype
+from pypy.rpython.objectmodel import free_non_gc_object
+
import struct
class GCError(Exception):
pass
-class FREED_OBJECT(object):
- def __getattribute__(self, attr):
- raise GCError("trying to access freed object")
- def __setattribute__(self, attr, value):
- raise GCError("trying to access freed object")
-
-
-def free_non_gc_object(obj):
- assert getattr(obj.__class__, "_alloc_flavor_", False) == "", "trying to free regular object"
- obj.__dict__ = {}
- obj.__class__ = FREED_OBJECT
-
class MarkSweepGC(object):
_alloc_flavor_ = ""
Modified: pypy/dist/pypy/rpython/memory/test/test_gc.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/test/test_gc.py (original)
+++ pypy/dist/pypy/rpython/memory/test/test_gc.py Fri Aug 19 14:13:27 2005
@@ -3,13 +3,14 @@
from pypy.annotation import model as annmodel
from pypy.translator.annrpython import RPythonAnnotator
from pypy.rpython.rtyper import RPythonTyper
-from pypy.rpython.memory.gc import free_non_gc_object, GCError, MarkSweepGC
+from pypy.rpython.memory.gc import GCError, MarkSweepGC
from pypy.rpython.memory.support import AddressLinkedList, INT_SIZE
from pypy.rpython.memory.lladdress import raw_malloc, raw_free, NULL
from pypy.rpython.memory.simulator import MemorySimulatorError
from pypy.rpython.memory import gclltype
from pypy.rpython.memory.test.test_llinterpsim import interpret
from pypy.rpython.memory.lladdress import simulator
+from pypy.rpython.objectmodel import free_non_gc_object
def setup_module(mod):
mod.logstate = py.log._getstate()
@@ -20,47 +21,6 @@
def teardown_module(mod):
gclltype.prepare_graphs_and_create_gc = gclltype.create_no_gc
-def test_free_non_gc_object():
- class TestClass(object):
- _alloc_flavor_ = ""
- def __init__(self, a):
- self.a = a
- def method1(self):
- return self.a
- def method2(self):
- return 42
- class TestClass2(object):
- pass
- t = TestClass(1)
- assert t.method1() == 1
- assert t.method2() == 42
- free_non_gc_object(t)
- py.test.raises(GCError, "t.method1()")
- py.test.raises(GCError, "t.method2()")
- py.test.raises(GCError, "t.a")
- py.test.raises(AssertionError, "free_non_gc_object(TestClass2())")
-
-def DONOTtest_rtype_free_non_gc_object():
- class TestClass(object):
- _alloc_flavor_ = ""
- def __init__(self, a):
- self.a = a
- def method1(self):
- return self.a
- def method2(self):
- return 42
- def malloc_and_free(a):
- ci = TestClass(a)
- b = ci.a
- free_non_gc_object(ci)
- return b
- a = RPythonAnnotator()
- #does not raise:
- s = a.build_types(malloc_and_free, [annmodel.SomeAddress()])
- assert isinstance(s, annmodel.SomeAddress)
- rtyper = RPythonTyper(a)
- rtyper.specialize()
-
class PseudoObjectModel(object):
"""Object model for testing purposes: you can specify roots and a
layout_mapping which is a dictionary of typeids to a list of offsets of
Modified: pypy/dist/pypy/rpython/memory/test/test_support.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/test/test_support.py (original)
+++ pypy/dist/pypy/rpython/memory/test/test_support.py Fri Aug 19 14:13:27 2005
@@ -1,4 +1,4 @@
-from pypy.rpython.memory.gc import free_non_gc_object
+from pypy.rpython.objectmodel import free_non_gc_object
from pypy.rpython.memory.support import AddressLinkedList
from pypy.rpython.memory.lladdress import raw_malloc, raw_free, NULL
Modified: pypy/dist/pypy/rpython/objectmodel.py
==============================================================================
--- pypy/dist/pypy/rpython/objectmodel.py (original)
+++ pypy/dist/pypy/rpython/objectmodel.py Fri Aug 19 14:13:27 2005
@@ -16,3 +16,16 @@
def we_are_translated():
return False
# annotation -> True
+
+
+class FREED_OBJECT(object):
+ def __getattribute__(self, attr):
+ raise RuntimeError("trying to access freed object")
+ def __setattribute__(self, attr, value):
+ raise RuntimeError("trying to access freed object")
+
+
+def free_non_gc_object(obj):
+ assert getattr(obj.__class__, "_alloc_flavor_", False) == "", "trying to free regular object"
+ obj.__dict__ = {}
+ obj.__class__ = FREED_OBJECT
Added: pypy/dist/pypy/rpython/test/test_nongc.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rpython/test/test_nongc.py Fri Aug 19 14:13:27 2005
@@ -0,0 +1,47 @@
+import py
+
+from pypy.annotation import model as annmodel
+from pypy.translator.annrpython import RPythonAnnotator
+from pypy.rpython.rtyper import RPythonTyper
+from pypy.rpython.objectmodel import free_non_gc_object
+
+def test_free_non_gc_object():
+ class TestClass(object):
+ _alloc_flavor_ = ""
+ def __init__(self, a):
+ self.a = a
+ def method1(self):
+ return self.a
+ def method2(self):
+ return 42
+ class TestClass2(object):
+ pass
+ t = TestClass(1)
+ assert t.method1() == 1
+ assert t.method2() == 42
+ free_non_gc_object(t)
+ py.test.raises(RuntimeError, "t.method1()")
+ py.test.raises(RuntimeError, "t.method2()")
+ py.test.raises(RuntimeError, "t.a")
+ py.test.raises(AssertionError, "free_non_gc_object(TestClass2())")
+
+def DONOTtest_rtype_free_non_gc_object():
+ class TestClass(object):
+ _alloc_flavor_ = ""
+ def __init__(self, a):
+ self.a = a
+ def method1(self):
+ return self.a
+ def method2(self):
+ return 42
+ def malloc_and_free(a):
+ ci = TestClass(a)
+ b = ci.a
+ free_non_gc_object(ci)
+ return b
+ a = RPythonAnnotator()
+ #does not raise:
+ s = a.build_types(malloc_and_free, [annmodel.SomeAddress()])
+ assert isinstance(s, annmodel.SomeAddress)
+ rtyper = RPythonTyper(a)
+ rtyper.specialize()
More information about the Pypy-commit
mailing list