@@ -62,6 +62,7 @@ static void _node_as_zval(php_sxe_object *sxe, xmlNodePtr node, zval *value, SXE
62
62
subnode -> document = sxe -> document ;
63
63
subnode -> document -> refcount ++ ;
64
64
subnode -> iter .type = itertype ;
65
+ printf ("node as zval %p %d\n" , subnode , itertype );
65
66
if (name ) {
66
67
subnode -> iter .name = (xmlChar * )estrdup (name );
67
68
}
@@ -908,12 +909,23 @@ static void sxe_dimension_delete(zend_object *object, zval *offset)
908
909
909
910
static inline zend_string * sxe_xmlNodeListGetString (xmlDocPtr doc , xmlNodePtr list , int inLine ) /* {{{ */
910
911
{
911
- xmlChar * tmp = xmlNodeListGetString ( doc , list , inLine ) ;
912
+ xmlChar * tmp ;
912
913
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
+ }
913
923
914
924
if (tmp ) {
915
925
res = zend_string_init ((char * )tmp , strlen ((char * )tmp ), 0 );
916
- xmlFree (tmp );
926
+ if (free_tmp ) {
927
+ xmlFree (tmp );
928
+ }
917
929
} else {
918
930
res = ZSTR_EMPTY_ALLOC ();
919
931
}
@@ -1313,6 +1325,7 @@ PHP_METHOD(SimpleXMLElement, xpath)
1313
1325
1314
1326
for (i = 0 ; i < result -> nodeNr ; ++ i ) {
1315
1327
nodeptr = result -> nodeTab [i ];
1328
+ printf ("nodeptr type %d\n" , nodeptr -> type );
1316
1329
if (nodeptr -> type == XML_TEXT_NODE || nodeptr -> type == XML_ELEMENT_NODE || nodeptr -> type == XML_ATTRIBUTE_NODE ) {
1317
1330
/**
1318
1331
* Detect the case where the last selector is text(), simplexml
@@ -1327,6 +1340,9 @@ PHP_METHOD(SimpleXMLElement, xpath)
1327
1340
_node_as_zval (sxe , nodeptr , & value , SXE_ITER_NONE , NULL , NULL , 0 );
1328
1341
}
1329
1342
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 );
1330
1346
add_next_index_zval (return_value , & value );
1331
1347
}
1332
1348
}
@@ -1616,7 +1632,9 @@ PHP_METHOD(SimpleXMLElement, getName)
1616
1632
sxe = Z_SXEOBJ_P (ZEND_THIS );
1617
1633
1618
1634
GET_NODE (sxe , node );
1635
+ printf ("node %s\n" , node -> name );
1619
1636
node = php_sxe_get_first_node (sxe , node );
1637
+ printf ("node %s\n" , node -> name );
1620
1638
if (node ) {
1621
1639
namelen = xmlStrlen (node -> name );
1622
1640
RETURN_STRINGL ((char * )node -> name , namelen );
@@ -1794,10 +1812,10 @@ PHP_METHOD(SimpleXMLElement, addAttribute)
1794
1812
/* }}} */
1795
1813
1796
1814
/* {{{ 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 )
1798
1816
{
1799
1817
if (contents ) {
1800
- ZVAL_STRINGL (object , contents , strlen ( contents ) );
1818
+ ZVAL_STR (object , contents );
1801
1819
} else {
1802
1820
ZVAL_NULL (object );
1803
1821
}
@@ -1829,9 +1847,8 @@ static zend_result cast_object(zval *object, int type, char *contents)
1829
1847
static zend_result sxe_object_cast_ex (zend_object * readobj , zval * writeobj , int type )
1830
1848
{
1831
1849
php_sxe_object * sxe ;
1832
- xmlChar * contents = NULL ;
1850
+ zend_string * contents = NULL ;
1833
1851
xmlNodePtr node ;
1834
- zend_result rv ;
1835
1852
1836
1853
sxe = php_sxe_fetch_object (readobj );
1837
1854
@@ -1845,10 +1862,12 @@ static zend_result sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int
1845
1862
return SUCCESS ;
1846
1863
}
1847
1864
1865
+ printf ("sxe_object_cast_ex type %d\n" , sxe -> iter .type );
1866
+
1848
1867
if (sxe -> iter .type != SXE_ITER_NONE ) {
1849
1868
node = php_sxe_get_first_node (sxe , NULL );
1850
1869
if (node ) {
1851
- contents = xmlNodeListGetString ((xmlDocPtr ) sxe -> document -> ptr , node -> children , 1 );
1870
+ contents = sxe_xmlNodeListGetString ((xmlDocPtr ) sxe -> document -> ptr , node -> children , 1 );
1852
1871
}
1853
1872
} else {
1854
1873
if (!sxe -> node ) {
@@ -1859,18 +1878,12 @@ static zend_result sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int
1859
1878
1860
1879
if (sxe -> node && sxe -> node -> node ) {
1861
1880
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 );
1863
1882
}
1864
1883
}
1865
1884
}
1866
1885
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 );
1874
1887
}
1875
1888
/* }}} */
1876
1889
@@ -2454,6 +2467,8 @@ static xmlNodePtr php_sxe_reset_iterator(php_sxe_object *sxe, int use_data) /* {
2454
2467
2455
2468
GET_NODE (sxe , node )
2456
2469
2470
+ printf ("sxe %p node %p %s, iter type %d\n" , sxe , node , node -> name , sxe -> iter .type );
2471
+
2457
2472
if (node ) {
2458
2473
switch (sxe -> iter .type ) {
2459
2474
case SXE_ITER_ELEMENT :
0 commit comments