Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
PHP 8.1: Dynamic functions are now sub-functions in op-arrays
  • Loading branch information
derickr committed Mar 4, 2021
1 parent 7987a00 commit f58762b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 33 additions & 1 deletion srm_oparray.c
Expand Up @@ -243,7 +243,9 @@ static const op_usage opcodes[] = {
/* 140 */ { "DECLARE_INHERITED_CLASS", ALL_USED },
#endif
/* 141 */ { "DECLARE_FUNCTION", ALL_USED },
#if PHP_VERSION_ID >= 70400
#if PHP_VERSION_ID >= 80100
/* 142 */ { "DECLARE_LAMBDA_FUNCTION", OP2_USED | OP2_INDEX | RES_USED },
#elif PHP_VERSION_ID >= 70400
/* 142 */ { "DECLARE_LAMBDA_FUNCTION", OP1_USED },
#else
/* 142 */ { "RAISE_ABSTRACT_ERROR", ALL_USED },
Expand Down Expand Up @@ -505,6 +507,9 @@ int vld_dump_znode (int *print_sep, unsigned int node_type, VLD_ZNODE node, unsi
case VLD_IS_OPLINE:
len += vld_printf (stderr, "->%d", VLD_ZNODE_JMP_LINE(node, opline, base_address));
break;
case VLD_IS_INDEX:
len += vld_printf (stderr, "[%d]", VLD_ZNODE_ELEM(node, var));
break;
case VLD_IS_CLASS:
#if PHP_VERSION_ID >= 70300
len += vld_dump_zval(*RT_CONSTANT((op_array->opcodes) + opline, node));
Expand Down Expand Up @@ -700,6 +705,9 @@ void vld_dump_op(int nr, zend_op * op_ptr, unsigned int base_address, int notdea
if (flags & OP2_OPNUM) {
op2_type = VLD_IS_OPNUM;
}
if (flags & OP2_INDEX) {
op2_type = VLD_IS_INDEX;
}
if (flags & OP1_CLASS) {
op1_type = VLD_IS_CLASS;
}
Expand Down Expand Up @@ -954,6 +962,30 @@ void vld_dump_oparray(zend_op_array *opa)

vld_set_free(set);
vld_branch_info_free(branch_info);

#if PHP_VERSION_ID >= 80100
if (!opa->num_dynamic_func_defs) {
return;
}
vld_printf(stderr, "\nDynamic Functions:\n");

for (i = 0; i < opa->num_dynamic_func_defs; i++) {
if (VLD_G(format)) {
vld_printf (stderr, "Dynamic Function:%s%d\n", VLD_G(col_sep), i);
} else {
vld_printf (stderr, "Dynamic Function %d\n", i);
}

vld_dump_oparray(opa->dynamic_func_defs[i]);

if (VLD_G(format)) {
vld_printf (stderr, "End of Dynamic Function:%s%d\n", VLD_G(col_sep), i);
} else {
vld_printf (stderr, "End of Dynamic Function %d\n", i);
}
vld_printf(stderr, "\n");
}
#endif
}

void opt_set_nop (zend_op_array *opa, int nr)
Expand Down
2 changes: 2 additions & 0 deletions srm_oparray.h
Expand Up @@ -44,6 +44,7 @@
#define OP1_CLASS 1<<11
#define RES_CLASS 1<<12
#define OP2_JMP_ARRAY 1<<13
#define OP2_INDEX 1<<14

#define SPECIAL 0xff

Expand All @@ -55,6 +56,7 @@
#define EXT_VAL_JMP_REL 1<<24
#define EXT_VAL_JMP_ABS 1<<25
#define VLD_IS_JMP_ARRAY 1<<26
#define VLD_IS_INDEX 1<<27

typedef struct _op_usage {
const char *name;
Expand Down

0 comments on commit f58762b

Please sign in to comment.