neo
neo copied to clipboard
Upstream is introducing newSeqUninit
ref https://github.com/nim-lang/Nim/pull/22739
Hi @ringabout , thank you for your contribution, but there is an issue to fix before that: shallowCopy has been removed, and hence neo is currently non functional on Nim 2.
I am not sure what is the best way to proceed - I have little time to figure out how to make copies shallow on Nim 2, and until that is done, there is little point in making this change, which only affects Nim 2 anyway.
I am open to suggestions
It breaks Nim CI, besides you can still use neo with Nim 2.0 in refc, which keeps shallowCopy.
You might be able to inspect the intenals of seqs, for instance
type
NimSeqV2[T] = object
len: int
p: pointer
proc unsafeShallowCopy*[T](dest: var seq[T], src: seq[T]) =
cast[ptr NimSeqV2[T]](addr dest).p = cast[ptr NimSeqV2[T]](addr src).p
cast[ptr NimSeqV2[T]](addr dest).len = cast[ptr NimSeqV2[T]](addr src).len
proc foo =
var x = @[1, 2, 3]
var y: seq[int]
unsafeShallowCopy(y, x)
echo (x, y)
foo()
but you need to be cautious of the lifetime of x or set x.p to nil if needed.