summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-10-03 14:27:52 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-10-03 14:27:52 +0000
commita6c756b8bce21d88db10fdeffcb5e87c7d66c6b9 (patch)
tree79ee2db6edcfe292ec9b18a72ffb0c54b631f8e8
parent0afd63bc32229c1f1e4cd4aff9065a2f0c885277 (diff)
XPath: If exceptions are enabled, std::bad_alloc is thrown for all out of memory situation (instead of xpath_exception)
git-svn-id: http://pugixml.googlecode.com/svn/trunk@759 99668b35-9821-0410-8761-19e4c4f06640
-rw-r--r--src/pugixml.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index b6b4f17..903416c 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -8196,11 +8196,20 @@ namespace pugi
#endif
}
+ void throw_error_oom()
+ {
+ #ifdef PUGIXML_NO_EXCEPTIONS
+ throw_error("Out of memory");
+ #else
+ throw std::bad_alloc();
+ #endif
+ }
+
void* alloc_node()
{
void* result = _alloc->allocate_nothrow(sizeof(xpath_ast_node));
- if (!result) throw_error("Out of memory");
+ if (!result) throw_error_oom();
return result;
}
@@ -8212,7 +8221,7 @@ namespace pugi
size_t length = static_cast<size_t>(value.end - value.begin);
char_t* c = static_cast<char_t*>(_alloc->allocate_nothrow((length + 1) * sizeof(char_t)));
- if (!c) throw_error("Out of memory");
+ if (!c) throw_error_oom();
memcpy(c, value.begin, length * sizeof(char_t));
c[length] = 0;
@@ -8489,7 +8498,7 @@ namespace pugi
double value = 0;
if (!convert_string_to_number(_lexer.contents().begin, _lexer.contents().end, &value))
- throw_error("Out of memory");
+ throw_error_oom();
xpath_ast_node* n = new (alloc_node()) xpath_ast_node(ast_number_constant, xpath_type_number, value);
_lexer.next();
@@ -9224,10 +9233,10 @@ namespace pugi
if (!alloc)
{
+ #ifdef PUGIXML_NO_EXCEPTIONS
_result.error = "Out of memory";
-
- #ifndef PUGIXML_NO_EXCEPTIONS
- throw xpath_exception(_result);
+ #else
+ throw std::bad_alloc();
#endif
}
else