From 1ae3cc2fad06aa17bdaf1f5fc7713df0a1f24c92 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 6 Mar 2018 22:14:30 +0100 Subject: [PATCH] Make unused parsers compile-time optional --- include/fc/io/json.hpp | 4 ++++ include/fc/io/json_relaxed.hpp | 1 - src/io/json.cpp | 8 +++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/fc/io/json.hpp b/include/fc/io/json.hpp index 8a46d13..10b5314 100644 --- a/include/fc/io/json.hpp +++ b/include/fc/io/json.hpp @@ -18,14 +18,18 @@ namespace fc enum parse_type { legacy_parser = 0, +#ifdef WITH_EXOTIC_JSON_PARSERS strict_parser = 1, relaxed_parser = 2, legacy_parser_with_string_doubles = 3 +#endif }; enum output_formatting { stringify_large_ints_and_doubles = 0, +#ifdef WITH_EXOTIC_JSON_PARSERS legacy_generator = 1 +#endif }; static ostream& to_stream( ostream& out, const fc::string&); diff --git a/include/fc/io/json_relaxed.hpp b/include/fc/io/json_relaxed.hpp index 26a89a5..dd6db73 100644 --- a/include/fc/io/json_relaxed.hpp +++ b/include/fc/io/json_relaxed.hpp @@ -671,5 +671,4 @@ namespace fc { namespace json_relaxed } return variant(); } - } } // fc::json_relaxed diff --git a/src/io/json.cpp b/src/io/json.cpp index 8f4f2c1..d3296c9 100644 --- a/src/io/json.cpp +++ b/src/io/json.cpp @@ -319,7 +319,11 @@ namespace fc if (str == "-." || str == ".") // check the obviously wrong things we could have encountered FC_THROW_EXCEPTION(parse_error_exception, "Can't parse token \"${token}\" as a JSON numeric constant", ("token", str)); if( dot ) - return parser_type == json::legacy_parser_with_string_doubles ? variant(str) : variant(to_double(str)); + return +#ifdef WITH_EXOTIC_JSON_PARSERS + parser_type == json::legacy_parser_with_string_doubles ? variant(str) : +#endif + variant(to_double(str)); if( neg ) return to_int64(str); return to_uint64(str); @@ -768,12 +772,14 @@ namespace fc { case legacy_parser: return variant_from_stream( in ); +#ifdef WITH_EXOTIC_JSON_PARSERS case legacy_parser_with_string_doubles: return variant_from_stream( in ); case strict_parser: return json_relaxed::variant_from_stream( in ); case relaxed_parser: return json_relaxed::variant_from_stream( in ); +#endif default: FC_ASSERT( false, "Unknown JSON parser type {ptype}", ("ptype", ptype) ); }