Remove setjmp()/longjmp()
This commit is contained in:
parent
c0f89f6f07
commit
74a24377a8
@ -21,12 +21,21 @@
|
||||
#pragma warning(disable : 4127) // conditional expression is constant
|
||||
#endif
|
||||
|
||||
#ifndef RAPIDJSON_PARSE_ERROR_NORETURN
|
||||
#define RAPIDJSON_PARSE_ERROR_NORETURN(msg, offset) \
|
||||
RAPIDJSON_MULTILINEMACRO_BEGIN \
|
||||
if (!HasParseError()) {\
|
||||
parseError_ = msg; \
|
||||
errorOffset_ = offset; \
|
||||
}\
|
||||
RAPIDJSON_MULTILINEMACRO_END
|
||||
#endif
|
||||
|
||||
#ifndef RAPIDJSON_PARSE_ERROR
|
||||
#define RAPIDJSON_PARSE_ERROR(msg, offset) \
|
||||
RAPIDJSON_MULTILINEMACRO_BEGIN \
|
||||
parseError_ = msg; \
|
||||
errorOffset_ = offset; \
|
||||
longjmp(jmpbuf_, 1); \
|
||||
RAPIDJSON_PARSE_ERROR_NORETURN(msg, offset); \
|
||||
return; \
|
||||
RAPIDJSON_MULTILINEMACRO_END
|
||||
#endif
|
||||
|
||||
@ -225,35 +234,23 @@ public:
|
||||
parseError_ = 0;
|
||||
errorOffset_ = 0;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4611) // interaction between '_setjmp' and C++ object destruction is non-portable
|
||||
#endif
|
||||
if (setjmp(jmpbuf_)) {
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
stack_.Clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
SkipWhitespace(is);
|
||||
|
||||
if (is.Peek() == '\0')
|
||||
RAPIDJSON_PARSE_ERROR("Text only contains white space(s)", is.Tell());
|
||||
RAPIDJSON_PARSE_ERROR_NORETURN("Text only contains white space(s)", is.Tell());
|
||||
else {
|
||||
switch (is.Peek()) {
|
||||
case '{': ParseObject<parseFlags>(is, handler); break;
|
||||
case '[': ParseArray<parseFlags>(is, handler); break;
|
||||
default: RAPIDJSON_PARSE_ERROR("Expect either an object or array at root", is.Tell());
|
||||
case '{': ParseObject<parseFlags>(is, handler); break;
|
||||
case '[': ParseArray<parseFlags>(is, handler); break;
|
||||
default: RAPIDJSON_PARSE_ERROR_NORETURN("Expect either an object or array at root", is.Tell());
|
||||
}
|
||||
SkipWhitespace(is);
|
||||
|
||||
if (is.Peek() != '\0')
|
||||
RAPIDJSON_PARSE_ERROR("Nothing should follow the root object or array.", is.Tell());
|
||||
RAPIDJSON_PARSE_ERROR_NORETURN("Nothing should follow the root object or array.", is.Tell());
|
||||
}
|
||||
|
||||
return true;
|
||||
return !HasParseError();
|
||||
}
|
||||
|
||||
bool HasParseError() const { return parseError_ != 0; }
|
||||
@ -375,8 +372,10 @@ private:
|
||||
codepoint -= 'A' - 10;
|
||||
else if (c >= 'a' && c <= 'f')
|
||||
codepoint -= 'a' - 10;
|
||||
else
|
||||
RAPIDJSON_PARSE_ERROR("Incorrect hex digit after \\u escape", s.Tell() - 1);
|
||||
else {
|
||||
RAPIDJSON_PARSE_ERROR_NORETURN("Incorrect hex digit after \\u escape", s.Tell() - 1);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
is = s; // Restore is
|
||||
return codepoint;
|
||||
|
Loading…
x
Reference in New Issue
Block a user