From cbf42c3c93629b11869ca0cd926feeb3fb437896 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine@gmail.com" Date: Tue, 6 Mar 2012 04:23:21 +0000 Subject: Removed setjmp from XML parsing; now pugixml does not require setjmp support (unless XPath is compiled in with PUGIXML_NO_EXCEPTIONS). Should improve compatibility with certain platforms (also makes pugixml clr:pure-compatible) git-svn-id: http://pugixml.googlecode.com/svn/trunk@837 99668b35-9821-0410-8761-19e4c4f06640 --- src/pugixml.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 38b9b74..2bccffb 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -17,12 +17,14 @@ #include #include #include -#include #include #ifndef PUGIXML_NO_XPATH # include # include +# ifdef PUGIXML_NO_EXCEPTIONS +# include +# endif #endif #ifndef PUGIXML_NO_STL @@ -1995,7 +1997,7 @@ namespace { xml_allocator alloc; char_t* error_offset; - jmp_buf error_handler; + xml_parse_status error_status; // Parser utilities. #define SKIPWS() { while (IS_CHARTYPE(*s, ct_space)) ++s; } @@ -2005,10 +2007,10 @@ namespace #define SCANFOR(X) { while (*s != 0 && !(X)) ++s; } #define SCANWHILE(X) { while ((X)) ++s; } #define ENDSEG() { ch = *s; *s = 0; ++s; } - #define THROW_ERROR(err, m) error_offset = m, longjmp(error_handler, err) + #define THROW_ERROR(err, m) return error_offset = m, error_status = err, static_cast(0) #define CHECK_ERROR(err, m) { if (*s == 0) THROW_ERROR(err, m); } - xml_parser(const xml_allocator& alloc_): alloc(alloc_), error_offset(0) + xml_parser(const xml_allocator& alloc_): alloc(alloc_), error_offset(0), error_status(status_ok) { } @@ -2063,6 +2065,7 @@ namespace { // nested ignore section s = parse_doctype_ignore(s); + if (!s) return s; } else if (s[0] == ']' && s[1] == ']' && s[2] == '>') { @@ -2075,8 +2078,6 @@ namespace } THROW_ERROR(status_bad_doctype, s); - - return s; } char_t* parse_doctype_group(char_t* s, char_t endch, bool toplevel) @@ -2092,17 +2093,20 @@ namespace { // ignore s = parse_doctype_ignore(s); + if (!s) return s; } else { // some control group s = parse_doctype_group(s, endch, false); + if (!s) return s; } } else if (s[0] == '<' || s[0] == '"' || s[0] == '\'') { // unknown tag (forbidden), or some primitive group s = parse_doctype_primitive(s); + if (!s) return s; } else if (*s == '>') { @@ -2206,6 +2210,7 @@ namespace char_t* mark = s + 9; s = parse_doctype_group(s, endch, true); + if (!s) return s; if (OPTSET(parse_doctype)) { @@ -2321,7 +2326,7 @@ namespace return s; } - void parse(char_t* s, xml_node_struct* xmldoc, unsigned int optmsk, char_t endch) + char_t* parse(char_t* s, xml_node_struct* xmldoc, unsigned int optmsk, char_t endch) { strconv_attribute_t strconv_attribute = get_strconv_attribute(optmsk); strconv_pcdata_t strconv_pcdata = get_strconv_pcdata(optmsk); @@ -2486,6 +2491,7 @@ namespace else if (*s == '?') // 'header & xml_memory_page_type_mask) + 1 == node_declaration) goto LOC_ATTRIBUTES; @@ -2493,6 +2499,7 @@ namespace else if (*s == '!') // '(error), parser.error_offset ? parser.error_offset - buffer : 0); + xml_parse_result result = make_parse_result(parser.error_status, parser.error_offset ? parser.error_offset - buffer : 0); assert(result.offset >= 0 && static_cast(result.offset) <= length); // update allocator state -- cgit v1.2.3