Skip to content

Commit b98e2e4

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 be82abb commit b98e2e4

6 files changed

Lines changed: 28 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;
@@ -702,7 +702,7 @@ static zend_op_array *zp_compile(zval *this_ptr, zend_function *function,
702702
uint32_t argc, zval *argv, zend_array *extra_named_params,
703703
const zend_array *named_positions,
704704
const zend_op_array *declaring_op_array,
705-
const zend_op *declaring_opline, void **cache_slot,
705+
const uint32_t *declaring_lineno_ptr, void **cache_slot,
706706
bool uses_variadic_placeholder) {
707707

708708
zend_op_array *op_array = NULL;
@@ -1012,10 +1012,10 @@ static zend_op_array *zp_compile(zval *this_ptr, zend_function *function,
10121012
}
10131013
#endif
10141014

1015-
zend_string *pfa_name = zp_pfa_name(declaring_op_array, declaring_opline);
1015+
zend_string *pfa_name = zp_pfa_name(declaring_op_array, declaring_lineno_ptr);
10161016

10171017
op_array = zend_accel_compile_pfa(closure_ast, declaring_op_array,
1018-
declaring_opline, function, pfa_name);
1018+
declaring_lineno_ptr, function, pfa_name);
10191019

10201020
zend_ast_destroy(closure_ast);
10211021

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

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

10541054
const zend_op_array *op_array = zend_accel_pfa_cache_get(declaring_op_array,
1055-
declaring_opline, function);
1055+
declaring_lineno_ptr, function);
10561056

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

@@ -1136,12 +1136,12 @@ void zend_partial_create(zval *result, zval *this_ptr, zend_function *function,
11361136
uint32_t argc, zval *argv, zend_array *extra_named_params,
11371137
const zend_array *named_positions,
11381138
const zend_op_array *declaring_op_array,
1139-
const zend_op *declaring_opline, void **cache_slot,
1139+
const uint32_t *declaring_lineno_ptr, void **cache_slot,
11401140
bool uses_variadic_placeholder) {
11411141

11421142
const zend_op_array *op_array = zp_get_op_array(this_ptr, function, argc, argv,
11431143
extra_named_params, named_positions,
1144-
declaring_op_array, declaring_opline,
1144+
declaring_op_array, declaring_lineno_ptr,
11451145
cache_slot, uses_variadic_placeholder);
11461146

11471147
if (UNEXPECTED(!op_array)) {

Zend/zend_partial.h

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

2222
BEGIN_EXTERN_C()
2323

24+
/* Create a partial application of 'function'
25+
* 'declaring_lineno_ptr' should be a pointer the zend_op.lineno or
26+
* zend_ast.lineno that declares the PFA. The address is used to build a cache
27+
* key. */
2428
void zend_partial_create(zval *result, zval *this_ptr, zend_function *function,
2529
uint32_t argc, zval *argv, zend_array *extra_named_params,
2630
const zend_array *named_positions,
2731
const zend_op_array *declaring_op_array,
28-
const zend_op *declaring_opline, void **cache_slot,
32+
const uint32_t *declaring_lineno_ptr, void **cache_slot,
2933
bool uses_variadic_placeholder);
3034

3135
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)