Skip to content

Commit e4db615

Browse files
author
Sterling Hughes
committed
make alan happy
1 parent 34b36fd commit e4db615

File tree

1 file changed

+44
-52
lines changed

1 file changed

+44
-52
lines changed

ext/simplexml/simplexml.c

Lines changed: 44 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,12 @@ _get_base_node_value(xmlNodePtr node, zval **value TSRMLS_DC)
367367
if (node->children && node->children->type == XML_TEXT_NODE && !xmlIsBlankNode(node->children)) {
368368
contents = xmlNodeListGetString(node->doc, node->children, 1);
369369
if (contents) {
370-
ZVAL_STRING(*value, contents, 1);
371-
xmlFree(contents);
370+
ZVAL_STRING(*value, contents, 0);
372371
}
373372
} else {
374373
subnode = php_sxe_object_new(TSRMLS_C);
375374
subnode->document = emalloc(sizeof(simplexml_ref_obj));
376-
subnode->document->refcount = 2;
375+
subnode->document->refcount = 1;
377376
subnode->document->ptr = node->doc;
378377
subnode->node = node;
379378

@@ -613,6 +612,44 @@ simplexml_ce_register_ns(INTERNAL_FUNCTION_PARAMETERS)
613612
}
614613
/* }}} */
615614

615+
/* {{{ simplexml_ce_to_xml_string()
616+
*/
617+
static void
618+
simplexml_ce_to_xml_string(INTERNAL_FUNCTION_PARAMETERS)
619+
{
620+
php_sxe_object *sxe;
621+
622+
if (ZEND_NUM_ARGS() != 0) {
623+
RETURN_FALSE;
624+
}
625+
626+
sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
627+
xmlDocDumpMemory((xmlDocPtr) sxe->document->ptr, (xmlChar **) &Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value));
628+
Z_TYPE_P(return_value) = IS_STRING;
629+
zval_add_ref(&return_value);
630+
}
631+
/* }}} */
632+
633+
/* {{{ simplexml_ce_to_xml_file()
634+
*/
635+
static void
636+
simplexml_ce_to_xml_file(INTERNAL_FUNCTION_PARAMETERS)
637+
{
638+
php_sxe_object *sxe;
639+
char *filename;
640+
int filename_len;
641+
642+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
643+
return;
644+
}
645+
646+
sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
647+
648+
xmlSaveFile(filename, (xmlDocPtr) sxe->document->ptr);
649+
650+
RETURN_TRUE;
651+
}
652+
/* }}} */
616653

617654
/* {{{ sxe_call_method()
618655
*/
@@ -627,6 +664,10 @@ sxe_call_method(char *method, INTERNAL_FUNCTION_PARAMETERS)
627664
simplexml_ce_schema_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU, SCHEMA_BLOB);
628665
} else if (!strcmp(method, "register_ns")) {
629666
simplexml_ce_register_ns(INTERNAL_FUNCTION_PARAM_PASSTHRU);
667+
} else if (!strcmp(method, "to_xml")) {
668+
simplexml_ce_to_xml_string(INTERNAL_FUNCTION_PARAM_PASSTHRU);
669+
} else if (!strcmp(method, "to_xml_file")) {
670+
simplexml_ce_to_xml_file(INTERNAL_FUNCTION_PARAM_PASSTHRU);
630671
} else {
631672
return 0;
632673
}
@@ -919,58 +960,9 @@ PHP_FUNCTION(simplexml_load_string)
919960
}
920961
/* }}} */
921962

922-
/* {{{ proto bool simplexml_save_document_file(string filename, simplexml_element node)
923-
Save a XML document to a file from a SimpleXML node */
924-
PHP_FUNCTION(simplexml_save_document_file)
925-
{
926-
php_sxe_object *sxe;
927-
zval *element;
928-
char *filename;
929-
int filename_len;
930-
931-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &filename, &filename_len, &element) == FAILURE) {
932-
return;
933-
}
934-
935-
sxe = php_sxe_fetch_object(element TSRMLS_CC);
936-
937-
xmlSaveFile(filename, (xmlDocPtr) sxe->document->ptr);
938-
939-
RETURN_TRUE;
940-
}
941-
/* }}} */
942-
943-
/* {{{ proto bool simplexml_save_document_string(string &var, simplexml_element node)
944-
Save a document to a variable from a SimpleXML node */
945-
PHP_FUNCTION(simplexml_save_document_string)
946-
{
947-
php_sxe_object *sxe;
948-
zval *data;
949-
zval *element;
950-
951-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &data, &element) == FAILURE) {
952-
return;
953-
}
954-
955-
sxe = php_sxe_fetch_object(element TSRMLS_CC);
956-
xmlDocDumpMemory((xmlDocPtr) sxe->document->ptr, (xmlChar **) &Z_STRVAL_P(data), &Z_STRLEN_P(data));
957-
Z_TYPE_P(data) = IS_STRING;
958-
zval_add_ref(&data);
959-
960-
RETURN_TRUE;
961-
}
962-
/* }}} */
963-
964-
/* this is lame, first_arg_force_ref (and others) doesn't
965-
work through dll linkage on windows. no other extension
966-
outside basic_functions uses first_arg_force_ref. */
967-
unsigned char fix_first_arg_force_ref[] = { 1, BYREF_FORCE };
968-
969963
function_entry simplexml_functions[] = {
970964
PHP_FE(simplexml_load_file, NULL)
971965
PHP_FE(simplexml_load_string, NULL)
972-
PHP_FE(simplexml_save_document_file, NULL)
973-
PHP_FE(simplexml_save_document_string, fix_first_arg_force_ref)
974966
{NULL, NULL, NULL}
975967
};
976968

0 commit comments

Comments
 (0)