@@ -228,9 +228,7 @@ static PHP_GINIT_FUNCTION(libxml)
228
228
ZVAL_UNDEF (& libxml_globals -> stream_context );
229
229
libxml_globals -> error_buffer .s = NULL ;
230
230
libxml_globals -> error_list = NULL ;
231
- ZVAL_NULL (& libxml_globals -> entity_loader .callback );
232
- libxml_globals -> entity_loader .fci .size = 0 ;
233
- libxml_globals -> entity_loader_disabled = 0 ;
231
+ libxml_globals -> entity_loader_callback = empty_fcall_info_cache ;
234
232
}
235
233
236
234
/* Channel libxml file io layer through the PHP streams subsystem.
@@ -573,13 +571,9 @@ static xmlParserInputPtr _php_libxml_external_entity_loader(const char *URL,
573
571
const char * resource = NULL ;
574
572
zval * ctxzv , retval ;
575
573
zval params [3 ];
576
- int status ;
577
- zend_fcall_info * fci ;
578
574
579
- fci = & LIBXML (entity_loader ).fci ;
580
-
581
- if (fci -> size == 0 ) {
582
- /* no custom user-land callback set up; delegate to original loader */
575
+ /* no custom user-land callback set up; delegate to original loader */
576
+ if (!ZEND_FCC_INITIALIZED (LIBXML (entity_loader_callback ))) {
583
577
return _php_libxml_default_entity_loader (URL , ID , context );
584
578
}
585
579
@@ -611,24 +605,14 @@ static xmlParserInputPtr _php_libxml_external_entity_loader(const char *URL,
611
605
612
606
#undef ADD_NULL_OR_STRING_KEY
613
607
614
- fci -> retval = & retval ;
615
- fci -> params = params ;
616
- fci -> param_count = sizeof (params )/sizeof (* params );
608
+ zend_call_known_fcc (& LIBXML (entity_loader_callback ), & retval , 3 , params , /* named_params */ NULL );
617
609
618
- status = zend_call_function (fci , & LIBXML (entity_loader ).fcc );
619
- if (status != SUCCESS || Z_ISUNDEF (retval )) {
610
+ if (Z_ISUNDEF (retval )) {
620
611
php_libxml_ctx_error (context ,
621
612
"Call to user entity loader callback '%s' has failed" ,
622
- Z_STRVAL ( fci -> function_name ));
613
+ ZSTR_VAL ( LIBXML ( entity_loader_callback ). function_handler -> common . function_name ));
623
614
} else {
624
- /*
625
- retval_ptr = *fci->retval_ptr_ptr;
626
- if (retval_ptr == NULL) {
627
- php_libxml_ctx_error(context,
628
- "Call to user entity loader callback '%s' has failed; "
629
- "probably it has thrown an exception",
630
- fci->function_name);
631
- } else */ if (Z_TYPE (retval ) == IS_STRING ) {
615
+ if (Z_TYPE (retval ) == IS_STRING ) {
632
616
is_string :
633
617
resource = Z_STRVAL (retval );
634
618
} else if (Z_TYPE (retval ) == IS_RESOURCE ) {
@@ -638,7 +622,7 @@ static xmlParserInputPtr _php_libxml_external_entity_loader(const char *URL,
638
622
php_libxml_ctx_error (context ,
639
623
"The user entity loader callback '%s' has returned a "
640
624
"resource, but it is not a stream" ,
641
- Z_STRVAL ( fci -> function_name ));
625
+ ZSTR_VAL ( LIBXML ( entity_loader_callback ). function_handler -> common . function_name ));
642
626
} else {
643
627
/* TODO: allow storing the encoding in the stream context? */
644
628
xmlCharEncoding enc = XML_CHAR_ENCODING_NONE ;
@@ -839,9 +823,9 @@ static PHP_RINIT_FUNCTION(libxml)
839
823
840
824
static PHP_RSHUTDOWN_FUNCTION (libxml )
841
825
{
842
- LIBXML (entity_loader ). fci . size = 0 ;
843
- zval_ptr_dtor_nogc (& LIBXML (entity_loader ). callback );
844
- ZVAL_NULL ( & LIBXML ( entity_loader ). callback );
826
+ if ( ZEND_FCC_INITIALIZED ( LIBXML (entity_loader_callback ))) {
827
+ zend_fcc_dtor (& LIBXML (entity_loader_callback ) );
828
+ }
845
829
846
830
return SUCCESS ;
847
831
}
@@ -1061,24 +1045,20 @@ PHP_FUNCTION(libxml_disable_entity_loader)
1061
1045
/* {{{ Changes the default external entity loader */
1062
1046
PHP_FUNCTION (libxml_set_external_entity_loader )
1063
1047
{
1064
- zval * callback ;
1065
1048
zend_fcall_info fci ;
1066
1049
zend_fcall_info_cache fcc ;
1067
1050
1068
1051
ZEND_PARSE_PARAMETERS_START (1 , 1 )
1069
- Z_PARAM_FUNC_OR_NULL_WITH_ZVAL (fci , fcc , callback )
1052
+ Z_PARAM_FUNC_OR_NULL (fci , fcc )
1070
1053
ZEND_PARSE_PARAMETERS_END ();
1071
1054
1072
- if (ZEND_FCI_INITIALIZED (fci )) { /* argument not null */
1073
- LIBXML (entity_loader ).fci = fci ;
1074
- LIBXML (entity_loader ).fcc = fcc ;
1075
- } else {
1076
- LIBXML (entity_loader ).fci .size = 0 ;
1055
+ /* Unset old callback if it's defined */
1056
+ if (ZEND_FCC_INITIALIZED (LIBXML (entity_loader_callback ))) {
1057
+ zend_fcc_dtor (& LIBXML (entity_loader_callback ));
1077
1058
}
1078
- if (! Z_ISNULL ( LIBXML ( entity_loader ). callback )) {
1079
- zval_ptr_dtor_nogc (& LIBXML (entity_loader ). callback );
1059
+ if (ZEND_FCI_INITIALIZED ( fci )) { /* argument not null */
1060
+ zend_fcc_dup (& LIBXML (entity_loader_callback ), & fcc );
1080
1061
}
1081
- ZVAL_COPY (& LIBXML (entity_loader ).callback , callback );
1082
1062
RETURN_TRUE ;
1083
1063
}
1084
1064
/* }}} */
@@ -1087,7 +1067,15 @@ PHP_FUNCTION(libxml_set_external_entity_loader)
1087
1067
PHP_FUNCTION (libxml_get_external_entity_loader )
1088
1068
{
1089
1069
ZEND_PARSE_PARAMETERS_NONE ();
1090
- RETURN_COPY (& LIBXML (entity_loader ).callback );
1070
+
1071
+ if (ZEND_FCC_INITIALIZED (LIBXML (entity_loader_callback ))) {
1072
+ zval tmp ;
1073
+ zend_get_callable_zval_from_fcc (& LIBXML (entity_loader_callback ), & tmp );
1074
+ RETVAL_COPY (& tmp );
1075
+ zval_ptr_dtor (& tmp );
1076
+ return ;
1077
+ }
1078
+ RETURN_NULL ();
1091
1079
}
1092
1080
/* }}} */
1093
1081
0 commit comments