Skip to content

Commit

Permalink
Merge branch 'develop' into 'main'
Browse files Browse the repository at this point in the history
tools v0.4.1

See merge request njoy/tools!11
  • Loading branch information
whaeck committed Jan 30, 2025
2 parents e0eb6b4 + 6c3c373 commit 7124bbf
Show file tree
Hide file tree
Showing 37 changed files with 494 additions and 100 deletions.
16 changes: 16 additions & 0 deletions .github/scripts/prep_valgrind_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#! /bin/bash
echo "
check_return_code() {
if [ \$? -ne 0 ]; then
echo \"Memory leak detected. Test Failed...\"
exit 1
fi
}
" > test_valgrind.sh

find . -iname "*.test" -type f | while IFS= read -r line; do
dirname=$(dirname "$line")
realname=$(basename "$line")
echo "cd ${dirname}; valgrind --leak-check=full --show-leak-kinds=all --errors-for-leak-kinds=all --error-exitcode=1 ./${realname}; check_return_code; cd -" >> test_valgrind.sh
done
20 changes: 18 additions & 2 deletions .github/workflows/ContinuousIntegration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ on:
pull_request:
branches: 'main'

# ubuntu-22.04 is x64
# macos-13 is intel
# macos-14 is arm64 (M1)
jobs:
build:
runs-on: ${{matrix.os}}
strategy:
matrix:
os: [ ubuntu-22.04, macos-12 ]
os: [ ubuntu-22.04, macos-13, macos-14 ]
cxx: [ clang++, g++-12 ]
build_type: [ Debug, Release ]

Expand All @@ -29,11 +32,24 @@ jobs:
- name: mkdir bin
run: mkdir bin
- name: cmake
run: cmake -DPYTHON_EXECUTABLE=$(which python3) -D CMAKE_CXX_COMPILER=`which ${{matrix.cxx}}` -D CMAKE_BUILD_TYPE=${{matrix.build_type}} -D tools.tests=ON ..
run: cmake -DCMAKE_CXX_FLAGS="-gdwarf-4" -DPYTHON_EXECUTABLE=$(which python3) -D CMAKE_CXX_COMPILER=`which ${{matrix.cxx}}` -D CMAKE_BUILD_TYPE=${{matrix.build_type}} -D tools.tests=ON ..
working-directory: ./bin
- name: make
run: make -j2
working-directory: ./bin
- name: ctest
run: ctest -j2
working-directory: ./bin

- name: Setup Valgrind on Ubuntu
if: ${{matrix.os == 'ubuntu-22.04'}}
run: |
sudo apt-get install valgrind;
bash .github/scripts/prep_valgrind_test.sh
working-directory: .

- name: Run tests with Valgrind
if: ${{matrix.os == 'ubuntu-22.04'}}
run: |
bash test_valgrind.sh
working-directory: .
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# Preamble
########################################################################

cmake_minimum_required( VERSION 3.24 )
cmake_minimum_required( VERSION 3.27 )

set( subproject OFF )
if( DEFINED PROJECT_NAME )
set( subproject ON )
endif()

project( tools
VERSION 0.4.0
VERSION 0.4.1
LANGUAGES CXX
)

Expand Down Expand Up @@ -83,7 +83,7 @@ if( tools.python )

target_link_libraries( tools.python PRIVATE tools )
target_include_directories( tools.python PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/python/src )
target_compile_options( tools.python PRIVATE "-fvisibility=hidden" )
set_target_properties( tools.python PROPERTIES CXX_VISIBILITY_PRESET hidden)
set_target_properties( tools.python PROPERTIES OUTPUT_NAME tools )
set_target_properties( tools.python PROPERTIES COMPILE_DEFINITIONS "PYBIND11" )
set_target_properties( tools.python PROPERTIES POSITION_INDEPENDENT_CODE ON )
Expand Down
7 changes: 7 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Release Notes—tools
Given here are some release notes for tools.

## tools v0.4.1
Bug fixes:
- iterator guards were added to the disco parser to avoid valgrind errors in ENDFtk.
- the stride_view iterator was missing the reference type, which is required to create vectors using these stride view iterators in C++17.

A few updates were made in the CMake files for Windows compilation issues. The GitHub CI was also updated: macos-14 (arm64 architecture) was added in addition to macos-13 (intel architecture).

## [tools v0.4.0](https://github.com/njoy/tools/pull/44)
New features:
- added a partial implementation of the C++23 ranges standard: chunk_view, chunk_by_view, stride_view and repeat_view (LLVM implementations for these views were used as models for our C++17 based implementations)
Expand Down
2 changes: 1 addition & 1 deletion cmake/dependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required( VERSION 3.24 )
cmake_minimum_required( VERSION 3.27 )
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/.cmake)
include( shacl_FetchContent )
#######################################################################
Expand Down
8 changes: 4 additions & 4 deletions src/tools/Log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ namespace tools {
*/
class Log {

static auto initialize_logger() {
static std::shared_ptr<spdlog::logger> initialize_logger() {

auto instance = spdlog::stdout_color_st( "njoy" );
std::shared_ptr<spdlog::logger> instance = spdlog::stdout_color_st( "njoy" );
instance->set_pattern( "[%^%l%$] %v" );
#ifndef NDEBUG
instance->set_level( spdlog::level::debug );
#endif
return instance;
}

static auto& logger() {
static std::shared_ptr<spdlog::logger>& logger() {

static auto instance = initialize_logger();
static std::shared_ptr<spdlog::logger> instance = initialize_logger();
return instance;
}

Expand Down
6 changes: 1 addition & 5 deletions src/tools/disco/BaseField/test/BaseField.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ class TestBaseField : protected BaseField {

SCENARIO( "BaseField" ) {

std::string string = " a\t\n\r\n\f";
string += char{ std::char_traits<char>::eof() };
std::string string = "+abc";
auto iter = string.begin();
unsigned int position = 0;

string = "+abc";
position = 0;
iter = string.begin();
TestBaseField::skipPlusSign( iter, position );
CHECK( iter == string.begin() + 1 );
CHECK( position == 1 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ class TestBaseFixedWidthField : protected BaseFixedWidthField< Width > {

SCENARIO( "BaseFixedWidthField" ) {

std::string string = " a\t\n\r\n\f";
string += char{ std::char_traits<char>::eof() };
std::string string = "+abc";
auto iter = string.begin();
unsigned int position = 0;

string = "+abc";
position = 0;
iter = string.begin();
TestBaseFixedWidthField< 6 >::skipPlusSign( iter, position );
CHECK( iter == string.begin() + 1 );
CHECK( position == 1 );
Expand Down
8 changes: 6 additions & 2 deletions src/tools/disco/Character.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ class Character : public BaseFixedWidthField< Width > {
* @param[in,out] iter an iterator to a character in a range
*/
template < typename Representation, typename Iterator >
static Representation read( Iterator& iter, const Iterator& ) {
static Representation read( Iterator& iter, const Iterator& end ) {

Representation value;
if ( iter >= end ) {

return value;
}
value.reserve( Width );

unsigned int position = 0;
while( position < Width && ! ( isNewLine( iter ) || isEndOfFile( iter ) ) ) {
while( position < Width && ! isNewLine( iter ) ) {

++position;
value.push_back( *iter++ );
Expand Down
4 changes: 2 additions & 2 deletions src/tools/disco/Column.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class Column : public BaseFixedWidthField< Width > {
* @param[in,out] iter an iterator to a character in a range
*/
template < typename Iterator >
static void read( Iterator& iter, const Iterator& ) {
static void read( Iterator& iter, const Iterator& end ) {

unsigned int position = 0;
while( position < Width && ! ( isNewLine( iter ) || isEndOfFile( iter ) ) ) {
while( position < Width && ! ( isNewLine( iter ) || iter >= end ) ) {

++position;
++iter;
Expand Down
4 changes: 0 additions & 4 deletions src/tools/disco/FreeFormatCharacter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ class FreeFormatCharacter : public BaseField {
iter = std::find_if( iter, end,
[] ( auto&& value )
{ return ! std::isspace( value ); } );
if ( isEndOfFile( iter ) ) {

throw std::runtime_error( "Cannot read valid string: end of file encountered" );
}

auto temp = std::find_if( iter, end,
[] ( auto&& value )
Expand Down
4 changes: 0 additions & 4 deletions src/tools/disco/FreeFormatInteger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ class FreeFormatInteger : public BaseField {
iter = std::find_if( iter, end,
[] ( auto&& value )
{ return ! std::isspace( value ); } );
if ( isEndOfFile( iter ) ) {

throw std::runtime_error( "Cannot read valid integer: end of file encountered" );
}

// we are using fast_float::from_chars instead of std::from_chars since
// not all standard c++ libraries implement the floating point version of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,6 @@ SCENARIO( "Integer" ) {
end = string.end();
CHECK( 123 == FreeFormatInteger::read< int >( iter, end ) );
CHECK( iter == end - 1 );

string = " +123";
string += char{ std::char_traits<char>::eof() };
iter = string.begin();
end = string.end();
CHECK( 123 == FreeFormatInteger::read< int >( iter, end ) );
CHECK( iter == end - 1 );
} // THEN
} // GIVEN

Expand Down
4 changes: 0 additions & 4 deletions src/tools/disco/FreeFormatReal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ class FreeFormatReal : public BaseField {
iter = std::find_if( iter, end,
[] ( auto&& value )
{ return ! std::isspace( value ); } );
if ( isEndOfFile( iter ) ) {

throw std::runtime_error( "Cannot read valid real value: end of file encountered" );
}

// we are using fast_float::from_chars_advanced instead of std::from_chars
// since not all standard c++ libraries implement the floating point version
Expand Down
7 changes: 0 additions & 7 deletions src/tools/disco/FreeFormatReal/test/FreeFormatReal.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,6 @@ SCENARIO( "Integer" ) {
end = string.end();
CHECK_THAT( 123, WithinRel( FreeFormatReal::read< double >( iter, end ) ) );
CHECK( iter == end - 1 );

string = " +123";
string += char{ std::char_traits<char>::eof() };
iter = string.begin();
end = string.end();
CHECK_THAT( 123, WithinRel( FreeFormatReal::read< double >( iter, end ) ) );
CHECK( iter == end - 1 );
} // THEN
} // GIVEN

Expand Down
10 changes: 5 additions & 5 deletions src/tools/disco/Integer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ class Integer : public BaseFixedWidthField< Width > {
* @param[in,out] iter an iterator to a character in a range
*/
template < typename Representation, typename Iterator >
static Representation read( Iterator& iter, const Iterator& ) {
static Representation read( Iterator& iter, const Iterator& end ) {

unsigned int position = 0;
const auto end = iter + Width;
const auto final = iter + Width;
Representation value = 0;

skipSpaces( iter, position );
if ( isNewLine( iter ) || isEndOfFile( iter ) || Width == position ) {
if ( isNewLine( iter ) || Width == position || iter >= end ) {

return value;
}
Expand All @@ -62,7 +62,7 @@ class Integer : public BaseFixedWidthField< Width > {
// we are using fast_float::from_chars instead of std::from_chars since
// not all standard c++ libraries implement the floating point version of
// std::from_chars
auto result = fast_float::from_chars( &*iter, &*end, value );
auto result = fast_float::from_chars( &*iter, &*final, value );
if ( result.ec == std::errc() ) {

auto advance = result.ptr - &*iter;
Expand All @@ -77,7 +77,7 @@ class Integer : public BaseFixedWidthField< Width > {
skipSpaces( iter, position );
if ( Width != position ) {

if ( ! isNewLine( iter ) && ! isEndOfFile( iter ) ) {
if ( ! isNewLine( iter ) ) {

throw std::runtime_error( "cannot parse invalid integer number 3" );
}
Expand Down
7 changes: 0 additions & 7 deletions src/tools/disco/Integer/test/Integer.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ SCENARIO( "Integer" ) {
end = string.end();
CHECK( 123 == Integer< 10 >::read< int >( begin, end ) );
CHECK( begin == end - 1 );

string = " +123";
string += char{ std::char_traits<char>::eof() };
begin = string.begin();
end = string.end();
CHECK( 123 == Integer< 10 >::read< int >( begin, end ) );
CHECK( begin == end - 1 );
} // THEN
} // GIVEN

Expand Down
10 changes: 5 additions & 5 deletions src/tools/disco/Real.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ class Real : public BaseFixedWidthField< Width > {
* @param[in,out] iter an iterator to a character in a range
*/
template < typename Representation, typename Iterator >
static Representation read( Iterator& iter, const Iterator& ) {
static Representation read( Iterator& iter, const Iterator& end ) {

unsigned int position = 0;
const auto end = iter + Width;
const auto final = iter + Width;
Representation value = 0.0;

skipSpaces( iter, position );
if ( isNewLine( iter ) || isEndOfFile( iter ) || Width == position ) {
if ( isNewLine( iter ) || Width == position || iter >= end ) {

return value;
}
Expand All @@ -56,7 +56,7 @@ class Real : public BaseFixedWidthField< Width > {
// of std::from_chars and because this allows us to read fortran formatted
// floats
fast_float::parse_options options{ fast_float::chars_format::fortran };
auto result = fast_float::from_chars_advanced( &*iter, &*end, value, options );
auto result = fast_float::from_chars_advanced( &*iter, &*final, value, options );
if ( result.ec == std::errc() ) {

auto advance = result.ptr - &*iter;
Expand All @@ -71,7 +71,7 @@ class Real : public BaseFixedWidthField< Width > {
skipSpaces( iter, position );
if ( Width != position ) {

if ( ! isNewLine( iter ) && ! isEndOfFile( iter ) ) {
if ( ! isNewLine( iter ) ) {

throw std::runtime_error( "cannot parse invalid real number 3" );
}
Expand Down
7 changes: 0 additions & 7 deletions src/tools/disco/Real/test/Real.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,6 @@ SCENARIO( "Real" ) {
end = string.end();
CHECK_THAT( 123, WithinRel( Real< 10 >::read< double >( begin, end ) ) );
CHECK( begin == end - 1 );

string = " +123";
string += char{ std::char_traits<char>::eof() };
begin = string.begin();
end = string.end();
CHECK_THAT( 123, WithinRel( Real< 10 >::read< double >( begin, end ) ) );
CHECK( begin == end - 1 );
} // THEN
} // GIVEN

Expand Down
2 changes: 1 addition & 1 deletion src/tools/disco/Record.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct Record<> {
template< typename Iterator >
static void read( Iterator& iter, const Iterator& end ) {

while ( iter != end && ! ( isNewLine( iter )|| isEndOfFile( iter ) ) ) {
while ( iter != end && ! ( isNewLine( iter ) ) ) {

++iter;
}
Expand Down
9 changes: 0 additions & 9 deletions src/tools/disco/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,6 @@ bool isWhiteSpace( const Iterator& iter ) {
return std::isspace( *iter );
}

/**
* @brief Return whether or not a character is the end of file character
*/
template < typename Iterator >
constexpr bool isEndOfFile( const Iterator& iter ) {

return std::char_traits< char >::eof() == *iter;
}

} // disco namespace
} // tools namespace
} // njoy namespace
Expand Down
Loading

0 comments on commit 7124bbf

Please sign in to comment.