In Debug and ReleaseSafe modes std.debug.assert()
asserts that the condition is true, orelse invokes illegal behaviour. In other modes it gets optimized away, which means that it won't impact the performance at all.
That said, safety-checked functions won't hurt, especially when they're likely to be misused by invalid data. This is a tradeoff between unchecked code that can do wacky stuff and unnecessary abstraction that can ruin the code base over time.
The task is to add safety-checks for Debug mode in functions that take in types that can't be of certain 'correct' value and might fail in case wrong value gets passed, e.g., when passing in a buffer that is zero-length.
Since commit 91e04e2c555736f4b35c797d371f4cd37ea4a4de there are a few things safety-checked:
- x86.cpu.__readVendor:
- Now checks if the provided
buffer
can contain 12 bytes or more.- x86.gdt.load:
- Checks whether or not the last element in the provided
table
is a null entry.- x86.seg.reload:
- Checks whether or not the actual segment selector is an executable one, if yes, fail.
NOTE: These safety-checks are ONLY AVAILABLE IN
Debug
andReleaseSafe
MODES. As a developer, if you build xcore in ReleaseFast or ReleaseSmall, your warranty is void, as the safety-checks will be omitted for performance reasons. If you develop like that, expect uncaught bugs.