-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add assert.h, fix installation of headers (#1)
* initial implementation of assert * fix use of return type * fix formatting * install header * change install headers * small fix * small fix
- Loading branch information
Showing
4 changed files
with
39 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef _FOUNDATION_LIBC_ASSERT_H_ | ||
#define _FOUNDATION_LIBC_ASSERT_H_ | ||
|
||
#ifndef NDEBUG | ||
#define assert(expr) | ||
#else | ||
extern void __assert(char const * assertion, char const * file, unsigned line) __attribute__((__noreturn__)); | ||
|
||
#define assert(expr) \ | ||
((expr) \ | ||
? void(0) \ | ||
: __assert(#expr, __FILE__, __LINE__)) | ||
|
||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const std = @import("std"); | ||
|
||
export fn __assert( | ||
assertion: ?[*:0]const u8, | ||
file: ?[*:0]const u8, | ||
line: c_uint, | ||
) noreturn { | ||
var buf: [256]u8 = undefined; | ||
const str = std.fmt.bufPrint(&buf, "assertion failed: '{?s}' in file {?s} line {}", .{ assertion, file, line }) catch { | ||
@panic("assertion failed"); | ||
}; | ||
|
||
@panic(str); | ||
} |