[pypy-svn] r47581 - pypy/dist/pypy/rpython/lltypesystem
arigo at codespeak.net
arigo at codespeak.net
Fri Oct 19 14:52:05 CEST 2007
Author: arigo
Date: Fri Oct 19 14:52:05 2007
New Revision: 47581
Modified:
pypy/dist/pypy/rpython/lltypesystem/llarena.py
Log:
Found an alternative to lltype.top_container() allowing a couple of hackish
lines to be removed.
Modified: pypy/dist/pypy/rpython/lltypesystem/llarena.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/llarena.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/llarena.py Fri Oct 19 14:52:05 2007
@@ -14,7 +14,7 @@
pass
class Arena(object):
- object_arena_location = {} # {topcontainer: (arena, offset)}
+ object_arena_location = {} # {container: (arena, offset)}
def __init__(self, nbytes, zero):
self.nbytes = nbytes
@@ -39,7 +39,7 @@
assert offset >= stop, "object overlaps cleared area"
else:
obj = ptr._obj
- del Arena.object_arena_location[lltype.top_container(obj)]
+ del Arena.object_arena_location[obj]
del self.objectptrs[offset]
del self.objectsizes[offset]
obj._free()
@@ -81,8 +81,7 @@
self.usagemap[offset:offset+bytes] = array.array('c', pattern)
self.objectptrs[offset] = addr2.ptr
self.objectsizes[offset] = bytes
- top = lltype.top_container(addr2.ptr._obj)
- Arena.object_arena_location[top] = self, offset
+ Arena.object_arena_location[addr2.ptr._obj] = self, offset
# common case: 'size' starts with a GCHeaderOffset. In this case
# we can also remember that the real object starts after the header.
while isinstance(size, RoundedUpForAllocation):
@@ -95,8 +94,7 @@
assert objoffset not in self.objectptrs
self.objectptrs[objoffset] = objaddr.ptr
self.objectsizes[objoffset] = bytes - hdrbytes
- top = lltype.top_container(objaddr.ptr._obj)
- Arena.object_arena_location[top] = self, objoffset
+ Arena.object_arena_location[objaddr.ptr._obj] = self, objoffset
return addr2
class fakearenaaddress(llmemory.fakeaddress):
@@ -153,18 +151,17 @@
if not other:
return None, None
obj = other.ptr._obj
- top = lltype.top_container(obj)
- if top not in Arena.object_arena_location:
- return None, None
- arena, offset = Arena.object_arena_location[top]
- # common case: top is a FixedSizeArray of size 1 with just obj in it
- T = lltype.typeOf(top)
- if (top is obj or (isinstance(T, lltype.FixedSizeArray) and
- top.getitem(0) is obj)):
- # in this case, addr(obj) == addr(top)
- pass
- else:
- # here, it's likely that addr(obj) is a bit larger than addr(top).
+ innerobject = False
+ while obj not in Arena.object_arena_location:
+ obj = obj._parentstructure()
+ if obj is None:
+ return None, None # not found in the arena
+ innerobject = True
+ arena, offset = Arena.object_arena_location[obj]
+ if innerobject:
+ # 'obj' is really inside the object allocated from the arena,
+ # so it's likely that its address "should be" a bit larger than
+ # what 'offset' says.
# We could estimate the correct offset but it's a bit messy;
# instead, let's check the answer doesn't depend on it
if self.arena is arena:
More information about the Pypy-commit
mailing list