mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-23 01:52:48 +03:00
tree: Report malloc failures
Fix many places where malloc failures aren't reported. Make some API function return an error code. Changing the return type from void to int is technically an ABI break but should be safe on most platforms. - xmlNodeSetContent - xmlNodeSetContentLen - xmlNodeAddContent - xmlNodeAddContentLen - xmlNodeSetBase Introduce new API functions that return a separate error code if a memory allocation fails. - xmlNodeGetAttrValue - xmlNodeGetBaseSafe - xmlGetNsListSafe Introduce private functions xmlTreeEnsureXMLDecl and xmlSplitQName4. Don't report low-level errors to the global error handler. Fix tree Introduce xmlGetNsListSafe Fix tree
This commit is contained in:
@@ -1022,6 +1022,10 @@ XMLPUBFUN xmlNsPtr
|
||||
const xmlChar *href);
|
||||
#if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XPATH_ENABLED) || \
|
||||
defined(LIBXML_SCHEMAS_ENABLED)
|
||||
XMLPUBFUN int
|
||||
xmlGetNsListSafe (const xmlDoc *doc,
|
||||
const xmlNode *node,
|
||||
xmlNsPtr **out);
|
||||
XMLPUBFUN xmlNsPtr *
|
||||
xmlGetNsList (const xmlDoc *doc,
|
||||
const xmlNode *node);
|
||||
@@ -1051,6 +1055,11 @@ XMLPUBFUN xmlAttrPtr
|
||||
const xmlChar *value);
|
||||
#endif /* defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XINCLUDE_ENABLED) || \
|
||||
defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_HTML_ENABLED) */
|
||||
XMLPUBFUN int
|
||||
xmlNodeGetAttrValue (const xmlNode *node,
|
||||
const xmlChar *name,
|
||||
const xmlChar *nsUri,
|
||||
xmlChar **out);
|
||||
XMLPUBFUN xmlChar *
|
||||
xmlGetNoNsProp (const xmlNode *node,
|
||||
const xmlChar *name);
|
||||
@@ -1085,19 +1094,19 @@ XMLPUBFUN xmlChar *
|
||||
const xmlNode *list,
|
||||
int inLine);
|
||||
#endif /* LIBXML_TREE_ENABLED */
|
||||
XMLPUBFUN void
|
||||
XMLPUBFUN int
|
||||
xmlNodeSetContent (xmlNodePtr cur,
|
||||
const xmlChar *content);
|
||||
#ifdef LIBXML_TREE_ENABLED
|
||||
XMLPUBFUN void
|
||||
XMLPUBFUN int
|
||||
xmlNodeSetContentLen (xmlNodePtr cur,
|
||||
const xmlChar *content,
|
||||
int len);
|
||||
#endif /* LIBXML_TREE_ENABLED */
|
||||
XMLPUBFUN void
|
||||
XMLPUBFUN int
|
||||
xmlNodeAddContent (xmlNodePtr cur,
|
||||
const xmlChar *content);
|
||||
XMLPUBFUN void
|
||||
XMLPUBFUN int
|
||||
xmlNodeAddContentLen (xmlNodePtr cur,
|
||||
const xmlChar *content,
|
||||
int len);
|
||||
@@ -1123,11 +1132,15 @@ XMLPUBFUN void
|
||||
xmlNodeSetSpacePreserve (xmlNodePtr cur,
|
||||
int val);
|
||||
#endif /* LIBXML_TREE_ENABLED */
|
||||
XMLPUBFUN int
|
||||
xmlNodeGetBaseSafe (const xmlDoc *doc,
|
||||
const xmlNode *cur,
|
||||
xmlChar **baseOut);
|
||||
XMLPUBFUN xmlChar *
|
||||
xmlNodeGetBase (const xmlDoc *doc,
|
||||
const xmlNode *cur);
|
||||
#if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XINCLUDE_ENABLED)
|
||||
XMLPUBFUN void
|
||||
XMLPUBFUN int
|
||||
xmlNodeSetBase (xmlNodePtr cur,
|
||||
const xmlChar *uri);
|
||||
#endif
|
||||
|
@@ -9,10 +9,14 @@
|
||||
XML_HIDDEN extern int
|
||||
__xmlRegisterCallbacks;
|
||||
|
||||
XML_HIDDEN xmlNsPtr
|
||||
xmlTreeEnsureXMLDecl(xmlDocPtr doc);
|
||||
XML_HIDDEN xmlNodePtr
|
||||
xmlStaticCopyNode(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent,
|
||||
int extended);
|
||||
XML_HIDDEN xmlNodePtr
|
||||
xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent);
|
||||
XML_HIDDEN const xmlChar *
|
||||
xmlSplitQName4(const xmlChar *name, xmlChar **prefixPtr);
|
||||
|
||||
#endif /* XML_TREE_H_PRIVATE__ */
|
||||
|
@@ -9,7 +9,7 @@ libxml2.debugMemory(1)
|
||||
#
|
||||
# Testing XML document serialization
|
||||
#
|
||||
doc = libxml2.parseDoc(
|
||||
doc = libxml2.readDoc(
|
||||
"""<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!DOCTYPE test [
|
||||
<!ELEMENT test (#PCDATA) >
|
||||
@@ -17,10 +17,11 @@ doc = libxml2.parseDoc(
|
||||
<!ATTLIST test abc:attr CDATA #FIXED "def" >
|
||||
]>
|
||||
<test />
|
||||
""")
|
||||
""", None, None, libxml2.XML_PARSE_DTDATTR)
|
||||
elem = doc.getRootElement()
|
||||
attr = elem.hasNsProp('attr', 'http://abc.org')
|
||||
if attr == None or attr.serialize()[:-1] != """<!ATTLIST test abc:attr CDATA #FIXED "def">""":
|
||||
print(attr.serialize())
|
||||
if attr == None:
|
||||
print("Failed to find defaulted attribute abc:attr")
|
||||
sys.exit(1)
|
||||
|
||||
|
Reference in New Issue
Block a user