nonlib: Add assertions to catch multiple calls to log_create() which would result in duplicate log entries.

pull/43/head
Jonathan Moore Liles 2013-03-18 17:21:29 -07:00
parent 0f6d481f88
commit 14099b7cfc
3 changed files with 49 additions and 6 deletions

View File

@ -53,8 +53,6 @@ char *Module::_copied_module_settings = 0;
Module::Module ( int W, int H, const char *L ) : Fl_Group( 0, 0, W, H, L )
{
init();
log_create();
}
Module::Module ( bool is_default, int W, int H, const char *L ) : Fl_Group( 0, 0, W, H, L ), Loggable( !is_default )
@ -62,15 +60,11 @@ Module::Module ( bool is_default, int W, int H, const char *L ) : Fl_Group( 0, 0
this->is_default( is_default );
init();
log_create();
}
Module::Module ( ) : Fl_Group( 0, 0, 50, 50, "Unnamed" )
{
init();
log_create();
}
Module::~Module ( )

View File

@ -44,6 +44,11 @@ using std::max;
#ifndef NDEBUG
bool Loggable::_snapshotting = false;
int Loggable::_snapshot_count = 0;
#endif
bool Loggable::_readonly = false;
FILE *Loggable::_fp;
unsigned int Loggable::_log_id = 0;
@ -533,12 +538,22 @@ Loggable::snapshot ( FILE *fp )
return false;
}
#ifndef NDEBUG
_snapshotting = true;
_snapshot_count++;
#endif
block_start();
Loggable::_snapshot_callback( _snapshot_callback_arg );
block_end();
#ifndef NDEBUG
_snapshotting = false;
#endif
_fp = ofp;
clear_dirty();
@ -776,6 +791,25 @@ Loggable::log_create ( void ) const
/* replaying, don't bother */
return;
#ifndef NDEBUG
if ( _snapshotting && _snapshot_count != _num_snapshot )
{
_num_snapshot_creates = 1;
_num_snapshot = _snapshot_count;
}
else if ( _snapshotting && _snapshot_count == _num_snapshot )
{
_num_snapshot_creates++;
ASSERT( _num_snapshot_creates < 2, "Attempt to log creation of same object twice in one snapshot! %s", class_name() );
}
else
{
_num_log_creates++;
ASSERT( _num_log_creates < 2, "Attempt to log creation of same object twice in the journal! %s", class_name() );
}
#endif
log( "%s 0x%X create ", class_name(), _id );
Log_Entry e;

View File

@ -96,6 +96,15 @@ private:
static unsigned int _relative_id;
#ifndef NDEBUG
static bool _snapshotting;
static int _snapshot_count;
mutable int _num_log_creates;
mutable int _num_snapshot;
mutable int _num_snapshot_creates;
#endif
unsigned int _id;
Log_Entry *_old_state;
@ -115,6 +124,12 @@ private:
void init ( bool loggable=true )
{
// _new_state
#ifndef NDEBUG
_num_log_creates = 0;
_num_snapshot = 0;
_num_snapshot_creates = 0;
#endif
_old_state = NULL;
_nest = 0;