@@ -62,6 +62,7 @@ static void _node_as_zval(php_sxe_object *sxe, xmlNodePtr node, zval *value, SXE
6262 subnode -> document = sxe -> document ;
6363 subnode -> document -> refcount ++ ;
6464 subnode -> iter .type = itertype ;
65+ printf ("node as zval %p %d\n" , subnode , itertype );
6566 if (name ) {
6667 subnode -> iter .name = (xmlChar * )estrdup (name );
6768 }
@@ -908,12 +909,23 @@ static void sxe_dimension_delete(zend_object *object, zval *offset)
908909
909910static inline zend_string * sxe_xmlNodeListGetString (xmlDocPtr doc , xmlNodePtr list , int inLine ) /* {{{ */
910911{
911- xmlChar * tmp = xmlNodeListGetString ( doc , list , inLine ) ;
912+ xmlChar * tmp ;
912913 zend_string * res ;
914+ bool free_tmp ;
915+
916+ if (list -> type == XML_PI_NODE ) {
917+ tmp = list -> content ;
918+ free_tmp = false;
919+ } else {
920+ tmp = xmlNodeListGetString (doc , list , inLine );
921+ free_tmp = true;
922+ }
913923
914924 if (tmp ) {
915925 res = zend_string_init ((char * )tmp , strlen ((char * )tmp ), 0 );
916- xmlFree (tmp );
926+ if (free_tmp ) {
927+ xmlFree (tmp );
928+ }
917929 } else {
918930 res = ZSTR_EMPTY_ALLOC ();
919931 }
@@ -1313,6 +1325,7 @@ PHP_METHOD(SimpleXMLElement, xpath)
13131325
13141326 for (i = 0 ; i < result -> nodeNr ; ++ i ) {
13151327 nodeptr = result -> nodeTab [i ];
1328+ printf ("nodeptr type %d\n" , nodeptr -> type );
13161329 if (nodeptr -> type == XML_TEXT_NODE || nodeptr -> type == XML_ELEMENT_NODE || nodeptr -> type == XML_ATTRIBUTE_NODE ) {
13171330 /**
13181331 * Detect the case where the last selector is text(), simplexml
@@ -1327,6 +1340,9 @@ PHP_METHOD(SimpleXMLElement, xpath)
13271340 _node_as_zval (sxe , nodeptr , & value , SXE_ITER_NONE , NULL , NULL , 0 );
13281341 }
13291342
1343+ add_next_index_zval (return_value , & value );
1344+ } else if (nodeptr -> type == XML_PI_NODE ) {
1345+ _node_as_zval (sxe , nodeptr , & value , SXE_ITER_NONE , NULL , NULL , 0 );
13301346 add_next_index_zval (return_value , & value );
13311347 }
13321348 }
@@ -1616,7 +1632,9 @@ PHP_METHOD(SimpleXMLElement, getName)
16161632 sxe = Z_SXEOBJ_P (ZEND_THIS );
16171633
16181634 GET_NODE (sxe , node );
1635+ printf ("node %s\n" , node -> name );
16191636 node = php_sxe_get_first_node (sxe , node );
1637+ printf ("node %s\n" , node -> name );
16201638 if (node ) {
16211639 namelen = xmlStrlen (node -> name );
16221640 RETURN_STRINGL ((char * )node -> name , namelen );
@@ -1794,10 +1812,10 @@ PHP_METHOD(SimpleXMLElement, addAttribute)
17941812/* }}} */
17951813
17961814/* {{{ cast_object() */
1797- static zend_result cast_object (zval * object , int type , char * contents )
1815+ static zend_result cast_object (zval * object , int type , zend_string * contents )
17981816{
17991817 if (contents ) {
1800- ZVAL_STRINGL (object , contents , strlen ( contents ) );
1818+ ZVAL_STR (object , contents );
18011819 } else {
18021820 ZVAL_NULL (object );
18031821 }
@@ -1829,9 +1847,8 @@ static zend_result cast_object(zval *object, int type, char *contents)
18291847static zend_result sxe_object_cast_ex (zend_object * readobj , zval * writeobj , int type )
18301848{
18311849 php_sxe_object * sxe ;
1832- xmlChar * contents = NULL ;
1850+ zend_string * contents = NULL ;
18331851 xmlNodePtr node ;
1834- zend_result rv ;
18351852
18361853 sxe = php_sxe_fetch_object (readobj );
18371854
@@ -1845,10 +1862,12 @@ static zend_result sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int
18451862 return SUCCESS ;
18461863 }
18471864
1865+ printf ("sxe_object_cast_ex type %d\n" , sxe -> iter .type );
1866+
18481867 if (sxe -> iter .type != SXE_ITER_NONE ) {
18491868 node = php_sxe_get_first_node (sxe , NULL );
18501869 if (node ) {
1851- contents = xmlNodeListGetString ((xmlDocPtr ) sxe -> document -> ptr , node -> children , 1 );
1870+ contents = sxe_xmlNodeListGetString ((xmlDocPtr ) sxe -> document -> ptr , node -> children , 1 );
18521871 }
18531872 } else {
18541873 if (!sxe -> node ) {
@@ -1859,18 +1878,12 @@ static zend_result sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int
18591878
18601879 if (sxe -> node && sxe -> node -> node ) {
18611880 if (sxe -> node -> node -> children ) {
1862- contents = xmlNodeListGetString ((xmlDocPtr ) sxe -> document -> ptr , sxe -> node -> node -> children , 1 );
1881+ contents = sxe_xmlNodeListGetString ((xmlDocPtr ) sxe -> document -> ptr , sxe -> node -> node -> children , 1 );
18631882 }
18641883 }
18651884 }
18661885
1867- rv = cast_object (writeobj , type , (char * )contents );
1868-
1869- if (contents ) {
1870- xmlFree (contents );
1871- }
1872-
1873- return rv ;
1886+ return cast_object (writeobj , type , contents );
18741887}
18751888/* }}} */
18761889
@@ -2454,6 +2467,8 @@ static xmlNodePtr php_sxe_reset_iterator(php_sxe_object *sxe, int use_data) /* {
24542467
24552468 GET_NODE (sxe , node )
24562469
2470+ printf ("sxe %p node %p %s, iter type %d\n" , sxe , node , node -> name , sxe -> iter .type );
2471+
24572472 if (node ) {
24582473 switch (sxe -> iter .type ) {
24592474 case SXE_ITER_ELEMENT :
0 commit comments