summary refs log tree commit diff stats
path: root/lib/pure/memfiles.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure/memfiles.nim')
-rw-r--r--lib/pure/memfiles.nim41
1 files changed, 21 insertions, 20 deletions
diff --git a/lib/pure/memfiles.nim b/lib/pure/memfiles.nim
index ffeb0beff..24dbfb6d3 100644
--- a/lib/pure/memfiles.nim
+++ b/lib/pure/memfiles.nim
@@ -1,7 +1,7 @@
 #
 #
-#            Nimrod's Runtime Library
-#        (c) Copyright 2014 Nimrod Contributors
+#            Nim's Runtime Library
+#        (c) Copyright 2014 Nim Contributors
 #
 #    See the file "copying.txt", included in this
 #    distribution, for details about the copyright.
@@ -22,7 +22,7 @@ else:
 import os
 
 type
-  TMemFile* = object {.pure.} ## represents a memory mapped file
+  MemFile* = object  ## represents a memory mapped file
     mem*: pointer    ## a pointer to the memory mapped file. The pointer
                      ## can be used directly to change the contents of the
                      ## file, if it was opened with write access.
@@ -34,8 +34,9 @@ type
     else:
       handle: cint
 
+{.deprecated: [TMemFile: MemFile].}
 
-proc mapMem*(m: var TMemFile, mode: TFileMode = fmRead,
+proc mapMem*(m: var MemFile, mode: FileMode = fmRead,
              mappedSize = -1, offset = 0): pointer =
   var readonly = mode == fmRead
   when defined(windows):
@@ -47,7 +48,7 @@ proc mapMem*(m: var TMemFile, mode: TFileMode = fmRead,
       if mappedSize == -1: 0 else: mappedSize,
       nil)
     if result == nil:
-      osError(osLastError())
+      raiseOSError(osLastError())
   else:
     assert mappedSize > 0
     result = mmap(
@@ -57,30 +58,30 @@ proc mapMem*(m: var TMemFile, mode: TFileMode = fmRead,
       if readonly: (MAP_PRIVATE or MAP_POPULATE) else: (MAP_SHARED or MAP_POPULATE),
       m.handle, offset)
     if result == cast[pointer](MAP_FAILED):
-      osError(osLastError())
+      raiseOSError(osLastError())
 
 
-proc unmapMem*(f: var TMemFile, p: pointer, size: int) =
+proc unmapMem*(f: var MemFile, p: pointer, size: int) =
   ## unmaps the memory region ``(p, <p+size)`` of the mapped file `f`.
   ## All changes are written back to the file system, if `f` was opened
   ## with write access. ``size`` must be of exactly the size that was requested
   ## via ``mapMem``.
   when defined(windows):
-    if unmapViewOfFile(p) == 0: osError(osLastError())
+    if unmapViewOfFile(p) == 0: raiseOSError(osLastError())
   else:
-    if munmap(p, size) != 0: osError(osLastError())
+    if munmap(p, size) != 0: raiseOSError(osLastError())
 
 
-proc open*(filename: string, mode: TFileMode = fmRead,
-           mappedSize = -1, offset = 0, newFileSize = -1): TMemFile =
+proc open*(filename: string, mode: FileMode = fmRead,
+           mappedSize = -1, offset = 0, newFileSize = -1): MemFile =
   ## opens a memory mapped file. If this fails, ``EOS`` is raised.
   ## `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
+  ## .. code-block:: nim
   ##   var
-  ##     mm, mm_full, mm_half: TMemFile
+  ##     mm, mm_full, mm_half: MemFile
   ##
   ##   mm = memfiles.open("/tmp/test.mmap", mode = fmWrite, newFileSize = 1024)    # Create a new file
   ##   mm.close()
@@ -100,11 +101,11 @@ proc open*(filename: string, mode: TFileMode = fmRead,
     result.size = 0
 
   when defined(windows):
-    template fail(errCode: TOSErrorCode, msg: expr) =
+    template fail(errCode: OSErrorCode, msg: expr) =
       rollback()
       if result.fHandle != 0: discard closeHandle(result.fHandle)
       if result.mapHandle != 0: discard closeHandle(result.mapHandle)
-      osError(errCode)
+      raiseOSError(errCode)
       # return false
       #raise newException(EIO, msg)
 
@@ -169,10 +170,10 @@ proc open*(filename: string, mode: TFileMode = fmRead,
       else: result.size = fileSize.int
 
   else:
-    template fail(errCode: TOSErrorCode, msg: expr) =
+    template fail(errCode: OSErrorCode, msg: expr) =
       rollback()
       if result.handle != 0: discard close(result.handle)
-      osError(errCode)
+      raiseOSError(errCode)
   
     var flags = if readonly: O_RDONLY else: O_RDWR
 
@@ -214,12 +215,12 @@ proc open*(filename: string, mode: TFileMode = fmRead,
     if result.mem == cast[pointer](MAP_FAILED):
       fail(osLastError(), "file mapping failed")
 
-proc close*(f: var TMemFile) =
+proc close*(f: var MemFile) =
   ## closes the memory mapped file `f`. All changes are written back to the
   ## file system, if `f` was opened with write access.
   
   var error = false
-  var lastErr: TOSErrorCode
+  var lastErr: OSErrorCode
 
   when defined(windows):
     if f.fHandle != INVALID_HANDLE_VALUE:
@@ -242,5 +243,5 @@ proc close*(f: var TMemFile) =
   else:
     f.handle = 0
   
-  if error: osError(lastErr)
+  if error: raiseOSError(lastErr)
 
=devel&id=d57fe6c904e996dca5adc0efa4d26c85032c1dc5'>^
eebee0eff ^
3d1c6de63 ^
e25474154 ^

72651de71 ^
3d1c6de63 ^


72651de71 ^
72651de71 ^



569c1ce5e ^
72651de71 ^
e25474154 ^

4cea15d27 ^
043921c7a ^
57fe3e8c4 ^
1c6f14dee ^
043921c7a ^
72651de71 ^
1786e3099 ^
e25474154 ^
043921c7a ^

72651de71 ^
8d99753d6 ^
eebee0eff ^
a068aaed3 ^

3051c52f5 ^
8d99753d6 ^
121519301 ^

42d0911d6 ^
72651de71 ^
804e2ac89 ^
a0a8934a4 ^
c7158af75 ^

55f8ed245 ^

9de3bc8ef ^
3d1c6de63 ^
e6f3f46cd ^



36e25a684 ^



36e25a684 ^
7063670a2 ^
e25474154 ^

e25474154 ^





72651de71 ^
14b5d5f26 ^



7063670a2 ^
e25474154 ^




1c6f14dee ^
e25474154 ^
e25474154 ^








7063670a2 ^
e25474154 ^

7063670a2 ^
674c05f42 ^

e25474154 ^



623fd8a8a ^
674c05f42 ^


623fd8a8a ^






e25474154 ^







36e25a684 ^
e25474154 ^
ade67f1ab ^
e25474154 ^



9fb36bd20 ^
99bcc233c ^
5b28d0820 ^
1786e3099 ^
ade67f1ab ^
804e2ac89 ^
55f8ed245 ^
c7158af75 ^
e25474154 ^
1786e3099 ^

e25474154 ^
1786e3099 ^








e25474154 ^




43de61f37 ^


e25474154 ^


e25474154 ^
121d4e0fc ^
e25474154 ^

e25474154 ^
121d4e0fc ^
22dc76a36 ^


121d4e0fc ^
e25474154 ^
6378fbd66 ^




1d02f2ea5 ^














e25474154 ^


dfb5cb3c5 ^




b595fc834 ^

79aaf213d ^
b595fc834 ^
c7158af75 ^



e25474154 ^




8682ed9bd ^

7063670a2 ^
8682ed9bd ^

e25474154 ^

8682ed9bd ^
d10b524c9 ^
c7158af75 ^
4fbba0a65 ^



03764f0ab ^
5b28d0820 ^



e25474154 ^
5b28d0820 ^

9fb36bd20 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274