flatten 20260225
This commit is contained in:
12
tjp/core/assert/debug_assert.cpp
Executable file
12
tjp/core/assert/debug_assert.cpp
Executable file
@@ -0,0 +1,12 @@
|
||||
// License: Modified MIT (NON-AI)
|
||||
// See the LICENSE file in the root directory for license information.
|
||||
// Copyright 2025 Timothy Prepscius
|
||||
|
||||
#include "debug_assert.h"
|
||||
|
||||
#ifdef ASSERTS
|
||||
void timprepscius_core_assert_abort()
|
||||
{
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
13
tjp/core/assert/debug_assert.h
Executable file
13
tjp/core/assert/debug_assert.h
Executable file
@@ -0,0 +1,13 @@
|
||||
// License: Modified MIT (NON-AI)
|
||||
// See the LICENSE file in the root directory for license information.
|
||||
// Copyright 2025 Timothy Prepscius
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../header_only/compile.h"
|
||||
|
||||
#ifdef TJP_CORE_HEADER_ONLY
|
||||
#include "debug_assert_simple.h"
|
||||
#else
|
||||
#include "debug_assert_complex.h"
|
||||
#endif
|
||||
34
tjp/core/assert/debug_assert_complex.h
Executable file
34
tjp/core/assert/debug_assert_complex.h
Executable file
@@ -0,0 +1,34 @@
|
||||
// License: Modified MIT (NON-AI)
|
||||
// See the LICENSE file in the root directory for license information.
|
||||
// Copyright 2025 Timothy Prepscius
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <assert.h>
|
||||
#include "../system/Debug.h"
|
||||
#include "../debug/Stack.h"
|
||||
#include "../log/Log.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifndef NASSERTS
|
||||
#define ASSERTS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef ASSERTS
|
||||
void timprepscius_core_assert_abort();
|
||||
|
||||
#define debug_assert(x) \
|
||||
if (!(x)) \
|
||||
{ \
|
||||
sLogDebug("errors", tjp::core::getStackString()); \
|
||||
sLogDebug("errors", #x << " failed at " << __FILE__ << " line " << __LINE__); \
|
||||
timprepscius_core_assert_abort(); \
|
||||
} \
|
||||
|
||||
#else
|
||||
|
||||
#define debug_assert(x)
|
||||
#endif
|
||||
|
||||
#define debug_assert_reason(x,y) debug_assert(x)
|
||||
25
tjp/core/assert/debug_assert_simple.h
Executable file
25
tjp/core/assert/debug_assert_simple.h
Executable file
@@ -0,0 +1,25 @@
|
||||
// License: Modified MIT (NON-AI)
|
||||
// See the LICENSE file in the root directory for license information.
|
||||
// Copyright 2025 Timothy Prepscius
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdlib>
|
||||
#include <assert.h>
|
||||
#include "../system/Debug.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifndef NASSERTS
|
||||
#define ASSERTS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef ASSERTS
|
||||
#define debug_assert(...) assert(__VA_ARGS__);
|
||||
#else
|
||||
#define debug_assert(...)
|
||||
#endif
|
||||
|
||||
#define release_assert(x,...) if (!(x)) std::abort();
|
||||
|
||||
#define debug_assert_reason(x,y) debug_assert(x)
|
||||
35
tjp/core/assert/handle_assert.cpp
Executable file
35
tjp/core/assert/handle_assert.cpp
Executable file
@@ -0,0 +1,35 @@
|
||||
// License: Modified MIT (NON-AI)
|
||||
// See the LICENSE file in the root directory for license information.
|
||||
// Copyright 2025 Timothy Prepscius
|
||||
|
||||
|
||||
#ifdef TJP_CORE_HEADER_ONLY
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "../header_only/compile.h"
|
||||
|
||||
#include "debug_assert.h"
|
||||
|
||||
TJP_CORE_HEADER_ONLY_INLINE
|
||||
bool &get_do_handle_asserts__()
|
||||
{
|
||||
static bool do_handle_asserts = false;
|
||||
return do_handle_asserts;
|
||||
}
|
||||
|
||||
TJP_CORE_HEADER_ONLY_INLINE
|
||||
bool set_do_handle_asserts_(bool v)
|
||||
{
|
||||
auto &r = get_do_handle_asserts__();
|
||||
r = v;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
TJP_CORE_HEADER_ONLY_INLINE
|
||||
bool get_do_handle_asserts_()
|
||||
{
|
||||
auto &r = get_do_handle_asserts__();
|
||||
return r;
|
||||
}
|
||||
18
tjp/core/assert/handle_assert.hpp
Executable file
18
tjp/core/assert/handle_assert.hpp
Executable file
@@ -0,0 +1,18 @@
|
||||
// License: Modified MIT (NON-AI)
|
||||
// See the LICENSE file in the root directory for license information.
|
||||
// Copyright 2025 Timothy Prepscius
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../header_only/compile.h"
|
||||
|
||||
//#ifdef TJP_CORE_HEADER_ONLY
|
||||
#ifdef TJP_CORE_USE_SIMPLE_ASSERT
|
||||
#include "handle_assert_simple.hpp"
|
||||
#else
|
||||
#include "handle_assert_complex.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef TJP_CORE_HEADER_ONLY
|
||||
#include "handle_assert.cpp"
|
||||
#endif
|
||||
40
tjp/core/assert/handle_assert_complex.hpp
Executable file
40
tjp/core/assert/handle_assert_complex.hpp
Executable file
@@ -0,0 +1,40 @@
|
||||
// License: Modified MIT (NON-AI)
|
||||
// See the LICENSE file in the root directory for license information.
|
||||
// Copyright 2025 Timothy Prepscius
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "debug_assert.h"
|
||||
#include "../debug/Stack.h"
|
||||
#include "../log/Log.h"
|
||||
|
||||
#ifdef ASSERTS
|
||||
|
||||
bool set_do_handle_asserts_(bool);
|
||||
#define set_do_handle_asserts(x) set_do_handle_asserts_(x)
|
||||
|
||||
bool get_do_handle_asserts_();
|
||||
#define get_do_handle_asserts() get_do_handle_asserts_()
|
||||
|
||||
inline
|
||||
bool do_handle_assert(const char *condition, const char *file, int line, const std::string &stack) {
|
||||
sLogDebug("errors", stack);
|
||||
sLogDebug("errors", condition << " failed at " << file << " line " << line);
|
||||
|
||||
if (!get_do_handle_asserts())
|
||||
abort();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#define handle_assert(x) if(!(x) && do_handle_assert(#x, __FILE__, __LINE__, tjp::core::getStackString()))
|
||||
|
||||
#define test_assert(x) (!(x) && do_handle_assert(#x, __FILE__, __LINE__, tjp::core::getStackString()))
|
||||
#else
|
||||
#define set_do_handle_asserts(x)
|
||||
#define get_do_handle_asserts() false
|
||||
|
||||
#define handle_assert(x) if(!(x))
|
||||
#define test_assert(x) (!(x))
|
||||
#endif
|
||||
|
||||
14
tjp/core/assert/handle_assert_simple.hpp
Executable file
14
tjp/core/assert/handle_assert_simple.hpp
Executable file
@@ -0,0 +1,14 @@
|
||||
// License: Modified MIT (NON-AI)
|
||||
// See the LICENSE file in the root directory for license information.
|
||||
// Copyright 2025 Timothy Prepscius
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "debug_assert.h"
|
||||
|
||||
#define set_do_handle_asserts(x)
|
||||
#define get_do_handle_asserts() false
|
||||
|
||||
#define handle_assert(x) if(!(x))
|
||||
#define test_assert(x) (!(x))
|
||||
|
||||
15
tjp/core/assert/release_assert.h
Executable file
15
tjp/core/assert/release_assert.h
Executable file
@@ -0,0 +1,15 @@
|
||||
// License: Modified MIT (NON-AI)
|
||||
// See the LICENSE file in the root directory for license information.
|
||||
// Copyright 2025 Timothy Prepscius
|
||||
|
||||
#pragma once
|
||||
|
||||
#define ALWAYS_assert_do(e, file, line) \
|
||||
((void)printf ("%s:%d: failed assertion `%s'\n", file, line, e), abort())
|
||||
|
||||
|
||||
#define ALWAYS_assert(e) \
|
||||
((void) ((e) ? ((void)0) : ALWAYS_assert_do (#e, __FILE__, __LINE__)))
|
||||
|
||||
#define release_assert(x) ALWAYS_assert(x)
|
||||
|
||||
Reference in New Issue
Block a user