diff --git a/doc/ZeroBuf.key/Data/st2-7603.jpg b/doc/ZeroBuf.key/Data/st2-7631.jpg similarity index 100% rename from doc/ZeroBuf.key/Data/st2-7603.jpg rename to doc/ZeroBuf.key/Data/st2-7631.jpg diff --git a/doc/ZeroBuf.key/Data/st3-7520.jpg b/doc/ZeroBuf.key/Data/st3-7616.jpg similarity index 88% rename from doc/ZeroBuf.key/Data/st3-7520.jpg rename to doc/ZeroBuf.key/Data/st3-7616.jpg index fa0ccb8..fb555c1 100644 Binary files a/doc/ZeroBuf.key/Data/st3-7520.jpg and b/doc/ZeroBuf.key/Data/st3-7616.jpg differ diff --git a/doc/ZeroBuf.key/Data/st5-7444.jpg b/doc/ZeroBuf.key/Data/st5-7630.jpg similarity index 77% rename from doc/ZeroBuf.key/Data/st5-7444.jpg rename to doc/ZeroBuf.key/Data/st5-7630.jpg index 646d50d..1dbeba4 100644 Binary files a/doc/ZeroBuf.key/Data/st5-7444.jpg and b/doc/ZeroBuf.key/Data/st5-7630.jpg differ diff --git a/doc/ZeroBuf.key/Index.zip b/doc/ZeroBuf.key/Index.zip index aebf492..088c135 100644 Binary files a/doc/ZeroBuf.key/Index.zip and b/doc/ZeroBuf.key/Index.zip differ diff --git a/doc/ZeroBuf.key/Metadata/Properties.plist b/doc/ZeroBuf.key/Metadata/Properties.plist index 8c0c06a..0f1dc9a 100644 Binary files a/doc/ZeroBuf.key/Metadata/Properties.plist and b/doc/ZeroBuf.key/Metadata/Properties.plist differ diff --git a/doc/ZeroBuf.pdf b/doc/ZeroBuf.pdf index aded6ce..e6584e4 100644 Binary files a/doc/ZeroBuf.pdf and b/doc/ZeroBuf.pdf differ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 01697bd..8eb5154 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,18 +1,20 @@ # Copyright (c) HBP 2015-2016 Daniel.Nachbaur@epfl.ch -# Change this number when adding tests to force a CMake run: 0 +# Change this number when adding tests to force a CMake run: 1 if(NOT BOOST_FOUND) return() endif() include(zerobufGenerateCxx) -zerobuf_generate_cxx(TESTSCHEMA ${CMAKE_CURRENT_BINARY_DIR} testSchema.fbs) +zerobuf_generate_cxx(TESTSCHEMA ${CMAKE_CURRENT_BINARY_DIR}/testschema + testSchema.fbs doubleString.fbs) include_directories(${CMAKE_CURRENT_BINARY_DIR}) set(TESTSCHEMA_LIBRARY_TYPE STATIC) set(TESTSCHEMA_INCLUDE_NAME testschema) set(TESTSCHEMA_LINK_LIBRARIES ZeroBuf) set(TESTSCHEMA_OMIT_EXPORT ON) +set(TESTSCHEMA_OMIT_INSTALL ON) common_library(testschema) set(TEST_LIBRARIES ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} diff --git a/tests/doubleString.cpp b/tests/doubleString.cpp new file mode 100644 index 0000000..159c42a --- /dev/null +++ b/tests/doubleString.cpp @@ -0,0 +1,36 @@ + +/* Copyright (c) 2016, Human Brain Project + * Stefan.Eilemann@epfl.ch + */ + +#define BOOST_TEST_MODULE doubleString + +#include + +#include +#include + +BOOST_AUTO_TEST_CASE(reallocation) +{ + // Repro: allocator bug with a specific order of calls + // https://github.com/HBPVIS/ZeroBuf/pull/50 + test::DoubleString doubleString; + doubleString.setKey( std::string( 1, 1 )); + doubleString.setValue( std::string( 12, 12 )); + doubleString.setKey( std::string( 8, 8 )); + doubleString.setValue( std::string( 16, 16 )); + doubleString.setKey( std::string( 12, 12 )); + doubleString.setValue( std::string( 17, 17 )); + + // Try to find another combination + for( size_t i = 0; i < 1000; ++i ) + { + size_t len = ::rand() % 20; + doubleString.setKey( std::string( len, len )); + + len = ::rand() % 20; + doubleString.setValue( std::string( len, len )); + BOOST_CHECK_LE( doubleString.toBinary().size, + 36/*header*/ + 19/*biggest hole*/ + 40/*20b strings*/ ); + } +} diff --git a/tests/doubleString.fbs b/tests/doubleString.fbs new file mode 100644 index 0000000..a15835b --- /dev/null +++ b/tests/doubleString.fbs @@ -0,0 +1,7 @@ + +namespace test; + +table DoubleString { + key: string; + value: string; +} diff --git a/tests/empty.cpp b/tests/empty.cpp index c4e6c63..4941f50 100644 --- a/tests/empty.cpp +++ b/tests/empty.cpp @@ -6,7 +6,7 @@ #define BOOST_TEST_MODULE empty #include -#include +#include #include BOOST_AUTO_TEST_CASE(empty) diff --git a/tests/nestedDynamicZerobuf.cpp b/tests/nestedDynamicZerobuf.cpp index 381e16a..623f09e 100644 --- a/tests/nestedDynamicZerobuf.cpp +++ b/tests/nestedDynamicZerobuf.cpp @@ -6,7 +6,7 @@ #define BOOST_TEST_MODULE nestedDynamicZerobuf #include -#include +#include #include diff --git a/tests/serialization.h b/tests/serialization.h index d7cf75f..c28996e 100644 --- a/tests/serialization.h +++ b/tests/serialization.h @@ -3,7 +3,7 @@ * Daniel Nachbaur */ -#include +#include #define SETVALUES(type, name) \ const std::vector< type > name##Vector { type(1), type(1), type(2), type(3) }; \ diff --git a/tests/testSchema.fbs b/tests/testSchema.fbs index 7e6bc64..e7db480 100644 --- a/tests/testSchema.fbs +++ b/tests/testSchema.fbs @@ -92,5 +92,3 @@ table TestSchema { nesteddynamic: [TestNested]; nestedMember: TestDynamic; } - -root_type TestSchema; diff --git a/zerobuf/NonMovingBaseAllocator.cpp b/zerobuf/NonMovingBaseAllocator.cpp index b988966..b8afc35 100644 --- a/zerobuf/NonMovingBaseAllocator.cpp +++ b/zerobuf/NonMovingBaseAllocator.cpp @@ -74,7 +74,8 @@ uint8_t* NonMovingBaseAllocator::updateAllocation( } // Check for a big enough hole - typedef std::map< size_t, size_t > ArrayMap; + //-- record allocations + typedef std::map< size_t, size_t > ArrayMap; // offset -> size ArrayMap arrays; // sort arrays by position for( size_t i = 0; i < _numDynamic; ++i ) { @@ -83,8 +84,9 @@ uint8_t* NonMovingBaseAllocator::updateAllocation( arrays[ offset ] = _getSize( i ); } + //-- find hole uint64_t start = _staticSize; - for( ArrayMap::const_iterator i = arrays.begin(); i != arrays.end(); ++i ) + for( auto i = arrays.cbegin(); i != arrays.cend(); ++i ) { assert( i->first >= start ); if( i->first - start >= newSize ) @@ -93,7 +95,17 @@ uint8_t* NonMovingBaseAllocator::updateAllocation( start = i->first + i->second; } + //-- check for space after last allocation + if( getSize() - start >= newSize ) + return _moveAllocation( index, copy, start, newSize ); + // realloc space at the end + if( start + newSize <= getSize( )) + throw std::runtime_error( + "Internal allocator error: allocation shrinks from " + + std::to_string( getSize( )) + " to " + std::to_string( start ) + + " + " + std::to_string( newSize )); + _resize( start + newSize ); return _moveAllocation( index, copy, start, newSize ); }