Пример #1
0
    def read(self, block_num):
        """This method reads a block from memory pool at specified block number.

        .. note:: Reading a block that has never been written will return an
                  empty buffer.

        :return: data at block.
        """
        data = ffi.new("char[]", self.block_size)
        ret = lib.pmemblk_read(self.block_pool, data, block_num)
        if ret == -1:
            raise RuntimeError(ffi.string(ret))
        return ffi.string(data)
Пример #2
0
def check_version(major_required, minor_required):
    """Checks the libpmemblk version according to the specified major
    and minor versions required.

    :param major_required: Major version required.
    :param minor_required: Minor version required.
    :return: returns True if the nvm has the required version,
          or raises a RuntimeError exception in case of failure.
    """
    ret = lib.pmemblk_check_version(major_required, minor_required)
    if ret != ffi.NULL:
        raise RuntimeError(ffi.string(ret))
    return True
Пример #3
0
def _raise_per_errno():
    """Raise appropriate error, based on current errno using current message.

    Assume the pmem library has detected an error, and use the current errno
    and errormessage to raise an appropriate Python exception.  Convert EINVAL
    into ValueError, ENOMEM into MemoryError, and all others into OSError.
    """
    # XXX should probably check for errno 0 and/or an unset message.
    err = ffi.errno
    msg = ffi.string(lib.pmemobj_errormsg())
    if err == 0:
        raise OSError("raise_per_errno called with errno 0", 0)
    # In python3 OSError would do this check for us.
    if err == errno.EINVAL:
        raise ValueError(msg)
    elif err == errno.ENOMEM:
        raise MemoryError(msg)
    else:
        # In Python3 some errnos may result in subclass exceptions, but
        # the above are not covered by the OSError subclass logic.
        raise OSError(err, msg)
Пример #4
0
    def raise_per_errno(self):
        """Raise appropriate error, based on current errno using current message.

        Assume the pmem library has detected an error, and use the current
        errno and error message to raise an appropriate Python exception.
        Convert EINVAL into ValueError, ENOMEM into MemoryError,
        and all others into OSError.
        """
        err = ffi.errno
        msg = ffi.string(self.msg_func())
        if err == 0:
            raise OSError("raise_per_errno called with errno 0", 0)
        if msg == "":
            msg = os.strerror(err)
        # In python3 OSError would do this check for us.
        if err == errno.EINVAL:
            raise ValueError(msg)
        elif err == errno.ENOMEM:
            raise MemoryError(msg)
        else:
            # In Python3 some errnos may result in subclass exceptions, but
            # the above are not covered by the OSError subclass logic.
            raise OSError(err, msg)
Пример #5
0
Файл: pool.py Проект: pmem/pynvm
 def _resurrect_builtins_str(self, obj_ptr):
     body = ffi.cast('char *', obj_ptr) + ffi.sizeof('PObject')
     s = ffi.string(body)
     if sys.version_info[0] > 2:
         s = s.decode('utf-8')
     return s
Пример #6
0
 def inner_walk(buf, len, arg):
     cast_buf = ffi.cast("char *", buf)
     data = cast_buf[0:len]
     ret = func(ffi.string(data))
     return int(ret)
Пример #7
0
 def _resurrect_builtins_str(self, obj_ptr):
     body = ffi.cast('char *', obj_ptr) + ffi.sizeof('PObject')
     s = ffi.string(body)
     if sys.version_info[0] > 2:
         s = s.decode('utf-8')
     return s
Пример #8
0
 def inner_walk(buf, len, arg):
     cast_buf = ffi.cast("char *", buf)
     data = cast_buf[0:len]
     ret = func(ffi.string(data))
     return int(ret)