mirror of
https://github.com/nim-lang/Nim.git
synced 2026-09-17 02:32:11 +00:00
…tor iterating over tuples in refc fixes #26158
This commit is contained in:
@@ -424,7 +424,15 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||
simpleAsgn(p.s(cpsStmts), dest, src)
|
||||
of tyArray:
|
||||
if containsGarbageCollectedRef(dest.t) and p.config.selectedGC notin {gcArc, gcAtomicArc, gcOrc, gcYrc, gcHooks}:
|
||||
genGenericAsgn(p, dest, src, flags)
|
||||
# Static array literals may contain GC-managed values (for example,
|
||||
# strings). They must be copied deeply so that the destination does not
|
||||
# attempt to adjust the reference count of the static literal's
|
||||
# interior pointers. This mirrors the handling for tuples and objects
|
||||
# above, where static sources force a real copy.
|
||||
let newflags =
|
||||
if src.storage == OnStatic: flags + {needToCopy}
|
||||
else: flags
|
||||
genGenericAsgn(p, dest, src, newflags)
|
||||
else:
|
||||
let rd = rdLoc(dest)
|
||||
let rs = rdLoc(src)
|
||||
|
||||
@@ -174,3 +174,19 @@ iterator pairs(): (int, int) {.closure.} =
|
||||
|
||||
for pair in pairs():
|
||||
echo pair
|
||||
|
||||
# issue #26158: static array literals containing strings must be copied safely
|
||||
# when a closure iterator stores them in its environment.
|
||||
iterator fromStatic(): int {.closure.} =
|
||||
for _ in static([(" ",)]):
|
||||
break
|
||||
|
||||
for _ in fromStatic():
|
||||
break
|
||||
|
||||
iterator fromLiteral(): int {.closure.} =
|
||||
for _ in [(" ",)]:
|
||||
break
|
||||
|
||||
for _ in fromLiteral():
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user