Author: sebor Date: Thu May 18 18:26:18 2006 New Revision: 407680 URL: http://svn.apache.org/viewvc?rev=407680&view=rev Log: 2006-05-18 Martin Sebor * rw_allocator.h (n_throws_): New member array to keep track of the number of exceptions thrown from each member function. * allocator.cpp (SharedAlloc ctor): Zero-initialized all arrays. (funcall): Incremented the member function call counter regarless of whether the call results in an exception or not to parallel the same algorithm used in operator_new(). Incremented the exception counter, n_throws_, for each thrown exception. Modified: incubator/stdcxx/trunk/tests/include/rw_allocator.h incubator/stdcxx/trunk/tests/src/allocator.cpp Modified: incubator/stdcxx/trunk/tests/include/rw_allocator.h URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/include/rw_allocator.h?rev=407680&r1=407679&r2=407680&view=diff ============================================================================== --- incubator/stdcxx/trunk/tests/include/rw_allocator.h (original) +++ incubator/stdcxx/trunk/tests/include/rw_allocator.h Thu May 18 18:26:18 2006 @@ -108,7 +108,12 @@ _RWSTD_SIZE_T n_refs_; // number of references // counter of the number of calls to each allocator member function + // made throughout the lifetime of this object _RWSTD_SIZE_T n_calls_ [n_funs]; + + // counter of the number of exceptions thrown by each member function + // throughout the lifetime of this object + _RWSTD_SIZE_T n_throws_ [n_funs]; // member function counter value that, when reached, will cause // an exception derived from std::bad_alloc to be thrown Modified: incubator/stdcxx/trunk/tests/src/allocator.cpp URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/allocator.cpp?rev=407680&r1=407679&r2=407680&view=diff ============================================================================== --- incubator/stdcxx/trunk/tests/src/allocator.cpp (original) +++ incubator/stdcxx/trunk/tests/src/allocator.cpp Thu May 18 18:26:18 2006 @@ -94,7 +94,8 @@ n_bytes_ (0), n_blocks_ (0), n_refs_ (0), id_ (0) { memset (n_calls_, 0, sizeof n_calls_); - memset (throw_at_calls_, -1, sizeof throw_at_calls_); + memset (n_throws_, 0, sizeof n_throws_); + memset (throw_at_calls_, 0, sizeof throw_at_calls_); } @@ -117,6 +118,10 @@ for (size_t i = 0; i != n; ++i) n_calls_ [i] = deadbeef; + n = sizeof n_throws_ / sizeof *n_throws_; + for (size_t i = 0; i != n; ++i) + n_throws_ [i] = deadbeef; + n = sizeof throw_at_calls_ / sizeof *throw_at_calls_; for (size_t i = 0; i != n; ++i) throw_at_calls_ [i] = deadbeef; @@ -165,6 +170,9 @@ /* virtual */ void SharedAlloc:: funcall (MemFun mf, const SharedAlloc *other /* = 0 */) { + // increment the number of calls regardless of success + ++n_calls_ [mf]; + if (m_ctor == mf) { // ordinary (not a copy or converting) ctor if (id_ <= 0) { @@ -217,13 +225,16 @@ // check the number of calls and throw an exception // if the specified limit has been reached - if (n_calls_ [mf] == throw_at_calls_ [mf]) + if (n_calls_ [mf] == throw_at_calls_ [mf]) { + // increment the exception counter for this function + ++n_throws_ [mf]; + _rw_throw_exception (__FILE__, __LINE__, "%s: reached call limit of %zu", _rw_funnames [mf], throw_at_calls_); - // increment the number of calls - ++n_calls_ [mf]; + RW_ASSERT (!"logic error: should not reach"); + } }