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

GC_ref on empty string fails with [GCASSERT] incRef: interiorPtr #10307

Closed
iffy opened this issue Jan 15, 2019 · 2 comments
Closed

GC_ref on empty string fails with [GCASSERT] incRef: interiorPtr #10307

iffy opened this issue Jan 15, 2019 · 2 comments

Comments

@iffy
Copy link
Contributor

iffy commented Jan 15, 2019

Calling GC_ref() on an empty string when running with -d:useGcAssert causes a GCASSERT error (which is different than if the string is non-empty).

Example

proc someProc(x:bool):cstring =
  var res:string = ""
  if x:
    res = "yes"
  echo "res.repr: ", res.repr
  GC_ref(res)
  result = res

echo "running someProc(true)"
echo someProc(true)

echo "running someProc(false)"
echo someProc(false)

Current Output

running someProc(true)
res.repr: 0x10d90f058"yes"
yes
running someProc(false)
res.repr: ""
[GCASSERT] incRef: interiorPtr
Traceback (most recent call last)
testthing.nim(13)        testthing
testthing.nim(6)         someProc
gc.nim(198)              nimGCref
gc.nim(116)              incRef

Expected Output

running someProc(true)
res.repr: 0x10d90f058"yes"
yes
running someProc(false)
res.repr: ""

Possible Solution

It seems from the repr output that empty strings are treated specially (and likely don't have a location in memory?) I could change my code to only call GC_ref/unref on non-empty strings, though it would complicate things slightly. If that's the solution, I'm happy to do it.

Additional Information

$ nim -v
Nim Compiler Version 0.19.1 [MacOSX: amd64]
Compiled at 2018-10-19
Copyright (c) 2006-2018 by Andreas Rumpf

git hash: 863d3ef4ed7d18877a42f0060ebe63c34a27cf32
active boot switches: -d:release
@stale
Copy link

stale bot commented Aug 4, 2020

This issue has been automatically marked as stale because it has not had recent activity. If you think it is still a valid issue, write a comment below; otherwise it will be closed. Thank you for your contributions.

@stale stale bot added the stale Staled PR/issues; remove the label after fixing them label Aug 4, 2020
ringabout added a commit to ringabout/Nim that referenced this issue Nov 4, 2020
@ringabout
Copy link
Member

It has been fixed since 0.19.2.

@stale stale bot removed the stale Staled PR/issues; remove the label after fixing them label Nov 4, 2020
@Araq Araq closed this as completed Nov 4, 2020
narimiran pushed a commit that referenced this issue Nov 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants