mirror of
https://github.com/Zygo/bees.git
synced 2025-05-17 21:35:45 +02:00
bytevector: introduce BEES_VALGRIND to help work around valgrind
valgrind doesn't understand ioctl arguments, so it does not know if or when they initialize memory, and it complains about conditionals depending on data that comes out of ioctls. That's a problem for bees, where every decision we ever make is based on data an ioctl gave us. Fix the initialization issue by using calloc instead of malloc for ByteVectors when we are building for valgrind. Don't enable this by default because all the callocs aren't necessary (assuming the rest of the code is correct) and hurt performance. Define BEES_VALGRIND in localconf to activate, e.g. echo CCFLAGS += -DBEES_VALGRIND=1 >> localconf Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
parent
01734e6d4b
commit
26acc6adfd
@ -65,9 +65,21 @@ namespace crucible {
|
|||||||
return m_ptr.get()[size];
|
return m_ptr.get()[size];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void *
|
||||||
|
bv_allocate(size_t size)
|
||||||
|
{
|
||||||
|
#ifdef BEES_VALGRIND
|
||||||
|
// XXX: only do this to shut up valgrind
|
||||||
|
return calloc(1, size);
|
||||||
|
#else
|
||||||
|
return malloc(size);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
ByteVector::ByteVector(size_t size)
|
ByteVector::ByteVector(size_t size)
|
||||||
{
|
{
|
||||||
m_ptr = Pointer(static_cast<value_type*>(malloc(size)), free);
|
m_ptr = Pointer(static_cast<value_type*>(bv_allocate(size)), free);
|
||||||
// bad_alloc doesn't fit THROW_CHECK's template
|
// bad_alloc doesn't fit THROW_CHECK's template
|
||||||
THROW_CHECK0(runtime_error, m_ptr);
|
THROW_CHECK0(runtime_error, m_ptr);
|
||||||
m_size = size;
|
m_size = size;
|
||||||
@ -77,7 +89,7 @@ namespace crucible {
|
|||||||
{
|
{
|
||||||
const size_t size = end - begin;
|
const size_t size = end - begin;
|
||||||
const size_t alloc_size = max(size, min_size);
|
const size_t alloc_size = max(size, min_size);
|
||||||
m_ptr = Pointer(static_cast<value_type*>(malloc(alloc_size)), free);
|
m_ptr = Pointer(static_cast<value_type*>(bv_allocate(alloc_size)), free);
|
||||||
THROW_CHECK0(runtime_error, m_ptr);
|
THROW_CHECK0(runtime_error, m_ptr);
|
||||||
m_size = alloc_size;
|
m_size = alloc_size;
|
||||||
memcpy(m_ptr.get(), begin, size);
|
memcpy(m_ptr.get(), begin, size);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user