From 369ac2dd2db036c591983839fcf4e6129a501be8 Mon Sep 17 00:00:00 2001 From: Charles Blake Date: Tue, 11 Dec 2018 10:27:27 -0500 Subject: [PATCH] Address dom96/Araq opinions in https://github.com/nim-lang/Nim/pull/9922 Updating accessors are also provided since the idea of this change is to allow "updating" operations external to the module which are by their very nature closely tied to module internals (as well as to OS interface details). --- lib/pure/memfiles.nim | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/pure/memfiles.nim b/lib/pure/memfiles.nim index 61eff3295d..b742423708 100644 --- a/lib/pure/memfiles.nim +++ b/lib/pure/memfiles.nim @@ -36,11 +36,26 @@ type size*: int ## size of the memory mapped file when defined(windows): - fHandle*: Handle - mapHandle*: Handle - wasOpened*: bool ## only close if wasOpened + fHandle: Handle + mapHandle: Handle + wasOpened: bool ## only close if wasOpened else: - handle*: cint + handle: cint + +when defined(windows): + proc fHandle*(m: MemFile): Handle = m.fHandle + proc mapHandle*(m: MemFile): Handle = m.mapHandle + proc wasOpened*(m: MemFile): bool = m.wasOpened + proc `fHandle=`*(m: var MemFile, fHandle: Handle) = + m.fHandle = fHandle + proc `mapHandle=`*(m: var MemFile, mapHandle: Handle) = + m.mapHandle = mapHandle + proc `wasOpened=`*(m: var MemFile, wasOpened: bool) = + m.wasOpened = wasOpened +else: + proc handle*(m: MemFile): cint = m.handle + proc `handle=`*(m: var MemFile, handle: cint) = + m.handle = handle proc mapMem*(m: var MemFile, mode: FileMode = fmRead, mappedSize = -1, offset = 0): pointer =