rrichards Mon Aug 7 10:11:04 2006 UTC Modified files: /php-src/ext/simplexml simplexml.c php_simplexml.h Log: MFB: asXML() needs to return bool when serializing doc and filename is passed in do not copy the content of the outputbuffer twice in asXML() fix compiler warnings
http://cvs.php.net/viewvc.cgi/php-src/ext/simplexml/simplexml.c?r1=1.213&r2=1.214&diff_format=u Index: php-src/ext/simplexml/simplexml.c diff -u php-src/ext/simplexml/simplexml.c:1.213 php-src/ext/simplexml/simplexml.c:1.214 --- php-src/ext/simplexml/simplexml.c:1.213 Sun Aug 6 19:39:38 2006 +++ php-src/ext/simplexml/simplexml.c Mon Aug 7 10:11:04 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: simplexml.c,v 1.213 2006/08/06 19:39:38 chregu Exp $ */ +/* $Id: simplexml.c,v 1.214 2006/08/07 10:11:04 rrichards Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -59,7 +59,7 @@ /* {{{ _node_as_zval() */ -static void _node_as_zval(php_sxe_object *sxe, xmlNodePtr node, zval *value, SXE_ITER itertype, char *name, char *nsprefix, int isprefix TSRMLS_DC) +static void _node_as_zval(php_sxe_object *sxe, xmlNodePtr node, zval *value, SXE_ITER itertype, char *name, xmlChar *nsprefix, int isprefix TSRMLS_DC) { php_sxe_object *subnode; @@ -68,10 +68,10 @@ subnode->document->refcount++; subnode->iter.type = itertype; if (name) { - subnode->iter.name = xmlStrdup(name); + subnode->iter.name = xmlStrdup((xmlChar *)name); } if (nsprefix && *nsprefix) { - subnode->iter.nsprefix = xmlStrdup(nsprefix); + subnode->iter.nsprefix = xmlStrdup((xmlChar *)nsprefix); subnode->iter.isprefix = isprefix; } @@ -162,7 +162,7 @@ } /* }}} */ -static xmlNodePtr sxe_find_element_by_name(php_sxe_object *sxe, xmlNodePtr node, char *name TSRMLS_DC) /* {{{ */ +static xmlNodePtr sxe_find_element_by_name(php_sxe_object *sxe, xmlNodePtr node, xmlChar *name TSRMLS_DC) /* {{{ */ { while (node) { SKIP_TEXT(node) @@ -204,7 +204,7 @@ while (node) { SKIP_TEXT(node) if (node->type == XML_ELEMENT_NODE && match_ns(sxe, node, sxe->iter.nsprefix, sxe->iter.isprefix)) { - if (!xmlStrcmp(node->name, *name)) { + if (!xmlStrcmp(node->name, (xmlChar *)*name)) { if (1||retnode) { *type = SXE_ITER_ELEMENT; @@ -292,7 +292,7 @@ } } else { while (attr) { - if ((!test || !xmlStrcmp(attr->name, sxe->iter.name)) && !xmlStrcmp(attr->name, name) && match_ns(sxe, (xmlNodePtr) attr, sxe->iter.nsprefix, sxe->iter.isprefix)) { + if ((!test || !xmlStrcmp(attr->name, sxe->iter.name)) && !xmlStrcmp(attr->name, (xmlChar *)name) && match_ns(sxe, (xmlNodePtr) attr, sxe->iter.nsprefix, sxe->iter.isprefix)) { _node_as_zval(sxe, (xmlNodePtr) attr, return_value, SXE_ITER_NONE, NULL, sxe->iter.nsprefix, sxe->iter.isprefix TSRMLS_CC); break; } @@ -369,7 +369,7 @@ if (!value) { - xmlNodeSetContentLen(node, "", 0); + xmlNodeSetContentLen(node, (xmlChar *)"", 0); return; } switch (Z_TYPE_P(value)) { @@ -386,7 +386,7 @@ convert_to_string(value); /* break missing intentionally */ case IS_STRING: - xmlNodeSetContentLen(node, Z_STRVAL_P(value), Z_STRLEN_P(value)); + xmlNodeSetContentLen(node, (xmlChar *)Z_STRVAL_P(value), Z_STRLEN_P(value)); if (value == &value_copy) { zval_dtor(value); } @@ -512,7 +512,7 @@ } } else { while (attr) { - if ((!test || !xmlStrcmp(attr->name, sxe->iter.name)) && !xmlStrcmp(attr->name, name) && match_ns(sxe, (xmlNodePtr) attr, sxe->iter.nsprefix, sxe->iter.isprefix)) { + if ((!test || !xmlStrcmp(attr->name, sxe->iter.name)) && !xmlStrcmp(attr->name, (xmlChar *)name) && match_ns(sxe, (xmlNodePtr) attr, sxe->iter.nsprefix, sxe->iter.isprefix)) { is_attr = 1; ++counter; break; @@ -534,7 +534,7 @@ while (node) { SKIP_TEXT(node); - if (!xmlStrcmp(node->name, name)) { + if (!xmlStrcmp(node->name, (xmlChar *)name)) { newnode = node; ++counter; } @@ -560,15 +560,15 @@ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot assign to an array of nodes (duplicate subnodes or attr detected)"); } else if (elements) { if (!node) { - newnode = xmlNewTextChild(mynode, mynode->ns, name, value ? Z_STRVAL_P(value) : NULL); + newnode = xmlNewTextChild(mynode, mynode->ns, (xmlChar *)name, value ? (xmlChar *)Z_STRVAL_P(value) : NULL); } else if (Z_TYPE_P(member) == IS_LONG) { if (cnt < Z_LVAL_P(member)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot add element %s number %ld when only %ld such elements exist", mynode->name, Z_LVAL_P(member), cnt); } - newnode = xmlNewTextChild(mynode->parent, mynode->ns, mynode->name, value ? Z_STRVAL_P(value) : NULL); + newnode = xmlNewTextChild(mynode->parent, mynode->ns, mynode->name, value ? (xmlChar *)Z_STRVAL_P(value) : NULL); } } else if (attribs) { - newnode = (xmlNodePtr)xmlNewProp(node, name, value ? Z_STRVAL_P(value) : NULL); + newnode = (xmlNodePtr)xmlNewProp(node, (xmlChar *)name, value ? (xmlChar *)Z_STRVAL_P(value) : NULL); } } @@ -691,7 +691,7 @@ } } else { while (attr) { - if ((!test || !xmlStrcmp(attr->name, sxe->iter.name)) && !xmlStrcmp(attr->name, Z_STRVAL_P(member)) && match_ns(sxe, (xmlNodePtr) attr, sxe->iter.nsprefix, sxe->iter.isprefix)) { + if ((!test || !xmlStrcmp(attr->name, sxe->iter.name)) && !xmlStrcmp(attr->name, (xmlChar *)Z_STRVAL_P(member)) && match_ns(sxe, (xmlNodePtr) attr, sxe->iter.nsprefix, sxe->iter.isprefix)) { exists = 1; break; } @@ -713,7 +713,7 @@ while (node) { xmlNodePtr nnext; nnext = node->next; - if (!xmlStrcmp(node->name, Z_STRVAL_P(member))) { + if (!xmlStrcmp(node->name, (xmlChar *)Z_STRVAL_P(member))) { break; } node = nnext; @@ -813,7 +813,7 @@ } else { while (attr) { anext = attr->next; - if ((!test || !xmlStrcmp(attr->name, sxe->iter.name)) && !xmlStrcmp(attr->name, Z_STRVAL_P(member)) && match_ns(sxe, (xmlNodePtr) attr, sxe->iter.nsprefix, sxe->iter.isprefix)) { + if ((!test || !xmlStrcmp(attr->name, sxe->iter.name)) && !xmlStrcmp(attr->name, (xmlChar *)Z_STRVAL_P(member)) && match_ns(sxe, (xmlNodePtr) attr, sxe->iter.nsprefix, sxe->iter.isprefix)) { xmlUnlinkNode((xmlNodePtr) attr); php_libxml_node_free_resource((xmlNodePtr) attr TSRMLS_CC); break; @@ -840,7 +840,7 @@ SKIP_TEXT(node); - if (!xmlStrcmp(node->name, Z_STRVAL_P(member))) { + if (!xmlStrcmp(node->name, (xmlChar *)Z_STRVAL_P(member))) { xmlUnlinkNode(node); php_libxml_node_free_resource(node TSRMLS_CC); } @@ -876,7 +876,7 @@ /* {{{ _get_base_node_value() */ -static void _get_base_node_value(php_sxe_object *sxe_ref, xmlNodePtr node, zval **value, char *nsprefix, int isprefix TSRMLS_DC) +static void _get_base_node_value(php_sxe_object *sxe_ref, xmlNodePtr node, zval **value, xmlChar *nsprefix, int isprefix TSRMLS_DC) { php_sxe_object *subnode; xmlChar *contents; @@ -886,7 +886,7 @@ if (node->children && node->children->type == XML_TEXT_NODE && !xmlIsBlankNode(node->children)) { contents = xmlNodeListGetString(node->doc, node->children, 1); if (contents) { - ZVAL_U_STRING(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), *value, contents, 1); + ZVAL_U_STRING(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), *value, (char *)contents, 1); xmlFree(contents); } } else { @@ -894,7 +894,7 @@ subnode->document = sxe_ref->document; subnode->document->refcount++; if (nsprefix && *nsprefix) { - subnode->iter.nsprefix = xmlStrdup(nsprefix); + subnode->iter.nsprefix = xmlStrdup((xmlChar *)nsprefix); subnode->iter.isprefix = isprefix; } php_libxml_increment_node_ptr((php_libxml_node_object *)subnode, node, NULL TSRMLS_CC); @@ -1103,7 +1103,7 @@ sxe->xpath->namespaces = ns; sxe->xpath->nsNr = nsnbr; - retval = xmlXPathEval(query, sxe->xpath); + retval = xmlXPathEval((xmlChar *)query, sxe->xpath); if (ns != NULL) { xmlFree(ns); sxe->xpath->namespaces = NULL; @@ -1163,7 +1163,7 @@ sxe->xpath = xmlXPathNewContext((xmlDocPtr) sxe->document->ptr); } - if (xmlXPathRegisterNs(sxe->xpath, prefix, ns_uri) != 0) { + if (xmlXPathRegisterNs(sxe->xpath, (xmlChar *)prefix, (xmlChar *)ns_uri) != 0) { RETURN_FALSE } RETURN_TRUE; @@ -1198,7 +1198,13 @@ if (node) { if (XML_DOCUMENT_NODE == node->parent->type) { - xmlSaveFile(filename, (xmlDocPtr) sxe->document->ptr); + int bytes; + bytes = xmlSaveFile(filename, (xmlDocPtr) sxe->document->ptr); + if (bytes == -1) { + RETURN_FALSE; + } else { + RETURN_TRUE; + } } else { outbuf = xmlOutputBufferCreateFilename(filename, NULL, 0); @@ -1222,6 +1228,8 @@ if (node) { if (XML_DOCUMENT_NODE == node->parent->type) { xmlDocDumpMemory((xmlDocPtr) sxe->document->ptr, &strval, &strval_len); + RETVAL_STRINGL((char *)strval, strval_len, 1); + xmlFree(strval); } else { /* Should we be passing encoding information instead of NULL? */ outbuf = xmlAllocOutputBuffer(NULL); @@ -1232,13 +1240,9 @@ xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 0, ((xmlDocPtr) sxe->document->ptr)->encoding); xmlOutputBufferFlush(outbuf); - strval = xmlStrndup(outbuf->buffer->content, outbuf->buffer->use); - strval_len = outbuf->buffer->use; + RETVAL_STRINGL((char *)outbuf->buffer->content, outbuf->buffer->use, 1); xmlOutputBufferClose(outbuf); } - - RETVAL_STRINGL(strval, strval_len, 1); - xmlFree(strval); } else { RETVAL_FALSE; } @@ -1376,7 +1380,7 @@ GET_NODE(sxe, node); node = php_sxe_get_first_node(sxe, node TSRMLS_CC); - _node_as_zval(sxe, node, return_value, SXE_ITER_CHILD, NULL, nsprefix, isprefix TSRMLS_CC); + _node_as_zval(sxe, node, return_value, SXE_ITER_CHILD, NULL, (xmlChar *)nsprefix, isprefix TSRMLS_CC); } /* }}} */ @@ -1421,7 +1425,7 @@ node = php_sxe_get_first_node(sxe, node TSRMLS_CC); - _node_as_zval(sxe, node, return_value, SXE_ITER_ATTRLIST, NULL, nsprefix, isprefix TSRMLS_CC); + _node_as_zval(sxe, node, return_value, SXE_ITER_ATTRLIST, NULL, (xmlChar *)nsprefix, isprefix TSRMLS_CC); } /* }}} */ @@ -1456,23 +1460,22 @@ node = php_sxe_get_first_node(sxe, node TSRMLS_CC); - localname = xmlSplitQName2(qname, &prefix); + localname = xmlSplitQName2((xmlChar *)qname, &prefix); if (localname == NULL) { - localname = xmlStrdup(qname); + localname = xmlStrdup((xmlChar *)qname); } - - newnode = xmlNewChild(node, NULL, localname, value); + newnode = xmlNewChild(node, NULL, localname, (xmlChar *)value); if (nsuri != NULL) { - nsptr = xmlSearchNsByHref(node->doc, node, nsuri); + nsptr = xmlSearchNsByHref(node->doc, node, (xmlChar *)nsuri); if (nsptr == NULL) { - nsptr = xmlNewNs(newnode, nsuri, prefix); + nsptr = xmlNewNs(newnode, (xmlChar *)nsuri, prefix); } newnode->ns = nsptr; } - _node_as_zval(sxe, newnode, return_value, SXE_ITER_NONE, localname, prefix, 0 TSRMLS_CC); + _node_as_zval(sxe, newnode, return_value, SXE_ITER_NONE, (char *)localname, prefix, 0 TSRMLS_CC); xmlFree(localname); if (prefix != NULL) { @@ -1517,12 +1520,12 @@ return; } - localname = xmlSplitQName2(qname, &prefix); + localname = xmlSplitQName2((xmlChar *)qname, &prefix); if (localname == NULL) { - localname = xmlStrdup(qname); + localname = xmlStrdup((xmlChar *)qname); } - attrp = xmlHasNsProp(node, localname, nsuri); + attrp = xmlHasNsProp(node, localname, (xmlChar *)nsuri); if (attrp != NULL && attrp->type != XML_ATTRIBUTE_DECL) { xmlFree(localname); if (prefix != NULL) { @@ -1533,13 +1536,13 @@ } if (nsuri != NULL) { - nsptr = xmlSearchNsByHref(node->doc, node, nsuri); + nsptr = xmlSearchNsByHref(node->doc, node, (xmlChar *)nsuri); if (nsptr == NULL) { - nsptr = xmlNewNs(node, nsuri, prefix); + nsptr = xmlNewNs(node, (xmlChar *)nsuri, prefix); } } - attrp = xmlNewNsProp(node, nsptr, localname, value); + attrp = xmlNewNsProp(node, nsptr, localname, (xmlChar *)value); xmlFree(localname); if (prefix != NULL) { @@ -1592,7 +1595,7 @@ static int sxe_object_cast(zval *readobj, zval *writeobj, int type TSRMLS_DC) { php_sxe_object *sxe; - char *contents = NULL; + xmlChar *contents = NULL; xmlNodePtr node; int rv; @@ -1624,7 +1627,7 @@ } } - rv = cast_object(writeobj, type, contents TSRMLS_CC); + rv = cast_object(writeobj, type, (char *)contents TSRMLS_CC); if (contents) { xmlFree(contents); @@ -1855,7 +1858,7 @@ ce = sxe_class_entry; } sxe = php_sxe_object_new(ce TSRMLS_CC); - sxe->iter.nsprefix = ns_len ? xmlStrdup(ns) : NULL; + sxe->iter.nsprefix = ns_len ? xmlStrdup((xmlChar *)ns) : NULL; sxe->iter.isprefix = isprefix; php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, docp TSRMLS_CC); php_libxml_increment_node_ptr((php_libxml_node_object *)sxe, xmlDocGetRootElement(docp), NULL TSRMLS_CC); @@ -1893,7 +1896,7 @@ ce = sxe_class_entry; } sxe = php_sxe_object_new(ce TSRMLS_CC); - sxe->iter.nsprefix = ns_len ? xmlStrdup(ns) : NULL; + sxe->iter.nsprefix = ns_len ? xmlStrdup((xmlChar *)ns) : NULL; sxe->iter.isprefix = isprefix; php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, docp TSRMLS_CC); php_libxml_increment_node_ptr((php_libxml_node_object *)sxe, xmlDocGetRootElement(docp), NULL TSRMLS_CC); @@ -1931,7 +1934,7 @@ return; } - sxe->iter.nsprefix = ns_len ? xmlStrdup(ns) : NULL; + sxe->iter.nsprefix = ns_len ? xmlStrdup((xmlChar *)ns) : NULL; sxe->iter.isprefix = isprefix; php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, docp TSRMLS_CC); php_libxml_increment_node_ptr((php_libxml_node_object *)sxe, xmlDocGetRootElement(docp), NULL TSRMLS_CC); @@ -1957,7 +1960,7 @@ static xmlNodePtr php_sxe_iterator_fetch(php_sxe_object *sxe, xmlNodePtr node, int use_data TSRMLS_DC) { - char *prefix = sxe->iter.nsprefix; + xmlChar *prefix = sxe->iter.nsprefix; int isprefix = sxe->iter.isprefix; int test_elem = sxe->iter.type == SXE_ITER_ELEMENT && sxe->iter.name; int test_attr = sxe->iter.type == SXE_ITER_ATTRLIST && sxe->iter.name; @@ -2268,7 +2271,7 @@ { php_info_print_table_start(); php_info_print_table_header(2, "Simplexml support", "enabled"); - php_info_print_table_row(2, "Revision", "$Revision: 1.213 $"); + php_info_print_table_row(2, "Revision", "$Revision: 1.214 $"); php_info_print_table_row(2, "Schema support", #ifdef LIBXML_SCHEMAS_ENABLED "enabled"); http://cvs.php.net/viewvc.cgi/php-src/ext/simplexml/php_simplexml.h?r1=1.25&r2=1.26&diff_format=u Index: php-src/ext/simplexml/php_simplexml.h diff -u php-src/ext/simplexml/php_simplexml.h:1.25 php-src/ext/simplexml/php_simplexml.h:1.26 --- php-src/ext/simplexml/php_simplexml.h:1.25 Fri Apr 14 15:15:21 2006 +++ php-src/ext/simplexml/php_simplexml.h Mon Aug 7 10:11:04 2006 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_simplexml.h,v 1.25 2006/04/14 15:15:21 helly Exp $ */ +/* $Id: php_simplexml.h,v 1.26 2006/08/07 10:11:04 rrichards Exp $ */ #ifndef PHP_SIMPLEXML_H #define PHP_SIMPLEXML_H @@ -67,8 +67,8 @@ HashTable *properties; xmlXPathContextPtr xpath; struct { - char *name; - char *nsprefix; + xmlChar *name; + xmlChar *nsprefix; int isprefix; SXE_ITER type; zval *data;
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php