Commit cce405b1 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent bc4a30e4
...@@ -100,11 +100,13 @@ cdef extern from "wcfs/internal/wcfs.h" namespace "wcfs" nogil: ...@@ -100,11 +100,13 @@ cdef extern from "wcfs/internal/wcfs.h" namespace "wcfs" nogil:
cppclass _FileH: cppclass _FileH:
size_t blksize size_t blksize
error close()
pair[Mapping, error] mmap(int64_t blk_start, int64_t blk_len) # `VMA *vma=nil` not exposed pair[Mapping, error] mmap(int64_t blk_start, int64_t blk_len) # `VMA *vma=nil` not exposed
cppclass FileH (refptr[_FileH]): cppclass FileH (refptr[_FileH]):
# FileH.X = FileH->X in C++ # FileH.X = FileH->X in C++
size_t blksize "_ptr()->blksize" size_t blksize "_ptr()->blksize"
error close "_ptr()->close" ()
pair[Mapping, error] mmap "_ptr()->mmap" (int64_t blk_start, int64_t blk_len) pair[Mapping, error] mmap "_ptr()->mmap" (int64_t blk_start, int64_t blk_len)
cppclass _Mapping: cppclass _Mapping:
......
...@@ -98,6 +98,12 @@ cdef class PyFileH: ...@@ -98,6 +98,12 @@ cdef class PyFileH:
def __dealloc__(PyFileH pywfileh): def __dealloc__(PyFileH pywfileh):
pywfileh.wfileh = nil pywfileh.wfileh = nil
def close(PyFileH pywfileh):
with nogil:
err = wfileh_close_pyexc(pywfileh.wfileh)
if err != nil:
raise pyerr(err)
def mmap(PyFileH pywfileh, int64_t blk_start, int64_t blk_len): def mmap(PyFileH pywfileh, int64_t blk_start, int64_t blk_len):
with nogil: with nogil:
_ = wfileh_mmap_pyexc(pywfileh.wfileh, blk_start, blk_len) _ = wfileh_mmap_pyexc(pywfileh.wfileh, blk_start, blk_len)
...@@ -285,6 +291,9 @@ cdef nogil: ...@@ -285,6 +291,9 @@ cdef nogil:
error wconn_resync_pyexc(Conn wconn, Tid at) except +topyexc: error wconn_resync_pyexc(Conn wconn, Tid at) except +topyexc:
return wconn.resync(at) return wconn.resync(at)
error wfileh_close_pyexc(FileH wfileh) except +topyexc:
return wfileh.close()
pair[Mapping, error] wfileh_mmap_pyexc(FileH wfileh, int64_t blk_start, int64_t blk_len) except +topyexc: pair[Mapping, error] wfileh_mmap_pyexc(FileH wfileh, int64_t blk_start, int64_t blk_len) except +topyexc:
return wfileh.mmap(blk_start, blk_len) return wfileh.mmap(blk_start, blk_len)
......
...@@ -295,6 +295,15 @@ pair<FileH, error> _Conn::open(zodb::Oid foid) { ...@@ -295,6 +295,15 @@ pair<FileH, error> _Conn::open(zodb::Oid foid) {
return make_pair(f, nil); return make_pair(f, nil);
} }
// close releases resources associated with FileH.
// XXX what happens with mappings?
error _FileH::close() {
_FileH& fileh = *this;
// XXX err ctx
return fileh._headf->close();
}
// mmap creates file mapping representing file[blk_start +blk_len) data as of wconn.at database state. // mmap creates file mapping representing file[blk_start +blk_len) data as of wconn.at database state.
// //
// If vma != nil, created mapping is associated with that vma of user-space virtual memory manager. // If vma != nil, created mapping is associated with that vma of user-space virtual memory manager.
......
...@@ -155,6 +155,7 @@ public: ...@@ -155,6 +155,7 @@ public:
void decref(); void decref();
public: public:
error close();
pair<Mapping, error> mmap(int64_t blk_start, int64_t blk_len, VMA *vma=nil); pair<Mapping, error> mmap(int64_t blk_start, int64_t blk_len, VMA *vma=nil);
}; };
......
...@@ -1744,7 +1744,7 @@ def test_wcfspy_virtmem(): ...@@ -1744,7 +1744,7 @@ def test_wcfspy_virtmem():
defer(wconn.close) defer(wconn.close)
fh = wconn.open(zf._p_oid) fh = wconn.open(zf._p_oid)
# XXX defer(fh.close) defer(fh.close)
# create mmap with 1 block beyond file size # create mmap with 1 block beyond file size
m1 = fh.mmap(2, 3) m1 = fh.mmap(2, 3)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment