mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
fixes some strictdefs warnings (#24502)
This commit is contained in:
@@ -10,8 +10,8 @@ type Cell* = object
|
||||
iterator parseTableCells*(s: string, delim = '\t'): Cell =
|
||||
## Iterates over all cells in a `delim`-delimited `s`, after a 1st
|
||||
## pass that computes number of rows, columns, and width of each column.
|
||||
var widths: seq[int]
|
||||
var cell: Cell
|
||||
var widths: seq[int] = @[]
|
||||
var cell: Cell = Cell()
|
||||
template update() =
|
||||
if widths.len<=cell.col:
|
||||
widths.setLen cell.col+1
|
||||
@@ -73,6 +73,7 @@ proc alignTable*(s: string, delim = '\t', fill = ' ', sep = " "): string =
|
||||
## to a width that's computed for each column; consecutive columns are
|
||||
## delimited by `sep`, and alignment space is filled using `fill`.
|
||||
## More customized formatting can be done by calling `parseTableCells` directly.
|
||||
result = ""
|
||||
for cell in parseTableCells(s, delim):
|
||||
result.add cell.text
|
||||
for i in cell.text.len..<cell.width:
|
||||
|
||||
@@ -26,7 +26,7 @@ proc handleHexChar*(c: char): int {.inline.} =
|
||||
of '0'..'9': result = (ord(c) - ord('0'))
|
||||
of 'a'..'f': result = (ord(c) - ord('a') + 10)
|
||||
of 'A'..'F': result = (ord(c) - ord('A') + 10)
|
||||
else: discard
|
||||
else: result = 0
|
||||
|
||||
proc decodePercent*(s: openArray[char], i: var int): char =
|
||||
## Converts `%xx` hexadecimal to the character with ordinal number `xx`.
|
||||
|
||||
@@ -75,11 +75,11 @@ const
|
||||
const
|
||||
signMask*: BitsType = not (not BitsType(0) shr 1)
|
||||
|
||||
proc constructDouble*(bits: BitsType): Double =
|
||||
result.bits = bits
|
||||
proc constructDouble*(bits: BitsType): Double =
|
||||
result = Double(bits: bits)
|
||||
|
||||
proc constructDouble*(value: ValueType): Double =
|
||||
result.bits = cast[typeof(result.bits)](value)
|
||||
proc constructDouble*(value: ValueType): Double =
|
||||
result = Double(bits: cast[typeof(result.bits)](value))
|
||||
|
||||
proc physicalSignificand*(this: Double): BitsType {.noSideEffect.} =
|
||||
return this.bits and significandMask
|
||||
@@ -1234,7 +1234,7 @@ proc formatDigits*[T: Ordinal](buffer: var openArray[char]; pos: T; digits: uint
|
||||
when true: #defined(vcc) and not defined(clang):
|
||||
## VC does not inline the memmove call below. (Even if compiled with /arch:AVX2.)
|
||||
## However, memcpy will be inlined.
|
||||
var tmp: array[16, char]
|
||||
var tmp = default(array[16, char])
|
||||
for i in 0..<16: tmp[i] = buffer[i+pos+decimalPoint]
|
||||
for i in 0..<16: buffer[i+pos+decimalPoint+1] = tmp[i]
|
||||
else:
|
||||
|
||||
@@ -41,6 +41,7 @@ proc diffFiles*(path1, path2: string): tuple[output: string, same: bool] =
|
||||
# This could be customized, e.g. non-git diff with `diff -uNdr`, or with
|
||||
# git diff options (e.g. --color-moved, --word-diff).
|
||||
# in general, `git diff` has more options than `diff`.
|
||||
result = default(tuple[output: string, same: bool])
|
||||
var status = 0
|
||||
(result.output, status) = execCmdEx("git diff --no-index $1 $2" % [path1.quoteShell, path2.quoteShell])
|
||||
doAssert (status == 0) or (status == 1)
|
||||
|
||||
@@ -36,7 +36,7 @@ iterator walkDirRecFilter*(dir: string, follow: proc(entry: PathEntry): bool = n
|
||||
]#
|
||||
var stack = @["."]
|
||||
var checkDir = checkDir
|
||||
var entry: PathEntry
|
||||
var entry: PathEntry = PathEntry()
|
||||
while stack.len > 0:
|
||||
let d = stack.pop()
|
||||
for k, p in walkDir(dir / d, relative = true, checkDir = checkDir):
|
||||
|
||||
@@ -158,6 +158,7 @@ proc getTempDir*(): string {.rtl, extern: "nos$1",
|
||||
const tempDir {.strdefine.}: string = tempDirDefault
|
||||
result = tempDir
|
||||
else:
|
||||
result = ""
|
||||
when nimvm:
|
||||
getTempDirImpl(result)
|
||||
else:
|
||||
|
||||
@@ -997,6 +997,7 @@ proc sameFile*(path1, path2: string): bool {.rtl, extern: "nos$1",
|
||||
##
|
||||
## See also:
|
||||
## * `sameFileContent proc`_
|
||||
result = false
|
||||
when defined(windows):
|
||||
var success = true
|
||||
var f1 = openHandle(path1)
|
||||
|
||||
@@ -39,11 +39,11 @@ const
|
||||
exponentMask: BitsType = maxIeeeExponent shl (significandSize - 1)
|
||||
signMask: BitsType = not (not BitsType(0) shr 1)
|
||||
|
||||
proc constructSingle(bits: BitsType): Single =
|
||||
result.bits = bits
|
||||
proc constructSingle(bits: BitsType): Single =
|
||||
result = Single(bits: bits)
|
||||
|
||||
proc constructSingle(value: ValueType): Single =
|
||||
result.bits = cast[typeof(result.bits)](value)
|
||||
proc constructSingle(value: ValueType): Single =
|
||||
result = Single(bits: cast[typeof(result.bits)](value))
|
||||
|
||||
proc physicalSignificand(this: Single): BitsType {.noSideEffect.} =
|
||||
return this.bits and significandMask
|
||||
|
||||
@@ -399,6 +399,8 @@ proc readLine*(f: File, line: var string): bool {.tags: [ReadIOEffect],
|
||||
## character(s) are not part of the returned string. Returns `false`
|
||||
## if the end of the file has been reached, `true` otherwise. If
|
||||
## `false` is returned `line` contains no new data.
|
||||
result = false
|
||||
|
||||
proc c_memchr(s: pointer, c: cint, n: csize_t): pointer {.
|
||||
importc: "memchr", header: "<string.h>".}
|
||||
|
||||
@@ -737,6 +739,8 @@ proc open*(f: var File, filename: string,
|
||||
discard c_setvbuf(f, nil, IOFBF, cast[csize_t](bufSize))
|
||||
elif bufSize == 0:
|
||||
discard c_setvbuf(f, nil, IONBF, 0)
|
||||
else:
|
||||
result = false
|
||||
|
||||
proc reopen*(f: File, filename: string, mode: FileMode = fmRead): bool {.
|
||||
tags: [], benign.} =
|
||||
@@ -754,6 +758,8 @@ proc reopen*(f: File, filename: string, mode: FileMode = fmRead): bool {.
|
||||
closeIgnoreError(f)
|
||||
return false
|
||||
result = true
|
||||
else:
|
||||
result = false
|
||||
|
||||
proc open*(f: var File, filehandle: FileHandle,
|
||||
mode: FileMode = fmRead): bool {.tags: [], raises: [], benign.} =
|
||||
@@ -778,6 +784,7 @@ proc open*(filename: string,
|
||||
## could not be opened.
|
||||
##
|
||||
## The file handle associated with the resulting `File` is not inheritable.
|
||||
result = default(File)
|
||||
if not open(result, filename, mode, bufSize):
|
||||
raise newException(IOError, "cannot open: " & filename)
|
||||
|
||||
|
||||
@@ -152,10 +152,12 @@ when not (defined(cpu16) or defined(cpu8)):
|
||||
yield result
|
||||
|
||||
proc newWideCString*(size: int): WideCStringObj =
|
||||
result = default(WideCStringObj)
|
||||
createWide(result, size * 2 + 2)
|
||||
|
||||
proc newWideCString*(source: cstring, L: int): WideCStringObj =
|
||||
## Warning:: `source` needs to be preallocated with the length `L`
|
||||
result = default(WideCStringObj)
|
||||
createWide(result, L * 2 + 2)
|
||||
var d = 0
|
||||
for ch in runes(source, L):
|
||||
|
||||
@@ -575,6 +575,7 @@ proc isAccessible(a: MemRegion, p: pointer): bool {.inline.} =
|
||||
result = contains(a.chunkStarts, pageIndex(p))
|
||||
|
||||
proc contains[T](list, x: T): bool =
|
||||
result = false
|
||||
var it = list
|
||||
while it != nil:
|
||||
if it == x: return true
|
||||
@@ -1164,6 +1165,7 @@ proc dealloc(allocator: var MemRegion, p: pointer) =
|
||||
rawDealloc(allocator, p)
|
||||
|
||||
proc realloc(allocator: var MemRegion, p: pointer, newsize: Natural): pointer =
|
||||
result = nil
|
||||
if newsize > 0:
|
||||
result = alloc(allocator, newsize)
|
||||
if p != nil:
|
||||
|
||||
@@ -211,6 +211,7 @@ when defined(gcOrc):
|
||||
#include cyclecollector
|
||||
|
||||
proc nimDecRefIsLast(p: pointer): bool {.compilerRtl, inl.} =
|
||||
result = false
|
||||
if p != nil:
|
||||
var cell = head(p)
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ proc initPtrTable(): PtrTable =
|
||||
template deinit(t: PtrTable) = dealloc(t)
|
||||
|
||||
proc get(t: PtrTable; key: pointer): pointer =
|
||||
result = nil
|
||||
var h = hashPtr(key)
|
||||
while true:
|
||||
let k = t.data[h and t.max][0]
|
||||
|
||||
@@ -11,24 +11,30 @@ when not defined(nimPreviewSlimSystem):
|
||||
|
||||
func `$`*(x: float | float32): string =
|
||||
## Outplace version of `addFloat`.
|
||||
result = ""
|
||||
result.addFloat(x)
|
||||
|
||||
proc `$`*(x: int): string {.raises: [].} =
|
||||
## Outplace version of `addInt`.
|
||||
result = ""
|
||||
result.addInt(x)
|
||||
|
||||
proc `$`*(x: int64): string {.raises: [].} =
|
||||
## Outplace version of `addInt`.
|
||||
result = ""
|
||||
result.addInt(x)
|
||||
|
||||
proc `$`*(x: uint64): string {.raises: [].} =
|
||||
## Outplace version of `addInt`.
|
||||
result = ""
|
||||
addInt(result, x)
|
||||
|
||||
# same as old `ctfeWhitelist` behavior, whether or not this is a good idea.
|
||||
template gen(T) =
|
||||
# xxx simplify this by supporting this in compiler: int{lit} | uint64{lit} | int64{lit}
|
||||
func `$`*(x: T{lit}): string {.compileTime.} = result.addInt(x)
|
||||
func `$`*(x: T{lit}): string {.compileTime.} =
|
||||
result = ""
|
||||
result.addInt(x)
|
||||
gen(int)
|
||||
gen(uint64)
|
||||
gen(int64)
|
||||
|
||||
@@ -117,6 +117,7 @@ template divImplFallback(name, T) {.dirty.} =
|
||||
if a == low(T) and b == T(-1):
|
||||
result = true
|
||||
else:
|
||||
result = false
|
||||
res[] = a div b
|
||||
|
||||
divImplFallback(nimDivInt, int)
|
||||
|
||||
@@ -85,7 +85,7 @@ when hasAlloc and not defined(js):
|
||||
|
||||
else:
|
||||
template incStat(what: untyped) = discard
|
||||
proc getAllocStats*(): AllocStats = discard
|
||||
proc getAllocStats*(): AllocStats = result = default(AllocStats)
|
||||
|
||||
template alloc*(size: Natural): pointer =
|
||||
## Allocates a new memory block with at least `size` bytes.
|
||||
|
||||
@@ -509,6 +509,7 @@ proc rememberCycle(isDestroyAction: bool; s: Cell; desc: PNimTypeV2) {.noinline.
|
||||
registerCycle(s, desc)
|
||||
|
||||
proc nimDecRefIsLastCyclicDyn(p: pointer): bool {.compilerRtl, inl.} =
|
||||
result = false
|
||||
if p != nil:
|
||||
var cell = head(p)
|
||||
if (cell.rc and not rcMask) == 0:
|
||||
@@ -520,6 +521,7 @@ proc nimDecRefIsLastCyclicDyn(p: pointer): bool {.compilerRtl, inl.} =
|
||||
rememberCycle(result, cell, cast[ptr PNimTypeV2](p)[])
|
||||
|
||||
proc nimDecRefIsLastDyn(p: pointer): bool {.compilerRtl, inl.} =
|
||||
result = false
|
||||
if p != nil:
|
||||
var cell = head(p)
|
||||
if (cell.rc and not rcMask) == 0:
|
||||
@@ -533,6 +535,7 @@ proc nimDecRefIsLastDyn(p: pointer): bool {.compilerRtl, inl.} =
|
||||
unregisterCycle(cell)
|
||||
|
||||
proc nimDecRefIsLastCyclicStatic(p: pointer; desc: PNimTypeV2): bool {.compilerRtl, inl.} =
|
||||
result = false
|
||||
if p != nil:
|
||||
var cell = head(p)
|
||||
if (cell.rc and not rcMask) == 0:
|
||||
|
||||
@@ -32,6 +32,7 @@ proc ltStrings(a, b: string): bool {.inline, compilerproc.} =
|
||||
cmpStrings(a, b) < 0
|
||||
|
||||
proc eqStrings(a, b: string): bool {.inline, compilerproc.} =
|
||||
result = false
|
||||
let alen = a.len
|
||||
let blen = b.len
|
||||
if alen == blen:
|
||||
|
||||
@@ -88,6 +88,7 @@ else:
|
||||
importc: "pthread_setspecific", header: pthreadh.}
|
||||
|
||||
proc threadVarAlloc(): ThreadVarSlot {.inline.} =
|
||||
result = default(ThreadVarSlot)
|
||||
discard pthread_key_create(addr(result), nil)
|
||||
proc threadVarSetValue(s: ThreadVarSlot, value: pointer) {.inline.} =
|
||||
discard pthread_setspecific(s, value)
|
||||
|
||||
Reference in New Issue
Block a user