Remove setjmp()/longjmp()
This commit is contained in:
parent
c0f89f6f07
commit
74a24377a8
@ -21,12 +21,21 @@
|
|||||||
#pragma warning(disable : 4127) // conditional expression is constant
|
#pragma warning(disable : 4127) // conditional expression is constant
|
||||||
#endif
|
#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
|
#ifndef RAPIDJSON_PARSE_ERROR
|
||||||
#define RAPIDJSON_PARSE_ERROR(msg, offset) \
|
#define RAPIDJSON_PARSE_ERROR(msg, offset) \
|
||||||
RAPIDJSON_MULTILINEMACRO_BEGIN \
|
RAPIDJSON_MULTILINEMACRO_BEGIN \
|
||||||
parseError_ = msg; \
|
RAPIDJSON_PARSE_ERROR_NORETURN(msg, offset); \
|
||||||
errorOffset_ = offset; \
|
return; \
|
||||||
longjmp(jmpbuf_, 1); \
|
|
||||||
RAPIDJSON_MULTILINEMACRO_END
|
RAPIDJSON_MULTILINEMACRO_END
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -225,35 +234,23 @@ public:
|
|||||||
parseError_ = 0;
|
parseError_ = 0;
|
||||||
errorOffset_ = 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);
|
SkipWhitespace(is);
|
||||||
|
|
||||||
if (is.Peek() == '\0')
|
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 {
|
else {
|
||||||
switch (is.Peek()) {
|
switch (is.Peek()) {
|
||||||
case '{': ParseObject<parseFlags>(is, handler); break;
|
case '{': ParseObject<parseFlags>(is, handler); break;
|
||||||
case '[': ParseArray<parseFlags>(is, handler); break;
|
case '[': ParseArray<parseFlags>(is, handler); break;
|
||||||
default: RAPIDJSON_PARSE_ERROR("Expect either an object or array at root", is.Tell());
|
default: RAPIDJSON_PARSE_ERROR_NORETURN("Expect either an object or array at root", is.Tell());
|
||||||
}
|
}
|
||||||
SkipWhitespace(is);
|
SkipWhitespace(is);
|
||||||
|
|
||||||
if (is.Peek() != '\0')
|
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; }
|
bool HasParseError() const { return parseError_ != 0; }
|
||||||
@ -375,8 +372,10 @@ private:
|
|||||||
codepoint -= 'A' - 10;
|
codepoint -= 'A' - 10;
|
||||||
else if (c >= 'a' && c <= 'f')
|
else if (c >= 'a' && c <= 'f')
|
||||||
codepoint -= 'a' - 10;
|
codepoint -= 'a' - 10;
|
||||||
else
|
else {
|
||||||
RAPIDJSON_PARSE_ERROR("Incorrect hex digit after \\u escape", s.Tell() - 1);
|
RAPIDJSON_PARSE_ERROR_NORETURN("Incorrect hex digit after \\u escape", s.Tell() - 1);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
is = s; // Restore is
|
is = s; // Restore is
|
||||||
return codepoint;
|
return codepoint;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user