Closed vitreo12 closed 3 years ago
Check the memory-safety
branch, which fixes this!
Remaining issues:
1) What about if/while/loop/for
statements? Right now the check is only added before them, but not in the body (which can still potentially do bad things).... DONE
2) What about dynamic data allocation? Right now it would still return a nil value if it fails to allocate, which is problematic when chaining things: data[0][0]
. The first [0]
can trigger failure in allocation, returning a nil which can't be checked, crashing
Final implementation involved wrapping setjmp
and longjmp
manually, and it's working flawlessy.
branch: memory-safety-custom-setjmp
Right now, these checks are only done in the constructor of
structs
, but thenil
fields would still be accessible elsewhere in theinit
block, probably causing crashes.try
/raise
/except
cannot be used as they require the initialization of Nim's runtime to work.struct
field in theinit
block under the hood. This needs for every access to astruct
field to first check if thestruct
isnil
. This is the better real-time safe option, but it requires some thinking, especially as this can not only happen on assignment, e.g.struct.field = something
, but also if passing thestruct.field
around.