[pypy-svn] r47287 - in pypy/branch/kill-keepalives-again/pypy/rpython: lltypesystem memory
arigo at codespeak.net
arigo at codespeak.net
Mon Oct 8 15:04:31 CEST 2007
Author: arigo
Date: Mon Oct 8 15:04:29 2007
New Revision: 47287
Modified:
pypy/branch/kill-keepalives-again/pypy/rpython/lltypesystem/llarena.py
pypy/branch/kill-keepalives-again/pypy/rpython/lltypesystem/llmemory.py
pypy/branch/kill-keepalives-again/pypy/rpython/memory/gcheader.py
Log:
Hacking more, but this check-in might be only for reference as I'm getting
unsure if it can ever sanely work.
Modified: pypy/branch/kill-keepalives-again/pypy/rpython/lltypesystem/llarena.py
==============================================================================
--- pypy/branch/kill-keepalives-again/pypy/rpython/lltypesystem/llarena.py (original)
+++ pypy/branch/kill-keepalives-again/pypy/rpython/lltypesystem/llarena.py Mon Oct 8 15:04:29 2007
@@ -27,6 +27,7 @@
for obj in self.objects.itervalues():
obj._free()
self.objects.clear()
+ self.pendinggcheaders = {}
if zero:
initialbyte = "0"
else:
@@ -62,6 +63,13 @@
p = lltype.malloc(TYPE, flavor='raw', zero=zero)
self.usagemap[offset:offset+size] = array.array('c', 'X' * size)
self.objects[offset] = p._obj
+ if offset in self.pendinggcheaders:
+ size_gc_header = self.pendinggcheaders.pop(offset)
+ gcheaderbuilder = size_gc_header.gcheaderbuilder
+ HDR = gcheaderbuilder.HDR
+ headeraddr = self.getaddr(offset) - size_gc_header
+ headerptr = llmemory.cast_adr_to_ptr(headeraddr, lltype.Ptr(HDR))
+ gcheaderbuilder.attach_header(p, headerptr)
class fakearenaaddress(llmemory.fakeaddress):
@@ -83,11 +91,18 @@
return '<arenaaddr %s + %d>' % (self.arena, self.offset)
def __add__(self, other):
- if isinstance(other, llmemory.AddressOffset):
- other = llmemory.raw_malloc_usage(other)
if isinstance(other, (int, long)):
- return self.arena.getaddr(self.offset + other)
- return NotImplemented
+ position = self.offset + other
+ elif isinstance(other, llmemory.AddressOffset):
+ position = self.offset + llmemory.raw_malloc_usage(other)
+ if isinstance(other, llmemory.GCHeaderOffset):
+ # take the expression 'addr + size_gc_header' as a hint that
+ # there is at 'addr' a GC header for the object
+ if position not in self.arena.objects:
+ self.arena.pendinggcheaders[position] = other
+ else:
+ return NotImplemented
+ return self.arena.getaddr(position)
def __sub__(self, other):
if isinstance(other, llmemory.AddressOffset):
@@ -111,6 +126,18 @@
else:
return llmemory.fakeaddress.__eq__(self, other)
+ def __lt__(self, other):
+ if isinstance(other, fakearenaaddress):
+ if self.arena is not other.arena:
+ return cmp(self.arena._getid(), other.arena._getid())
+ else:
+ return cmp(self.offset, other.offset)
+ elif isinstance(other, llmemory.fakeaddress) and not other:
+ return 1 # 'self' > NULL
+ else:
+ raise TypeError("comparing a %s and a %s" % (
+ self.__class__.__name__, other.__class__.__name__))
+
def _cast_to_ptr(self, EXPECTED_TYPE):
if EXPECTED_TYPE == llmemory.GCREF:
obj = lltype._opaque(EXPECTED_TYPE.TO, _original_address = self)
Modified: pypy/branch/kill-keepalives-again/pypy/rpython/lltypesystem/llmemory.py
==============================================================================
--- pypy/branch/kill-keepalives-again/pypy/rpython/lltypesystem/llmemory.py (original)
+++ pypy/branch/kill-keepalives-again/pypy/rpython/lltypesystem/llmemory.py Mon Oct 8 15:04:29 2007
@@ -351,6 +351,15 @@
else:
return NotImplemented
+ def __lt__(self, other):
+ raise TypeError("cannot compare fakeaddresses with '<'")
+ def __le__(self, other):
+ return self == other or self < other
+ def __gt__(self, other):
+ return not (self == other or self < other)
+ def __ge__(self, other):
+ return not (self < other)
+
def ref(self):
if not self:
raise NullAddressError
Modified: pypy/branch/kill-keepalives-again/pypy/rpython/memory/gcheader.py
==============================================================================
--- pypy/branch/kill-keepalives-again/pypy/rpython/memory/gcheader.py (original)
+++ pypy/branch/kill-keepalives-again/pypy/rpython/memory/gcheader.py Mon Oct 8 15:04:29 2007
@@ -28,16 +28,19 @@
def get_header(self, gcptr):
return self.obj2header.get(gcptr._as_obj(), None)
- def new_header(self, gcptr):
+ def attach_header(self, gcptr, headerptr):
gcobj = gcptr._as_obj()
assert gcobj not in self.obj2header
# sanity checks
assert gcobj._TYPE._gckind == 'gc'
assert not isinstance(gcobj._TYPE, lltype.GcOpaqueType)
assert not gcobj._parentstructure()
- headerptr = lltype.malloc(self.HDR, immortal=True)
self.obj2header[gcobj] = headerptr
header2obj[headerptr._obj] = gcptr._as_ptr()
+
+ def new_header(self, gcptr):
+ headerptr = lltype.malloc(self.HDR, immortal=True)
+ self.attach_header(gcptr, headerptr)
return headerptr
def _freeze_(self):
More information about the Pypy-commit
mailing list