fixes some strictdefs warnings (#24502)

This commit is contained in:
ringabout
2024-12-04 18:28:13 +08:00
committed by GitHub
parent c3120b6121
commit 8f4bfda5f4
19 changed files with 44 additions and 15 deletions

View File

@@ -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:

View File

@@ -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)

View File

@@ -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]

View File

@@ -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)

View File

@@ -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)

View File

@@ -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.

View File

@@ -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:

View File

@@ -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:

View File

@@ -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)