mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-07-03 14:14:11 +00:00
Assert if get_or_create() causes other calls to itself.
This is to try and prevent infinite recursions.
This commit is contained in:
parent
fe7e9c4af9
commit
c28398a1b3
1 changed files with 32 additions and 0 deletions
|
@ -21,8 +21,29 @@
|
||||||
#include <ciso646>
|
#include <ciso646>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
#if !defined(NDEBUG)
|
||||||
|
# define LEANBASE_ASSERT_REENTRANCY
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace mchlib {
|
namespace mchlib {
|
||||||
namespace scantask {
|
namespace scantask {
|
||||||
|
#if defined(LEANBASE_ASSERT_REENTRANCY)
|
||||||
|
struct AutoSetBool {
|
||||||
|
explicit AutoSetBool ( bool* parBool ) :
|
||||||
|
m_bool(parBool)
|
||||||
|
{
|
||||||
|
assert(m_bool);
|
||||||
|
assert(not *m_bool);
|
||||||
|
*m_bool = true;
|
||||||
|
}
|
||||||
|
~AutoSetBool ( void ) noexcept {
|
||||||
|
*m_bool = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool* m_bool;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class LeanBase {
|
class LeanBase {
|
||||||
protected:
|
protected:
|
||||||
|
@ -39,16 +60,27 @@ namespace mchlib {
|
||||||
virtual T& on_data_get ( void ) = 0;
|
virtual T& on_data_get ( void ) = 0;
|
||||||
|
|
||||||
bool m_data_created;
|
bool m_data_created;
|
||||||
|
#if defined(LEANBASE_ASSERT_REENTRANCY)
|
||||||
|
bool m_inside_call;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
LeanBase<T>::LeanBase() :
|
LeanBase<T>::LeanBase() :
|
||||||
m_data_created(false)
|
m_data_created(false)
|
||||||
|
#if defined(LEANBASE_ASSERT_REENTRANCY)
|
||||||
|
, m_inside_call(false)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T& LeanBase<T>::get_or_create() {
|
T& LeanBase<T>::get_or_create() {
|
||||||
|
#if defined(LEANBASE_ASSERT_REENTRANCY)
|
||||||
|
assert(not m_inside_call);
|
||||||
|
AutoSetBool auto_bool(&m_inside_call);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (not m_data_created) {
|
if (not m_data_created) {
|
||||||
m_data_created = true;
|
m_data_created = true;
|
||||||
this->on_data_fill();
|
this->on_data_fill();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue