diff --git a/libc/Makefile b/libc/Makefile
index ab4fd390..ea9f43d3 100644
--- a/libc/Makefile
+++ b/libc/Makefile
@@ -17,7 +17,7 @@ CXXFLAGS=-std=gnu++11 -fno-exceptions -fno-rtti
ASFLAGS=
FREEOBJS=\
-assert/_assert.o \
+assert/__assert.o \
aux/c++.o \
aux/op-new.o \
ctype/ctype.o \
diff --git a/libc/assert/_assert.cpp b/libc/assert/__assert.cpp
similarity index 71%
rename from libc/assert/_assert.cpp
rename to libc/assert/__assert.cpp
index 659fea68..2ec63332 100644
--- a/libc/assert/_assert.cpp
+++ b/libc/assert/__assert.cpp
@@ -1,6 +1,6 @@
/*******************************************************************************
- Copyright(C) Jonas 'Sortie' Termansen 2012.
+ Copyright(C) Jonas 'Sortie' Termansen 2012, 2013.
This file is part of the Sortix C Library.
@@ -17,31 +17,33 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- assert/_assert.cpp
+ assert/__assert.cpp
Reports the occurence of an assertion failure.
*******************************************************************************/
#include
#include
-#if !defined(__is_sortix_kernel)
#include
#include
-#endif
+
#if defined(__is_sortix_kernel)
#include
#include
#endif
-void _assert(const char* filename, unsigned int line, const char* functionname,
- const char* expression)
+extern "C"
+void __assert(const char* filename,
+ unsigned long line,
+ const char* function_name,
+ const char* expression)
{
-#if !defined(__is_sortix_kernel)
- fprintf(stderr, "Assertion failure: %s:%u: %s: %s\n", filename, line,
- functionname, expression);
- abort();
+#if __is_sortix_kernel
+ Sortix::PanicF("Assertion failure: %s:%lu: %s: %s\n", filename, line,
+ function_name, expression);
#else
- Sortix::PanicF("Assertion failure: %s:%u: %s: %s\n", filename, line,
- functionname, expression);
+ fprintf(stderr, "Assertion failure: %s:%lu: %s: %s\n", filename, line,
+ function_name, expression);
+ abort();
#endif
}
diff --git a/libc/include/assert.h b/libc/include/assert.h
index ec5ada24..959cbb43 100644
--- a/libc/include/assert.h
+++ b/libc/include/assert.h
@@ -1,6 +1,6 @@
/*******************************************************************************
- Copyright(C) Jonas 'Sortie' Termansen 2012.
+ Copyright(C) Jonas 'Sortie' Termansen 2012, 2013.
This file is part of the Sortix C Library.
@@ -22,21 +22,23 @@
*******************************************************************************/
-#ifndef _ASSERT_H
-#define _ASSERT_H 1
+#ifndef INCLUDE_ASSERT_H
+#define INCLUDE_ASSERT_H
#include
-/* stdlib.h is not needed, but GCC fixincludes thinks it is, so fool it. */
-#if 0
-#include
-#endif
-
__BEGIN_DECLS
+/* Determine how the value should be cast to void. */
+#if defined __cplusplus
+#define __ASSERT_VOID_CAST(x) static_cast(x)
+#else
+#define __ASSERT_VOID_CAST(x) (void) x
+#endif
+
/* The actual implementation of assert. */
-void _assert(const char* filename, unsigned int line, const char* functionname,
- const char* expression) __attribute__ ((noreturn));
+__attribute__((noreturn))
+void __assert(const char*, unsigned long, const char*, const char*);
__END_DECLS
@@ -47,20 +49,15 @@ __END_DECLS
#undef assert
#endif
-/* Redefine the assert macro on each inclusion. */
-#ifdef NDEBUG
+/* If not debugging, we'll declare a no-operation assert macro. */
+#if defined(NDEBUG)
+#define assert(ignore) (__ASSERT_VOID_CAST(0))
+#endif
-#define assert(ignore) ((void) 0)
-
-#else /* !NDEBUG */
-
-/* Use __builtin_expect to tell the compiler that we don't expect a failure to
- happen and thus it can do better branch prediction. Naturally we don't
- optimize for the case where the program is about to abort(). */
+/* Otherwise, declare the normal assert macro. */
+#if !defined(NDEBUG)
#define assert(invariant) \
- if ( __builtin_expect(!(invariant), 0) ) \
- { \
- _assert(__FILE__, __LINE__, __PRETTY_FUNCTION__, #invariant); \
- }
-
-#endif /* !NDEBUG */
+ ((invariant) \
+ ? __ASSERT_VOID_CAST(0) \
+ : __assert(__FILE__, __LINE__, __PRETTY_FUNCTION__, #invariant))
+#endif