Skip to content

Commit 4e3bdef

Browse files
proof of concept
1 parent b978fac commit 4e3bdef

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

infra/util/ReallyAssert.hpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,29 @@
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+
1230
namespace 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

Comments
 (0)