Пример #1
0
 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()
Пример #2
0
 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()
Пример #3
0
        def func(no):

            try:
                mmap.mmap(no, 123)
            except RValueError:
                pass
            else:
                raise Exception("didn't raise")
Пример #4
0
        def func(no):

            try:
                mmap.mmap(no, 123)
            except RValueError:
                pass
            else:
                raise Exception("didn't raise")
Пример #5
0
 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()
Пример #6
0
    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()
Пример #7
0
    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()
Пример #8
0
 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()
Пример #9
0
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
Пример #10
0
 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()
Пример #11
0
 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()
Пример #12
0
 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()
Пример #13
0
    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')
Пример #14
0
 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()
Пример #15
0
 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()
Пример #16
0
 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()
Пример #17
0
 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()
Пример #18
0
 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()
Пример #19
0
 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()
Пример #20
0
 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()
Пример #21
0
 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()
Пример #22
0
 def func(no):
     m = mmap.mmap(no, 1)
     m.close()
     try:
         m.read(1)
     except RValueError:
         pass
     else:
         raise Exception("Did not raise")
Пример #23
0
 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()
Пример #24
0
 def func(no):
     m = mmap.mmap(no, 1)
     m.close()
     try:
         m.read(1)
     except RValueError:
         pass
     else:
         raise Exception("Did not raise")
Пример #25
0
 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()
Пример #26
0
 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)
Пример #27
0
 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()
Пример #28
0
 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)
Пример #29
0
 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()
Пример #30
0
 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()
Пример #31
0
 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()
Пример #32
0
 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()
Пример #33
0
    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')
Пример #34
0
 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)
Пример #35
0
    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()
Пример #36
0
    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()
Пример #37
0
 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()
Пример #38
0
    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()
Пример #39
0
 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()
Пример #40
0
 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)
Пример #41
0
    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()
Пример #42
0
        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()
Пример #43
0
        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()
Пример #44
0
 def func(no):
     m = mmap.mmap(no, 1)
     assert m.read(99) == "c"
Пример #45
0
 def entry_point(argv):
     try:
         res = mmap(0, 1024)
     except OSError:
         return 0
     return 1
Пример #46
0
 def func(no):
     m = mmap.mmap(no, 6)
     assert m.len() == 6
     m.close()
Пример #47
0
 def func(no):
     m = mmap.mmap(no, 1)
     assert m.tell() >= 0
     m.close()
Пример #48
0
 def func(no):
     m = mmap.mmap(no, 1)
     assert m.read(99) == "c"
Пример #49
0
 def func(no):
     m = mmap.mmap(no, 6)
     assert m.len() == 6
     m.close()
Пример #50
0
 def func(no):
     m = mmap.mmap(no, 5)
     assert m.file_size() == 6 # size of the underline file, not the mmap
     m.close()
Пример #51
0
 def func(no):
     m = mmap.mmap(no, 1)
     r = m.read_byte()
     m.close()
     return r
Пример #52
0
 def func(no):
     m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE)
     m.close()
     m.close() # didn't explode
Пример #53
0
 def func(no):
     m = mmap.mmap(no, 1)
     assert m.tell() >= 0
     m.close()
Пример #54
0
 def func(no):
     m = mmap.mmap(no, 5)
     assert m.file_size(
     ) == 6  # size of the underline file, not the mmap
     m.close()
Пример #55
0
 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')
Пример #56
0
 def func(no):
     m = mmap.mmap(no, 1)
     r = m.read_byte()
     m.close()
     return r
Пример #57
0
 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')
Пример #58
0
 def func(no):
     m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE)
     m.close()
     m.close()  # didn't explode