This demonstrates a bug I keep finding while trying to make a Node native addon using Nim as the C-code generator.
Requirements:
- Node (I'm using 11.7.0)
- Nim (I'm using 0.19.9)
To see the problem:
make clean
npm i --ignore-scripts
make NIMBASE=/path/to/your/nimbase.h
make test
This will delete and regenerate files in csrc/
, build/
, lib/
and dist/
. I've committed my versions of dist/
and csrc/
to the repo for reference.
jssrc/test.ts
- TypeScript code that's run when you domake test
jssrc/main.ts
- JS module imported bytest.ts
and which wraps the native Node addonclib.nim
- My C library which provides an echo functionjstonimbinding.cpp
- Some C++ code that usesnode-addon-api
to wrap the C library into a form Node can consumebinding.gyp
- The magical incantation that compiles the Node addon.
On my computer, running this produces a ton of output, ending with:
C++ passing message: Hello 4129-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[GCASSERT] decRef
Traceback (most recent call last)
strformat.nim(268) hello_echo
gc.nim(245) unsureAsgnRef
gc.nim(109) decRef
make: *** [test] Error 1
In other cases, I've seen different errors (e.g. "incRef: interior pointer").