コード例 #1
0
ファイル: pmemblk.py プロジェクト: wwyf/pynvm
    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
ファイル: pmemblk.py プロジェクト: wwyf/pynvm
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
ファイル: pool.py プロジェクト: bitdancer/pynvm
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
ファイル: compat.py プロジェクト: pdeng6/pynvm
    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
ファイル: pmemlog.py プロジェクト: perone/pynvm
 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
ファイル: pool.py プロジェクト: pdeng6/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
コード例 #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)