Skip to content

Commit ba99bcb

Browse files
committed
Use a pointer to the declaring opline->lineno as unique addr, instead of the declaring opline itself
This makes the API compatible with creating partials from AST: We can pass &ast->lineno to zend_partial_create()
1 parent f5efdc6 commit ba99bcb

6 files changed

Lines changed: 27 additions & 24 deletions

File tree

Zend/zend_partial.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -503,14 +503,14 @@ static zend_ast *zp_param_attributes_to_ast(zend_function *function,
503503
}
504504

505505
static zend_string *zp_pfa_name(const zend_op_array *declaring_op_array,
506-
const zend_op *declaring_opline)
506+
const uint32_t *declaring_lineno_ptr)
507507
{
508508
/* We attempt to generate a name that hints at where the PFA was created,
509509
* similarly to Closures (GH-13550).
510510
* We do not attempt to make the name unique. */
511511

512512
zend_string *filename = declaring_op_array->filename;
513-
uint32_t start_lineno = declaring_opline->lineno;
513+
uint32_t start_lineno = *declaring_lineno_ptr;
514514

515515
zend_string *class = zend_empty_string;
516516
zend_string *separator = zend_empty_string;
@@ -701,7 +701,7 @@ static zend_op_array *zp_compile(zval *this_ptr, zend_function *function,
701701
uint32_t argc, zval *argv, zend_array *extra_named_params,
702702
const zend_array *named_positions,
703703
const zend_op_array *declaring_op_array,
704-
const zend_op *declaring_opline, void **cache_slot,
704+
const uint32_t *declaring_lineno_ptr, void **cache_slot,
705705
bool uses_variadic_placeholder) {
706706

707707
zend_op_array *op_array = NULL;
@@ -1011,10 +1011,10 @@ static zend_op_array *zp_compile(zval *this_ptr, zend_function *function,
10111011
}
10121012
#endif
10131013

1014-
zend_string *pfa_name = zp_pfa_name(declaring_op_array, declaring_opline);
1014+
zend_string *pfa_name = zp_pfa_name(declaring_op_array, declaring_lineno_ptr);
10151015

10161016
op_array = zend_accel_compile_pfa(closure_ast, declaring_op_array,
1017-
declaring_opline, function, pfa_name);
1017+
declaring_lineno_ptr, function, pfa_name);
10181018

10191019
zend_ast_destroy(closure_ast);
10201020

@@ -1040,7 +1040,7 @@ static const zend_op_array *zp_get_op_array(zval *this_ptr, zend_function *funct
10401040
uint32_t argc, zval *argv, zend_array *extra_named_params,
10411041
const zend_array *named_positions,
10421042
const zend_op_array *declaring_op_array,
1043-
const zend_op *declaring_opline, void **cache_slot,
1043+
const uint32_t *declaring_lineno_ptr, void **cache_slot,
10441044
bool uses_variadic_placeholder) {
10451045

10461046
if (EXPECTED(function->type == ZEND_INTERNAL_FUNCTION
@@ -1051,11 +1051,11 @@ static const zend_op_array *zp_get_op_array(zval *this_ptr, zend_function *funct
10511051
}
10521052

10531053
const zend_op_array *op_array = zend_accel_pfa_cache_get(declaring_op_array,
1054-
declaring_opline, function);
1054+
declaring_lineno_ptr, function);
10551055

10561056
if (UNEXPECTED(!op_array)) {
10571057
op_array = zp_compile(this_ptr, function, argc, argv,
1058-
extra_named_params, named_positions, declaring_op_array, declaring_opline,
1058+
extra_named_params, named_positions, declaring_op_array, declaring_lineno_ptr,
10591059
cache_slot, uses_variadic_placeholder);
10601060
}
10611061

@@ -1121,12 +1121,12 @@ void zend_partial_create(zval *result, zval *this_ptr, zend_function *function,
11211121
uint32_t argc, zval *argv, zend_array *extra_named_params,
11221122
const zend_array *named_positions,
11231123
const zend_op_array *declaring_op_array,
1124-
const zend_op *declaring_opline, void **cache_slot,
1124+
const uint32_t *declaring_lineno_ptr, void **cache_slot,
11251125
bool uses_variadic_placeholder) {
11261126

11271127
const zend_op_array *op_array = zp_get_op_array(this_ptr, function, argc, argv,
11281128
extra_named_params, named_positions,
1129-
declaring_op_array, declaring_opline,
1129+
declaring_op_array, declaring_lineno_ptr,
11301130
cache_slot, uses_variadic_placeholder);
11311131

11321132
if (UNEXPECTED(!op_array)) {

Zend/zend_partial.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121

2222
BEGIN_EXTERN_C()
2323

24+
/* Create a partial application of 'function'
25+
* 'declaring_op_array' and 'declaring_lineno_ptr' are used to build a cache key.
26+
* The latter should be a pointer to a zend_op.lineno or a zend_ast.lineno. */
2427
void zend_partial_create(zval *result, zval *this_ptr, zend_function *function,
2528
uint32_t argc, zval *argv, zend_array *extra_named_params,
2629
const zend_array *named_positions,
2730
const zend_op_array *declaring_op_array,
28-
const zend_op *declaring_opline, void **cache_slot,
31+
const uint32_t *declaring_lineno_ptr, void **cache_slot,
2932
bool uses_variadic_placeholder);
3033

3134
void zend_partial_op_array_dtor(zval *pDest);

Zend/zend_vm_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9881,7 +9881,7 @@ ZEND_VM_HANDLER(212, ZEND_CALLABLE_CONVERT_PARTIAL, CACHE_SLOT, CONST|UNUSED, NU
98819881
(ZEND_CALL_INFO(call) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) ?
98829882
call->extra_named_params : NULL,
98839883
OP2_TYPE == IS_CONST ? Z_ARRVAL_P(named_positions) : NULL,
9884-
&EX(func)->op_array, opline, cache_slot,
9884+
&EX(func)->op_array, &opline->lineno, cache_slot,
98859885
opline->extended_value & ZEND_FCALL_USES_VARIADIC_PLACEHOLDER);
98869886

98879887
if (ZEND_CALL_INFO(call) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) {

Zend/zend_vm_execute.h

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/opcache/ZendAccelerator.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,15 +2024,15 @@ static char *zend_accel_uintptr_hex(char *dest, uintptr_t n)
20242024
* a scheme, except file:// and phar://. */
20252025
#define PFA_KEY_PREFIX "pfa://"
20262026

2027-
static zend_string *zend_accel_pfa_key(const zend_op *declaring_opline,
2027+
static zend_string *zend_accel_pfa_key(const uint32_t *declaring_lineno_ptr,
20282028
const zend_function *called_function)
20292029
{
20302030
const size_t max_key_len = strlen(PFA_KEY_PREFIX) + (sizeof(uintptr_t)*2) + strlen(":") + (sizeof(uintptr_t)*2);
20312031
zend_string *key = zend_string_alloc(max_key_len, 0);
20322032

20332033
char *dest = ZSTR_VAL(key);
20342034
dest = zend_mempcpy(dest, PFA_KEY_PREFIX, strlen(PFA_KEY_PREFIX));
2035-
dest = zend_accel_uintptr_hex(dest, (uintptr_t)declaring_opline);
2035+
dest = zend_accel_uintptr_hex(dest, (uintptr_t)declaring_lineno_ptr);
20362036
*dest++ = ':';
20372037

20382038
const void *ptr;
@@ -2055,9 +2055,9 @@ static zend_string *zend_accel_pfa_key(const zend_op *declaring_opline,
20552055
}
20562056

20572057
const zend_op_array *zend_accel_pfa_cache_get(const zend_op_array *declaring_op_array,
2058-
const zend_op *declaring_opline, const zend_function *called_function)
2058+
const uint32_t *declaring_lineno_ptr, const zend_function *called_function)
20592059
{
2060-
zend_string *key = zend_accel_pfa_key(declaring_opline, called_function);
2060+
zend_string *key = zend_accel_pfa_key(declaring_lineno_ptr, called_function);
20612061
zend_op_array *op_array = NULL;
20622062

20632063
/* A PFA is SHM-cacheable if the declaring_op_array and called_function are
@@ -2085,7 +2085,7 @@ const zend_op_array *zend_accel_pfa_cache_get(const zend_op_array *declaring_op_
20852085

20862086
zend_op_array *zend_accel_compile_pfa(zend_ast *ast,
20872087
const zend_op_array *declaring_op_array,
2088-
const zend_op *declaring_opline,
2088+
const uint32_t *declaring_lineno_ptr,
20892089
const zend_function *called_function,
20902090
zend_string *pfa_func_name)
20912091
{
@@ -2121,7 +2121,7 @@ zend_op_array *zend_accel_compile_pfa(zend_ast *ast,
21212121
zend_string_release(op_array->dynamic_func_defs[0]->function_name);
21222122
op_array->dynamic_func_defs[0]->function_name = pfa_func_name;
21232123

2124-
zend_string *key = zend_accel_pfa_key(declaring_opline, called_function);
2124+
zend_string *key = zend_accel_pfa_key(declaring_lineno_ptr, called_function);
21252125

21262126
/* Cache op_array only if the declaring op_array and the called function
21272127
* are cached */

ext/opcache/ZendAccelerator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,12 @@ zend_string* ZEND_FASTCALL accel_new_interned_string(zend_string *str);
335335
uint32_t zend_accel_get_class_name_map_ptr(zend_string *type_name);
336336

337337
const zend_op_array *zend_accel_pfa_cache_get(const zend_op_array *declaring_op_array,
338-
const zend_op *declaring_opline,
338+
const uint32_t *declaring_lineno_ptr,
339339
const zend_function *called_function);
340340

341341
zend_op_array *zend_accel_compile_pfa(zend_ast *ast,
342342
const zend_op_array *declaring_op_array,
343-
const zend_op *declaring_opline,
343+
const uint32_t *declaring_lineno_ptr,
344344
const zend_function *called_function,
345345
zend_string *pfa_func_name);
346346

0 commit comments

Comments
 (0)