rrichards Sun Feb 15 13:57:12 2004 EDT
Modified files:
/php-src/ext/dom characterdata.c attr.c
Log:
switch to zend_parse_method_parameters for consistancy
insure object parameters are correct class types
convert zvals to correct type if needed for property writes
fix a few segfaults found while testing
http://cvs.php.net/diff.php/php-src/ext/dom/characterdata.c?r1=1.10&r2=1.11&ty=u
Index: php-src/ext/dom/characterdata.c
diff -u php-src/ext/dom/characterdata.c:1.10 php-src/ext/dom/characterdata.c:1.11
--- php-src/ext/dom/characterdata.c:1.10 Thu Jan 8 03:15:16 2004
+++ php-src/ext/dom/characterdata.c Sun Feb 15 13:57:10 2004
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: characterdata.c,v 1.10 2004/01/08 08:15:16 andi Exp $ */
+/* $Id: characterdata.c,v 1.11 2004/02/15 18:57:10 rrichards Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -60,21 +60,36 @@
if ((content = xmlNodeGetContent(nodep)) != NULL) {
ZVAL_STRING(*retval, content, 1);
+ xmlFree(content);
} else {
ZVAL_EMPTY_STRING(*retval);
}
- xmlFree(content);
-
return SUCCESS;
}
int dom_characterdata_data_write(dom_object *obj, zval *newval TSRMLS_DC)
{
+ zval value_copy;
xmlNode *nodep;
nodep = dom_object_get_node(obj);
+
+ if (newval->type != IS_STRING) {
+ if(newval->refcount > 1) {
+ value_copy = *newval;
+ zval_copy_ctor(&value_copy);
+ newval = &value_copy;
+ }
+ convert_to_string(newval);
+ }
+
xmlNodeSetContentLen(nodep, Z_STRVAL_P(newval), Z_STRLEN_P(newval) + 1);
+
+ if (newval == &value_copy) {
+ zval_dtor(newval);
+ }
+
return SUCCESS;
}
@@ -89,16 +104,19 @@
{
xmlNodePtr nodep;
xmlChar *content;
- long length;
+ long length = 0;
nodep = dom_object_get_node(obj);
ALLOC_ZVAL(*retval);
content = xmlNodeGetContent(nodep);
- length = xmlUTF8Strlen(content);
- xmlFree(content);
+ if (content) {
+ length = xmlUTF8Strlen(content);
+ xmlFree(content);
+ }
+
ZVAL_LONG(*retval, length);
return SUCCESS;
@@ -107,14 +125,13 @@
/* }}} */
-
-
/* {{{ proto domstring dom_characterdata_substring_data(unsigned long offset,
unsigned long count);
URL:
http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-6531BCCF
Since:
*/
PHP_FUNCTION(dom_characterdata_substring_data)
{
+ zval *id;
xmlChar *cur;
xmlChar *substring;
xmlNodePtr node;
@@ -122,12 +139,12 @@
int length;
dom_object *intern;
- DOM_GET_THIS_OBJ(node, getThis(), xmlNodePtr, intern);
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &offset, &count) ==
FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll",
&id, dom_characterdata_class_entry, &offset, &count) == FAILURE) {
return;
}
+ DOM_GET_OBJ(node, id, xmlNodePtr, intern);
+
cur = xmlNodeGetContent(node);
if (cur == NULL) {
RETURN_FALSE;
@@ -170,13 +187,12 @@
char *arg;
int arg_len;
-
- DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr, intern);
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) ==
FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
&id, dom_characterdata_class_entry, &arg, &arg_len) == FAILURE) {
return;
}
+ DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
+
xmlTextConcat(nodep, arg, arg_len);
RETURN_TRUE;
@@ -190,6 +206,7 @@
*/
PHP_FUNCTION(dom_characterdata_insert_data)
{
+ zval *id;
xmlChar *cur, *first, *second;
xmlNodePtr node;
char *arg;
@@ -197,12 +214,12 @@
int length, arg_len;
dom_object *intern;
- DOM_GET_THIS_OBJ(node, getThis(), xmlNodePtr, intern);
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &offset, &arg,
&arg_len) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ols",
&id, dom_characterdata_class_entry, &offset, &arg, &arg_len) == FAILURE) {
return;
}
+ DOM_GET_OBJ(node, id, xmlNodePtr, intern);
+
cur = xmlNodeGetContent(node);
if (cur == NULL) {
RETURN_FALSE;
@@ -238,18 +255,19 @@
*/
PHP_FUNCTION(dom_characterdata_delete_data)
{
+ zval *id;
xmlChar *cur, *substring, *second;
xmlNodePtr node;
long offset, count;
int length;
dom_object *intern;
- DOM_GET_THIS_OBJ(node, getThis(), xmlNodePtr, intern);
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &offset, &count) ==
FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll",
&id, dom_characterdata_class_entry, &offset, &count) == FAILURE) {
return;
}
+ DOM_GET_OBJ(node, id, xmlNodePtr, intern);
+
cur = xmlNodeGetContent(node);
if (cur == NULL) {
RETURN_FALSE;
@@ -293,6 +311,7 @@
*/
PHP_FUNCTION(dom_characterdata_replace_data)
{
+ zval *id;
xmlChar *cur, *substring, *second = NULL;
xmlNodePtr node;
char *arg;
@@ -300,12 +319,12 @@
int length, arg_len;
dom_object *intern;
- DOM_GET_THIS_OBJ(node, getThis(), xmlNodePtr, intern);
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lls", &offset, &count,
&arg, &arg_len) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Olls",
&id, dom_characterdata_class_entry, &offset, &count, &arg, &arg_len) == FAILURE) {
return;
}
+ DOM_GET_OBJ(node, id, xmlNodePtr, intern);
+
cur = xmlNodeGetContent(node);
if (cur == NULL) {
RETURN_FALSE;
http://cvs.php.net/diff.php/php-src/ext/dom/attr.c?r1=1.10&r2=1.11&ty=u
Index: php-src/ext/dom/attr.c
diff -u php-src/ext/dom/attr.c:1.10 php-src/ext/dom/attr.c:1.11
--- php-src/ext/dom/attr.c:1.10 Thu Jan 22 16:16:05 2004
+++ php-src/ext/dom/attr.c Sun Feb 15 13:57:10 2004
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: attr.c,v 1.10 2004/01/22 21:16:05 rrichards Exp $ */
+/* $Id: attr.c,v 1.11 2004/02/15 18:57:10 rrichards Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -136,18 +136,18 @@
if ((content = xmlNodeGetContent((xmlNodePtr) attrp)) != NULL) {
ZVAL_STRING(*retval, content, 1);
+ xmlFree(content);
} else {
ZVAL_EMPTY_STRING(*retval);
}
- xmlFree(content);
-
return SUCCESS;
}
int dom_attr_value_write(dom_object *obj, zval *newval TSRMLS_DC)
{
+ zval value_copy;
xmlAttrPtr attrp;
attrp = (xmlAttrPtr) dom_object_get_node(obj);
@@ -155,8 +155,22 @@
if (attrp->children) {
node_list_unlink(attrp->children TSRMLS_CC);
}
+
+ if (newval->type != IS_STRING) {
+ if(newval->refcount > 1) {
+ value_copy = *newval;
+ zval_copy_ctor(&value_copy);
+ newval = &value_copy;
+ }
+ convert_to_string(newval);
+ }
+
xmlNodeSetContentLen((xmlNodePtr) attrp, Z_STRVAL_P(newval),
Z_STRLEN_P(newval) + 1);
+ if (newval == &value_copy) {
+ zval_dtor(newval);
+ }
+
return SUCCESS;
}
@@ -223,7 +237,11 @@
xmlAttrPtr attrp;
xmlNodePtr nodep;
- DOM_GET_THIS_OBJ(attrp, id, xmlAttrPtr, intern);
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
&id, dom_attr_class_entry) == FAILURE) {
+ return;
+ }
+
+ DOM_GET_OBJ(attrp, id, xmlAttrPtr, intern);
nodep = attrp->parent;
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php