@@ -1317,51 +1317,24 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, size_t so
1317
1317
}
1318
1318
/* }}} */
1319
1319
1320
- /* {{{ static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode) */
1321
- static void dom_parse_document (INTERNAL_FUNCTION_PARAMETERS , int mode ) {
1322
- xmlDoc * docp = NULL , * newdoc ;
1323
- dom_doc_propsptr doc_prop ;
1324
- dom_object * intern ;
1325
- char * source ;
1326
- size_t source_len ;
1327
- int refcount ;
1328
- zend_long options = 0 ;
1329
-
1330
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "s|l" , & source , & source_len , & options ) == FAILURE ) {
1331
- RETURN_THROWS ();
1332
- }
1333
-
1334
- if (!source_len ) {
1335
- zend_argument_value_error (1 , "must not be empty" );
1336
- RETURN_THROWS ();
1337
- }
1338
- if (ZEND_SIZE_T_INT_OVFL (source_len )) {
1339
- php_error_docref (NULL , E_WARNING , "Input string is too long" );
1340
- RETURN_FALSE ;
1341
- }
1342
- if (ZEND_LONG_EXCEEDS_INT (options )) {
1343
- php_error_docref (NULL , E_WARNING , "Invalid options" );
1344
- RETURN_FALSE ;
1345
- }
1346
-
1347
- newdoc = dom_document_parser (ZEND_THIS , mode , source , source_len , options );
1348
-
1320
+ static void dom_finish_loading_document (zval * this , zval * return_value , xmlDocPtr newdoc )
1321
+ {
1349
1322
if (!newdoc )
1350
1323
RETURN_FALSE ;
1351
1324
1352
- intern = Z_DOMOBJ_P (ZEND_THIS );
1325
+ dom_object * intern = Z_DOMOBJ_P (this );
1353
1326
size_t old_modification_nr = 0 ;
1354
1327
if (intern != NULL ) {
1355
- docp = (xmlDocPtr ) dom_object_get_node (intern );
1356
- doc_prop = NULL ;
1328
+ xmlDocPtr docp = (xmlDocPtr ) dom_object_get_node (intern );
1329
+ dom_doc_propsptr doc_prop = NULL ;
1357
1330
if (docp != NULL ) {
1358
1331
const php_libxml_doc_ptr * doc_ptr = docp -> _private ;
1359
1332
ZEND_ASSERT (doc_ptr != NULL ); /* Must exist, we have a document */
1360
1333
old_modification_nr = doc_ptr -> cache_tag .modification_nr ;
1361
1334
php_libxml_decrement_node_ptr ((php_libxml_node_object * ) intern );
1362
1335
doc_prop = intern -> document -> doc_props ;
1363
1336
intern -> document -> doc_props = NULL ;
1364
- refcount = php_libxml_decrement_doc_ref ((php_libxml_node_object * )intern );
1337
+ int refcount = php_libxml_decrement_doc_ref ((php_libxml_node_object * )intern );
1365
1338
if (refcount != 0 ) {
1366
1339
docp -> _private = NULL ;
1367
1340
}
@@ -1383,6 +1356,34 @@ static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode) {
1383
1356
1384
1357
RETURN_TRUE ;
1385
1358
}
1359
+
1360
+ /* {{{ static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode) */
1361
+ static void dom_parse_document (INTERNAL_FUNCTION_PARAMETERS , int mode ) {
1362
+ char * source ;
1363
+ size_t source_len ;
1364
+ zend_long options = 0 ;
1365
+
1366
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "s|l" , & source , & source_len , & options ) == FAILURE ) {
1367
+ RETURN_THROWS ();
1368
+ }
1369
+
1370
+ if (!source_len ) {
1371
+ zend_argument_value_error (1 , "must not be empty" );
1372
+ RETURN_THROWS ();
1373
+ }
1374
+ if (ZEND_SIZE_T_INT_OVFL (source_len )) {
1375
+ php_error_docref (NULL , E_WARNING , "Input string is too long" );
1376
+ RETURN_FALSE ;
1377
+ }
1378
+ if (ZEND_LONG_EXCEEDS_INT (options )) {
1379
+ php_error_docref (NULL , E_WARNING , "Invalid options" );
1380
+ RETURN_FALSE ;
1381
+ }
1382
+
1383
+ xmlDocPtr newdoc = dom_document_parser (ZEND_THIS , mode , source , source_len , options );
1384
+
1385
+ dom_finish_loading_document (ZEND_THIS , return_value , newdoc );
1386
+ }
1386
1387
/* }}} end dom_parser_document */
1387
1388
1388
1389
/* {{{ URL: http://www.w3.org/TR/DOM-Level-3-LS/load-save.html#LS-DocumentLS-load
@@ -1869,12 +1870,8 @@ PHP_METHOD(DOMDocument, relaxNGValidateSource)
1869
1870
1870
1871
static void dom_load_html (INTERNAL_FUNCTION_PARAMETERS , int mode ) /* {{{ */
1871
1872
{
1872
- xmlDoc * docp = NULL , * newdoc ;
1873
- dom_object * intern ;
1874
- dom_doc_propsptr doc_prop ;
1875
1873
char * source ;
1876
1874
size_t source_len ;
1877
- int refcount ;
1878
1875
zend_long options = 0 ;
1879
1876
htmlParserCtxtPtr ctxt ;
1880
1877
@@ -1922,45 +1919,10 @@ static void dom_load_html(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
1922
1919
htmlCtxtUseOptions (ctxt , (int )options );
1923
1920
}
1924
1921
htmlParseDocument (ctxt );
1925
- newdoc = ctxt -> myDoc ;
1922
+ xmlDocPtr newdoc = ctxt -> myDoc ;
1926
1923
htmlFreeParserCtxt (ctxt );
1927
1924
1928
- if (!newdoc )
1929
- RETURN_FALSE ;
1930
-
1931
- intern = Z_DOMOBJ_P (ZEND_THIS );
1932
- size_t old_modification_nr = 0 ;
1933
- if (intern != NULL ) {
1934
- docp = (xmlDocPtr ) dom_object_get_node (intern );
1935
- doc_prop = NULL ;
1936
- if (docp != NULL ) {
1937
- const php_libxml_doc_ptr * doc_ptr = docp -> _private ;
1938
- ZEND_ASSERT (doc_ptr != NULL ); /* Must exist, we have a document */
1939
- old_modification_nr = doc_ptr -> cache_tag .modification_nr ;
1940
- php_libxml_decrement_node_ptr ((php_libxml_node_object * ) intern );
1941
- doc_prop = intern -> document -> doc_props ;
1942
- intern -> document -> doc_props = NULL ;
1943
- refcount = php_libxml_decrement_doc_ref ((php_libxml_node_object * )intern );
1944
- if (refcount != 0 ) {
1945
- docp -> _private = NULL ;
1946
- }
1947
- }
1948
- intern -> document = NULL ;
1949
- if (php_libxml_increment_doc_ref ((php_libxml_node_object * )intern , newdoc ) == -1 ) {
1950
- RETURN_FALSE ;
1951
- }
1952
- intern -> document -> doc_props = doc_prop ;
1953
- }
1954
-
1955
- php_libxml_increment_node_ptr ((php_libxml_node_object * )intern , (xmlNodePtr )newdoc , (void * )intern );
1956
- /* Since iterators should invalidate, we need to start the modification number from the old counter */
1957
- if (old_modification_nr != 0 ) {
1958
- php_libxml_doc_ptr * doc_ptr = (php_libxml_doc_ptr * ) ((php_libxml_node_object * ) intern )-> node ; /* downcast */
1959
- doc_ptr -> cache_tag .modification_nr = old_modification_nr ;
1960
- php_libxml_invalidate_node_list_cache (doc_ptr );
1961
- }
1962
-
1963
- RETURN_TRUE ;
1925
+ dom_finish_loading_document (ZEND_THIS , return_value , newdoc );
1964
1926
}
1965
1927
/* }}} */
1966
1928
0 commit comments