From c210e1255cc902130ba76d4d1f014ac0f724d145 Mon Sep 17 00:00:00 2001 From: boydgreenfield Date: Mon, 5 May 2014 14:56:14 -0700 Subject: [PATCH 1/4] Clarify newFileSize & mappedSize params in memfiles.open() docs --- lib/pure/memfiles.nim | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/pure/memfiles.nim b/lib/pure/memfiles.nim index 807f3da433..97220b90b3 100644 --- a/lib/pure/memfiles.nim +++ b/lib/pure/memfiles.nim @@ -74,9 +74,22 @@ proc unmapMem*(f: var TMemFile, p: pointer, size: int) = proc open*(filename: string, mode: TFileMode = fmRead, mappedSize = -1, offset = 0, newFileSize = -1): TMemFile = ## opens a memory mapped file. If this fails, ``EOS`` is raised. - ## `newFileSize` can only be set if the file is not opened with ``fmRead`` - ## access. `mappedSize` and `offset` can be used to map only a slice of - ## the file. + ## `newFileSize` can only be set if the file does not exist and is opened + ## with write access (e.g., with fmReadWrite). `mappedSize` and `offset` + ## can be used to map only a slice of the file. Example: + ## + ## .. code-block:: nimrod + ## var + ## mm, mm_full, mm_half: TMemFile + ## + ## mm = memfiles.open("/tmp/test.mmap", mode = fmWrite, newFileSize = 1024) # Create a new file + ## mm.close() + ## + ## # Read the whole file, would fail if newFileSize was set + ## mm_full = memfiles.open("/tmp/test.mmap", mode = fmReadWrite, mappedSize = -1) + ## + ## # Read the first 512 bytes + ## mm_half = memfiles.open("/tmp/test.mmap", mode = fmReadWrite, mappedSize = 512) # The file can be resized only when write mode is used: assert newFileSize == -1 or mode != fmRead From a309a5f38abd7c6d57f1e80a3aef81c3c3501f65 Mon Sep 17 00:00:00 2001 From: boydgreenfield Date: Mon, 5 May 2014 16:42:30 -0700 Subject: [PATCH 2/4] Update posix open() call to incl. permissions This explicitly grants user read/write access to newly-created mmap files. Previously, on some systems files would be created but could not be re-opened as the user lacked sufficient permissions. --- lib/pure/memfiles.nim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/pure/memfiles.nim b/lib/pure/memfiles.nim index 97220b90b3..31fefc6c82 100644 --- a/lib/pure/memfiles.nim +++ b/lib/pure/memfiles.nim @@ -178,8 +178,11 @@ proc open*(filename: string, mode: TFileMode = fmRead, if newFileSize != -1: flags = flags or O_CREAT or O_TRUNC + var permissions_mode = S_IRUSR or S_IWUSR + result.handle = open(filename, flags, permissions_mode) + else: + result.handle = open(filename, flags) - result.handle = open(filename, flags) if result.handle == -1: # XXX: errno is supposed to be set here # Is there an exception that wraps it? From 876cad3a914a42ab5ead3d5c9a610bb10790276c Mon Sep 17 00:00:00 2001 From: boydgreenfield Date: Tue, 20 May 2014 16:57:33 -0400 Subject: [PATCH 3/4] Fix missing import in nimprof.nim when --threads:on --- lib/pure/nimprof.nim | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pure/nimprof.nim b/lib/pure/nimprof.nim index 3d0cc21541..132ea9462e 100644 --- a/lib/pure/nimprof.nim +++ b/lib/pure/nimprof.nim @@ -60,6 +60,7 @@ when not defined(memProfiler): else: interval = intervalInUs * 1000 - tickCountCorrection when withThreads: + import locks var profilingLock: TLock From fd352cc0b541074d845e1ad275b8568ed460e24f Mon Sep 17 00:00:00 2001 From: boydgreenfield Date: Tue, 20 May 2014 17:02:51 -0400 Subject: [PATCH 4/4] Revert 876cad3a - making nimprof fix on a new branch --- lib/pure/nimprof.nim | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/pure/nimprof.nim b/lib/pure/nimprof.nim index 132ea9462e..3d0cc21541 100644 --- a/lib/pure/nimprof.nim +++ b/lib/pure/nimprof.nim @@ -60,7 +60,6 @@ when not defined(memProfiler): else: interval = intervalInUs * 1000 - tickCountCorrection when withThreads: - import locks var profilingLock: TLock