From 14099b7cfc5f2b99a3c73f3513ac699c77cd0b71 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Mon, 18 Mar 2013 17:21:29 -0700 Subject: [PATCH] nonlib: Add assertions to catch multiple calls to log_create() which would result in duplicate log entries. --- mixer/src/Module.C | 6 ------ nonlib/Loggable.C | 34 ++++++++++++++++++++++++++++++++++ nonlib/Loggable.H | 15 +++++++++++++++ 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/mixer/src/Module.C b/mixer/src/Module.C index a889f6f..1ae4b0b 100644 --- a/mixer/src/Module.C +++ b/mixer/src/Module.C @@ -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 ( ) diff --git a/nonlib/Loggable.C b/nonlib/Loggable.C index 2bb6ebc..8e94ea3 100644 --- a/nonlib/Loggable.C +++ b/nonlib/Loggable.C @@ -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; diff --git a/nonlib/Loggable.H b/nonlib/Loggable.H index 25ed00a..2b1242c 100644 --- a/nonlib/Loggable.H +++ b/nonlib/Loggable.H @@ -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;