Skip to content

Commit

Permalink
Export zend_use_resource_as_offset()
Browse files Browse the repository at this point in the history
Use a common implementation to generate this error message, as
we do so in quite a few places dealing with array keys.
  • Loading branch information
nikic committed Aug 31, 2021
1 parent 7d6a7e7 commit 5b2ddf5
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -1987,7 +1987,7 @@ ZEND_API zend_result array_set_zval_key(HashTable *ht, zval *key, zval *value) /
result = zend_hash_update(ht, ZSTR_EMPTY_ALLOC(), value);
break;
case IS_RESOURCE:
zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(key), Z_RES_HANDLE_P(key));
zend_use_resource_as_offset(key);
result = zend_hash_index_update(ht, Z_RES_HANDLE_P(key), value);
break;
case IS_FALSE:
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -2164,7 +2164,7 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_cannot_add_element(vo
zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied");
}

static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_resource_as_offset(const zval *dim)
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_use_resource_as_offset(const zval *dim)
{
zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim));
}
Expand Down
1 change: 1 addition & 0 deletions Zend/zend_execute.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_missing_arg_error(zend_execute_data *
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_function(const zend_function *fbc);
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_false_to_array_deprecated(void);
ZEND_COLD void ZEND_FASTCALL zend_param_must_be_ref(const zend_function *func, uint32_t arg_num);
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_use_resource_as_offset(const zval *dim);

ZEND_API bool ZEND_FASTCALL zend_verify_ref_assignable_zval(zend_reference *ref, zval *zv, bool strict);
ZEND_API bool ZEND_FASTCALL zend_verify_prop_assignable_by_ref(zend_property_info *prop_info, zval *orig_val, bool strict);
Expand Down
10 changes: 5 additions & 5 deletions ext/opcache/jit/zend_jit_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_r_helper(zend_array *ht, zval *dim,
hval = zend_dval_to_lval_safe(Z_DVAL_P(dim));
goto num_index;
case IS_RESOURCE:
zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim));
zend_use_resource_as_offset(dim);
hval = Z_RES_HANDLE_P(dim);
goto num_index;
case IS_FALSE:
Expand Down Expand Up @@ -449,7 +449,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_is_helper(zend_array *ht, zval *dim
hval = zend_dval_to_lval_safe(Z_DVAL_P(dim));
goto num_index;
case IS_RESOURCE:
zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim));
zend_use_resource_as_offset(dim);
hval = Z_RES_HANDLE_P(dim);
goto num_index;
case IS_FALSE:
Expand Down Expand Up @@ -512,7 +512,7 @@ static int ZEND_FASTCALL zend_jit_fetch_dim_isset_helper(zend_array *ht, zval *d
hval = zend_dval_to_lval_safe(Z_DVAL_P(dim));
goto num_index;
case IS_RESOURCE:
zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim));
zend_use_resource_as_offset(dim);
hval = Z_RES_HANDLE_P(dim);
goto num_index;
case IS_FALSE:
Expand Down Expand Up @@ -579,7 +579,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *di
hval = zend_dval_to_lval_safe(Z_DVAL_P(dim));
goto num_index;
case IS_RESOURCE:
zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim));
zend_use_resource_as_offset(dim);
hval = Z_RES_HANDLE_P(dim);
goto num_index;
case IS_FALSE:
Expand Down Expand Up @@ -642,7 +642,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim
hval = zend_dval_to_lval_safe(Z_DVAL_P(dim));
goto num_index;
case IS_RESOURCE:
zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim));
zend_use_resource_as_offset(dim);
hval = Z_RES_HANDLE_P(dim);
goto num_index;
case IS_FALSE:
Expand Down
3 changes: 1 addition & 2 deletions ext/spl/spl_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ static zend_result get_hash_key(spl_hash_key *key, spl_array_object *intern, zva
}
return SUCCESS;
case IS_RESOURCE:
zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)",
Z_RES_P(offset)->handle, Z_RES_P(offset)->handle);
zend_use_resource_as_offset(offset);
key->key = NULL;
key->h = Z_RES_P(offset)->handle;
break;
Expand Down
3 changes: 1 addition & 2 deletions ext/spl/spl_fixedarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,7 @@ static zend_long spl_offset_convert_to_long(zval *offset) /* {{{ */
offset = Z_REFVAL_P(offset);
goto try_again;
case IS_RESOURCE:
zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)",
Z_RES_HANDLE_P(offset), Z_RES_HANDLE_P(offset));
zend_use_resource_as_offset(offset);
return Z_RES_HANDLE_P(offset);
}

Expand Down
2 changes: 1 addition & 1 deletion ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -6086,7 +6086,7 @@ PHP_FUNCTION(array_key_exists)
RETVAL_BOOL(zend_hash_index_exists(ht, 1));
break;
case IS_RESOURCE:
zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(key), Z_RES_HANDLE_P(key));
zend_use_resource_as_offset(key);
RETVAL_BOOL(zend_hash_index_exists(ht, Z_RES_HANDLE_P(key)));
break;
default:
Expand Down

0 comments on commit 5b2ddf5

Please sign in to comment.