5151#include "zend_closures.h"
5252#include "zend_attributes.h"
5353#include "zend_exceptions.h"
54+ #include "zend_partial.h"
5455#include "ext/opcache/ZendAccelerator.h"
5556
5657static zend_always_inline bool Z_IS_PLACEHOLDER_P (const zval * p ) {
@@ -502,49 +503,6 @@ static zend_ast *zp_param_attributes_to_ast(zend_function *function,
502503 return attributes_ast ;
503504}
504505
505- static zend_string * zp_pfa_name (const zend_op_array * declaring_op_array ,
506- const uint32_t * declaring_lineno_ptr )
507- {
508- /* We attempt to generate a name that hints at where the PFA was created,
509- * similarly to Closures (GH-13550).
510- * We do not attempt to make the name unique. */
511-
512- zend_string * filename = declaring_op_array -> filename ;
513- uint32_t start_lineno = * declaring_lineno_ptr ;
514-
515- zend_string * class = zend_empty_string ;
516- zend_string * separator = zend_empty_string ;
517- zend_string * function = filename ;
518- const char * parens = "" ;
519-
520- if (declaring_op_array -> function_name ) {
521- function = declaring_op_array -> function_name ;
522- if (declaring_op_array -> fn_flags & ZEND_ACC_CLOSURE ) {
523- /* If the parent function is a closure, don't redundantly
524- * add the classname and parentheses. */
525- } else {
526- parens = "()" ;
527-
528- if (declaring_op_array -> scope && declaring_op_array -> scope -> name ) {
529- class = declaring_op_array -> scope -> name ;
530- separator = ZSTR_KNOWN (ZEND_STR_PAAMAYIM_NEKUDOTAYIM );
531- }
532- }
533- }
534-
535- zend_string * name = zend_strpprintf_unchecked (
536- 0 ,
537- "{closure:pfa:%S%S%S%s:%" PRIu32 "}" ,
538- class ,
539- separator ,
540- function ,
541- parens ,
542- start_lineno
543- );
544-
545- return name ;
546- }
547-
548506/* Generate the AST for calling the actual function */
549507static zend_ast * zp_compile_forwarding_call (
550508 zval * this_ptr , zend_function * function ,
@@ -700,9 +658,9 @@ static uint32_t zp_compute_num_required(const zend_function *function,
700658static zend_op_array * zp_compile (zval * this_ptr , zend_function * function ,
701659 uint32_t argc , zval * argv , zend_array * extra_named_params ,
702660 const zend_array * named_positions ,
703- const zend_op_array * declaring_op_array ,
661+ zend_string * declaring_filename ,
704662 const uint32_t * declaring_lineno_ptr , void * * cache_slot ,
705- bool uses_variadic_placeholder ) {
663+ zend_string * pfa_name , uint32_t flags ) {
706664
707665 zend_op_array * op_array = NULL ;
708666
@@ -712,6 +670,8 @@ static zend_op_array *zp_compile(zval *this_ptr, zend_function *function,
712670 return NULL ;
713671 }
714672
673+ bool uses_variadic_placeholder = flags & ZEND_PARTIAL_USES_VARIADIC_PLACEHOLDER ;
674+
715675 if (UNEXPECTED (zp_args_check (function , argc , argv , extra_named_params , uses_variadic_placeholder ) != SUCCESS )) {
716676 ZEND_ASSERT (EG (exception ));
717677 return NULL ;
@@ -1011,10 +971,8 @@ static zend_op_array *zp_compile(zval *this_ptr, zend_function *function,
1011971 }
1012972#endif
1013973
1014- zend_string * pfa_name = zp_pfa_name (declaring_op_array , declaring_lineno_ptr );
1015-
1016- op_array = zend_accel_compile_pfa (closure_ast , declaring_op_array ,
1017- declaring_lineno_ptr , function , pfa_name );
974+ op_array = zend_accel_compile_pfa (closure_ast , declaring_filename ,
975+ declaring_lineno_ptr , function , pfa_name , flags & ZEND_PARTIAL_CACHEABLE_IN_SHM );
1018976
1019977 zend_ast_destroy (closure_ast );
1020978
@@ -1039,9 +997,9 @@ static zend_op_array *zp_compile(zval *this_ptr, zend_function *function,
1039997static const zend_op_array * zp_get_op_array (zval * this_ptr , zend_function * function ,
1040998 uint32_t argc , zval * argv , zend_array * extra_named_params ,
1041999 const zend_array * named_positions ,
1042- const zend_op_array * declaring_op_array ,
1000+ zend_string * declaring_filename ,
10431001 const uint32_t * declaring_lineno_ptr , void * * cache_slot ,
1044- bool uses_variadic_placeholder ) {
1002+ zend_string * pfa_name , uint32_t flags ) {
10451003
10461004 if (EXPECTED (function -> type == ZEND_INTERNAL_FUNCTION
10471005 ? cache_slot [0 ] == function
@@ -1050,13 +1008,13 @@ static const zend_op_array *zp_get_op_array(zval *this_ptr, zend_function *funct
10501008 return cache_slot [1 ];
10511009 }
10521010
1053- const zend_op_array * op_array = zend_accel_pfa_cache_get (declaring_op_array ,
1054- declaring_lineno_ptr , function );
1011+ const zend_op_array * op_array = zend_accel_pfa_cache_get (declaring_lineno_ptr , function ,
1012+ flags & ZEND_PARTIAL_CACHEABLE_IN_SHM );
10551013
10561014 if (UNEXPECTED (!op_array )) {
10571015 op_array = zp_compile (this_ptr , function , argc , argv ,
1058- extra_named_params , named_positions , declaring_op_array , declaring_lineno_ptr ,
1059- cache_slot , uses_variadic_placeholder );
1016+ extra_named_params , named_positions , declaring_filename , declaring_lineno_ptr ,
1017+ cache_slot , pfa_name , flags );
10601018 }
10611019
10621020 if (EXPECTED (op_array ) && !(function -> common .fn_flags & ZEND_ACC_NEVER_CACHE )) {
@@ -1120,14 +1078,16 @@ static void zp_bind(zval *result, zend_function *function, uint32_t argc, zval *
11201078void zend_partial_create (zval * result , zval * this_ptr , zend_function * function ,
11211079 uint32_t argc , zval * argv , zend_array * extra_named_params ,
11221080 const zend_array * named_positions ,
1123- const zend_op_array * declaring_op_array ,
1081+ zend_string * declaring_filename ,
11241082 const uint32_t * declaring_lineno_ptr , void * * cache_slot ,
1125- bool uses_variadic_placeholder ) {
1083+ zend_string * pfa_name , uint32_t flags ) {
1084+
1085+ ZEND_ASSERT (pfa_name );
11261086
11271087 const zend_op_array * op_array = zp_get_op_array (this_ptr , function , argc , argv ,
11281088 extra_named_params , named_positions ,
1129- declaring_op_array , declaring_lineno_ptr ,
1130- cache_slot , uses_variadic_placeholder );
1089+ declaring_filename , declaring_lineno_ptr ,
1090+ cache_slot , pfa_name , flags );
11311091
11321092 if (UNEXPECTED (!op_array )) {
11331093 ZEND_ASSERT (EG (exception ));
0 commit comments