28#define _RWSTD_TEST_SRC
41static const char*
const
44 "UserAlloc (const UserAlloc&)",
45 "UserAlloc (const UserAlloc<U>&)",
47 "operator= (const UserAlloc&)",
48 "operator=<U>(const UserAlloc<U>&)",
49 "allocate (size_type, void*)",
50 "deallocate (pointer, size_type)",
51 "construct (pointer, const_reference)",
53 "address (reference) const",
64 : max_bytes_ (nbytes), max_blocks_ (nblocks),
65 n_bytes_ (0), n_blocks_ (0), n_refs_ (0), id_ (0)
76 static size_t deadbeef = 0;
78 deadbeef = size_t (0xdeadbeefU);
79 if (deadbeef < deadbeef << 1) {
83 deadbeef |= size_t (0xdeadbeefU);
89 for (
size_t i = 0;
i !=
n; ++
i)
93 for (
size_t i = 0;
i !=
n; ++
i)
97 for (
size_t i = 0;
i !=
n; ++
i)
107 const size_t nbytes = nelems *
size;
111 "allocate (%zu): reached block limit of %zu",
116 "allocate (%zu): reached size limit of %zu",
167 RW_ASSERT (0 <= id_ && id_ <= _rw_id_gen);
181 po->id_ = ++_rw_id_gen;
188 RW_ASSERT (0 <= id_ && id_ <= _rw_id_gen);
204 "UserAlloc::%s: reached call limit of %zu",
207 RW_ASSERT (!
"logic error: should not reach");
220 static size_t instbuf [
sizeof (
SharedAlloc) /
sizeof (
size_t) + 1];
252 return _rw_func_names [mf];
258_rw_check_leaks (
int line,
size_t expect_blocks,
size_t expect_bytes)
266 if (_RWSTD_SIZE_MAX == expect_blocks)
267 expect_blocks = nblocks;
269 if (_RWSTD_SIZE_MAX == expect_bytes)
270 expect_bytes = nbytes;
272 rw_assert (nblocks == expect_blocks && nbytes == expect_bytes,
274 "line %d. %{$FUNCALL} operator new allocated "
275 "%zu bytes in %zu blocks, expected %zu bytes "
277 __LINE__, nbytes, nblocks,
278 expect_bytes, expect_blocks);
290 size_t expect_blocks ,
291 size_t expect_bytes )
293 _rw_check_leaks (
line, expect_blocks, expect_bytes);
298 static size_t nbytes;
299 static size_t nblocks;
303 const size_t leaked_bytes = palloc->
n_bytes_ - nbytes;
304 const size_t leaked_blocks = palloc->
n_blocks_ - nblocks;
306 if (_RWSTD_SIZE_MAX == expect_blocks)
307 expect_blocks = leaked_blocks;
309 if (_RWSTD_SIZE_MAX == expect_bytes)
310 expect_bytes = nbytes;
312 rw_assert ( leaked_blocks == expect_blocks
313 && leaked_bytes == expect_bytes, 0,
line,
314 "line %d. %{$FUNCALL} UserAlloc allocated "
315 "%zu bytes in %zu blocks, expected %zu bytes "
317 __LINE__, leaked_bytes, leaked_blocks,
318 expect_bytes, expect_blocks);
void(* operator_delete)(void *, void *)
void *(* operator_new)(size_t, void *)
#define _RWSTD_CONST_CAST(T, x)
_TEST_EXPORT void rw_check_leaks(const SharedAlloc *palloc, int line, size_t expect_blocks, size_t expect_bytes)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
_TEST_EXPORT void rw_throw(ExceptionId exid, const char *file, int line, const char *function, const char *fmt,...)
_TEST_EXPORT _RWSTD_SIZE_T rwt_check_leaks(_RWSTD_SIZE_T *, const rwt_free_store *)
virtual void deallocate(void *, _RWSTD_SIZE_T, _RWSTD_SIZE_T)
SharedAlloc(_RWSTD_SIZE_T=_RWSTD_SIZE_MAX, _RWSTD_SIZE_T=_RWSTD_SIZE_MAX)
virtual void funcall(MemFun, const SharedAlloc *=0)
static SharedAlloc * instance(SharedAlloc *=0)
_RWSTD_SIZE_T max_blocks_
virtual _RWSTD_SIZE_T max_size(_RWSTD_SIZE_T=1)
_RWSTD_SIZE_T throw_at_calls_[n_funs]
_RWSTD_SIZE_T n_calls_[n_funs]
_RWSTD_SIZE_T n_throws_[n_funs]
void reset_call_counters()
static const char * func_name(MemFun)
virtual void * allocate(_RWSTD_SIZE_T, _RWSTD_SIZE_T, const void *)