make tmemfile2 work again
This commit is contained in:
parent
20950ee073
commit
8bcaee1fdf
3 changed files with 6 additions and 3 deletions
|
|
@ -1769,6 +1769,7 @@ proc convStrToCStr(p: BProc, n: PNode, d: var TLoc) =
|
||||||
initLocExpr(p, n.sons[0], a)
|
initLocExpr(p, n.sons[0], a)
|
||||||
putIntoDest(p, d, n,
|
putIntoDest(p, d, n,
|
||||||
ropecg(p.module, "#nimToCStringConv($1)", [rdLoc(a)]),
|
ropecg(p.module, "#nimToCStringConv($1)", [rdLoc(a)]),
|
||||||
|
# "($1 ? $1->data : (NCSTRING)\"\")" % [a.rdLoc],
|
||||||
a.storage)
|
a.storage)
|
||||||
|
|
||||||
proc convCStrToStr(p: BProc, n: PNode, d: var TLoc) =
|
proc convCStrToStr(p: BProc, n: PNode, d: var TLoc) =
|
||||||
|
|
|
||||||
|
|
@ -399,7 +399,8 @@ iterator lines*(mfile: MemFile, buf: var TaintedString, delim='\l', eat='\r'): T
|
||||||
|
|
||||||
for ms in memSlices(mfile, delim, eat):
|
for ms in memSlices(mfile, delim, eat):
|
||||||
setLen(buf.string, ms.size)
|
setLen(buf.string, ms.size)
|
||||||
copyMem(buf.cstring, ms.data, ms.size)
|
if ms.size > 0:
|
||||||
|
copyMem(addr buf[0], ms.data, ms.size)
|
||||||
yield buf
|
yield buf
|
||||||
|
|
||||||
iterator lines*(mfile: MemFile, delim='\l', eat='\r'): TaintedString {.inline.} =
|
iterator lines*(mfile: MemFile, delim='\l', eat='\r'): TaintedString {.inline.} =
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,9 @@ mm.close()
|
||||||
|
|
||||||
# read, change
|
# read, change
|
||||||
mm_full = memfiles.open(fn, mode = fmWrite, mappedSize = -1, allowRemap = true)
|
mm_full = memfiles.open(fn, mode = fmWrite, mappedSize = -1, allowRemap = true)
|
||||||
echo "Full read size: ",mm_full.size
|
let size = mm_full.size
|
||||||
p = mm_full.mapMem(fmReadWrite, 20, 0)
|
p = mm_full.mapMem(fmReadWrite, 20, 0)
|
||||||
|
echo "Full read size: ", size
|
||||||
var p2 = cast[cstring](p)
|
var p2 = cast[cstring](p)
|
||||||
p2[0] = 'H'
|
p2[0] = 'H'
|
||||||
p2[1] = 'e'
|
p2[1] = 'e'
|
||||||
|
|
@ -32,7 +33,7 @@ mm_full.close()
|
||||||
|
|
||||||
# read half, and verify data change
|
# read half, and verify data change
|
||||||
mm_half = memfiles.open(fn, mode = fmRead, mappedSize = 10)
|
mm_half = memfiles.open(fn, mode = fmRead, mappedSize = 10)
|
||||||
echo "Half read size: ",mm_half.size, " Data: ", cast[cstring](mm_half.mem)
|
echo "Half read size: ", mm_half.size, " Data: ", cast[cstring](mm_half.mem)
|
||||||
mm_half.close()
|
mm_half.close()
|
||||||
|
|
||||||
if fileExists(fn): removeFile(fn)
|
if fileExists(fn): removeFile(fn)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue