Skip to content

Commit

Permalink
libpressio version 0.9.1
Browse files Browse the repository at this point in the history
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
  • Loading branch information
robertu94 committed Aug 27, 2019
1 parent 11238eb commit e92b562
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 41 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -51,7 +51,7 @@ add_library(libpressio
target_include_directories(libpressio
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
$<INSTALL_INTERFACE:include/libpressio>
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include
)
target_compile_options(libpressio PRIVATE $<$<CONFIG:Debug>: -Wall -Werror -Wextra -Wpedantic>)
Expand Down
2 changes: 1 addition & 1 deletion COPYRIGHT.txt
Original file line number Diff line number Diff line change
@@ -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

Expand Down
46 changes: 26 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 7 additions & 8 deletions include/libpressio_ext/cpp/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <variant>
#include <string>
#include <map>
#include <type_traits>
#include "pressio_options.h"
#include "pressio_option.h"

Expand Down Expand Up @@ -72,16 +73,18 @@ struct pressio_option final {
/**
* \returns returns true if the option holds the current type
*/
template <class T>
template <class T, std::enable_if_t<!std::is_same_v<T,std::monostate>,int> = 0>
bool holds_alternative() const {
return std::holds_alternative<std::optional<T>>(option);
}

/** Specialization for the std::monostate singleton
* \returns true if the option has no specified type or value
*/
template <>
bool holds_alternative<std::monostate>() const;
template <class T, std::enable_if_t<std::is_same_v<T,std::monostate>,int> = 0>
bool holds_alternative() const {
return std::holds_alternative<std::monostate>(option);
}

/**
* \returns a std::optional which holds a value if the option has one or an empty optional otherwise
Expand Down Expand Up @@ -121,6 +124,7 @@ struct pressio_option final {
case pressio_option_userptr_type:
return get<void*>().has_value();
case pressio_option_unset_type:
default:
return false;
}
}
Expand Down Expand Up @@ -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<std::monostate>() const;
/**
* represents a map of dynamically typed objects
*/
Expand Down
3 changes: 3 additions & 0 deletions include/libpressio_ext/cpp/printers.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ operator<<(std::basic_ostream<CharT, Traits>& 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";
}
Expand Down Expand Up @@ -60,6 +61,7 @@ operator<<(std::basic_ostream<CharT, Traits>& out, pressio_option const& option)
case pressio_option_userptr_type:
return out << option.get_value<void*>();
case pressio_option_unset_type:
default:
return out << "<empty>";
}
} else {
Expand Down Expand Up @@ -113,6 +115,7 @@ operator<<(std::basic_ostream<CharT, Traits>& 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";
}
Expand Down
9 changes: 7 additions & 2 deletions src/plugins/io/posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ extern "C" {
size_t size = static_cast<size_t>(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) {
Expand Down
7 changes: 0 additions & 7 deletions src/pressio_option.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::monostate>() const {
return std::holds_alternative<std::monostate>(option);
}


extern "C" {
Expand Down
3 changes: 2 additions & 1 deletion test/test_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<char*>(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);
}

Expand Down

0 comments on commit e92b562

Please sign in to comment.