@@ -374,11 +374,9 @@ static zval *sxe_dimension_read(zend_object *object, zval *offset, int type, zva
374
374
/* }}} */
375
375
376
376
/* {{{ change_node_zval() */
377
- static void change_node_zval (xmlNodePtr node , zval * value )
377
+ static void change_node_zval (xmlNodePtr node , zend_string * value )
378
378
{
379
- xmlChar * buffer ;
380
- ZEND_ASSERT (Z_TYPE_P (value ) == IS_STRING );
381
- buffer = xmlEncodeEntitiesReentrant (node -> doc , (xmlChar * )Z_STRVAL_P (value ));
379
+ xmlChar * buffer = xmlEncodeEntitiesReentrant (node -> doc , (xmlChar * )ZSTR_VAL (value ));
382
380
/* check for NULL buffer in case of memory error in xmlEncodeEntitiesReentrant */
383
381
if (buffer ) {
384
382
xmlNodeSetContent (node , buffer );
@@ -400,10 +398,10 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
400
398
int is_attr = 0 ;
401
399
int nodendx = 0 ;
402
400
int test = 0 ;
403
- int new_value = 0 ;
404
401
zend_long cnt = 0 ;
405
- zval tmp_zv , zval_copy ;
402
+ zval tmp_zv ;
406
403
zend_string * trim_str ;
404
+ zend_string * value_str = NULL ;
407
405
408
406
sxe = php_sxe_fetch_object (object );
409
407
@@ -484,23 +482,18 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
484
482
case IS_TRUE :
485
483
case IS_DOUBLE :
486
484
case IS_NULL :
487
- if (Z_TYPE_P (value ) != IS_STRING ) {
488
- ZVAL_STR (& zval_copy , zval_get_string_func (value ));
489
- value = & zval_copy ;
490
- new_value = 1 ;
491
- }
492
- break ;
493
485
case IS_STRING :
486
+ value_str = zval_get_string (value );
494
487
break ;
495
488
case IS_OBJECT :
496
489
if (Z_OBJCE_P (value ) == sxe_class_entry ) {
490
+ zval zval_copy ;
497
491
if (sxe_object_cast_ex (Z_OBJ_P (value ), & zval_copy , IS_STRING ) == FAILURE ) {
498
492
zend_error (E_ERROR , "Unable to cast node to string" );
499
493
/* FIXME: Should not be fatal */
500
494
}
501
495
502
- value = & zval_copy ;
503
- new_value = 1 ;
496
+ value_str = Z_STR (zval_copy );
504
497
break ;
505
498
}
506
499
/* break is missing intentionally */
@@ -544,8 +537,8 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
544
537
if (!member || Z_TYPE_P (member ) == IS_LONG ) {
545
538
if (node -> type == XML_ATTRIBUTE_NODE ) {
546
539
zend_throw_error (NULL , "Cannot create duplicate attribute" );
547
- if (new_value ) {
548
- zval_ptr_dtor ( value );
540
+ if (value_str ) {
541
+ zend_string_release ( value_str );
549
542
}
550
543
return & EG (error_zval );
551
544
}
@@ -583,34 +576,34 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
583
576
if (is_attr ) {
584
577
newnode = (xmlNodePtr ) attr ;
585
578
}
586
- if (value ) {
579
+ if (value_str ) {
587
580
while ((tempnode = (xmlNodePtr ) newnode -> children )) {
588
581
xmlUnlinkNode (tempnode );
589
582
php_libxml_node_free_resource ((xmlNodePtr ) tempnode );
590
583
}
591
- change_node_zval (newnode , value );
584
+ change_node_zval (newnode , value_str );
592
585
}
593
586
} else if (counter > 1 ) {
594
587
php_error_docref (NULL , E_WARNING , "Cannot assign to an array of nodes (duplicate subnodes or attr detected)" );
595
588
value = & EG (error_zval );
596
589
} else if (elements ) {
597
590
if (!node ) {
598
591
if (!member || Z_TYPE_P (member ) == IS_LONG ) {
599
- newnode = xmlNewTextChild (mynode -> parent , mynode -> ns , mynode -> name , value ? (xmlChar * )Z_STRVAL_P ( value ) : NULL );
592
+ newnode = xmlNewTextChild (mynode -> parent , mynode -> ns , mynode -> name , value_str ? (xmlChar * )ZSTR_VAL ( value_str ) : NULL );
600
593
} else {
601
- newnode = xmlNewTextChild (mynode , mynode -> ns , (xmlChar * )Z_STRVAL_P (member ), value ? (xmlChar * )Z_STRVAL_P ( value ) : NULL );
594
+ newnode = xmlNewTextChild (mynode , mynode -> ns , (xmlChar * )Z_STRVAL_P (member ), value_str ? (xmlChar * )ZSTR_VAL ( value_str ) : NULL );
602
595
}
603
596
} else if (!member || Z_TYPE_P (member ) == IS_LONG ) {
604
597
if (member && cnt < Z_LVAL_P (member )) {
605
598
php_error_docref (NULL , E_WARNING , "Cannot add element %s number " ZEND_LONG_FMT " when only " ZEND_LONG_FMT " such elements exist" , mynode -> name , Z_LVAL_P (member ), cnt );
606
599
}
607
- newnode = xmlNewTextChild (mynode -> parent , mynode -> ns , mynode -> name , value ? (xmlChar * )Z_STRVAL_P ( value ) : NULL );
600
+ newnode = xmlNewTextChild (mynode -> parent , mynode -> ns , mynode -> name , value_str ? (xmlChar * )ZSTR_VAL ( value_str ) : NULL );
608
601
}
609
602
} else if (attribs ) {
610
603
if (Z_TYPE_P (member ) == IS_LONG ) {
611
604
php_error_docref (NULL , E_WARNING , "Cannot change attribute number " ZEND_LONG_FMT " when only %d attributes exist" , Z_LVAL_P (member ), nodendx );
612
605
} else {
613
- newnode = (xmlNodePtr )xmlNewProp (node , (xmlChar * )Z_STRVAL_P (member ), value ? (xmlChar * )Z_STRVAL_P ( value ) : NULL );
606
+ newnode = (xmlNodePtr )xmlNewProp (node , (xmlChar * )Z_STRVAL_P (member ), value_str ? (xmlChar * )ZSTR_VAL ( value_str ) : NULL );
614
607
}
615
608
}
616
609
}
@@ -621,8 +614,8 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
621
614
if (pnewnode ) {
622
615
* pnewnode = newnode ;
623
616
}
624
- if (new_value ) {
625
- zval_ptr_dtor ( value );
617
+ if (value_str ) {
618
+ zend_string_release ( value_str );
626
619
}
627
620
return value ;
628
621
}
0 commit comments