Changed many assert() calls to VERIFY()

This commit is contained in:
John Wiegley 2009-03-04 04:29:10 -04:00
parent dcac306467
commit 2d63c9364a
8 changed files with 49 additions and 54 deletions

View file

@ -129,7 +129,7 @@ void amount_t::shutdown()
void amount_t::_copy(const amount_t& amt) void amount_t::_copy(const amount_t& amt)
{ {
assert(amt.valid()); VERIFY(amt.valid());
if (quantity != amt.quantity) { if (quantity != amt.quantity) {
if (quantity) if (quantity)
@ -231,7 +231,7 @@ amount_t& amount_t::operator=(const amount_t& amt)
int amount_t::compare(const amount_t& amt) const int amount_t::compare(const amount_t& amt) const
{ {
assert(amt.valid()); VERIFY(amt.valid());
if (! quantity || ! amt.quantity) { if (! quantity || ! amt.quantity) {
if (quantity) if (quantity)
@ -266,7 +266,7 @@ bool amount_t::operator==(const amount_t& amt) const
amount_t& amount_t::operator+=(const amount_t& amt) amount_t& amount_t::operator+=(const amount_t& amt)
{ {
assert(amt.valid()); VERIFY(amt.valid());
if (! quantity || ! amt.quantity) { if (! quantity || ! amt.quantity) {
if (quantity) if (quantity)
@ -297,7 +297,7 @@ amount_t& amount_t::operator+=(const amount_t& amt)
amount_t& amount_t::operator-=(const amount_t& amt) amount_t& amount_t::operator-=(const amount_t& amt)
{ {
assert(amt.valid()); VERIFY(amt.valid());
if (! quantity || ! amt.quantity) { if (! quantity || ! amt.quantity) {
if (quantity) if (quantity)
@ -328,7 +328,7 @@ amount_t& amount_t::operator-=(const amount_t& amt)
amount_t& amount_t::operator*=(const amount_t& amt) amount_t& amount_t::operator*=(const amount_t& amt)
{ {
assert(amt.valid()); VERIFY(amt.valid());
if (! quantity || ! amt.quantity) { if (! quantity || ! amt.quantity) {
if (quantity) if (quantity)
@ -359,7 +359,7 @@ amount_t& amount_t::operator*=(const amount_t& amt)
amount_t& amount_t::operator/=(const amount_t& amt) amount_t& amount_t::operator/=(const amount_t& amt)
{ {
assert(amt.valid()); VERIFY(amt.valid());
if (! quantity || ! amt.quantity) { if (! quantity || ! amt.quantity) {
if (quantity) if (quantity)

View file

@ -148,14 +148,14 @@ public:
value_t& as_value_lval() { value_t& as_value_lval() {
assert(is_value()); assert(is_value());
value_t& val(boost::get<value_t>(data)); value_t& val(boost::get<value_t>(data));
assert(val.valid()); VERIFY(val.valid());
return val; return val;
} }
const value_t& as_value() const { const value_t& as_value() const {
return const_cast<op_t *>(this)->as_value_lval(); return const_cast<op_t *>(this)->as_value_lval();
} }
void set_value(const value_t& val) { void set_value(const value_t& val) {
assert(val.valid()); VERIFY(val.valid());
data = val; data = val;
} }

View file

@ -430,7 +430,7 @@ void instance_t::clock_out_directive(char * line,
void instance_t::default_commodity_directive(char * line) void instance_t::default_commodity_directive(char * line)
{ {
amount_t amt(skip_ws(line + 1)); amount_t amt(skip_ws(line + 1));
assert(amt.valid()); VERIFY(amt.valid());
amount_t::current_pool->default_commodity = &amt.commodity(); amount_t::current_pool->default_commodity = &amt.commodity();
amt.commodity().add_flags(COMMODITY_KNOWN); amt.commodity().add_flags(COMMODITY_KNOWN);
} }
@ -494,7 +494,7 @@ void instance_t::price_xact_directive(char * line)
string symbol; string symbol;
parse_symbol(symbol_and_price, symbol); parse_symbol(symbol_and_price, symbol);
amount_t price(symbol_and_price); amount_t price(symbol_and_price);
assert(price.valid()); VERIFY(price.valid());
if (commodity_t * commodity = if (commodity_t * commodity =
amount_t::current_pool->find_or_create(symbol)) { amount_t::current_pool->find_or_create(symbol)) {

View file

@ -89,7 +89,7 @@ namespace {
std::sprintf(buf, "%lds", long((when - event.checkin).total_seconds())); std::sprintf(buf, "%lds", long((when - event.checkin).total_seconds()));
amount_t amt; amount_t amt;
amt.parse(buf); amt.parse(buf);
assert(amt.valid()); VERIFY(amt.valid());
post_t * post = new post_t(event.account, amt, POST_VIRTUAL); post_t * post = new post_t(event.account, amt, POST_VIRTUAL);
post->set_state(item_t::CLEARED); post->set_state(item_t::CLEARED);

View file

@ -70,7 +70,7 @@ public:
const char * p = input.c_str(); const char * p = input.c_str();
std::size_t len = input.length(); std::size_t len = input.length();
assert(utf8::is_valid(p, p + len)); VERIFY(utf8::is_valid(p, p + len));
utf8::utf8to32(p, p + len, std::back_inserter(utf32chars)); utf8::utf8to32(p, p + len, std::back_inserter(utf32chars));
} }
~unistring() { ~unistring() {

View file

@ -120,21 +120,18 @@ value_t::operator bool() const
void value_t::set_type(type_t new_type) void value_t::set_type(type_t new_type)
{ {
assert(new_type >= VOID && new_type <= POINTER);
if (new_type == VOID) { if (new_type == VOID) {
#if BOOST_VERSION >= 103700 #if BOOST_VERSION >= 103700
storage.reset(); storage.reset();
#else #else
storage = intrusive_ptr<storage_t>(); storage = intrusive_ptr<storage_t>();
#endif #endif
assert(is_null());
} else { } else {
if (! storage || storage->refc > 1) if (! storage || storage->refc > 1)
storage = new storage_t; storage = new storage_t;
else else
storage->destroy(); storage->destroy();
storage->type = new_type; storage->type = new_type;
assert(is_type(new_type));
} }
} }

View file

@ -166,7 +166,7 @@ private:
*/ */
~storage_t() { ~storage_t() {
TRACE_DTOR(value_t::storage_t); TRACE_DTOR(value_t::storage_t);
assert(refc == 0); VERIFY(refc == 0);
destroy(); destroy();
} }
@ -190,13 +190,13 @@ private:
void acquire() const { void acquire() const {
DEBUG("value.storage.refcount", DEBUG("value.storage.refcount",
"Acquiring " << this << ", refc now " << refc + 1); "Acquiring " << this << ", refc now " << refc + 1);
assert(refc >= 0); VERIFY(refc >= 0);
refc++; refc++;
} }
void release() const { void release() const {
DEBUG("value.storage.refcount", DEBUG("value.storage.refcount",
"Releasing " << this << ", refc now " << refc - 1); "Releasing " << this << ", refc now " << refc - 1);
assert(refc > 0); VERIFY(refc > 0);
if (--refc == 0) if (--refc == 0)
checked_delete(this); checked_delete(this);
} }
@ -235,7 +235,7 @@ private:
* subsequently be modified. * subsequently be modified.
*/ */
void _dup() { void _dup() {
assert(storage); VERIFY(storage);
if (storage->refc > 1) if (storage->refc > 1)
storage = new storage_t(*storage.get()); storage = new storage_t(*storage.get());
} }
@ -462,18 +462,16 @@ public:
bool is_zero() const; bool is_zero() const;
bool is_null() const { bool is_null() const {
if (! storage) { if (! storage) {
assert(is_type(VOID)); VERIFY(is_type(VOID));
return true; return true;
} else { } else {
assert(! is_type(VOID)); VERIFY(! is_type(VOID));
return false; return false;
} }
} }
type_t type() const { type_t type() const {
type_t result = storage ? storage->type : VOID; return storage ? storage->type : VOID;
assert(result >= VOID && result <= POINTER);
return result;
} }
bool is_type(type_t _type) const { bool is_type(type_t _type) const {
return type() == _type; return type() == _type;
@ -516,12 +514,12 @@ public:
return is_type(BOOLEAN); return is_type(BOOLEAN);
} }
bool& as_boolean_lval() { bool& as_boolean_lval() {
assert(is_boolean()); VERIFY(is_boolean());
_dup(); _dup();
return boost::get<bool>(storage->data); return boost::get<bool>(storage->data);
} }
const bool& as_boolean() const { const bool& as_boolean() const {
assert(is_boolean()); VERIFY(is_boolean());
return boost::get<bool>(storage->data); return boost::get<bool>(storage->data);
} }
void set_boolean(const bool val) { void set_boolean(const bool val) {
@ -533,12 +531,12 @@ public:
return is_type(DATETIME); return is_type(DATETIME);
} }
datetime_t& as_datetime_lval() { datetime_t& as_datetime_lval() {
assert(is_datetime()); VERIFY(is_datetime());
_dup(); _dup();
return boost::get<datetime_t>(storage->data); return boost::get<datetime_t>(storage->data);
} }
const datetime_t& as_datetime() const { const datetime_t& as_datetime() const {
assert(is_datetime()); VERIFY(is_datetime());
return boost::get<datetime_t>(storage->data); return boost::get<datetime_t>(storage->data);
} }
void set_datetime(const datetime_t& val) { void set_datetime(const datetime_t& val) {
@ -550,12 +548,12 @@ public:
return is_type(DATE); return is_type(DATE);
} }
date_t& as_date_lval() { date_t& as_date_lval() {
assert(is_date()); VERIFY(is_date());
_dup(); _dup();
return boost::get<date_t>(storage->data); return boost::get<date_t>(storage->data);
} }
const date_t& as_date() const { const date_t& as_date() const {
assert(is_date()); VERIFY(is_date());
return boost::get<date_t>(storage->data); return boost::get<date_t>(storage->data);
} }
void set_date(const date_t& val) { void set_date(const date_t& val) {
@ -567,12 +565,12 @@ public:
return is_type(INTEGER); return is_type(INTEGER);
} }
long& as_long_lval() { long& as_long_lval() {
assert(is_long()); VERIFY(is_long());
_dup(); _dup();
return boost::get<long>(storage->data); return boost::get<long>(storage->data);
} }
const long& as_long() const { const long& as_long() const {
assert(is_long()); VERIFY(is_long());
return boost::get<long>(storage->data); return boost::get<long>(storage->data);
} }
void set_long(const long val) { void set_long(const long val) {
@ -584,16 +582,16 @@ public:
return is_type(AMOUNT); return is_type(AMOUNT);
} }
amount_t& as_amount_lval() { amount_t& as_amount_lval() {
assert(is_amount()); VERIFY(is_amount());
_dup(); _dup();
return boost::get<amount_t>(storage->data); return boost::get<amount_t>(storage->data);
} }
const amount_t& as_amount() const { const amount_t& as_amount() const {
assert(is_amount()); VERIFY(is_amount());
return boost::get<amount_t>(storage->data); return boost::get<amount_t>(storage->data);
} }
void set_amount(const amount_t& val) { void set_amount(const amount_t& val) {
assert(val.valid()); VERIFY(val.valid());
set_type(AMOUNT); set_type(AMOUNT);
storage->data = val; storage->data = val;
} }
@ -602,16 +600,16 @@ public:
return is_type(BALANCE); return is_type(BALANCE);
} }
balance_t& as_balance_lval() { balance_t& as_balance_lval() {
assert(is_balance()); VERIFY(is_balance());
_dup(); _dup();
return *boost::get<balance_t *>(storage->data); return *boost::get<balance_t *>(storage->data);
} }
const balance_t& as_balance() const { const balance_t& as_balance() const {
assert(is_balance()); VERIFY(is_balance());
return *boost::get<balance_t *>(storage->data); return *boost::get<balance_t *>(storage->data);
} }
void set_balance(const balance_t& val) { void set_balance(const balance_t& val) {
assert(val.valid()); VERIFY(val.valid());
set_type(BALANCE); set_type(BALANCE);
storage->data = new balance_t(val); storage->data = new balance_t(val);
} }
@ -620,12 +618,12 @@ public:
return is_type(STRING); return is_type(STRING);
} }
string& as_string_lval() { string& as_string_lval() {
assert(is_string()); VERIFY(is_string());
_dup(); _dup();
return boost::get<string>(storage->data); return boost::get<string>(storage->data);
} }
const string& as_string() const { const string& as_string() const {
assert(is_string()); VERIFY(is_string());
return boost::get<string>(storage->data); return boost::get<string>(storage->data);
} }
void set_string(const string& val = "") { void set_string(const string& val = "") {
@ -641,13 +639,13 @@ public:
return is_type(MASK); return is_type(MASK);
} }
mask_t& as_mask_lval() { mask_t& as_mask_lval() {
assert(is_mask()); VERIFY(is_mask());
_dup(); _dup();
VERIFY(boost::get<mask_t>(storage->data).valid()); VERIFY(boost::get<mask_t>(storage->data).valid());
return boost::get<mask_t>(storage->data); return boost::get<mask_t>(storage->data);
} }
const mask_t& as_mask() const { const mask_t& as_mask() const {
assert(is_mask()); VERIFY(is_mask());
VERIFY(boost::get<mask_t>(storage->data).valid()); VERIFY(boost::get<mask_t>(storage->data).valid());
return boost::get<mask_t>(storage->data); return boost::get<mask_t>(storage->data);
} }
@ -664,12 +662,12 @@ public:
return is_type(SEQUENCE); return is_type(SEQUENCE);
} }
sequence_t& as_sequence_lval() { sequence_t& as_sequence_lval() {
assert(is_sequence()); VERIFY(is_sequence());
_dup(); _dup();
return *boost::get<sequence_t *>(storage->data); return *boost::get<sequence_t *>(storage->data);
} }
const sequence_t& as_sequence() const { const sequence_t& as_sequence() const {
assert(is_sequence()); VERIFY(is_sequence());
return *boost::get<sequence_t *>(storage->data); return *boost::get<sequence_t *>(storage->data);
} }
void set_sequence(const sequence_t& val) { void set_sequence(const sequence_t& val) {
@ -689,7 +687,7 @@ public:
return is_type(POINTER); return is_type(POINTER);
} }
boost::any& as_any_pointer_lval() { boost::any& as_any_pointer_lval() {
assert(is_pointer()); VERIFY(is_pointer());
_dup(); _dup();
return boost::get<boost::any>(storage->data); return boost::get<boost::any>(storage->data);
} }
@ -702,7 +700,7 @@ public:
return *as_pointer_lval<T>(); return *as_pointer_lval<T>();
} }
const boost::any& as_any_pointer() const { const boost::any& as_any_pointer() const {
assert(is_pointer()); VERIFY(is_pointer());
return boost::get<boost::any>(storage->data); return boost::get<boost::any>(storage->data);
} }
template <typename T> template <typename T>
@ -785,7 +783,7 @@ public:
* Collection-style access methods for SEQUENCE values. * Collection-style access methods for SEQUENCE values.
*/ */
value_t& operator[](const int index) { value_t& operator[](const int index) {
assert(! is_null()); VERIFY(! is_null());
if (is_sequence()) if (is_sequence())
return as_sequence_lval()[index]; return as_sequence_lval()[index];
else if (index == 0) else if (index == 0)
@ -796,7 +794,7 @@ public:
return null; return null;
} }
const value_t& operator[](const int index) const { const value_t& operator[](const int index) const {
assert(! is_null()); VERIFY(! is_null());
if (is_sequence()) if (is_sequence())
return as_sequence()[index]; return as_sequence()[index];
else if (index == 0) else if (index == 0)
@ -818,7 +816,7 @@ public:
} }
void pop_back() { void pop_back() {
assert(! is_null()); VERIFY(! is_null());
if (! is_sequence()) { if (! is_sequence()) {
#if BOOST_VERSION >= 103700 #if BOOST_VERSION >= 103700
@ -845,24 +843,24 @@ public:
} }
sequence_t::iterator begin() { sequence_t::iterator begin() {
assert(is_sequence()); VERIFY(is_sequence());
return as_sequence_lval().begin(); return as_sequence_lval().begin();
} }
sequence_t::iterator end() { sequence_t::iterator end() {
assert(is_sequence()); VERIFY(is_sequence());
// This special hack is because we never used end() in a context which // This special hack is because we never used end() in a context which
// needs us to call _dup(). // needs us to call _dup().
return boost::get<sequence_t *>(storage->data)->end(); return boost::get<sequence_t *>(storage->data)->end();
} }
sequence_t::const_iterator begin() const { sequence_t::const_iterator begin() const {
assert(is_sequence()); VERIFY(is_sequence());
return as_sequence().begin(); return as_sequence().begin();
} }
sequence_t::const_iterator end() const { sequence_t::const_iterator end() const {
assert(is_sequence()); VERIFY(is_sequence());
return as_sequence().end(); return as_sequence().end();
} }

View file

@ -112,7 +112,7 @@ bool xact_base_t::finalize()
null_post = post; null_post = post;
} }
} }
assert(balance.valid()); VERIFY(balance.valid());
#if defined(DEBUG_ON) #if defined(DEBUG_ON)
DEBUG("xact.finalize", "initial balance = " << balance); DEBUG("xact.finalize", "initial balance = " << balance);