com php-src: Normalize SimpleXML::asXML() argument handling: ext/simplexml/simplexml.c
| From: | Nikita Popov | Date: | Thu, 15 Aug 2019 09:18:56 +0000 |
| Subject: | com php-src: Normalize SimpleXML::asXML() argument handling: ext/simplexml/simplexml.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-107931@lists.php.net to get a copy of this message | ||
Commit: 743d27631fa600f071d4b3b1cf061708a9866f5b
Author: Nikita Popov <nikita.ppv@gmail.com> Thu, 15 Aug 2019 11:18:56 +0200
Parents: deceafbe63da2ca4639c4f0f4c72ec6bfd89211a
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=743d27631fa600f071d4b3b1cf061708a9866f5b
Log:
Normalize SimpleXML::asXML() argument handling
Remove odd manual checks in favor of a standard zpp call.
Changed paths:
M ext/simplexml/simplexml.c
Diff:
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c
index 8279770..58d2cca 100644
--- a/ext/simplexml/simplexml.c
+++ b/ext/simplexml/simplexml.c
@@ -1429,88 +1429,76 @@ SXE_METHOD(asXML)
xmlOutputBufferPtr outbuf;
xmlChar *strval;
int strval_len;
- char *filename;
+ char *filename = NULL;
size_t filename_len;
- if (ZEND_NUM_ARGS() > 1) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|p", &filename, &filename_len) ==
FAILURE) {
RETURN_FALSE;
}
- if (ZEND_NUM_ARGS() == 1) {
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename, &filename_len) ==
FAILURE) {
- RETURN_FALSE;
- }
-
- sxe = Z_SXEOBJ_P(ZEND_THIS);
- GET_NODE(sxe, node);
- node = php_sxe_get_first_node(sxe, node);
-
- if (node) {
- if (node->parent && (XML_DOCUMENT_NODE == node->parent->type)) {
- int bytes;
- bytes = xmlSaveFile(filename, (xmlDocPtr) sxe->document->ptr);
- if (bytes == -1) {
- RETURN_FALSE;
- } else {
- RETURN_TRUE;
- }
- } else {
- outbuf = xmlOutputBufferCreateFilename(filename, NULL, 0);
-
- if (outbuf == NULL) {
- RETURN_FALSE;
- }
-
- xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 0, NULL);
- xmlOutputBufferClose(outbuf);
- RETURN_TRUE;
- }
- } else {
- RETURN_FALSE;
- }
- }
-
sxe = Z_SXEOBJ_P(ZEND_THIS);
GET_NODE(sxe, node);
node = php_sxe_get_first_node(sxe, node);
- if (node) {
+ if (!node) {
+ RETURN_FALSE;
+ }
+
+ if (filename) {
if (node->parent && (XML_DOCUMENT_NODE == node->parent->type)) {
- xmlDocDumpMemoryEnc((xmlDocPtr) sxe->document->ptr, &strval, &strval_len, (const
char *) ((xmlDocPtr) sxe->document->ptr)->encoding);
- if (!strval) {
- RETVAL_FALSE;
+ int bytes;
+ bytes = xmlSaveFile(filename, (xmlDocPtr) sxe->document->ptr);
+ if (bytes == -1) {
+ RETURN_FALSE;
} else {
- RETVAL_STRINGL((char *)strval, strval_len);
+ RETURN_TRUE;
}
- xmlFree(strval);
} else {
- char *return_content;
- size_t return_len;
- /* Should we be passing encoding information instead of NULL? */
- outbuf = xmlAllocOutputBuffer(NULL);
+ outbuf = xmlOutputBufferCreateFilename(filename, NULL, 0);
if (outbuf == NULL) {
RETURN_FALSE;
}
- xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 0, (const char *)
((xmlDocPtr) sxe->document->ptr)->encoding);
- xmlOutputBufferFlush(outbuf);
+ xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 0, NULL);
+ xmlOutputBufferClose(outbuf);
+ RETURN_TRUE;
+ }
+ }
+
+ if (node->parent && (XML_DOCUMENT_NODE == node->parent->type)) {
+ xmlDocDumpMemoryEnc((xmlDocPtr) sxe->document->ptr, &strval, &strval_len, (const
char *) ((xmlDocPtr) sxe->document->ptr)->encoding);
+ if (!strval) {
+ RETVAL_FALSE;
+ } else {
+ RETVAL_STRINGL((char *)strval, strval_len);
+ }
+ xmlFree(strval);
+ } else {
+ char *return_content;
+ size_t return_len;
+ /* Should we be passing encoding information instead of NULL? */
+ outbuf = xmlAllocOutputBuffer(NULL);
+
+ if (outbuf == NULL) {
+ RETURN_FALSE;
+ }
+
+ xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 0, (const char *)
((xmlDocPtr) sxe->document->ptr)->encoding);
+ xmlOutputBufferFlush(outbuf);
#ifdef LIBXML2_NEW_BUFFER
- return_content = (char *)xmlOutputBufferGetContent(outbuf);
- return_len = xmlOutputBufferGetSize(outbuf);
+ return_content = (char *)xmlOutputBufferGetContent(outbuf);
+ return_len = xmlOutputBufferGetSize(outbuf);
#else
- return_content = (char *)outbuf->buffer->content;
- return_len = outbuf->buffer->use;
+ return_content = (char *)outbuf->buffer->content;
+ return_len = outbuf->buffer->use;
#endif
- if (!return_content) {
- RETVAL_FALSE;
- } else {
- RETVAL_STRINGL(return_content, return_len);
- }
- xmlOutputBufferClose(outbuf);
+ if (!return_content) {
+ RETVAL_FALSE;
+ } else {
+ RETVAL_STRINGL(return_content, return_len);
}
- } else {
- RETVAL_FALSE;
+ xmlOutputBufferClose(outbuf);
}
}
/* }}} */