From d4b23743282f401f58b24747806f4d5ab1b9e263 Mon Sep 17 00:00:00 2001 From: Robert Underwood Date: Fri, 30 Aug 2019 08:51:02 -0500 Subject: [PATCH] libpressio version 0.10.3 - Clang-Tidy configuration was added - Several Bug Fixes from Clang-Tidy - pass vectors by const& to reduce unnecessary copies - make move constructors noexcept to enable additional performance optimizations - explicitly call version functions in sz_plugin to prevent virtual call lookup - type mismatch in zfp_plugin has been corrected - removed unnessisary null character in tmpfile string in test_io --- .clang-tidy | 34 +++++++++++++++++++++++++++ CMakeLists.txt | 2 +- COPYRIGHT.txt | 2 +- include/libpressio_ext/cpp/data.h | 15 ++++++------ src/plugins/compressors/sz_plugin.cc | 2 +- src/plugins/compressors/zfp_plugin.cc | 7 ++++-- src/plugins/metrics/time.cc | 1 + test/test_io.cc | 2 +- 8 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 00000000..988d6910 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,34 @@ +--- +Checks: 'clang-diagnostic-*,clang-analyzer-*,bugprone-*,-bugprone-macro-parentheses,performance-*,portability-*,security-*,moderize*' +WarningsAsErrors: '' +HeaderFilterRegex: '.*' +AnalyzeTemporaryDtors: false +FormatStyle: none +User: runderwood +CheckOptions: + - key: cert-dcl16-c.NewSuffixes + value: 'L;LL;LU;LLU' + - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic + value: '1' + - key: google-readability-braces-around-statements.ShortStatementLines + value: '1' + - key: google-readability-function-size.StatementThreshold + value: '800' + - key: google-readability-namespace-comments.ShortNamespaceLines + value: '10' + - key: google-readability-namespace-comments.SpacesBeforeComments + value: '2' + - key: modernize-loop-convert.MaxCopySize + value: '16' + - key: modernize-loop-convert.MinConfidence + value: reasonable + - key: modernize-loop-convert.NamingStyle + value: CamelCase + - key: modernize-pass-by-value.IncludeStyle + value: llvm + - key: modernize-replace-auto-ptr.IncludeStyle + value: llvm + - key: modernize-use-nullptr.NullMacros + value: 'NULL' +... + diff --git a/CMakeLists.txt b/CMakeLists.txt index d67ef759..36884f9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR) -project(libpressio VERSION "0.10.2" LANGUAGES CXX C) +project(libpressio VERSION "0.10.3" LANGUAGES CXX C) enable_testing() set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/COPYRIGHT.txt b/COPYRIGHT.txt index 3148294a..3e9b2f11 100644 --- a/COPYRIGHT.txt +++ b/COPYRIGHT.txt @@ -1,6 +1,6 @@ Copyright © 2019 , UChicago Argonne, LLC All Rights Reserved -[libpressio, Version 0.10.2] +[libpressio, Version 0.10.3] Robert Underwood Argonne National Laboratory diff --git a/include/libpressio_ext/cpp/data.h b/include/libpressio_ext/cpp/data.h index 4eb8a48a..b735edca 100644 --- a/include/libpressio_ext/cpp/data.h +++ b/include/libpressio_ext/cpp/data.h @@ -43,7 +43,7 @@ struct pressio_data { * \returns an empty data object (i.e. has no data) * \see pressio_data_new_empty * */ - static pressio_data empty(const pressio_dtype dtype, std::vector const dimensions) { + static pressio_data empty(const pressio_dtype dtype, std::vector const& dimensions) { return pressio_data(dtype, nullptr, nullptr, nullptr, dimensions.size(), dimensions.data()); } /** @@ -55,14 +55,15 @@ struct pressio_data { * \returns an non-owning data object (i.e. calling pressio_data_free will not deallocate this memory) * \see pressio_data_new_nonowning * */ - static pressio_data nonowning(const pressio_dtype dtype, void* data, std::vector const dimensions) { + static pressio_data nonowning(const pressio_dtype dtype, void* data, std::vector const& dimensions) { return pressio_data::nonowning(dtype, data, dimensions.size(), dimensions.data()); } /** * creates a copy of a data buffer * * \param[in] dtype the type of the buffer - * \param[in] src the buffer to copy \param[in] dimensions the dimensions of the buffer \returns an owning copy of the data object \see pressio_data_new_copy */ static pressio_data copy(const enum pressio_dtype dtype, void* src, std::vector const dimensions) { + * \param[in] src the buffer to copy \param[in] dimensions the dimensions of the buffer \returns an owning copy of the data object \see pressio_data_new_copy */ + static pressio_data copy(const enum pressio_dtype dtype, void* src, std::vector const& dimensions) { return pressio_data::copy(dtype, src, dimensions.size(), dimensions.data()); } /** @@ -73,7 +74,7 @@ struct pressio_data { * \returns an owning data object with uninitialized memory * \see pressio_data_new_owning * */ - static pressio_data owning(const pressio_dtype dtype, std::vector const dimensions) { + static pressio_data owning(const pressio_dtype dtype, std::vector const& dimensions) { return pressio_data::owning(dtype, dimensions.size(), dimensions.data()); } /** @@ -89,7 +90,7 @@ struct pressio_data { * */ static pressio_data move(const pressio_dtype dtype, void* data, - std::vector const dimensions, + std::vector const& dimensions, pressio_data_delete_fn deleter, void* metadata) { return pressio_data::move(dtype, data, dimensions.size(), dimensions.data(), deleter, metadata); @@ -194,7 +195,7 @@ struct pressio_data { * \param[in] rhs the data buffer to move from * \returns a reference to the object moved into */ - pressio_data(pressio_data&& rhs): + pressio_data(pressio_data&& rhs) noexcept: data_dtype(rhs.data_dtype), data_ptr(std::exchange(rhs.data_ptr, nullptr)), metadata_ptr(std::exchange(rhs.metadata_ptr, nullptr)), @@ -207,7 +208,7 @@ struct pressio_data { * \param[in] rhs the data buffer to move from * \returns a l-value reference to the object moved into */ - pressio_data& operator=(pressio_data && rhs) { + pressio_data& operator=(pressio_data && rhs) noexcept { data_dtype = rhs.data_dtype, data_ptr = std::exchange(rhs.data_ptr, nullptr), metadata_ptr = std::exchange(rhs.metadata_ptr, nullptr), diff --git a/src/plugins/compressors/sz_plugin.cc b/src/plugins/compressors/sz_plugin.cc index 3b499a3b..779a4dff 100644 --- a/src/plugins/compressors/sz_plugin.cc +++ b/src/plugins/compressors/sz_plugin.cc @@ -15,7 +15,7 @@ class sz_plugin: public libpressio_compressor_plugin { public: sz_plugin() { std::stringstream ss; - ss << major_version() << "." << minor_version() << "." << patch_version() << "." << revision_version(); + ss << sz_plugin::major_version() << "." << sz_plugin::minor_version() << "." << sz_plugin::patch_version() << "." << revision_version(); sz_version = ss.str(); SZ_Init(NULL); }; diff --git a/src/plugins/compressors/zfp_plugin.cc b/src/plugins/compressors/zfp_plugin.cc index 18a41e5b..4c4bf364 100644 --- a/src/plugins/compressors/zfp_plugin.cc +++ b/src/plugins/compressors/zfp_plugin.cc @@ -47,11 +47,12 @@ class zfp_plugin: public libpressio_compressor_plugin { } else if (double tolerance; pressio_options_get_double(options, "zfp:accuracy", &tolerance) == pressio_options_key_set) { zfp_stream_set_accuracy(zfp, tolerance); } else if (double rate; pressio_options_get_double(options, "zfp:rate", &rate) == pressio_options_key_set) { - unsigned int type, dims, wra; + unsigned int type, dims; + int wra; if( pressio_options_get_uinteger(options, "zfp:type", &type) == pressio_options_key_set && pressio_options_get_uinteger(options, "zfp:dims", &dims) == pressio_options_key_set && - pressio_options_get_uinteger(options, "zfp:wra", &wra) == pressio_options_key_set) { + pressio_options_get_integer(options, "zfp:wra", &wra) == pressio_options_key_set) { zfp_stream_set_rate(zfp, rate, (zfp_type)type, dims, wra); } else { set_error(1, "if you set rate, you must set type, dims, and wra for the rate mode"); @@ -165,6 +166,7 @@ class zfp_plugin: public libpressio_compressor_plugin { *type = zfp_type_float; break; default: + *type = zfp_type_none; invalid_type(); } return 0; @@ -194,6 +196,7 @@ class zfp_plugin: public libpressio_compressor_plugin { *field = zfp_field_4d(in_data, type, r0, r1, r2, r3); break; default: + *field = nullptr; return invalid_dimensions(); } return 0; diff --git a/src/plugins/metrics/time.cc b/src/plugins/metrics/time.cc index 824833ee..2d4d3048 100644 --- a/src/plugins/metrics/time.cc +++ b/src/plugins/metrics/time.cc @@ -85,6 +85,7 @@ class time_plugin : public libpressio_metrics_plugin { return opt; } + private: timer check_options; timer set_options; timer get_options; diff --git a/test/test_io.cc b/test/test_io.cc index 79fc8cd6..84905519 100644 --- a/test/test_io.cc +++ b/test/test_io.cc @@ -127,7 +127,7 @@ TEST_F(PressioDataIOTests, TestWrite) { size_t buffer_size; int* buffer = static_cast(pressio_data_ptr(data, &buffer_size)); std::iota(buffer, buffer + pressio_data_num_dimensions(data), 0); - auto tmpwrite_name = std::string("test_io_readXXXXXX\0"); + auto tmpwrite_name = std::string("test_io_readXXXXXX"); auto tmpwrite_fd = mkstemp(const_cast(tmpwrite_name.data())); EXPECT_EQ(pressio_io_data_write(data, tmpwrite_fd), sizeof(int)*6); pressio_data_free(data);