44// really_assert is a macro similar to assert, however it is not compiled away in release mode
55
66#include < cassert>
7+ #include < cstdint>
78#include < cstdlib>
89
910#ifdef EMIL_HOST_BUILD
1011#include < functional>
1112
13+ namespace
14+ {
15+ // Source - https://stackoverflow.com/a/19004720
16+ // Posted by Chetan Reddy, modified by community. See post 'Timeline' for change history
17+ // Retrieved 2026-01-06, License - CC BY-SA 4.0
18+
19+ constexpr int32_t basename_index (const char * const path, const int32_t index = 0 , const int32_t slash_index = -1 )
20+ {
21+ return path[index]
22+ ? (path[index] == ' /'
23+ ? basename_index (path, index + 1 , index)
24+ : basename_index (path, index + 1 , slash_index))
25+ : (slash_index + 1 );
26+ }
27+
28+ }
29+
1230namespace infra
1331{
1432 using AssertionFailureHandler = std::function<void (const char * condition, const char * file, int line)>;
@@ -19,9 +37,17 @@ namespace infra
1937}
2038#endif
2139
40+ #define STRINGIZE_DETAIL (x ) #x
41+ #define STRINGIZE (x ) STRINGIZE_DETAIL(x)
42+
43+ // TODO(HW): Does this work for ehader files and everything?
44+ #define __FILENAME__ ({ static const int32_t basename_idx = basename_index (__FILE__); \
45+ static_assert (basename_idx >= 0 , " compile-time basename" ); \
46+ __FILE__ " :" STRINGIZE (__LINE__) " : " + basename_idx; })
47+
2248#ifdef EMIL_HOST_BUILD
2349#define INFRA_UTIL_REALLY_ASSERT_TRIGGER (condition ) \
24- infra::HandleAssertionFailure (#condition, __FILE__ , __LINE__)
50+ infra::HandleAssertionFailure (#condition, __FILENAME__ , __LINE__)
2551#else
2652#define INFRA_UTIL_REALLY_ASSERT_TRIGGER (condition )
2753#endif
0 commit comments