Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dermojo committed Jul 17, 2019
2 parents cbd5394 + 8eeacb8 commit f284740
Show file tree
Hide file tree
Showing 24 changed files with 2,928 additions and 2,416 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "extern/googletest"]
path = extern/googletest
url = https://github.com/google/googletest.git
[submodule "extern/gsl-lite"]
path = extern/gsl-lite
url = https://github.com/martinmoene/gsl-lite.git
43 changes: 33 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dist: trusty
dist: xenial
language: cpp

matrix:
Expand Down Expand Up @@ -36,6 +36,22 @@ matrix:
- g++-6
- lcov
env: MYCC=gcc-6 MYCXX=g++-6 CODE_COVERAGE=on
- compiler: gcc
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-7
env: MYCC=gcc-7 MYCXX=g++-7
- compiler: gcc
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-8
env: MYCC=gcc-8 MYCXX=g++-8
- compiler: clang
addons:
apt:
Expand All @@ -59,7 +75,7 @@ matrix:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-4.0
- llvm-toolchain-xenial
packages:
- clang-4.0
env: MYCC=clang-4.0 MYCXX=clang++-4.0
Expand All @@ -68,7 +84,7 @@ matrix:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-5.0
- llvm-toolchain-xenial
packages:
- clang-5.0
env: MYCC=clang-5.0 MYCXX=clang++-5.0
Expand All @@ -77,27 +93,34 @@ matrix:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-6.0
- llvm-toolchain-xenial-6.0
packages:
- clang-6.0
env: MYCC=clang-6.0 MYCXX=clang++-6.0
- compiler: clang-7
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-xenial-7
packages:
- clang-7
env: MYCC=clang MYCXX=clang++
- compiler: clang
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-6.0
- llvm-toolchain-xenial-6.0
packages:
- clang-6.0
env: MYCC=clang-6.0 MYCXX=clang++-6.0 ENABLE_ASAN=on
# workaround for missing PTRACE capability, see https://github.com/travis-ci/travis-ci/issues/8836
sudo: required
- compiler: clang
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-6.0
- llvm-toolchain-xenial-6.0
packages:
- clang-6.0
env: MYCC=clang-6.0 MYCXX=clang++-6.0 ENABLE_UBSAN=on
Expand All @@ -114,7 +137,7 @@ matrix:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-6.0
- llvm-toolchain-xenial-6.0
packages:
- clang-format-6.0
- clang-6.0
Expand All @@ -139,7 +162,7 @@ matrix:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-6.0
- llvm-toolchain-xenial-6.0
packages:
- clang-tidy-6.0
- clang-6.0
Expand Down
23 changes: 19 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ endif()
add_subdirectory(extern/googletest)
enable_testing()

# include GSL-Lite for unit testing
add_subdirectory(extern/gsl-lite)

#
# Build targets
#
Expand All @@ -27,8 +30,14 @@ enable_testing()
add_executable(testlib
test/test_storagearray.cpp
test/test_storagepassword.cpp
test/test_stringcore.cpp
test/test_stringbase.cpp
test/test_stringbase_erase.cpp
test/test_stringbase_find.cpp
test/test_stringbase_replace.cpp
test/test_stringcore.cpp
test/test_stringcore_access.cpp
test/test_stringcore_assign.cpp
test/test_stringcore_construct.cpp
test/test_traits.cpp
test/test_pagealloc.cpp
)
Expand All @@ -50,10 +59,11 @@ add_dependencies(runtest testlib)
# compiling the library, and will be added to consumers' build
# paths.
target_include_directories(testlib PUBLIC include)
target_include_directories(testlib SYSTEM PUBLIC extern/gsl-lite/include)
target_include_directories(example PUBLIC include)

# Link test executable against gtest & gtest_main
target_link_libraries(testlib gtest_main )
target_link_libraries(testlib gtest_main gtest)

set_property(TARGET testlib PROPERTY CXX_STANDARD 11)
set_property(TARGET testlib PROPERTY CXX_STANDARD_REQUIRED ON)
Expand All @@ -66,14 +76,19 @@ if(MSVC)
# Prevent deprecation errors for std::tr1 in googletest
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pipe")
target_compile_options(testlib PUBLIC -Wall -Werror -Wextra -pedantic
-Wunused -Wredundant-decls -Wunreachable-code
-Wold-style-cast -Wshadow
-Wconversion -Wsign-conversion -Wno-conversion-null
-Wcast-align)
# These are enabled on Clang and don't help...
target_compile_options(testlib PUBLIC -Wno-missing-braces
-Wno-gnu-zero-variadic-macro-arguments)
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
target_compile_options(testlib PUBLIC -Wno-missing-braces
-Wno-gnu-zero-variadic-macro-arguments)
endif()
# raised for gsl::byte
target_compile_options(testlib PUBLIC -Wno-missing-field-initializers)
target_link_libraries(testlib pthread)
endif()

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ are for you.
The SPSL itself only relies on the STL and has no dependencies. To compile the tests, you'll need:
* [CMake](https://cmake.org/) 3.2 or higher
* [GoogleTest](https://github.com/google/googletest) (as [git submodule](https://git-scm.com/docs/git-submodule))
* [GSL-Lite](https://github.com/martinmoene/gsl-lite) (as [git submodule](https://git-scm.com/docs/git-submodule)):
Used to test compatibility with `gsl::byte`.
Supported compilers (we'll, the ones I've tested) include GCC 4.9+ and clang 3.8+
on Linux and Microsoft Visual Studio 2015.
Expand Down
6 changes: 3 additions & 3 deletions Toolchain-cross-mingw-linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ set(COMPILER_POSTFIX "")

# which compilers to use for C and C++
set(CMAKE_RC_COMPILER ${COMPILER_PREFIX}-windres)
set(CMAKE_C_COMPILER ${COMPILER_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${COMPILER_PREFIX}-g++)
set(CMAKE_C_COMPILER ${COMPILER_PREFIX}-gcc-posix)
set(CMAKE_CXX_COMPILER ${COMPILER_PREFIX}-g++-posix)

# the target environment is located here
set(CMAKE_FIND_ROOT_PATH /usr/${COMPILER_PREFIX} ) #${USER_ROOT_PATH})

# adjust the default behaviour of the FIND_XXX() commands:
# adjust the default behavior of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
Expand Down
1 change: 1 addition & 0 deletions extern/gsl-lite
Submodule gsl-lite added at 0e2f2a
6 changes: 3 additions & 3 deletions include/spsl/pagealloc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,7 @@ class SensitiveSegmentAllocator
SensitiveSegmentAllocator() : m_alloc(&SensitivePageAllocator::getDefaultInstance()) {}
SensitiveSegmentAllocator(SensitivePageAllocator& alloc) noexcept : m_alloc(&alloc) {}
SensitiveSegmentAllocator(const SensitiveSegmentAllocator& other) noexcept = default;
SensitiveSegmentAllocator(SensitiveSegmentAllocator&& other) noexcept
: SensitiveSegmentAllocator()
SensitiveSegmentAllocator(SensitiveSegmentAllocator&& other) noexcept : m_alloc(nullptr)
{
this->swap(other);
}
Expand Down Expand Up @@ -586,7 +585,8 @@ class SensitiveSegmentAllocator
std::size_t max_size() const noexcept { return m_alloc->max_size() / sizeof(T); }

private:
/// non-owning pointer to the "real" allocator (never nullptr, but cannot use a reference...)
/// non-owning pointer to the "real" allocator
/// (nullptr is only possible in a moved-from state)
SensitivePageAllocator* m_alloc;
};
} // namespace spsl
Expand Down
20 changes: 10 additions & 10 deletions include/spsl/storage_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class StorageArray
using this_type = StorageArray<char_type, MaxSize, overflow_policy>;
using traits_type = typename std::char_traits<char_type>;

static constexpr char_type nul = static_cast<char_type>(0);
static constexpr char_type nul() { return char_type(); }

// size information functions
constexpr static size_type max_size() { return MaxSize; }
Expand All @@ -58,7 +58,7 @@ class StorageArray
inline size_type capacity_left() const { return max_size() - size(); }

// default constructor
StorageArray() : m_length(0), m_buffer() { m_buffer[0] = nul; }
StorageArray() : m_length(0), m_buffer() { m_buffer[0] = nul(); }

// implement copy & move
StorageArray(const this_type& other) noexcept : StorageArray()
Expand Down Expand Up @@ -111,7 +111,7 @@ class StorageArray
count = overflow_policy::checkAssign(count, ch, max_size());
traits_type::assign(m_buffer.data(), count, ch);
m_length = count;
m_buffer[m_length] = nul;
m_buffer[m_length] = nul();
}

template <typename InputIt, typename = checkInputIter<InputIt>>
Expand All @@ -128,7 +128,7 @@ class StorageArray

void clear()
{
m_buffer[0] = nul;
m_buffer[0] = nul();
m_length = 0;
}
void push_back(char_type c)
Expand All @@ -138,14 +138,14 @@ class StorageArray
if (n)
{
m_buffer[m_length++] = c;
m_buffer[m_length] = nul;
m_buffer[m_length] = nul();
}
}
void pop_back()
{
// the standard leaves it as "undefined" if m_length == 0, but we'll just keep it sane
if (m_length != 0)
m_buffer[--m_length] = nul;
m_buffer[--m_length] = nul();
}

void insert(size_type index, size_type count, char_type ch)
Expand Down Expand Up @@ -207,7 +207,7 @@ class StorageArray

traits_type::assign(m_buffer.data() + m_length, count, ch);
m_length += count;
m_buffer[m_length] = nul;
m_buffer[m_length] = nul();
}

void append(const char_type* s, size_type n)
Expand All @@ -217,7 +217,7 @@ class StorageArray

traits_type::copy(m_buffer.data() + m_length, s, n);
m_length += n;
m_buffer[m_length] = nul;
m_buffer[m_length] = nul();
}

template <typename InputIt, typename = checkInputIter<InputIt>>
Expand All @@ -233,7 +233,7 @@ class StorageArray
if (count < size())
{
m_length = count;
m_buffer[m_length] = nul;
m_buffer[m_length] = nul();
}
else if (count > size())
{
Expand Down Expand Up @@ -318,7 +318,7 @@ class StorageArray
{
traits_type::copy(m_buffer.data(), s, len);
m_length = len;
m_buffer[m_length] = nul;
m_buffer[m_length] = nul();
}

protected:
Expand Down
14 changes: 5 additions & 9 deletions include/spsl/storage_password.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class StoragePassword : private Allocator
using traits_type = typename std::char_traits<char_type>;
using allocator = Allocator;

static constexpr char_type nul = static_cast<char_type>(0);
static constexpr char_type nul() { return char_type(); }

// size information functions
size_type max_size() const
Expand Down Expand Up @@ -107,7 +107,7 @@ class StoragePassword : private Allocator
if (size())
traits_type::copy(newbuf, m_buffer, size() + 1);
else
newbuf[0] = 0;
newbuf[0] = nul();

// wipe all existing data
if (m_buffer != _b)
Expand Down Expand Up @@ -136,9 +136,7 @@ class StoragePassword : private Allocator
void _set_length(size_type n)
{
_l.m_length = n;
// workaround to pass nul as reference
char_type _term = nul;
traits_type::assign(m_buffer[n], _term);
traits_type::assign(m_buffer[n], nul());
}

// default constructor
Expand Down Expand Up @@ -226,9 +224,7 @@ class StoragePassword : private Allocator
{
reserve(size() + 1);
traits_type::assign(m_buffer[_l.m_length++], c);
// workaround to pass nul as reference
char_type _term = nul;
traits_type::assign(m_buffer[_l.m_length], _term);
traits_type::assign(m_buffer[_l.m_length], nul());
}
void pop_back()
{
Expand Down Expand Up @@ -395,7 +391,7 @@ class StoragePassword : private Allocator
if (count < size())
{
// wipe the remaining content
traits_type::assign(m_buffer + count, size() - count, nul);
traits_type::assign(m_buffer + count, size() - count, nul());
}
else if (count > size())
{
Expand Down
Loading

0 comments on commit f284740

Please sign in to comment.