From e92b5621d3faa89c427fe620178789386d08de01 Mon Sep 17 00:00:00 2001 From: Robert Underwood Date: Tue, 27 Aug 2019 14:46:16 -0500 Subject: [PATCH] libpressio version 0.9.1 Bug Fixes - Previously the wrong INSTALL_INTERFACE was provided to target_include_directories which caused projects using libpressio to fail to compile. A properly name spaced version is now provided. - Fixed bug in pressio_option::holds_alternative that prevented compilation on gcc-8.3. Template specialization has been replaced with SFINAE using std::enable_if_t. libpressio now compiles on GCC-8.3 and Clang 8 using libstdc++ from GCC-8.3. - Formatted README.markdown with clang-tidy --- CMakeLists.txt | 4 +-- COPYRIGHT.txt | 2 +- README.md | 46 +++++++++++++++------------ include/libpressio_ext/cpp/options.h | 15 ++++----- include/libpressio_ext/cpp/printers.h | 3 ++ src/plugins/io/posix.cc | 9 ++++-- src/pressio_option.cc | 7 ---- test/test_io.cc | 3 +- 8 files changed, 48 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b62f8a..c0f9e5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR) -project(libpressio VERSION "0.9.0" LANGUAGES CXX C) +project(libpressio VERSION "0.9.1" LANGUAGES CXX C) enable_testing() set(CMAKE_EXPORT_COMPILE_COMMANDS ON) @@ -51,7 +51,7 @@ add_library(libpressio target_include_directories(libpressio PUBLIC $ - $ + $ PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include ) target_compile_options(libpressio PRIVATE $<$: -Wall -Werror -Wextra -Wpedantic>) diff --git a/COPYRIGHT.txt b/COPYRIGHT.txt index e4c46e0..01bfd4f 100644 --- a/COPYRIGHT.txt +++ b/COPYRIGHT.txt @@ -1,6 +1,6 @@ Copyright © 2019 , UChicago Argonne, LLC All Rights Reserved -[libpressio, Version 0.9.0] +[libpressio, Version 0.9.1] Robert Underwood Argonne National Laboratory diff --git a/README.md b/README.md index 03ea05f..d261127 100644 --- a/README.md +++ b/README.md @@ -72,53 +72,59 @@ Here is a minimal example with error checking of how to use LibPressio: #include "make_input_data.h" - -int main(int argc, char *argv[]) +int +main(int argc, char* argv[]) { struct pressio* library = pressio_instance(); struct pressio_compressor* compressor = pressio_get_compressor(library, "sz"); - struct pressio_options* sz_options = pressio_compressor_get_options(compressor); + struct pressio_options* sz_options = + pressio_compressor_get_options(compressor); pressio_options_set_integer(sz_options, "sz:error_bound_mode", ABS); pressio_options_set_double(sz_options, "sz:abs_err_bound", 0.5); - if(pressio_compressor_check_options(compressor, sz_options)) { + if (pressio_compressor_check_options(compressor, sz_options)) { printf("%s\n", pressio_compressor_error_msg(compressor)); exit(pressio_compressor_error_code(compressor)); } - if(pressio_compressor_set_options(compressor, sz_options)) { + if (pressio_compressor_set_options(compressor, sz_options)) { printf("%s\n", pressio_compressor_error_msg(compressor)); exit(pressio_compressor_error_code(compressor)); } - - //load a 300x300x300 dataset into data created with malloc + + // load a 300x300x300 dataset into data created with malloc double* rawinput_data = make_input_data(); - size_t dims[] = {300,300,300}; - struct pressio_data* input_data = pressio_data_new_move(pressio_double_dtype, rawinput_data, 3, dims, pressio_data_libc_free_fn, NULL); + size_t dims[] = { 300, 300, 300 }; + struct pressio_data* input_data = + pressio_data_new_move(pressio_double_dtype, rawinput_data, 3, dims, + pressio_data_libc_free_fn, NULL); - //creates an output dataset pointer - struct pressio_data* compressed_data = pressio_data_new_empty(pressio_byte_dtype, 0, NULL); + // creates an output dataset pointer + struct pressio_data* compressed_data = + pressio_data_new_empty(pressio_byte_dtype, 0, NULL); - //configure the decompressed output area - struct pressio_data* decompressed_data = pressio_data_new_empty(pressio_double_dtype, 3, dims); + // configure the decompressed output area + struct pressio_data* decompressed_data = + pressio_data_new_empty(pressio_double_dtype, 3, dims); - //compress the data - if(pressio_compressor_compress(compressor, input_data, compressed_data)) { + // compress the data + if (pressio_compressor_compress(compressor, input_data, compressed_data)) { printf("%s\n", pressio_compressor_error_msg(compressor)); exit(pressio_compressor_error_code(compressor)); } - - //decompress the data - if(pressio_compressor_decompress(compressor, compressed_data, decompressed_data)) { + + // decompress the data + if (pressio_compressor_decompress(compressor, compressed_data, + decompressed_data)) { printf("%s\n", pressio_compressor_error_msg(compressor)); exit(pressio_compressor_error_code(compressor)); } - //free the input, decompressed, and compressed data + // free the input, decompressed, and compressed data pressio_data_free(decompressed_data); pressio_data_free(compressed_data); pressio_data_free(input_data); - //free options and the library + // free options and the library pressio_options_free(sz_options); pressio_release(&library); return 0; diff --git a/include/libpressio_ext/cpp/options.h b/include/libpressio_ext/cpp/options.h index f4cb443..25f7fe7 100644 --- a/include/libpressio_ext/cpp/options.h +++ b/include/libpressio_ext/cpp/options.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "pressio_options.h" #include "pressio_option.h" @@ -72,7 +73,7 @@ struct pressio_option final { /** * \returns returns true if the option holds the current type */ - template + template ,int> = 0> bool holds_alternative() const { return std::holds_alternative>(option); } @@ -80,8 +81,10 @@ struct pressio_option final { /** Specialization for the std::monostate singleton * \returns true if the option has no specified type or value */ - template <> - bool holds_alternative() const; + template ,int> = 0> + bool holds_alternative() const { + return std::holds_alternative(option); + } /** * \returns a std::optional which holds a value if the option has one or an empty optional otherwise @@ -121,6 +124,7 @@ struct pressio_option final { case pressio_option_userptr_type: return get().has_value(); case pressio_option_unset_type: + default: return false; } } @@ -191,11 +195,6 @@ struct pressio_option final { template<> pressio_option::pressio_option(std::monostate value); -/** Specialization for the std::monostate singleton - * \returns true if the option has no specified type or value - */ -template <> -bool pressio_option::holds_alternative() const; /** * represents a map of dynamically typed objects */ diff --git a/include/libpressio_ext/cpp/printers.h b/include/libpressio_ext/cpp/printers.h index 400fec0..784549b 100644 --- a/include/libpressio_ext/cpp/printers.h +++ b/include/libpressio_ext/cpp/printers.h @@ -29,6 +29,7 @@ operator<<(std::basic_ostream& out, enum pressio_option_type type return out << "char*"; case pressio_option_userptr_type: return out << "void*"; + default: case pressio_option_unset_type: return out << "unset"; } @@ -60,6 +61,7 @@ operator<<(std::basic_ostream& out, pressio_option const& option) case pressio_option_userptr_type: return out << option.get_value(); case pressio_option_unset_type: + default: return out << ""; } } else { @@ -113,6 +115,7 @@ operator<<(std::basic_ostream& out, enum pressio_dtype type) return out << "int32_t"; case pressio_int64_dtype: return out << "int64_t"; + default: case pressio_byte_dtype: return out << "byte"; } diff --git a/src/plugins/io/posix.cc b/src/plugins/io/posix.cc index 026edb4..e645133 100644 --- a/src/plugins/io/posix.cc +++ b/src/plugins/io/posix.cc @@ -39,8 +39,13 @@ extern "C" { size_t size = static_cast(statbuf.st_size); ret = pressio_data_new_owning(pressio_byte_dtype, 1, &size); } - read(in_filedes, pressio_data_ptr(ret, nullptr), pressio_data_get_bytes(ret)); - return ret; + size_t bytes_read = read(in_filedes, pressio_data_ptr(ret, nullptr), pressio_data_get_bytes(ret)); + if(bytes_read != pressio_data_get_bytes(ret)) { + pressio_data_free(ret); + return nullptr; + } else { + return ret; + } } struct pressio_data* pressio_io_data_fread(struct pressio_data* dims, FILE* in_file) { diff --git a/src/pressio_option.cc b/src/pressio_option.cc index 7ce1647..ab19f04 100644 --- a/src/pressio_option.cc +++ b/src/pressio_option.cc @@ -6,13 +6,6 @@ template<> pressio_option::pressio_option(std::monostate value): option(value) {} -/** Specialization for the std::monostate singleton - * \returns true if the option has no specified type or value - */ -template <> -bool pressio_option::holds_alternative() const { - return std::holds_alternative(option); -} extern "C" { diff --git a/test/test_io.cc b/test/test_io.cc index 77bd6f3..79fc8cd 100644 --- a/test/test_io.cc +++ b/test/test_io.cc @@ -11,7 +11,8 @@ class PressioDataIOTests: public ::testing::Test { std::iota(std::begin(data), std::end(data), 0); tmp_name = std::string("test_io_readXXXXXX\0"); tmp_fd = mkstemp(const_cast(tmp_name.data())); - write(tmp_fd, data.data(), sizeof(int)*data.size()); + size_t bytes_written = write(tmp_fd, data.data(), sizeof(int)*data.size()); + ASSERT_EQ(bytes_written, data.size() * sizeof(int)); lseek(tmp_fd, 0, SEEK_SET); }