[pypy-svn] r15595 - in pypy/dist/pypy/rpython/memory: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Thu Aug 4 10:39:23 CEST 2005
Author: cfbolz
Date: Thu Aug 4 10:39:22 2005
New Revision: 15595
Modified:
pypy/dist/pypy/rpython/memory/lladdress.py
pypy/dist/pypy/rpython/memory/simulator.py
pypy/dist/pypy/rpython/memory/test/test_address.py
Log:
add implementation of raw_malloc
Modified: pypy/dist/pypy/rpython/memory/lladdress.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/lladdress.py (original)
+++ pypy/dist/pypy/rpython/memory/lladdress.py Thu Aug 4 10:39:22 2005
@@ -119,7 +119,7 @@
simulator.free(addr.intaddress)
def raw_memcopy(addr1, addr2, size):
- pass
+ simulator.memcopy(addr1.intaddress, addr2.intaddress, size)
supported_access_types = {"signed": lltype.Signed,
Modified: pypy/dist/pypy/rpython/memory/simulator.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/simulator.py (original)
+++ pypy/dist/pypy/rpython/memory/simulator.py Thu Aug 4 10:39:22 2005
@@ -50,6 +50,16 @@
self.status[offset:offset + len(value)] = s
assert len(self.memory) == self.size
+ def memcopy(self, offset1, other, offset2, size):
+ if offset1 + size > self.size:
+ raise MemorySimulatorError, "trying to access memory between blocks"
+ if offset2 + size > other.size:
+ raise MemorySimulatorError, "trying to access memory between blocks"
+ print self.memory[offset1:offset1+size]
+ print self.status[offset1:offset1+size]
+ other.memory[offset2:offset2+size] = self.memory[offset1:offset1+size]
+ other.status[offset2:offset2+size] = self.status[offset1:offset1+size]
+
class MemorySimulator(object):
size_of_simulated_ram = 64 * 1024 * 1024
def __init__(self, ram_size = None):
@@ -100,5 +110,8 @@
block.setbytes(offset, struct.pack(fmt, *types))
def memcopy(self, address1, address2, size):
- data = self.getstruct("c" * size, address1)
- self.setstruct("c" * size, address2, *data)
+ block1 = self.find_block(address1)
+ block2 = self.find_block(address2)
+ offset1 = address1 - block1.baseaddress
+ offset2 = address2 - block2.baseaddress
+ block1.memcopy(offset1, block2, offset2, size)
Modified: pypy/dist/pypy/rpython/memory/test/test_address.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/test/test_address.py (original)
+++ pypy/dist/pypy/rpython/memory/test/test_address.py Thu Aug 4 10:39:22 2005
@@ -137,4 +137,16 @@
assert addr.attached[1] == g
assert addr.attached[0](1) == 2
assert addr.attached[1](0) == -1
-
+
+ def test_memcopy(self):
+ def f(x):
+ return x + 1
+ addr = raw_malloc(100)
+ addr.attached[0] = f
+ (addr + 10).signed[0] = 42
+ (addr + 20).char[0] = "a"
+ addr1 = raw_malloc(100)
+ raw_memcopy(addr, addr1, 100)
+ assert addr1.attached[0](0) == 1
+ assert (addr1 + 10).signed[0] == 42
+ assert (addr1 + 20).char[0] == "a"
More information about the Pypy-commit
mailing list