Skip to content

Commit

Permalink
libpressio verison 0.66.3
Browse files Browse the repository at this point in the history
Bug Fixes:

+ fixed several cases where JSON parsing errors could cause an uncaught
  exception in C
  • Loading branch information
robertu94 committed Jun 21, 2021
1 parent 9cbe040 commit c2cd1d5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 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.66.2" LANGUAGES CXX C)
project(libpressio VERSION "0.66.3" LANGUAGES CXX C)

#correct was to set a default build type
# https://blog.kitware.com/cmake-and-the-default-build-type/
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 © 2021 , UChicago Argonne, LLC
All Rights Reserved
[libpressio, Version 0.65.0]
[libpressio, Version 0.66.3]
Robert Underwood
Argonne National Laboratory

Expand Down
13 changes: 12 additions & 1 deletion src/pressio_options_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <pressio_options.h>
#include <vector>
#include <stdexcept>
#include <sstream>

void to_json(nlohmann::json& j, pressio_data const& data){
j["dims"] = data.dimensions();
Expand Down Expand Up @@ -256,10 +257,20 @@ void from_json(nlohmann::json const& j, pressio_options& options) {

extern "C" {
struct pressio_options* pressio_options_new_json(struct pressio* library, const char* json) {
nlohmann::json parsed = nlohmann::json::parse(json);
pressio_options* options = nullptr;
try {
nlohmann::json parsed = nlohmann::json::parse(json);
options = new pressio_options(parsed.get<pressio_options>());
} catch (nlohmann::detail::out_of_range& ex) {
if(library) {
library->set_error(2, ex.what());
}
} catch (nlohmann::detail::parse_error& ex) {
if(library) {
std::stringstream err_msg;
err_msg << ex.what() << "\n" << json;
library->set_error(2, err_msg.str());
}
} catch (std::runtime_error& ex) {
if(library) {
library->set_error(1, ex.what());
Expand Down

0 comments on commit c2cd1d5

Please sign in to comment.