def func(no): m = mmap.mmap(no, 6, access=mmap.ACCESS_READ) m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE) m.write_byte("x") m.seek(0) assert m.read(6) == "xoobar" m.close()
def func(no): try: mmap.mmap(no, 123) except RValueError: pass else: raise Exception("didn't raise")
def func(): m = mmap.mmap(-1, 1000, tagname="foo") # same tagname, but larger size try: m2 = mmap.mmap(-1, 5000, tagname="foo") m2.getitem(4500) except WindowsError: pass m.close()
def test_windows_crasher_1(self): if sys.platform != "win32": skip("Windows-only test") m = mmap.mmap(-1, 1000, tagname="foo") # same tagname, but larger size try: m2 = mmap.mmap(-1, 5000, tagname="foo") m2.getitem(4500) except WindowsError: pass m.close()
def func(no): m = mmap.mmap(no, 6) assert m.getitem(0) == 'f' assert m.getitem(-1) == 'r' # sl = slice(1, 2) # assert m.get_item(sl) == 'o' m.close()
def do_allocation_in_far_regions(): """On 32 bits: this reserves 1.25GB of address space, or 2.5GB on Linux, which helps test this module for address values that are signed or unsigned. On 64-bits: reserves 10 times 2GB of address space. This should help to find 32-vs-64-bit issues in the JIT. It is likely that objects are further apart than 32 bits can represent; it is also possible to hit the corner case of being precisely e.g. 2GB - 8 bytes apart. Avoid this function if your OS reserves actual RAM from mmap() eagerly. """ global far_regions if not far_regions: from pypy.rlib import rmmap if sys.maxint > 0x7FFFFFFF: PIECESIZE = 0x80000000 else: if sys.platform == 'linux': PIECESIZE = 0x10000000 else: PIECESIZE = 0x08000000 PIECES = 10 m = rmmap.mmap(-1, PIECES * PIECESIZE, rmmap.MAP_PRIVATE|rmmap.MAP_ANONYMOUS|rmmap.MAP_NORESERVE, rmmap.PROT_READ|rmmap.PROT_WRITE) m.close = lambda : None # leak instead of giving a spurious # error at CPython's shutdown m._ll2ctypes_pieces = [] for i in range(PIECES): m._ll2ctypes_pieces.append((i * PIECESIZE, (i+1) * PIECESIZE)) far_regions = m
def func(no): m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE) f_size = os.fstat(no).st_size assert intmask(m.file_size()) == f_size == 6 m.resize(10) f_size = os.fstat(no).st_size assert intmask(m.file_size()) == f_size == 10 m.close()
def func(no): m = mmap.mmap(no, 12) assert m.find("\0", 0, 13) == -1 # no searching past the stop assert m.find("\0", 0, 13, True) == -1 m.close() # m = mmap.mmap(no, 13) assert m.find("b", 0, 7) == 3 assert m.find("z", 0, 7) == -1 assert m.find("o", 11, 13) == -1 assert m.find("ob", 0, 7) == 2 assert m.find("\0", 0, 13) == 12 assert m.find("o", 1, 4) == 1 assert m.find("o", 2, 4) == 2 assert m.find("o", 2, -4) == 2 assert m.find("o", 8, -5) == -1 m.close()
def mmap(space, fileno, length, flags=rmmap.MAP_SHARED, prot=rmmap.PROT_WRITE | rmmap.PROT_READ, access=rmmap._ACCESS_DEFAULT): try: return space.wrap(W_MMap(space, rmmap.mmap(fileno, length, flags, prot, access))) except OSError, e: raise wrap_oserror(space, e, 'w_EnvironmentError')
def func(no): m = mmap.mmap(no, 7) assert m.find("b") == 3 assert m.find("z") == -1 assert m.find("o", 5) == -1 assert m.find("ob") == 2 assert m.find("\0") == 6 m.close()
def func(no): m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE) f_size = os.fstat(no).st_size assert m.file_size() == f_size == 6 m.resize(10) f_size = os.fstat(no).st_size assert m.file_size() == f_size == 10 m.close()
def func(no): m = mmap.mmap(no, 4) if os.name == "nt": # windows replaces \n with \r. it's time to change to \n only MS! assert m.readline() == "foo\r" elif os.name == "posix": assert m.readline() == "foo\n" assert m.readline() == "" m.close()
def func(no): m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE) m.move(1, 3, 3) assert m.read(6) == "fbarar" m.seek(0) m.move(1, 3, 2) a = m.read(6) assert a == "frarar" m.close()
def test_write_readonly(self): if os.name == "nt": skip("Needs PROT_READ") f = open(self.tmpname + "l", "w+") f.write("foobar") f.flush() m = mmap.mmap(f.fileno(), 6, prot=mmap.PROT_READ) raises(RTypeError, m.write, "foo") f.close()
def func(no): m = mmap.mmap(no, 1) m.close() try: m.read(1) except RValueError: pass else: raise Exception("Did not raise")
def mmap(space, w_subtype, fileno, length, tagname="", access=rmmap._ACCESS_DEFAULT, offset=0): self = space.allocate_instance(W_MMap, w_subtype) try: W_MMap.__init__(self, space, rmmap.mmap(fileno, length, tagname, access, offset)) except OSError, e: raise mmap_error(space, e)
def func(no): m = mmap.mmap(no, 1) assert m.read_byte() == "c" try: m.read_byte() except RValueError: pass else: raise Exception("Did not raise") m.close()
def mmap(space, w_subtype, fileno, length, flags=rmmap.MAP_SHARED, prot=rmmap.PROT_WRITE | rmmap.PROT_READ, access=rmmap._ACCESS_DEFAULT, offset=0): self = space.allocate_instance(W_MMap, w_subtype) try: W_MMap.__init__(self, space, rmmap.mmap(fileno, length, flags, prot, access, offset)) except OSError, e: raise mmap_error(space, e)
def func(no): m = mmap.mmap(no, 6) m.seek(0) assert m.tell() == 0 m.read(1) m.seek(1, 1) assert m.tell() == 2 m.seek(0) m.seek(-1, 2) assert m.tell() == 5 m.close()
def test_write_without_protwrite(self): if os.name == "nt": skip("Needs PROT_WRITE") f = open(self.tmpname + "l2", "w+") f.write("foobar") f.flush() m = mmap.mmap(f.fileno(), 6, prot=~mmap.PROT_WRITE) raises(RTypeError, m.write_byte, 'a') raises(RTypeError, m.write, "foo") m.close() f.close()
def mmap(space, fileno, length, flags=rmmap.MAP_SHARED, prot=rmmap.PROT_WRITE | rmmap.PROT_READ, access=rmmap._ACCESS_DEFAULT): try: return space.wrap( W_MMap(space, rmmap.mmap(fileno, length, flags, prot, access))) except OSError, e: raise wrap_oserror(space, e, 'w_EnvironmentError')
def mmap(space, w_subtype, fileno, length, tagname="", access=rmmap._ACCESS_DEFAULT, offset=0): self = space.allocate_instance(W_MMap, w_subtype) try: W_MMap.__init__( self, space, rmmap.mmap(fileno, length, tagname, access, offset)) except OSError, e: raise mmap_error(space, e)
def test_windows_crasher_2(self): if sys.platform != "win32": skip("Windows-only test") f = open(self.tmpname + "t", "w+") f.write("foobar") f.flush() f = open(self.tmpname + "t", "r+b") m = mmap.mmap(f.fileno(), 0) f.close() raises(WindowsError, m.resize, 0) raises(RValueError, m.getitem, 0) m.close()
def func(no): m = mmap.mmap(no, 6, access=mmap.ACCESS_READ) try: m.write('x') except RTypeError: pass else: assert False try: m.resize(7) except RTypeError: pass else: assert False m.close()
def test_find_rfind(self): f = open(self.tmpname + "g", "w+") f.write("foobarfoobar\0") f.flush() m = mmap.mmap(f.fileno(), 13) for s1 in range(-20, 20): for e1 in range(-20, 20): expected = "foobarfoobar\0".find("ob", s1, e1) assert m.find("ob", s1, e1, False) == expected expected = "foobarfoobar\0".rfind("ob", s1, e1) assert m.find("ob", s1, e1, True) == expected m.close() f.close()
def mmap(space, w_subtype, fileno, length, flags=rmmap.MAP_SHARED, prot=rmmap.PROT_WRITE | rmmap.PROT_READ, access=rmmap._ACCESS_DEFAULT, offset=0): self = space.allocate_instance(W_MMap, w_subtype) try: W_MMap.__init__( self, space, rmmap.mmap(fileno, length, flags, prot, access, offset)) except OSError, e: raise mmap_error(space, e)
def func(no): m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE) # def f(m): m[1:3] = u'xx' # py.test.raises(IndexError, f, m) # def f(m): m[1:4] = "zz" # py.test.raises(IndexError, f, m) # def f(m): m[1:6] = "z" * 6 # py.test.raises(IndexError, f, m) # def f(m): m[:2] = "z" * 5 # m[1:3] = 'xx' # assert m.read(6) == "fxxbar" # m.seek(0) m.setitem(0, 'x') assert m.getitem(0) == 'x' m.setitem(-6, 'y') data = m.read(6) assert data == "yoobar" # yxxbar with slice's stuff m.close()
def func(no): m = mmap.mmap(no, 1) assert m.read(99) == "c"
def entry_point(argv): try: res = mmap(0, 1024) except OSError: return 0 return 1
def func(no): m = mmap.mmap(no, 6) assert m.len() == 6 m.close()
def func(no): m = mmap.mmap(no, 1) assert m.tell() >= 0 m.close()
def func(no): m = mmap.mmap(no, 5) assert m.file_size() == 6 # size of the underline file, not the mmap m.close()
def func(no): m = mmap.mmap(no, 1) r = m.read_byte() m.close() return r
def func(no): m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE) m.close() m.close() # didn't explode
def func(no): m = mmap.mmap(no, 5) assert m.file_size( ) == 6 # size of the underline file, not the mmap m.close()
def mmap(space, fileno, length, tagname="", access=rmmap._ACCESS_DEFAULT): try: return space.wrap(W_MMap(space, rmmap.mmap(fileno, length, tagname, access))) except OSError, e: raise wrap_oserror(space, e, 'w_EnvironmentError')
def mmap(space, fileno, length, tagname="", access=rmmap._ACCESS_DEFAULT): try: return space.wrap( W_MMap(space, rmmap.mmap(fileno, length, tagname, access))) except OSError, e: raise wrap_oserror(space, e, 'w_EnvironmentError')