Merge branch 'assert' into 'master'
Make assert more hygienic See merge request redox-os/relibc!166
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
#ifndef _ASSERT_H
|
||||
#define _ASSERT_H
|
||||
|
||||
#ifdef NDEBUG
|
||||
# define assert(cond)
|
||||
#else
|
||||
# include <stdio.h>
|
||||
# define assert(cond) if (!(cond)) { \
|
||||
fprintf(stderr, "%s: %s:%d: Assertion `%s` failed.\n", __func__, __FILE__, __LINE__, #cond); \
|
||||
abort(); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef _BITS_ASSERT_H
|
||||
#define _BITS_ASSERT_H
|
||||
|
||||
#ifdef NDEBUG
|
||||
# define assert(cond)
|
||||
#else
|
||||
# define assert(cond) if (!(cond)) { \
|
||||
__assert(__func__, __FILE__, __LINE__, #cond); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
sys_includes = ["bits/assert.h"]
|
||||
include_guard = "_ASSERT_H"
|
||||
language = "C"
|
||||
style = "Tag"
|
||||
|
||||
[enum]
|
||||
prefix_with_name = true
|
||||
@@ -0,0 +1,17 @@
|
||||
//! assert implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/assert.h.html
|
||||
|
||||
use c_str::CStr;
|
||||
use core::fmt::Write;
|
||||
use header::{stdio, stdlib};
|
||||
use platform;
|
||||
use platform::types::*;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn __assert(func: *const c_char, file: *const c_char, line: c_int, cond: *const c_char) {
|
||||
let func = CStr::from_ptr(func).to_str().unwrap();
|
||||
let file = CStr::from_ptr(file).to_str().unwrap();
|
||||
let cond = CStr::from_ptr(cond).to_str().unwrap();
|
||||
|
||||
write!(*stdio::stderr, "{}: {}:{}: Assertion `{}` failed.\n", func, file, line, cond).unwrap();
|
||||
stdlib::abort();
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
pub mod aio;
|
||||
pub mod arpa_inet;
|
||||
pub mod assert;
|
||||
pub mod ctype;
|
||||
pub mod dirent;
|
||||
pub mod errno;
|
||||
|
||||
Reference in New Issue
Block a user