From 2b853c4067a7bfd6caf6fe98665d1a63977306b1 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Thu, 22 Dec 2011 03:18:24 +0000 Subject: [PATCH] Got rid of several unnecessary includes of . Including causes the file to be polluted with a static initializer for the __ioinit symbol. This can harm binary startup time. For more info, see here: http://neugierig.org/software/chromium/notes/2011/08/static-initializers.html --- include/json/assertions.h | 9 +++++++-- include/json/reader.h | 1 - include/json/writer.h | 1 - src/lib_json/json_reader.cpp | 10 ++++++++-- src/lib_json/json_value.cpp | 1 - src/lib_json/json_writer.cpp | 1 - 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/include/json/assertions.h b/include/json/assertions.h index 84eb5d7..2a22cc4 100644 --- a/include/json/assertions.h +++ b/include/json/assertions.h @@ -7,7 +7,6 @@ # define CPPTL_JSON_ASSERTIONS_H_INCLUDED #include -#include #if !defined(JSON_IS_AMALGAMATION) # include @@ -18,7 +17,13 @@ #define JSON_FAIL_MESSAGE( message ) throw std::runtime_error( message ); #else // JSON_USE_EXCEPTION #define JSON_ASSERT( condition ) assert( condition ); -#define JSON_FAIL_MESSAGE( message ) { std::cerr << std::endl << message << std::endl; exit(123); } + +// The call to assert() will show the failure message in debug builds. In +// release bugs we write to invalid memory in order to crash hard instead of +// calling exit(), so that a debugger or crash reporter gets the chance to take +// over. +#define JSON_FAIL_MESSAGE( message ) { assert(false && message); strcpy(reinterpret_cast(666), message); } + #endif #define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) { JSON_FAIL_MESSAGE( message ) } diff --git a/include/json/reader.h b/include/json/reader.h index 0a324df..a3023b3 100644 --- a/include/json/reader.h +++ b/include/json/reader.h @@ -13,7 +13,6 @@ # include # include # include -# include namespace Json { diff --git a/include/json/writer.h b/include/json/writer.h index 4789363..38d41e1 100644 --- a/include/json/writer.h +++ b/include/json/writer.h @@ -11,7 +11,6 @@ #endif // if !defined(JSON_IS_AMALGAMATION) # include # include -# include namespace Json { diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index e55745e..1f3873a 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #if _MSC_VER >= 1400 // VC++ 8.0 @@ -904,7 +903,14 @@ std::istream& operator>>( std::istream &sin, Value &root ) { Json::Reader reader; bool ok = reader.parse(sin, root, true); - if (!ok) JSON_FAIL_MESSAGE(reader.getFormattedErrorMessages()); + if (!ok) { + fprintf( + stderr, + "Error from reader: %s", + reader.getFormattedErrorMessages().c_str()); + + JSON_FAIL_MESSAGE("reader error"); + } return sin; } diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 3ba36fe..91f312e 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -12,7 +12,6 @@ # endif // #ifndef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR #endif // if !defined(JSON_IS_AMALGAMATION) #include -#include #include #include #include diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index 47e768c..b44def3 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include