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

Fix weird GC issue #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix weird GC issue #1

wants to merge 1 commit into from

Conversation

mratsim
Copy link

@mratsim mratsim commented Aug 26, 2019

This fixes the your issue.

Debugging process:

My log were different from the one you reported on the forum (I also used GcAssert)

[GCASSERT] decRef: waZctDecRefTraceback (most recent call last)
/home/beta/Programming/scratchspace/nim-help/t_raptor_db.nim(246) t_raptor_db
/home/beta/Programming/scratchspace/nim-help/t_raptor_db.nim(220) main
/home/beta/Programming/scratchspace/nim-help/raptor_db.nim(271) get_length_cutoff
/home/beta/Programming/scratchspace/nim-help/raptor_db.nim(227) load_rdb
/home/beta/Programming/scratchspace/nim-help/raptor_db.nim(168) strlen
/home/beta/.choosenim/toolchains/nim-#devel/lib/system/strmantle.nim(74) nimIntToStr
/home/beta/.choosenim/toolchains/nim-#devel/lib/system/gc.nim(439) newObj

I looked into strlen to check if there wasn't an issue in its usage as it's easy to misuse.
I added an echo addr(a) to check the address and the error changed completely to

GCASSERT] decRef: waZctDecRefTraceback (most recent call last)
/home/beta/Programming/scratchspace/nim-help/t_raptor_db.nim(246) t_raptor_db
/home/beta/Programming/scratchspace/nim-help/t_raptor_db.nim(196) main
/home/beta/Programming/scratchspace/nim-help/raptor_db.nim(273) get_length_cutoff
/home/beta/Programming/scratchspace/nim-help/raptor_db.nim(205) load_rdb
/home/beta/.choosenim/toolchains/nim-#devel/lib/system/gc.nim(435) newObjNoInit

I looked into the C code into what called newObjNoInit, found that it was creating a new string.

But in general a new string even uninitialized works fine in Nim. Looking back into the code,
the only unusual thing related to GC was returning a ref Db (instead of having a type DbRef = ref Db alias) so I tried to remove that and code compiled and ran successfully.


proc strlen(a: var Headroom): int =
echo " calc strlen"
echo addr(a) # Changes the stacktrace to load_rbd(205), newObjNoInit
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right this line changes the stacktrace. Odd.

stderr.write("BEFORE")
new(result)
# new(result)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha. The problem is with writing into addr result.version, which is nim-string, not cstring.

Thanks!

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