Skip to content

Commit fb53ace

Browse files
committed
Update zend_vm_opcode_handler_t for SWITCH VM
1 parent ed49acd commit fb53ace

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

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.

Zend/zend_vm_gen.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ function gen_null_label($f, $kind, $prolog) {
11861186
out($f,$prolog."ZEND_NULL_HANDLER,\n");
11871187
break;
11881188
case ZEND_VM_KIND_SWITCH:
1189-
out($f,$prolog."(void*)(uintptr_t)-1,\n");
1189+
out($f,$prolog."-1,\n");
11901190
break;
11911191
case ZEND_VM_KIND_GOTO:
11921192
out($f,$prolog."(void*)&&ZEND_NULL_LABEL,\n");
@@ -1388,7 +1388,7 @@ function gen_labels($f, $spec, $kind, $prolog, &$specs, $switch_labels = array()
13881388
out($f,"$prolog{$spec_name}_HANDLER,\n");
13891389
break;
13901390
case ZEND_VM_KIND_SWITCH:
1391-
out($f,$prolog."(void*)(uintptr_t)$switch_labels[$spec_name],\n");
1391+
out($f,$prolog."$switch_labels[$spec_name],\n");
13921392
break;
13931393
case ZEND_VM_KIND_GOTO:
13941394
out($f,$prolog."(void*)&&{$spec_name}_LABEL,\n");
@@ -1436,7 +1436,7 @@ function gen_labels($f, $spec, $kind, $prolog, &$specs, $switch_labels = array()
14361436
out($f,$prolog."ZEND_NULL_HANDLER,\n");
14371437
break;
14381438
case ZEND_VM_KIND_SWITCH:
1439-
out($f,$prolog."(void*)(uintptr_t)-1,\n");
1439+
out($f,$prolog."-1,\n");
14401440
break;
14411441
case ZEND_VM_KIND_GOTO:
14421442
out($f,$prolog."(void*)&&ZEND_NULL_LABEL,\n");
@@ -1467,7 +1467,7 @@ function gen_labels($f, $spec, $kind, $prolog, &$specs, $switch_labels = array()
14671467
out($f,$prolog.$dsc["op"]."_HANDLER,\n");
14681468
break;
14691469
case ZEND_VM_KIND_SWITCH:
1470-
out($f,$prolog."(void*)(uintptr_t)".((string)$num).",\n");
1470+
out($f,$prolog.((string)$num).",\n");
14711471
break;
14721472
case ZEND_VM_KIND_GOTO:
14731473
out($f,$prolog."(void*)&&".$dsc["op"]."_LABEL,\n");
@@ -1480,7 +1480,7 @@ function gen_labels($f, $spec, $kind, $prolog, &$specs, $switch_labels = array()
14801480
out($f,$prolog."ZEND_NULL_HANDLER,\n");
14811481
break;
14821482
case ZEND_VM_KIND_SWITCH:
1483-
out($f,$prolog."(void*)(uintptr_t)-1,\n");
1483+
out($f,$prolog."-1,\n");
14841484
break;
14851485
case ZEND_VM_KIND_GOTO:
14861486
out($f,$prolog."(void*)&&ZEND_NULL_LABEL,\n");
@@ -1497,7 +1497,7 @@ function gen_labels($f, $spec, $kind, $prolog, &$specs, $switch_labels = array()
14971497
out($f,$prolog."ZEND_NULL_HANDLER\n");
14981498
break;
14991499
case ZEND_VM_KIND_SWITCH:
1500-
out($f,$prolog."(void*)(uintptr_t)-1\n");
1500+
out($f,$prolog."-1\n");
15011501
break;
15021502
case ZEND_VM_KIND_GOTO:
15031503
out($f,$prolog."(void*)&&ZEND_NULL_LABEL\n");
@@ -1822,7 +1822,7 @@ function gen_executor($f, $skl, $spec, $kind, $executor_name, $initializer_name)
18221822
out($f,"#endif\n");
18231823
}
18241824
out($f,"#if (ZEND_VM_KIND != ZEND_VM_KIND_HYBRID) || !ZEND_VM_SPEC\n");
1825-
out($f,"static const void *zend_vm_get_opcode_handler(uint8_t opcode, const zend_op* op);\n");
1825+
out($f,"static zend_vm_opcode_handler_t zend_vm_get_opcode_handler(uint8_t opcode, const zend_op* op);\n");
18261826
out($f,"#endif\n\n");
18271827
if ($kind == ZEND_VM_KIND_HYBRID) {
18281828
out($f,"#if (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)\n");
@@ -2040,7 +2040,7 @@ function gen_executor($f, $skl, $spec, $kind, $executor_name, $initializer_name)
20402040
break;
20412041
case "HELPER_VARS":
20422042
if ($kind == ZEND_VM_KIND_SWITCH) {
2043-
out($f,$m[1]."const void *dispatch_handler;\n");
2043+
out($f,$m[1]."zend_vm_opcode_handler_t dispatch_handler;\n");
20442044
}
20452045
if ($kind != ZEND_VM_KIND_CALL && count($params)) {
20462046
if ($kind == ZEND_VM_KIND_HYBRID) {
@@ -2098,7 +2098,7 @@ function gen_executor($f, $skl, $spec, $kind, $executor_name, $initializer_name)
20982098
gen_labels($f, $spec, ($kind == ZEND_VM_KIND_HYBRID) ? ZEND_VM_KIND_GOTO : $kind, $prolog."\t\t", $specs);
20992099
out($f,$prolog."\t};\n");
21002100
out($f,$prolog."\tzend_opcode_handlers = (zend_vm_opcode_handler_t*) labels;\n");
2101-
out($f,$prolog."\tzend_handlers_count = sizeof(labels) / sizeof(void*);\n");
2101+
out($f,$prolog."\tzend_handlers_count = sizeof(labels) / sizeof(labels[0]);\n");
21022102
if ($kind == ZEND_VM_KIND_HYBRID) {
21032103
out($f,$prolog."\tmemset(&hybrid_halt_op, 0, sizeof(hybrid_halt_op));\n");
21042104
out($f,$prolog."\thybrid_halt_op.handler = (void*)&&HYBRID_HALT_LABEL;\n");
@@ -2230,7 +2230,7 @@ function gen_executor($f, $skl, $spec, $kind, $executor_name, $initializer_name)
22302230
out($f,"#else\n");
22312231
}
22322232
out($f,$prolog."zend_opcode_handlers = labels;\n");
2233-
out($f,$prolog."zend_handlers_count = sizeof(labels) / sizeof(void*);\n");
2233+
out($f,$prolog."zend_handlers_count = sizeof(labels) / sizeof(labels[0]);\n");
22342234
out($f,$prolog."zend_spec_handlers = specs;\n");
22352235
if ($kind == ZEND_VM_KIND_HYBRID) {
22362236
out($f,"#endif\n");
@@ -2369,9 +2369,12 @@ function gen_vm_opcodes_header(
23692369
$str .= "#elif ZEND_VM_KIND == ZEND_VM_KIND_CALL\n";
23702370
$str .= "typedef const struct _zend_op *(ZEND_FASTCALL *zend_vm_opcode_handler_t)(struct _zend_execute_data *execute_data, const struct _zend_op *opline);\n";
23712371
$str .= "typedef const struct _zend_op *(ZEND_FASTCALL *zend_vm_opcode_handler_func_t)(struct _zend_execute_data *execute_data, const struct _zend_op *opline);\n";
2372-
$str .= "#else\n";
2372+
$str .= "#elif ZEND_VM_KIND == ZEND_VM_KIND_SWITCH\n";
2373+
$str .= "typedef int zend_vm_opcode_handler_t;\n";
2374+
$str .= "#elif ZEND_VM_KIND == ZEND_VM_KIND_GOTO\n";
23732375
$str .= "typedef const void* zend_vm_opcode_handler_t;\n";
2374-
$str .= "typedef const void* zend_vm_opcode_handler_func_t;\n";
2376+
$str .= "#else\n";
2377+
$str .= "# error\n";
23752378
$str .= "#endif\n";
23762379
$str .= "\n";
23772380
foreach ($vm_op_flags as $name => $val) {
@@ -2855,7 +2858,7 @@ function gen_vm($def, $skel) {
28552858
}
28562859
out($f, "}\n\n");
28572860
out($f, "#if (ZEND_VM_KIND != ZEND_VM_KIND_HYBRID) || !ZEND_VM_SPEC\n");
2858-
out($f, "static const void *zend_vm_get_opcode_handler(uint8_t opcode, const zend_op* op)\n");
2861+
out($f, "static zend_vm_opcode_handler_t zend_vm_get_opcode_handler(uint8_t opcode, const zend_op* op)\n");
28592862
out($f, "{\n");
28602863
if (!ZEND_VM_SPEC) {
28612864
out($f, "\treturn zend_opcode_handlers[zend_vm_get_opcode_handler_idx(opcode, op)];\n");

Zend/zend_vm_opcodes.h

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

0 commit comments

Comments
 (0)