Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream is introducing newSeqUninit #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ringabout
Copy link

@ringabout ringabout commented Sep 21, 2023

@andreaferretti
Copy link
Owner

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

@ringabout
Copy link
Author

ringabout commented Sep 25, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants