mirror of
https://github.com/php/php-src.git
synced 2025-01-23 04:04:16 +08:00
add FFI::isNull() to check whether a FFI\CData is a null pointer
This commit is contained in:
parent
ea92b9b655
commit
f6ff7eb335
@ -4361,6 +4361,35 @@ ZEND_METHOD(FFI, string) /* {{{ */
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
ZEND_METHOD(FFI, isNull) /* {{{ */
|
||||
{
|
||||
zval *zv;
|
||||
zend_ffi_type *type;
|
||||
void *ptr = NULL;
|
||||
|
||||
ZEND_FFI_VALIDATE_API_RESTRICTION();
|
||||
ZEND_PARSE_PARAMETERS_START(1, 1)
|
||||
Z_PARAM_ZVAL(zv);
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
ZVAL_DEREF(zv);
|
||||
if (Z_TYPE_P(zv) == IS_OBJECT && Z_OBJCE_P(zv) == zend_ffi_cdata_ce) {
|
||||
zend_ffi_cdata *cdata = (zend_ffi_cdata*)Z_OBJ_P(zv);
|
||||
type = ZEND_FFI_TYPE(cdata->type);
|
||||
ptr = cdata->ptr;
|
||||
} else {
|
||||
zend_wrong_parameter_class_error(1, "FFI\\CData", zv);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type->kind != ZEND_FFI_TYPE_POINTER){
|
||||
zend_throw_error(zend_ffi_exception_ce, "FFI\\Cdata is not a pointer");
|
||||
}
|
||||
|
||||
RETURN_BOOL(*(void**)ptr == NULL);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_func_cdef, 0, 0, 0)
|
||||
ZEND_ARG_INFO(0, code)
|
||||
ZEND_ARG_INFO(0, lib)
|
||||
@ -4437,6 +4466,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_func_string, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, size)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_func_isnull, 0, 0, 1)
|
||||
ZEND_ARG_INFO(ZEND_SEND_PREFER_REF, ptr)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
static const zend_function_entry zend_ffi_functions[] = {
|
||||
ZEND_ME(FFI, cdef, arginfo_func_cdef, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
|
||||
ZEND_ME(FFI, load, arginfo_func_load, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
|
||||
@ -4454,6 +4487,7 @@ static const zend_function_entry zend_ffi_functions[] = {
|
||||
ZEND_ME(FFI, memcmp, arginfo_func_memcmp, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
|
||||
ZEND_ME(FFI, memset, arginfo_func_memset, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
|
||||
ZEND_ME(FFI, string, arginfo_func_string, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
|
||||
ZEND_ME(FFI, isNull, arginfo_func_isnull, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
|
||||
ZEND_FE_END
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user