diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/securehash.nim | 14 | ||||
-rw-r--r-- | lib/pure/strtabs.nim | 2 | ||||
-rw-r--r-- | lib/pure/times.nim | 7 | ||||
-rw-r--r-- | lib/system/gc.nim | 1 |
4 files changed, 12 insertions, 12 deletions
diff --git a/lib/pure/securehash.nim b/lib/pure/securehash.nim index 1f00ce8d3..f141732a7 100644 --- a/lib/pure/securehash.nim +++ b/lib/pure/securehash.nim @@ -43,13 +43,13 @@ type # Ported to Nim by Erik O'Leary type - Sha1State = array[0 .. 5-1, uint32] + Sha1State* = array[0 .. 5-1, uint32] Sha1Buffer = array[0 .. 80-1, uint32] template clearBuffer(w: Sha1Buffer, len = 16) = zeroMem(addr(w), len * sizeof(uint32)) -proc init(result: var Sha1State) = +proc init*(result: var Sha1State) = result[0] = 0x67452301'u32 result[1] = 0xefcdab89'u32 result[2] = 0x98badcfe'u32 @@ -112,7 +112,7 @@ proc innerHash(state: var Sha1State, w: var Sha1Buffer) = wrap state[3], d wrap state[4], e -template computeInternal(src: untyped) = +proc sha1(src: cstring; len: int): Sha1Digest = #Initialize state var state: Sha1State init(state) @@ -121,10 +121,10 @@ template computeInternal(src: untyped) = var w: Sha1Buffer #Loop through all complete 64byte blocks. - let byteLen = src.len + let byteLen = len let endOfFullBlocks = byteLen - 64 var endCurrentBlock = 0 - var currentBlock = 0 + var currentBlock = 0 while currentBlock <= endOfFullBlocks: endCurrentBlock = currentBlock + 64 @@ -169,9 +169,9 @@ template computeInternal(src: untyped) = for i in 0 .. Sha1DigestSize-1: result[i] = uint8((int(state[i shr 2]) shr ((3-(i and 3)) * 8)) and 255) -proc sha1(src: string) : Sha1Digest = +proc sha1(src: string): Sha1Digest = ## Calculate SHA1 from input string - computeInternal(src) + sha1(src, src.len) proc secureHash*(str: string): SecureHash = SecureHash(sha1(str)) proc secureHashFile*(filename: string): SecureHash = secureHash(readFile(filename)) diff --git a/lib/pure/strtabs.nim b/lib/pure/strtabs.nim index c5d471dfa..02bf439b2 100644 --- a/lib/pure/strtabs.nim +++ b/lib/pure/strtabs.nim @@ -108,7 +108,7 @@ proc rawGet(t: StringTableRef, key: string): int = h = nextTry(h, high(t.data)) result = - 1 -template get(t: StringTableRef, key: string): stmt {.immediate.} = +template get(t: StringTableRef, key: string) = var index = rawGet(t, key) if index >= 0: result = t.data[index].val else: diff --git a/lib/pure/times.nim b/lib/pure/times.nim index cf4e7dde6..99fdb5b0e 100644 --- a/lib/pure/times.nim +++ b/lib/pure/times.nim @@ -519,9 +519,6 @@ when not defined(JS): # copying is needed anyway to provide reentrancity; thus # the conversion is not expensive - proc timeInfoToTime(timeInfo: TimeInfo): Time = - toTime(timeInfo) - proc toTime(timeInfo: TimeInfo): Time = var cTimeInfo = timeInfo # for C++ we have to make a copy # because the header of mktime is broken in my version of libc @@ -537,6 +534,8 @@ when not defined(JS): # As timeInfoToTM does ignore the timezone, we need to adjust this here. result = Time(TimeImpl(result) + timeInfo.timezone) + proc timeInfoToTime(timeInfo: TimeInfo): Time = toTime(timeInfo) + const epochDiff = 116444736000000000'i64 rateDiff = 10000000'i64 # 100 nsecs @@ -616,7 +615,7 @@ elif defined(JS): result.weekday = weekDays[t.getUTCDay()] result.yearday = 0 - proc timeInfoToTime*(timeInfo: TimeInfo): Time = toTime(timeInfo) + proc timeInfoToTime(timeInfo: TimeInfo): Time = toTime(timeInfo) proc toTime*(timeInfo: TimeInfo): Time = result = internGetTime() diff --git a/lib/system/gc.nim b/lib/system/gc.nim index 6c418cc3a..8d9dc9025 100644 --- a/lib/system/gc.nim +++ b/lib/system/gc.nim @@ -467,6 +467,7 @@ proc rawNewObj(typ: PNimType, size: int, gch: var GcHeap): pointer = gcAssert(typ.kind in {tyRef, tyString, tySequence}, "newObj: 1") collectCT(gch) var res = cast[PCell](rawAlloc(gch.region, size + sizeof(Cell))) + gcAssert typ.kind in {tyString, tySequence} or size >= typ.base.size, "size too small" gcAssert((cast[ByteAddress](res) and (MemAlign-1)) == 0, "newObj: 2") # now it is buffered in the ZCT res.typ = typ |