diff options
author | Dmitry Stogov <dmitry@zend.com> | 2019-09-10 11:23:12 +0300 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2019-09-10 11:23:12 +0300 |
commit | 21c3cdf66824a0522779fa252a675173d02dc724 (patch) | |
tree | 2608e040d7d5e0a43b85c4a36c4b56a95a3a8948 | |
parent | 825dac1445144e9c78dc74782eefecc8979f02cc (diff) | |
download | php-git-21c3cdf66824a0522779fa252a675173d02dc724.tar.gz |
NEWS entry, test and minor cleanup for FFI::isNull()
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | ext/ffi/ffi.c | 14 | ||||
-rw-r--r-- | ext/ffi/tests/045.phpt | 29 |
3 files changed, 37 insertions, 7 deletions
@@ -3,6 +3,7 @@ PHP NEWS ?? ??? ????, PHP 7.4.0RC2 - FFI: + . Added missing FFI::isNull(). (Philip Hofstetter) . Fixed bug #78488 (OOB in ZEND_FUNCTION(ffi_trampoline)). (Dmitry) - Opcache: diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index 83838ae6a1..1d6f84b6b2 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -4364,8 +4364,8 @@ ZEND_METHOD(FFI, string) /* {{{ */ ZEND_METHOD(FFI, isNull) /* {{{ */ { zval *zv; + zend_ffi_cdata *cdata; zend_ffi_type *type; - void *ptr = NULL; ZEND_FFI_VALIDATE_API_RESTRICTION(); ZEND_PARSE_PARAMETERS_START(1, 1) @@ -4373,20 +4373,20 @@ ZEND_METHOD(FFI, isNull) /* {{{ */ 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 { + if (Z_TYPE_P(zv) != IS_OBJECT || Z_OBJCE_P(zv) != zend_ffi_cdata_ce) { zend_wrong_parameter_class_error(1, "FFI\\CData", zv); return; } + cdata = (zend_ffi_cdata*)Z_OBJ_P(zv); + type = ZEND_FFI_TYPE(cdata->type); + if (type->kind != ZEND_FFI_TYPE_POINTER){ zend_throw_error(zend_ffi_exception_ce, "FFI\\Cdata is not a pointer"); + return; } - RETURN_BOOL(*(void**)ptr == NULL); + RETURN_BOOL(*(void**)cdata->ptr == NULL); } /* }}} */ diff --git a/ext/ffi/tests/045.phpt b/ext/ffi/tests/045.phpt new file mode 100644 index 0000000000..7118df9eb7 --- /dev/null +++ b/ext/ffi/tests/045.phpt @@ -0,0 +1,29 @@ +--TEST-- +FFI 045: FFI::isNull() +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--INI-- +ffi.enable=1 +--FILE-- +<?php +var_dump(FFI::isNull(FFI::new("int*"))); +$i = FFI::new("int"); +var_dump(FFI::isNull(FFI::addr($i))); +try { + var_dump(FFI::isNull(null)); +} catch (Throwable $e) { + echo get_class($e) . ": " . $e->getMessage()."\n"; +} +try { + var_dump(FFI::isNull(FFI::new("int[0]"))); +} catch (Throwable $e) { + echo get_class($e) . ": " . $e->getMessage()."\n"; +} +?> +--EXPECTF-- +bool(true) +bool(false) + +Warning: FFI::isNull() expects parameter 1 to be FFI\CData, null given in %s045.php on line %d +NULL +FFI\Exception: FFI\Cdata is not a pointer |