Skip to content

Commit 0f51752

Browse files
committed
Fix few problems in passing argumets to FFI calls
1 parent dc9cc44 commit 0f51752

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

ext/opcache/jit/zend_jit_ir_ffi.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ static int zend_jit_ffi_send_val(zend_jit_ctx *jit,
123123
}
124124
ZEND_ASSERT(opline->op2.num > 0 && opline->op2.num <= TRACE_FRAME_NUM_ARGS(call));
125125

126+
if (op1_info & MAY_BE_REF) {
127+
op1_addr = jit_ZVAL_DEREF(jit, op1_addr);
128+
op1_info &= ~MAY_BE_REF;
129+
if (opline->op1_type & (IS_VAR|IS_TMP_VAR)) {
130+
// TODO: dtor ???
131+
}
132+
}
133+
126134
if (opline->op2.num - 1 < zend_hash_num_elements(type->func.args)) {
127135
type = zend_hash_index_find_ptr(type->func.args, opline->op2.num - 1);
128136
type = ZEND_FFI_TYPE(type);
@@ -241,9 +249,14 @@ static int zend_jit_ffi_send_val(zend_jit_ctx *jit,
241249
if (opline->op1_type & (IS_VAR|IS_TMP_VAR)) {
242250
arg_flags |= ZREG_FFI_ZVAL_DTOR;
243251
}
252+
} else if ((op1_info & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_NULL) {
253+
arg_type = IS_NULL;
254+
ref = IR_NULL;
244255
} else if (op1_ffi_type
245256
&& op1_ffi_type->kind == ZEND_FFI_TYPE_POINTER
246-
&& ZEND_FFI_TYPE(type->pointer.type) == ZEND_FFI_TYPE(op1_ffi_type->pointer.type)) {
257+
&& (ZEND_FFI_TYPE(type->pointer.type) == ZEND_FFI_TYPE(op1_ffi_type->pointer.type)
258+
|| zend_ffi_api->is_compatible_type(ZEND_FFI_TYPE(op1_ffi_type->pointer.type), ZEND_FFI_TYPE(type->pointer.type)))) {
259+
// TODO: guards ???
247260
arg_type = IS_OBJECT;
248261
ref = jit_Z_PTR(jit, op1_addr);
249262
arg_flags |= ZREG_FFI_PTR_LOAD;
@@ -252,7 +265,9 @@ static int zend_jit_ffi_send_val(zend_jit_ctx *jit,
252265
}
253266
} else if (op1_ffi_type
254267
&& op1_ffi_type->kind == ZEND_FFI_TYPE_ARRAY
255-
&& ZEND_FFI_TYPE(type->pointer.type) == ZEND_FFI_TYPE(op1_ffi_type->array.type)) {
268+
&& (ZEND_FFI_TYPE(type->pointer.type) == ZEND_FFI_TYPE(op1_ffi_type->array.type)
269+
|| zend_ffi_api->is_compatible_type(ZEND_FFI_TYPE(op1_ffi_type->pointer.type), ZEND_FFI_TYPE(type->pointer.type)))) {
270+
// TODO: guards ???
256271
arg_type = IS_OBJECT;
257272
ref = jit_Z_PTR(jit, op1_addr);
258273
if (opline->op1_type & (IS_VAR|IS_TMP_VAR)) {

0 commit comments

Comments
 (0)