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 ,
@@ -701,9 +659,9 @@ static uint32_t zp_compute_num_required(const zend_function *function,
701659static zend_op_array * zp_compile (zval * this_ptr , zend_function * function ,
702660 uint32_t argc , zval * argv , zend_array * extra_named_params ,
703661 const zend_array * named_positions ,
704- const zend_op_array * declaring_op_array ,
662+ zend_string * declaring_filename ,
705663 const uint32_t * declaring_lineno_ptr , void * * cache_slot ,
706- bool uses_variadic_placeholder ) {
664+ zend_string * pfa_name , uint32_t flags ) {
707665
708666 zend_op_array * op_array = NULL ;
709667
@@ -713,6 +671,8 @@ static zend_op_array *zp_compile(zval *this_ptr, zend_function *function,
713671 return NULL ;
714672 }
715673
674+ bool uses_variadic_placeholder = flags & ZEND_PARTIAL_USES_VARIADIC_PLACEHOLDER ;
675+
716676 if (UNEXPECTED (zp_args_check (function , argc , argv , extra_named_params , uses_variadic_placeholder ) != SUCCESS )) {
717677 ZEND_ASSERT (EG (exception ));
718678 return NULL ;
@@ -1012,10 +972,8 @@ static zend_op_array *zp_compile(zval *this_ptr, zend_function *function,
1012972 }
1013973#endif
1014974
1015- zend_string * pfa_name = zp_pfa_name (declaring_op_array , declaring_lineno_ptr );
1016-
1017- op_array = zend_accel_compile_pfa (closure_ast , declaring_op_array ,
1018- declaring_lineno_ptr , function , pfa_name );
975+ op_array = zend_accel_compile_pfa (closure_ast , declaring_filename ,
976+ declaring_lineno_ptr , function , pfa_name , flags & ZEND_PARTIAL_CACHEABLE_IN_SHM );
1019977
1020978 zend_ast_destroy (closure_ast );
1021979
@@ -1040,9 +998,9 @@ static zend_op_array *zp_compile(zval *this_ptr, zend_function *function,
1040998static const zend_op_array * zp_get_op_array (zval * this_ptr , zend_function * function ,
1041999 uint32_t argc , zval * argv , zend_array * extra_named_params ,
10421000 const zend_array * named_positions ,
1043- const zend_op_array * declaring_op_array ,
1001+ zend_string * declaring_filename ,
10441002 const uint32_t * declaring_lineno_ptr , void * * cache_slot ,
1045- bool uses_variadic_placeholder ) {
1003+ zend_string * pfa_name , uint32_t flags ) {
10461004
10471005 if (EXPECTED (function -> type == ZEND_INTERNAL_FUNCTION
10481006 ? cache_slot [0 ] == function
@@ -1051,13 +1009,13 @@ static const zend_op_array *zp_get_op_array(zval *this_ptr, zend_function *funct
10511009 return cache_slot [1 ];
10521010 }
10531011
1054- const zend_op_array * op_array = zend_accel_pfa_cache_get (declaring_op_array ,
1055- declaring_lineno_ptr , function );
1012+ const zend_op_array * op_array = zend_accel_pfa_cache_get (declaring_lineno_ptr , function ,
1013+ flags & ZEND_PARTIAL_CACHEABLE_IN_SHM );
10561014
10571015 if (UNEXPECTED (!op_array )) {
10581016 op_array = zp_compile (this_ptr , function , argc , argv ,
1059- extra_named_params , named_positions , declaring_op_array , declaring_lineno_ptr ,
1060- cache_slot , uses_variadic_placeholder );
1017+ extra_named_params , named_positions , declaring_filename , declaring_lineno_ptr ,
1018+ cache_slot , pfa_name , flags );
10611019 }
10621020
10631021 if (EXPECTED (op_array ) && !(function -> common .fn_flags & ZEND_ACC_NEVER_CACHE )) {
@@ -1135,14 +1093,16 @@ static void zp_bind(zval *result, zend_function *function, uint32_t argc, zval *
11351093void zend_partial_create (zval * result , zval * this_ptr , zend_function * function ,
11361094 uint32_t argc , zval * argv , zend_array * extra_named_params ,
11371095 const zend_array * named_positions ,
1138- const zend_op_array * declaring_op_array ,
1096+ zend_string * declaring_filename ,
11391097 const uint32_t * declaring_lineno_ptr , void * * cache_slot ,
1140- bool uses_variadic_placeholder ) {
1098+ zend_string * pfa_name , uint32_t flags ) {
1099+
1100+ ZEND_ASSERT (pfa_name );
11411101
11421102 const zend_op_array * op_array = zp_get_op_array (this_ptr , function , argc , argv ,
11431103 extra_named_params , named_positions ,
1144- declaring_op_array , declaring_lineno_ptr ,
1145- cache_slot , uses_variadic_placeholder );
1104+ declaring_filename , declaring_lineno_ptr ,
1105+ cache_slot , pfa_name , flags );
11461106
11471107 if (UNEXPECTED (!op_array )) {
11481108 ZEND_ASSERT (EG (exception ));
0 commit comments