[Committed][PATCH 2/3] JSON: Do not use throw when exception is disabled.

5 views
Skip to first unread message

ether zhhb

unread,
Apr 29, 2011, 11:40:06 PM4/29/11
to polly-commits
git-svn-id: https://llvm.org/svn/llvm-project/polly/trunk@130575
91177308-0d34-0410-b5e6-96231b3b80d8
---
lib/JSON/json_reader.cpp | 5 +++++
lib/JSON/json_value.cpp | 7 ++++++-
2 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/lib/JSON/json_reader.cpp b/lib/JSON/json_reader.cpp
index 4eb2d11..680c2b6 100644
--- a/lib/JSON/json_reader.cpp
+++ b/lib/JSON/json_reader.cpp
@@ -877,7 +877,12 @@ std::istream& operator>>( std::istream &sin, Value &root )
Json::Reader reader;
bool ok = reader.parse(sin, root, true);
//JSON_ASSERT( ok );
+#if JSON_USE_EXCEPTION
if (!ok) throw std::runtime_error(reader.getFormatedErrorMessages());
+#else
+ assert(ok && "Bad Format!");
+ (void) ok;
+#endif
return sin;
}

diff --git a/lib/JSON/json_value.cpp b/lib/JSON/json_value.cpp
index 573205f..34acce9 100644
--- a/lib/JSON/json_value.cpp
+++ b/lib/JSON/json_value.cpp
@@ -15,7 +15,12 @@

#define JSON_ASSERT_UNREACHABLE assert( false )
#define JSON_ASSERT( condition ) assert( condition ); // @todo <=
change this into an exception throw
-#define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition ))
throw std::runtime_error( message );
+// Do not use throw when exception is disable.
+#if JSON_USE_EXCEPTION
+# define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition
)) throw std::runtime_error( message );
+#else
+# define JSON_ASSERT_MESSAGE( condition, message ) JSON_ASSERT(
condition ) // @todo <= provide the message
+#endif

namespace Json {

--
1.7.4

Tobias Grosser

unread,
Apr 30, 2011, 11:43:00 AM4/30/11
to polly-...@googlegroups.com, ether zhhb
Thank you ether. Those JSON changes look great.

Tobi

ether zhhb

unread,
Apr 30, 2011, 12:10:29 PM4/30/11
to Tobias Grosser, polly-...@googlegroups.com
hi tobi,

you are welcome, we can also try to commit this to the "main stream"
of this JSON library? but i do not know where did you find the library
:)

best regards
ether

Tobias Grosser

unread,
Apr 30, 2011, 12:12:43 PM4/30/11
to ether zhhb, polly-...@googlegroups.com
On 04/30/2011 06:10 PM, ether zhhb wrote:
> hi tobi,
>
> you are welcome, we can also try to commit this to the "main stream"
> of this JSON library? but i do not know where did you find the library

It is jsoncpp[1] version 0.5. We should probably add this information to
lib/JSON/LICENSE.txt.

Tobi

[1] http://jsoncpp.sourceforge.net/

ether zhhb

unread,
Apr 30, 2011, 12:32:53 PM4/30/11
to Tobias Grosser, polly-...@googlegroups.com
On Sun, May 1, 2011 at 12:12 AM, Tobias Grosser <tob...@grosser.es> wrote:
> On 04/30/2011 06:10 PM, ether zhhb wrote:
>>
>> hi tobi,
>>
>> you are welcome, we can also try to commit this to the "main stream"
>> of this JSON library? but i do not know where did you find the library
>
> It is jsoncpp[1] version 0.5. We should probably add this information to
> lib/JSON/LICENSE.txt.
yep
>
> Tobi
>
> [1] http://jsoncpp.sourceforge.net/
>
Reply all
Reply to author
Forward
0 new messages