vitreo12 / omni

DSL for low-level audio programming.
https://vitreo12.github.io/omni/
MIT License
187 stars 6 forks source link

Stricter memory safety when `omni_alloc` returns nil #152

Closed vitreo12 closed 3 years ago

vitreo12 commented 3 years ago

Right now, these checks are only done in the constructor of structs, but the nil fields would still be accessible elsewhere in the init block, probably causing crashes. try / raise / except cannot be used as they require the initialization of Nim's runtime to work.

vitreo12 commented 3 years ago

Check the memory-safety branch, which fixes this!

vitreo12 commented 3 years ago

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

vitreo12 commented 3 years ago

Final implementation involved wrapping setjmp and longjmp manually, and it's working flawlessy.

branch: memory-safety-custom-setjmp