Commit 28f4d7d4 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent aaf238b5
......@@ -30,7 +30,7 @@
from golang cimport chan, structZ, string, error, refptr
from golang cimport context
from libc.stdint cimport int64_t, uint64_t
from libc.stdint cimport int64_t, uint64_t, uint8_t
from libcpp.utility cimport pair
from libcpp.vector cimport vector
......@@ -99,13 +99,28 @@ cdef extern from "wcfs/internal/wcfs.h" namespace "wcfs" nogil:
error resync "_ptr()->resync" (Tid at)
cppclass _FileH:
# XXX add mmap?
pass
pair[Mapping, error] mmap(int64_t blk_start, int64_t blk_len) # `VMA *vma=nil` not exposed
cppclass FileH (refptr[_FileH]):
# FileH.X = FileH->X in C++
# XXX add mmap?
pass
pair[Mapping, error] mmap "_ptr()->mmap" (int64_t blk_start, int64_t blk_len)
cppclass _Mapping:
int64_t blk_start
int64_t blk_stop() const
uint8_t *mem_start
uint8_t *mem_stop
void unmap()
cppclass Mapping (refptr[_Mapping]):
# Mapping.X = Mapping->X in C++
int64_t blk_start "_ptr()->blk_start"
int64_t blk_stop "_ptr()->blk_stop" () const
uint8_t *mem_start "_ptr()->mem_start"
uint8_t *mem_stop "_ptr()->mem_stop"
void unmap "_ptr()->unmap" ()
# ---- python bits ----
......@@ -119,6 +134,9 @@ cdef class PyConn:
cdef class PyFileH:
cdef FileH wfileh
cdef class PyMapping:
cdef Mapping wmmap
cdef class PyWatchLink:
cdef WatchLink wlink
......
......@@ -96,6 +96,28 @@ cdef class PyFileH:
def __dealloc__(PyFileH pywfileh):
pywfileh.wfileh = nil
def mmap(PyFileH pywfileh, int64_t blk_start, int64_t blk_len):
with nogil:
_ = wfileh_mmap_pyexc(pywfileh.wfileh, blk_start, blk_len)
wmmap = _.first
err = _.second
if err != nil:
raise pyerr(err)
cdef PyMapping pywmmap = PyMapping.__new__(PyMapping)
pywmmap.wmmap = wmmap
return pywmmap
cdef class PyMapping:
def __dealloc__(PyMapping pywmmap):
pywmmap.wmmap = nil # XXX unmap too ?
def unmap(PyMapping pywmmap):
with nogil:
wmmap_unmap_pyexc(pywmmap.wmmap) # XXX +err
# ----------------------------------------
cdef class PyWatchLink:
......@@ -233,6 +255,12 @@ cdef nogil:
error wconn_resync_pyexc(Conn wconn, Tid at) except +topyexc:
return wconn.resync(at)
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)
void wmmap_unmap_pyexc(Mapping wmmap) except +topyexc:
wmmap.unmap()
error wlink_close_pyexc(WatchLink wlink) except +topyexc:
return wlink.close()
......
......@@ -1743,8 +1743,11 @@ def test_wcfspy_virtmem():
wconn = t.wc.connect(at1)
defer(wconn.close)
wf = wconn.open(zf._p_oid)
# XXX defer(wf.close)
# create mmap with 1 block beyond file size
m1 = wconn.mmap(zf._p_oid, 2, 3)
m1 = wf.mmap(2, 3)
defer(m1.unmap)
assert m1.blk_start == 2
......
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