Skip to content

Commit

Permalink
libpressio version 0.33.0
Browse files Browse the repository at this point in the history
Major Changes

+ Added a noop IO module to make it easier to disable IO
+ Added `supported_metrics()` and `supported_io()` methods to struct pressio for symmetry
+ Added `pressio_supported_metrics()` methods
+ BREAKING CHANGE: pressio_supported_compressors() now returns
  a static string based on what is found in the registry.  While this
  should normally be the consistent with LIBPRESSIO_COMPRESSORS, it
  won't include external compressors.  This change better conforms with
  the documented and intended behavior.

Bug Fixes:

+ The POSIX pressio_io_data_fwrite function now correctly returns the
  number of bytes written as documented.  Previously it returned the
  number of objects written.
+ The POSIX io module now returns error messages on failures
+ the POSIX io module no longer initializes file_ptr to nullptr to avoid
  a bug where it is intentionally set.
  • Loading branch information
robertu94 committed Feb 14, 2020
1 parent c7d6736 commit b72c479
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 17 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(libpressio VERSION "0.32.0" LANGUAGES CXX C)
project(libpressio VERSION "0.33.0" LANGUAGES CXX C)

#correct was to set a default build type
# https://blog.kitware.com/cmake-and-the-default-build-type/
Expand Down Expand Up @@ -86,6 +86,7 @@ add_library(libpressio
./src/plugins/metrics/error_stat.cc
./src/plugins/metrics/pearsons.cc
./src/plugins/io/posix.cc
./src/plugins/io/noop.cc
./src/plugins/io/io.cc

#public headers
Expand Down
14 changes: 14 additions & 0 deletions include/libpressio_ext/cpp/pressio.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,20 @@ struct pressio {
*/
static const char* supported_compressors();

/**
* \returns the supported metrics list for this version of libpressio
*
* \see pressio_supported_metrics
*/
static const char* supported_metrics();

/**
* \returns the supported io modules list for this version of libpressio
*
* \see pressio_supported_io
*/
static const char* supported_io();

/**
* \returns the major version number of libpressio
*/
Expand Down
8 changes: 1 addition & 7 deletions src/plugins/io/io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@ void pressio_io_free(struct pressio_io* io) {
delete io;
}
const char* pressio_supported_io_modules() {
static std::string modules;
std::ostringstream os;
for (auto const& it : io_plugins()) {
os << it.first << " ";
}
modules = os.str();
return modules.c_str();
return pressio::supported_io();
}

struct pressio_options* pressio_io_get_configuration(struct pressio_io const* io) {
Expand Down
45 changes: 45 additions & 0 deletions src/plugins/io/noop.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <sys/stat.h>
#include <unistd.h>
#include <vector>
#include "pressio_data.h"
#include "pressio_compressor.h"
#include "libpressio_ext/io/posix.h"
#include "libpressio_ext/cpp/pressio.h"
#include "libpressio_ext/cpp/options.h"
#include "libpressio_ext/cpp/data.h"
#include "libpressio_ext/cpp/io.h"

struct noop_io : public libpressio_io_plugin {
virtual struct pressio_data* read_impl(struct pressio_data* data) override {
if(data != nullptr) pressio_data_free(data);
return nullptr;
}

virtual int write_impl(struct pressio_data const*) override{
return 0;
}
virtual struct pressio_options get_configuration_impl() const override{
return {
{"pressio:thread_safe", static_cast<int>(pressio_thread_safety_multiple)}
};
}

virtual int set_options_impl(struct pressio_options const&) override{
return 0;
}
virtual struct pressio_options get_options_impl() const override{
return {};
}

int patch_version() const override{
return 1;
}
virtual const char* version() const override{
return "0.0.1";
}

private:
};

static pressio_register X(io_plugins(), "noop", [](){ return compat::make_unique<noop_io>(); });

61 changes: 53 additions & 8 deletions src/plugins/io/posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ extern "C" {
}

struct pressio_data* pressio_io_data_fread(struct pressio_data* dims, FILE* in_file) {
if(in_file == nullptr) return nullptr;
return pressio_io_data_read(dims, fileno(in_file));
}

Expand All @@ -68,7 +69,7 @@ extern "C" {
pressio_dtype_size(pressio_data_dtype(data)),
pressio_data_num_elements(data),
out_file
);
) * pressio_dtype_size(pressio_data_dtype(data));
}

size_t pressio_io_data_write(struct pressio_data const* data, int out_filedes) {
Expand All @@ -92,18 +93,62 @@ extern "C" {

struct posix_io : public libpressio_io_plugin {
virtual struct pressio_data* read_impl(struct pressio_data* data) override {
if(path) return pressio_io_data_path_read(data, path->c_str());
if(file_ptr) return pressio_io_data_fread(data, *file_ptr);
if(fd) return pressio_io_data_read(data, *fd);
errno = 0;
if(path) {
auto ret = pressio_io_data_path_read(data, path->c_str());
if(ret == nullptr) {
if(errno != 0)set_error(2, strerror(errno));
else set_error(3, "invalid dims");
}
return ret;
}
if(file_ptr) {
auto ret = pressio_io_data_fread(data, *file_ptr);
if(ret == nullptr) {
if(errno != 0)set_error(2, strerror(errno));
else set_error(3, "invalid dims");
}
return ret;
}
if(fd) {
auto ret = pressio_io_data_read(data, *fd);
if(ret == nullptr) {
if(errno != 0) set_error(2, strerror(errno));
else set_error(3, "invalid dims");
}
return ret;
}

invalid_configuration();
return nullptr;
}

virtual int write_impl(struct pressio_data const* data) override{
if(path) return pressio_io_data_path_write(data, path->c_str()) != data->size_in_bytes();
else if(file_ptr) return pressio_io_data_fwrite(data, *file_ptr) != data->size_in_bytes();
else if(fd) return pressio_io_data_write(data, *fd) != data->size_in_bytes();
errno = 0;
if(path) {
int ret = pressio_io_data_path_write(data, path->c_str()) != data->size_in_bytes();
if(ret) {
if(errno) return set_error(2, strerror(errno));
else return set_error(3, "unknown failure");
}
return ret;
}
else if(file_ptr) {
int ret = pressio_io_data_fwrite(data, *file_ptr) != data->size_in_bytes();
if(ret) {
if(errno) set_error(2, strerror(errno));
else set_error(3, "unknown failure");
}
return ret;
}
else if(fd) {
int ret = pressio_io_data_write(data, *fd) != data->size_in_bytes();
if(ret) {
if(errno) set_error(2, strerror(errno));
else set_error(3, "unknown failure");
}
return ret;
}
return invalid_configuration();
}
virtual struct pressio_options get_configuration_impl() const override{
Expand Down Expand Up @@ -163,7 +208,7 @@ struct posix_io : public libpressio_io_plugin {
}

std::optional<std::string> path;
std::optional<FILE*> file_ptr = nullptr;
std::optional<FILE*> file_ptr;
std::optional<int> fd;
};

Expand Down
27 changes: 26 additions & 1 deletion src/pressio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <map>
#include <memory>
#include <string>
#include <sstream>
#include <functional>
#include "pressio.h"
#include "pressio_version.h"
Expand Down Expand Up @@ -73,6 +74,10 @@ const char* pressio_supported_compressors() {
return pressio::supported_compressors();
}

const char* pressio_supported_metrics() {
return pressio::supported_metrics();
}

unsigned int pressio_major_version() {
return pressio::major_version();
}
Expand All @@ -96,8 +101,28 @@ const char* pressio::features() {
return LIBPRESSIO_FEATURES;
}

template <class T>
static std::string build_from(T const& plugins) {
std::ostringstream os;
for (auto const& it : plugins) {
os << it.first << " ";
}
return os.str();
}

const char* pressio::supported_compressors() {
return LIBPRESSIO_COMPRESSORS;
static std::string modules = build_from(compressor_plugins());
return modules.c_str();
}

const char* pressio::supported_metrics() {
static std::string modules = build_from(metrics_plugins());
return modules.c_str();
}

const char* pressio::supported_io() {
static std::string modules = build_from(io_plugins());
return modules.c_str();
}

unsigned int pressio::major_version() {
Expand Down

0 comments on commit b72c479

Please sign in to comment.