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

unpack_items_imp uses same address #65

Closed
KayRichter opened this issue Apr 2, 2022 · 0 comments
Closed

unpack_items_imp uses same address #65

KayRichter opened this issue Apr 2, 2022 · 0 comments

Comments

@KayRichter
Copy link

Unpacking a sequence of ref object in unpack_items_imp writes to same address.

The following code should echo 2 3 5 but echos 5 5 5:

import msgpack4nim, streams
import msgpack4nim / msgpack4collection
import lists

type Element = ref object
  value: int

proc newElement(value: int): Element =
  result = new Element
  result.value = value

var elementList = initDoublyLinkedList[Element]()
elementList.add(newElement(2))
elementList.add(newElement(3))
elementList.add(newElement(5))

var strm = MsgStream.init()
strm.pack(elementList)

var sstrm = MsgStream.init(strm.data)
var unpackedList: DoublyLinkedList[Element]
sstrm.unpack(unpackedList)

for e in unpackedList:
  echo e.value

Moving var x: T into the for loop in the unpack_items_imp template fixed the problem for me.

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

No branches or pull requests

1 participant