From 4acf0084dcd63ec369a610ec966db33f322694c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Sat, 1 Jul 2023 13:37:11 +0200 Subject: [PATCH] Deprecate calling FFI::cast(), FFI::new(), and FFI::type() statically --- ext/ffi/ffi.c | 42 ++++++++++--- ext/ffi/tests/005.phpt | 6 +- ext/ffi/tests/006.phpt | 6 +- ext/ffi/tests/007.phpt | 8 ++- ext/ffi/tests/008.phpt | 6 +- ext/ffi/tests/009.phpt | 6 +- ext/ffi/tests/010.phpt | 2 +- ext/ffi/tests/011.phpt | 6 +- ext/ffi/tests/012.phpt | 2 +- ext/ffi/tests/013.phpt | 8 ++- ext/ffi/tests/014.phpt | 8 ++- ext/ffi/tests/017.phpt | 5 ++ ext/ffi/tests/020.phpt | 14 +++-- ext/ffi/tests/021.phpt | 63 ++++++++++++++++++- ext/ffi/tests/022.phpt | 4 +- ext/ffi/tests/023.phpt | 8 ++- ext/ffi/tests/024.phpt | 2 +- ext/ffi/tests/025.phpt | 6 +- ext/ffi/tests/026.phpt | 2 +- ext/ffi/tests/027.phpt | 10 +-- ext/ffi/tests/030.phpt | 6 +- ext/ffi/tests/031.phpt | 2 +- ext/ffi/tests/032.phpt | 2 +- ext/ffi/tests/033.phpt | 14 +++-- ext/ffi/tests/034.phpt | 8 ++- ext/ffi/tests/035.phpt | 4 +- ext/ffi/tests/036.phpt | 11 ++-- ext/ffi/tests/037.phpt | 4 +- ext/ffi/tests/038.phpt | 6 +- ext/ffi/tests/039.phpt | 2 +- ext/ffi/tests/040.phpt | 10 +-- ext/ffi/tests/041.phpt | 20 +++--- ext/ffi/tests/042.phpt | 2 +- ext/ffi/tests/045.phpt | 6 +- ext/ffi/tests/046.phpt | 15 ++++- ext/ffi/tests/047.phpt | 6 +- ext/ffi/tests/arrayPointer.phpt | 2 +- ext/ffi/tests/bug77768.phpt | 2 +- ext/ffi/tests/bug78761.phpt | 2 +- ext/ffi/tests/bug78762.phpt | 2 +- ext/ffi/tests/bug79532.phpt | 2 +- ext/ffi/tests/bug79749.phpt | 4 +- ext/ffi/tests/deprecations.phpt | 61 ++++++++++++++++++ ext/ffi/tests/gh7867.phpt | 8 +-- ext/ffi/tests/gh9697.phpt | 2 +- ...ray_sum_objects_operation_no_cast_FFI.phpt | 2 +- .../tests/general_functions/bug77638_2.phpt | 2 +- 47 files changed, 311 insertions(+), 110 deletions(-) create mode 100644 ext/ffi/tests/deprecations.phpt diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index e82b81fe3bd..275a1df25c8 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -3736,6 +3736,7 @@ ZEND_METHOD(FFI, new) /* {{{ */ bool owned = 1; bool persistent = 0; bool is_const = 0; + bool is_static_call = Z_TYPE(EX(This)) != IS_OBJECT; zend_ffi_flags flags = ZEND_FFI_FLAG_OWNED; ZEND_FFI_VALIDATE_API_RESTRICTION(); @@ -3746,6 +3747,13 @@ ZEND_METHOD(FFI, new) /* {{{ */ Z_PARAM_BOOL(persistent) ZEND_PARSE_PARAMETERS_END(); + if (is_static_call) { + zend_error(E_DEPRECATED, "Calling FFI::new() statically is deprecated"); + if (EG(exception)) { + RETURN_THROWS(); + } + } + if (!owned) { flags &= ~ZEND_FFI_FLAG_OWNED; } @@ -3757,7 +3765,7 @@ ZEND_METHOD(FFI, new) /* {{{ */ if (type_def) { zend_ffi_dcl dcl = ZEND_FFI_ATTR_INIT; - if (Z_TYPE(EX(This)) == IS_OBJECT) { + if (!is_static_call) { zend_ffi *ffi = (zend_ffi*)Z_OBJ(EX(This)); FFI_G(symbols) = ffi->symbols; FFI_G(tags) = ffi->tags; @@ -3770,7 +3778,7 @@ ZEND_METHOD(FFI, new) /* {{{ */ if (zend_ffi_parse_type(ZSTR_VAL(type_def), ZSTR_LEN(type_def), &dcl) == FAILURE) { zend_ffi_type_dtor(dcl.type); - if (Z_TYPE(EX(This)) != IS_OBJECT) { + if (is_static_call) { if (FFI_G(tags)) { zend_hash_destroy(FFI_G(tags)); efree(FFI_G(tags)); @@ -3790,7 +3798,7 @@ ZEND_METHOD(FFI, new) /* {{{ */ is_const = 1; } - if (Z_TYPE(EX(This)) != IS_OBJECT) { + if (is_static_call) { if (FFI_G(tags)) { zend_ffi_tags_cleanup(&dcl); } @@ -3886,6 +3894,7 @@ ZEND_METHOD(FFI, cast) /* {{{ */ zend_ffi_type *old_type, *type, *type_ptr; zend_ffi_cdata *old_cdata, *cdata; bool is_const = 0; + bool is_static_call = Z_TYPE(EX(This)) != IS_OBJECT; zval *zv, *arg; void *ptr; @@ -3895,13 +3904,20 @@ ZEND_METHOD(FFI, cast) /* {{{ */ Z_PARAM_ZVAL(zv) ZEND_PARSE_PARAMETERS_END(); + if (is_static_call) { + zend_error(E_DEPRECATED, "Calling FFI::cast() statically is deprecated"); + if (EG(exception)) { + RETURN_THROWS(); + } + } + arg = zv; ZVAL_DEREF(zv); if (type_def) { zend_ffi_dcl dcl = ZEND_FFI_ATTR_INIT; - if (Z_TYPE(EX(This)) == IS_OBJECT) { + if (!is_static_call) { zend_ffi *ffi = (zend_ffi*)Z_OBJ(EX(This)); FFI_G(symbols) = ffi->symbols; FFI_G(tags) = ffi->tags; @@ -3914,7 +3930,7 @@ ZEND_METHOD(FFI, cast) /* {{{ */ if (zend_ffi_parse_type(ZSTR_VAL(type_def), ZSTR_LEN(type_def), &dcl) == FAILURE) { zend_ffi_type_dtor(dcl.type); - if (Z_TYPE(EX(This)) != IS_OBJECT) { + if (is_static_call) { if (FFI_G(tags)) { zend_hash_destroy(FFI_G(tags)); efree(FFI_G(tags)); @@ -3934,7 +3950,7 @@ ZEND_METHOD(FFI, cast) /* {{{ */ is_const = 1; } - if (Z_TYPE(EX(This)) != IS_OBJECT) { + if (is_static_call) { if (FFI_G(tags)) { zend_ffi_tags_cleanup(&dcl); } @@ -4061,13 +4077,21 @@ ZEND_METHOD(FFI, type) /* {{{ */ zend_ffi_ctype *ctype; zend_ffi_dcl dcl = ZEND_FFI_ATTR_INIT; zend_string *type_def; + bool is_static_call = Z_TYPE(EX(This)) != IS_OBJECT; ZEND_FFI_VALIDATE_API_RESTRICTION(); ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(type_def); ZEND_PARSE_PARAMETERS_END(); - if (Z_TYPE(EX(This)) == IS_OBJECT) { + if (is_static_call) { + zend_error(E_DEPRECATED, "Calling FFI::type() statically is deprecated"); + if (EG(exception)) { + RETURN_THROWS(); + } + } + + if (!is_static_call) { zend_ffi *ffi = (zend_ffi*)Z_OBJ(EX(This)); FFI_G(symbols) = ffi->symbols; FFI_G(tags) = ffi->tags; @@ -4080,7 +4104,7 @@ ZEND_METHOD(FFI, type) /* {{{ */ if (zend_ffi_parse_type(ZSTR_VAL(type_def), ZSTR_LEN(type_def), &dcl) == FAILURE) { zend_ffi_type_dtor(dcl.type); - if (Z_TYPE(EX(This)) != IS_OBJECT) { + if (is_static_call) { if (FFI_G(tags)) { zend_hash_destroy(FFI_G(tags)); efree(FFI_G(tags)); @@ -4095,7 +4119,7 @@ ZEND_METHOD(FFI, type) /* {{{ */ return; } - if (Z_TYPE(EX(This)) != IS_OBJECT) { + if (is_static_call) { if (FFI_G(tags)) { zend_ffi_tags_cleanup(&dcl); } diff --git a/ext/ffi/tests/005.phpt b/ext/ffi/tests/005.phpt index 389c44487a6..8da2e55050d 100644 --- a/ext/ffi/tests/005.phpt +++ b/ext/ffi/tests/005.phpt @@ -6,8 +6,10 @@ ffi ffi.enable=1 --FILE-- new("int[2][2]"); +$v = $ffi->new("int[2]"); $v[1] = 42; $m[1] = $v; var_dump($m); diff --git a/ext/ffi/tests/006.phpt b/ext/ffi/tests/006.phpt index 743904bf1ba..466cb43666c 100644 --- a/ext/ffi/tests/006.phpt +++ b/ext/ffi/tests/006.phpt @@ -6,8 +6,10 @@ ffi ffi.enable=1 --FILE-- new("int*[2]"); +$v[1] = $ffi->new("int[1]", false); $v[1][0] = 42; var_dump($v); FFI::free($v[1]); diff --git a/ext/ffi/tests/007.phpt b/ext/ffi/tests/007.phpt index 8aa6c67f3e2..fed8fa767c7 100644 --- a/ext/ffi/tests/007.phpt +++ b/ext/ffi/tests/007.phpt @@ -6,9 +6,11 @@ ffi ffi.enable=1 --FILE-- new("int*[3]"); +$v[0] = $ffi->new("int[1]", false); +$v[1] = $ffi->new("int[1]", false); $v[2] = $v[1]; $v[1][0] = 42; var_dump($v[0] == $v[1]); diff --git a/ext/ffi/tests/008.phpt b/ext/ffi/tests/008.phpt index 40e4f251fc5..9ad015eac54 100644 --- a/ext/ffi/tests/008.phpt +++ b/ext/ffi/tests/008.phpt @@ -6,7 +6,9 @@ ffi ffi.enable=1 --FILE-- new("int[3]"); $a[1] = 10; $a[2] = 20; var_dump(count($a)); @@ -14,7 +16,7 @@ foreach ($a as $key => $val) { echo "$key => $val\n"; } -$a = FFI::new("struct {int x,y;}"); +$a = $ffi->new("struct {int x,y;}"); try { var_dump(count($a)); } catch (Throwable $e) { diff --git a/ext/ffi/tests/009.phpt b/ext/ffi/tests/009.phpt index 96badc986fb..3e4346f79ad 100644 --- a/ext/ffi/tests/009.phpt +++ b/ext/ffi/tests/009.phpt @@ -6,10 +6,12 @@ ffi ffi.enable=1 --FILE-- new("int[3]"); $a[1] = 10; $a[2] = 20; -$b = FFI::new("int[4]"); +$b = $ffi->new("int[4]"); var_dump(FFI::memcmp($b, $a, FFI::sizeof($a))); FFI::memcpy($b, $a, FFI::sizeof($a)); var_dump($b); diff --git a/ext/ffi/tests/010.phpt b/ext/ffi/tests/010.phpt index c5dea69bb40..ea17aef08c5 100644 --- a/ext/ffi/tests/010.phpt +++ b/ext/ffi/tests/010.phpt @@ -6,7 +6,7 @@ ffi ffi.enable=1 --FILE-- new("int[3]"); FFI::memset($a, ord("a"), FFI::sizeof($a)); var_dump(FFI::string($a, FFI::sizeof($a))); ?> diff --git a/ext/ffi/tests/011.phpt b/ext/ffi/tests/011.phpt index 97b2dd221e6..4a1985b4dc2 100644 --- a/ext/ffi/tests/011.phpt +++ b/ext/ffi/tests/011.phpt @@ -6,10 +6,12 @@ ffi ffi.enable=1 --FILE-- new("uint8_t[4]"); $a[0] = 255; $a[1] = 255; -var_dump(FFI::cast("uint16_t[2]", $a)); +var_dump($ffi->cast("uint16_t[2]", $a)); ?> --EXPECTF-- object(FFI\CData:uint16_t[2])#%d (2) { diff --git a/ext/ffi/tests/012.phpt b/ext/ffi/tests/012.phpt index f43b469c275..8695b0ca017 100644 --- a/ext/ffi/tests/012.phpt +++ b/ext/ffi/tests/012.phpt @@ -7,7 +7,7 @@ ffi.enable=1 --FILE-- new("int[2]"))); } catch (Throwable $e) { echo get_class($e) . ": " . $e->getMessage()."\n"; } diff --git a/ext/ffi/tests/013.phpt b/ext/ffi/tests/013.phpt index 80295164b21..dc8b99c1d71 100644 --- a/ext/ffi/tests/013.phpt +++ b/ext/ffi/tests/013.phpt @@ -6,19 +6,21 @@ ffi ffi.enable=1 --FILE-- new("int[1][2][3]"); var_dump(count($a)); var_dump(count($a[0])); var_dump(count($a[0][0])); try { - var_dump(FFI::new("void")); + var_dump($ffi->new("void")); } catch (Throwable $e) { echo get_class($e) . ": " . $e->getMessage()."\n"; } try { - var_dump(FFI::new("void[1]")); + var_dump($ffi->new("void[1]")); } catch (Throwable $e) { echo get_class($e) . ": " . $e->getMessage()."\n"; } diff --git a/ext/ffi/tests/014.phpt b/ext/ffi/tests/014.phpt index 3fe64f6f73a..d0f877e7a7f 100644 --- a/ext/ffi/tests/014.phpt +++ b/ext/ffi/tests/014.phpt @@ -6,9 +6,11 @@ ffi ffi.enable=1 --FILE-- new("uint32_t[2]"))); +var_dump(FFI::sizeof($ffi->new("uint32_t([2])"))); +var_dump(FFI::sizeof($ffi->new("uint32_t([2])[2]"))); ?> ok --EXPECT-- diff --git a/ext/ffi/tests/017.phpt b/ext/ffi/tests/017.phpt index 766bc4bdae2..30f1efdde66 100644 --- a/ext/ffi/tests/017.phpt +++ b/ext/ffi/tests/017.phpt @@ -24,8 +24,13 @@ try { ?> ok --EXPECTF-- +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d FFI\ParserException: function type is not allowed at line 1 + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d FFI\ParserException: Struct/union can't contain an instance of itself at line 1 + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d object(FFI\CData:struct X)#%d (1) { ["ptr"]=> NULL diff --git a/ext/ffi/tests/020.phpt b/ext/ffi/tests/020.phpt index 1f510a0753b..37cb6b17d11 100644 --- a/ext/ffi/tests/020.phpt +++ b/ext/ffi/tests/020.phpt @@ -6,8 +6,10 @@ ffi ffi.enable=1 --FILE-- new("struct {int x; const int y;}"); $p->x = 1; $p->y = 1; echo "ok\n"; @@ -15,7 +17,7 @@ try { echo get_class($e) . ": " . $e->getMessage()."\n"; } try { - $p = FFI::new("struct {const int x; int y;}"); + $p = $ffi->new("struct {const int x; int y;}"); $p->y = 1; $p->x = 1; echo "ok\n"; @@ -23,28 +25,28 @@ try { echo get_class($e) . ": " . $e->getMessage()."\n"; } try { - $p = FFI::new("const struct {int x; int y;}"); + $p = $ffi->new("const struct {int x; int y;}"); $p->x = 1; echo "ok\n"; } catch (Throwable $e) { echo get_class($e) . ": " . $e->getMessage()."\n"; } try { - $p = FFI::new("const int[10]"); + $p = $ffi->new("const int[10]"); $p[1] = 1; echo "ok\n"; } catch (Throwable $e) { echo get_class($e) . ": " . $e->getMessage()."\n"; } try { - $p = FFI::new("const int * [1]"); + $p = $ffi->new("const int * [1]"); $p[0] = null; echo "ok\n"; } catch (Throwable $e) { echo get_class($e) . ": " . $e->getMessage()."\n"; } try { - $p = FFI::new("int * const [1]"); + $p = $ffi->new("int * const [1]"); $p[0] = null; echo "ok\n"; } catch (Throwable $e) { diff --git a/ext/ffi/tests/021.phpt b/ext/ffi/tests/021.phpt index ceaf96d7b95..87cf75348d8 100644 --- a/ext/ffi/tests/021.phpt +++ b/ext/ffi/tests/021.phpt @@ -53,5 +53,66 @@ test(4, "enum __attribute__((packed)) {a14=-0x80000000}"); test(8, "enum __attribute__((packed)) {a14=-0x80000001}"); ?> ok ---EXPECT-- +--EXPECTF-- +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d + +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d ok diff --git a/ext/ffi/tests/022.phpt b/ext/ffi/tests/022.phpt index 444939ec78a..d2c16af94b5 100644 --- a/ext/ffi/tests/022.phpt +++ b/ext/ffi/tests/022.phpt @@ -7,13 +7,13 @@ ffi.enable=1 --FILE-- new($type)) !== $size) { echo "FAIL: sizeof($type) != $size\n"; } } function test_align($align, $type) { - if (FFI::alignof(FFI::new($type)) !== $align) { + if (FFI::alignof(FFI::cdef()->new($type)) !== $align) { echo "FAIL: alignof($type) != $align\n"; } } diff --git a/ext/ffi/tests/023.phpt b/ext/ffi/tests/023.phpt index b248e08842f..9cf77d723b0 100644 --- a/ext/ffi/tests/023.phpt +++ b/ext/ffi/tests/023.phpt @@ -6,13 +6,15 @@ ffi ffi.enable=1 --FILE-- new("struct {}"))); } catch (Throwable $e) { echo get_class($e) . ": " . $e->getMessage() . "\n"; } - var_dump(FFI::sizeof(FFI::new("struct {int a}"))); - var_dump(FFI::sizeof(FFI::new("struct {int a; int b}"))); + var_dump(FFI::sizeof($ffi->new("struct {int a}"))); + var_dump(FFI::sizeof($ffi->new("struct {int a; int b}"))); ?> ok --EXPECT-- diff --git a/ext/ffi/tests/024.phpt b/ext/ffi/tests/024.phpt index ca6379f3523..1d6c0afaa64 100644 --- a/ext/ffi/tests/024.phpt +++ b/ext/ffi/tests/024.phpt @@ -6,7 +6,7 @@ ffi ffi.enable=1 --FILE-- new(" struct { int a; struct { diff --git a/ext/ffi/tests/025.phpt b/ext/ffi/tests/025.phpt index ba1e75e223f..b1cdab9463e 100644 --- a/ext/ffi/tests/025.phpt +++ b/ext/ffi/tests/025.phpt @@ -6,7 +6,9 @@ ffi ffi.enable=1 --FILE-- new("int"); $x->cdata = 5; var_dump($x); $x->cdata += 2; @@ -14,7 +16,7 @@ ffi.enable=1 echo "$x\n\n"; unset($x); - $x = FFI::new("char"); + $x = $ffi->new("char"); $x->cdata = 'a'; var_dump($x); $x->cdata++; diff --git a/ext/ffi/tests/026.phpt b/ext/ffi/tests/026.phpt index 62e4a3fdf49..b7ec7d07623 100644 --- a/ext/ffi/tests/026.phpt +++ b/ext/ffi/tests/026.phpt @@ -6,7 +6,7 @@ ffi ffi.enable=1 --FILE-- new("int[3]"); $a[1] = 10; $a[2] = 20; var_dump($a); diff --git a/ext/ffi/tests/027.phpt b/ext/ffi/tests/027.phpt index 3711dd0a869..b71bab4001b 100644 --- a/ext/ffi/tests/027.phpt +++ b/ext/ffi/tests/027.phpt @@ -6,8 +6,10 @@ ffi ffi.enable=1 --FILE-- new("int[*]"); echo "ok\n"; } catch (Throwable $e) { echo get_class($e) . ": " . $e->getMessage()."\n"; @@ -31,17 +33,17 @@ try { echo get_class($e) . ": " . $e->getMessage()."\n"; } try { - var_dump(FFI::sizeof(FFI::new("int[0]"))); + var_dump(FFI::sizeof($ffi->new("int[0]"))); } catch (Throwable $e) { echo get_class($e) . ": " . $e->getMessage()."\n"; } try { - var_dump(FFI::sizeof(FFI::new("int[]"))); + var_dump(FFI::sizeof($ffi->new("int[]"))); } catch (Throwable $e) { echo get_class($e) . ": " . $e->getMessage()."\n"; } try { - var_dump(FFI::sizeof(FFI::cast("int[]", FFI::new("int[2]")))); + var_dump(FFI::sizeof($ffi->cast("int[]", $ffi->new("int[2]")))); } catch (Throwable $e) { echo get_class($e) . ": " . $e->getMessage()."\n"; } diff --git a/ext/ffi/tests/030.phpt b/ext/ffi/tests/030.phpt index e067b0a99e8..4014ec6b568 100644 --- a/ext/ffi/tests/030.phpt +++ b/ext/ffi/tests/030.phpt @@ -6,8 +6,10 @@ ffi ffi.enable=1 --FILE-- new("bool[2]"))); +$p = $ffi->new("bool[2]"); var_dump($p); $p[1] = true; var_dump($p[0]); diff --git a/ext/ffi/tests/031.phpt b/ext/ffi/tests/031.phpt index b7c7ecdb648..d4b43f8f6e6 100644 --- a/ext/ffi/tests/031.phpt +++ b/ext/ffi/tests/031.phpt @@ -8,7 +8,7 @@ ffi.enable=1 new($type)); if ($size !== $expected_size) { echo "FAIL: sizeof($type) != $expected_size ($size)\n"; } diff --git a/ext/ffi/tests/032.phpt b/ext/ffi/tests/032.phpt index 38b7b9f5f62..83580284b73 100644 --- a/ext/ffi/tests/032.phpt +++ b/ext/ffi/tests/032.phpt @@ -6,7 +6,7 @@ ffi ffi.enable=1 --FILE-- new(" union { struct __attribute__((packed)) { int a:2; diff --git a/ext/ffi/tests/033.phpt b/ext/ffi/tests/033.phpt index a09ab18bb60..62ed6e8d727 100644 --- a/ext/ffi/tests/033.phpt +++ b/ext/ffi/tests/033.phpt @@ -6,22 +6,24 @@ ffi ffi.enable=1 --FILE-- new("uint8_t[2]"); +$p2 = $ffi->new("uint16_t[2]", true, true); var_dump($p1, $p2); $t1 = FFI::typeof($p1); var_dump($t1); -$p4 = FFI::new($t1); +$p4 = $ffi->new($t1); var_dump($p4); -$t2 = FFI::type("uint16_t[2]"); +$t2 = $ffi->type("uint16_t[2]"); var_dump($t2); -$p4 = FFI::new($t2); +$p4 = $ffi->new($t2); var_dump($p4); -$t2 = FFI::type("uint32_t"); +$t2 = $ffi->type("uint32_t"); var_dump($t2); $t3 = FFI::arrayType($t2, [2, 2]); var_dump($t3); diff --git a/ext/ffi/tests/034.phpt b/ext/ffi/tests/034.phpt index 46779f31ec5..db243882987 100644 --- a/ext/ffi/tests/034.phpt +++ b/ext/ffi/tests/034.phpt @@ -6,9 +6,11 @@ ffi ffi.enable=1 --FILE-- new("uint8_t[2]"); +$p2 = $ffi->new("uint16_t[2]"); +$p3 = $ffi->new("uint32_t[2]"); var_dump(FFI::sizeof($p1), FFI::sizeof($p2), FFI::sizeof($p3)); var_dump(FFI::alignof($p1), FFI::alignof($p2), FFI::alignof($p3)); var_dump(FFI::sizeof(FFI::typeof($p1)), FFI::sizeof(FFI::typeof($p2)), FFI::sizeof(FFI::typeof($p3))); diff --git a/ext/ffi/tests/035.phpt b/ext/ffi/tests/035.phpt index b36f2467081..bd8c6df71f9 100644 --- a/ext/ffi/tests/035.phpt +++ b/ext/ffi/tests/035.phpt @@ -1,12 +1,12 @@ --TEST-- -FFI 035: FFI::new() not-owned +FFI 035: FFI::cdef()->new() not-owned --EXTENSIONS-- ffi --INI-- ffi.enable=1 --FILE-- new("uint16_t[2]", false); var_dump($p); FFI::free($p); diff --git a/ext/ffi/tests/036.phpt b/ext/ffi/tests/036.phpt index 06e81c7dc64..ed94fd7a44b 100644 --- a/ext/ffi/tests/036.phpt +++ b/ext/ffi/tests/036.phpt @@ -6,18 +6,21 @@ ffi ffi.enable=1 --FILE-- type("int*"); function foo($ptr) { global $type; - //$buf = FFI::new("int*[1]"); /* this loses type and crash */ - $buf = FFI::new(FFI::arrayType($type, [1])); + global $ffi; + //$buf = $ffi->new("int*[1]"); /* this loses type and crash */ + $buf = $ffi->new(FFI::arrayType($type, [1])); $buf[0] = $ptr; //... return $buf[0]; } -$int = FFI::new("int"); +$int = $ffi->new("int"); $int->cdata = 42; var_dump(foo(FFI::addr($int))); ?> diff --git a/ext/ffi/tests/037.phpt b/ext/ffi/tests/037.phpt index 60efbfed5e7..19c4cf80015 100644 --- a/ext/ffi/tests/037.phpt +++ b/ext/ffi/tests/037.phpt @@ -7,13 +7,13 @@ ffi.enable=1 --FILE-- new("int*[1]"); $buf[0] = $ptr; //... return $buf[0]; } -$int = FFI::new("int"); +$int = FFI::cdef()->new("int"); $int->cdata = 42; var_dump(foo(FFI::addr($int))); ?> diff --git a/ext/ffi/tests/038.phpt b/ext/ffi/tests/038.phpt index 2fdce4d6104..29fad9e2522 100644 --- a/ext/ffi/tests/038.phpt +++ b/ext/ffi/tests/038.phpt @@ -6,11 +6,13 @@ ffi ffi.enable=1 --FILE-- new("int[10]"); for ($i = 0; $i < 10; $i++) { $a[$i] = $i; } -$p = FFI::cast("int*", $a); +$p = $ffi->cast("int*", $a); var_dump($p[0]); var_dump($p[2]); vaR_dump($p) diff --git a/ext/ffi/tests/039.phpt b/ext/ffi/tests/039.phpt index d859e16452d..13bfa27d5e0 100644 --- a/ext/ffi/tests/039.phpt +++ b/ext/ffi/tests/039.phpt @@ -6,7 +6,7 @@ ffi ffi.enable=1 --FILE-- new("int[10]"); for ($i = 0; $i < 10; $i++) { $a[$i] = $i; } diff --git a/ext/ffi/tests/040.phpt b/ext/ffi/tests/040.phpt index 0e460577f07..133c28e48f8 100644 --- a/ext/ffi/tests/040.phpt +++ b/ext/ffi/tests/040.phpt @@ -12,11 +12,13 @@ if (pack('S', 0xABCD) !== pack('v', 0xABCD)) { ffi.enable=1 --FILE-- new("int"); $x->cdata = 5; var_dump($x); var_dump(FFI::typeof($x)); -var_dump(FFI::cast("int8_t[4]", $x)); +var_dump($ffi->cast("int8_t[4]", $x)); $p = FFI::addr($x); var_dump($p); $p[0] += 2; @@ -28,11 +30,11 @@ var_dump(FFI::string($x, 4)); echo "\n"; -$y = FFI::new("int[2]"); +$y = FFI::cdef()->new("int[2]"); $y[0] = 6; var_dump($y[0]); var_dump(FFI::typeof($y[0])); -var_dump(FFI::cast("int8_t[4]", $y[0])); +var_dump(FFI::cdef()->cast("int8_t[4]", $y[0])); $p = FFI::addr($y[0]); var_dump($p); $p[0] += 2; diff --git a/ext/ffi/tests/041.phpt b/ext/ffi/tests/041.phpt index 572997e939c..557ccebdc78 100644 --- a/ext/ffi/tests/041.phpt +++ b/ext/ffi/tests/041.phpt @@ -8,10 +8,10 @@ ffi.enable=1 new(FFI::cdef()->type($str)); } else { - $type = FFI::type($str); - return FFI::new($type); + $type = FFI::cdef()->type($str); + return FFI::cdef()->new($type); } } var_dump(test_new_ownership("int", 1)); @@ -21,9 +21,9 @@ var_dump(test_new_ownership("int[2]", 0)); function test_type_ownership($str, $transfer) { if ($transfer) { - return FFI::typeof(FFI::new($str)); + return FFI::typeof(FFI::cdef()->new($str)); } else { - $data = FFI::new($str); + $data = FFI::cdef()->new($str); return FFI::typeof($data); } } @@ -34,10 +34,10 @@ var_dump(test_type_ownership("int[2]", 0)); function test_cast_ownership($str, $transfer) { if ($transfer) { - return FFI::cast(FFI::type($str), FFI::new($str)); + return FFI::cdef()->cast(FFI::cdef()->type($str), FFI::cdef()->new($str)); } else { - $type = FFI::type($str); - return FFI::cast($type, FFI::new($str)); + $type = FFI::cdef()->type($str); + return FFI::cdef()->cast($type, FFI::cdef()->new($str)); } } var_dump(test_cast_ownership("int", 1)); @@ -47,9 +47,9 @@ var_dump(test_cast_ownership("int[2]", 0)); function test_array_ownership($str, $transfer) { if ($transfer) { - return FFI::arrayType(FFI::type($str), [2]); + return FFI::arrayType(FFI::cdef()->type($str), [2]); } else { - $type = FFI::type($str); + $type = FFI::cdef()->type($str); return FFI::arrayType($type, [2]); } } diff --git a/ext/ffi/tests/042.phpt b/ext/ffi/tests/042.phpt index 4eb8c0b2349..6e0dd6292ae 100644 --- a/ext/ffi/tests/042.phpt +++ b/ext/ffi/tests/042.phpt @@ -6,7 +6,7 @@ ffi ffi.enable=1 --FILE-- new("uint8_t[8]"); $a[] = 0; ?> --EXPECTF-- diff --git a/ext/ffi/tests/045.phpt b/ext/ffi/tests/045.phpt index e132eb9b727..84cecae0156 100644 --- a/ext/ffi/tests/045.phpt +++ b/ext/ffi/tests/045.phpt @@ -6,8 +6,8 @@ ffi ffi.enable=1 --FILE-- new("int*"))); +$i = FFI::cdef()->new("int"); var_dump(FFI::isNull(FFI::addr($i))); try { var_dump(FFI::isNull(null)); @@ -15,7 +15,7 @@ try { echo get_class($e) . ": " . $e->getMessage()."\n"; } try { - var_dump(FFI::isNull(FFI::new("int[0]"))); + var_dump(FFI::isNull(FFI::cdef()->new("int[0]"))); } catch (Throwable $e) { echo get_class($e) . ": " . $e->getMessage()."\n"; } diff --git a/ext/ffi/tests/046.phpt b/ext/ffi/tests/046.phpt index ebce17728b4..0cea22eba78 100644 --- a/ext/ffi/tests/046.phpt +++ b/ext/ffi/tests/046.phpt @@ -51,18 +51,27 @@ var_dump($x->getPointerType()->getFuncParameterCount()); var_dump($x->getPointerType()->getFuncParameterType(0)->getKind() === $x::TYPE_DOUBLE); var_dump($x->getPointerType()->getFuncParameterType(1)->getKind() === $x::TYPE_SINT32); ?> ---EXPECT-- +--EXPECTF-- +Deprecated: Calling FFI::type() statically is deprecated in %s on line %d bool(true) int(1) int(1) + +Deprecated: Calling FFI::type() statically is deprecated in %s on line %d bool(true) bool(true) + +Deprecated: Calling FFI::type() statically is deprecated in %s on line %d bool(true) int(5) bool(true) int(5) + +Deprecated: Calling FFI::type() statically is deprecated in %s on line %d bool(true) bool(true) + +Deprecated: Calling FFI::type() statically is deprecated in %s on line %d bool(true) bool(false) array(2) { @@ -75,6 +84,8 @@ int(0) int(8) bool(true) bool(true) + +Deprecated: Calling FFI::type() statically is deprecated in %s on line %d bool(true) bool(true) array(2) { @@ -87,6 +98,8 @@ int(0) int(0) bool(true) bool(true) + +Deprecated: Calling FFI::type() statically is deprecated in %s on line %d bool(true) bool(true) bool(true) diff --git a/ext/ffi/tests/047.phpt b/ext/ffi/tests/047.phpt index 8bd83320b50..e09da3fe9ee 100644 --- a/ext/ffi/tests/047.phpt +++ b/ext/ffi/tests/047.phpt @@ -6,11 +6,11 @@ ffi ffi.enable=1 --FILE-- new("int"); $x->cdata = 42; var_dump($x); -$x = FFI::new("int*"); +$x = FFI::cdef()->new("int*"); try { $x->cdata = 42; var_dump($x); @@ -18,7 +18,7 @@ try { echo $e->getMessage() . "\n"; } -$x = FFI::new("struct {int cdata;}"); +$x = FFI::cdef()->new("struct {int cdata;}"); try { $x->cdata = 42; var_dump($x); diff --git a/ext/ffi/tests/arrayPointer.phpt b/ext/ffi/tests/arrayPointer.phpt index 3a2b06563ad..144d95fcfcb 100644 --- a/ext/ffi/tests/arrayPointer.phpt +++ b/ext/ffi/tests/arrayPointer.phpt @@ -7,7 +7,7 @@ ffi.enable=1 --FILE-- new('int'); var_dump(reset($data)); var_dump(end($data)); var_dump(next($data)); diff --git a/ext/ffi/tests/bug77768.phpt b/ext/ffi/tests/bug77768.phpt index 90c38d7da75..d16b2eeee6c 100644 --- a/ext/ffi/tests/bug77768.phpt +++ b/ext/ffi/tests/bug77768.phpt @@ -33,7 +33,7 @@ int printf(const char *format, ...); "); var_dump(FFI::sizeof($x->new("uint8_t"))); -var_dump(FFI::sizeof(FFI::new("uint8_t"))); +var_dump(FFI::sizeof(FFI::cdef()->new("uint8_t"))); ?> --EXPECT-- int(4) diff --git a/ext/ffi/tests/bug78761.phpt b/ext/ffi/tests/bug78761.phpt index f2a19d8457f..fc1c6612911 100644 --- a/ext/ffi/tests/bug78761.phpt +++ b/ext/ffi/tests/bug78761.phpt @@ -14,7 +14,7 @@ opcache.preload={PWD}/bug78761_preload.php --FILE-- cast('char[10]', FFI::cdef()->new('char[1]')); } catch (FFI\Exception $ex) { echo $ex->getMessage(), PHP_EOL; } diff --git a/ext/ffi/tests/bug78762.phpt b/ext/ffi/tests/bug78762.phpt index 3c492fe823f..5c621d3547e 100644 --- a/ext/ffi/tests/bug78762.phpt +++ b/ext/ffi/tests/bug78762.phpt @@ -5,7 +5,7 @@ ffi --FILE-- cast('char[10]', FFI::cdef()->new('char[1]')); } catch (FFI\Exception $ex) { echo $ex->getMessage(), PHP_EOL; } diff --git a/ext/ffi/tests/bug79532.phpt b/ext/ffi/tests/bug79532.phpt index 3b3864ed0ac..386c62540c1 100644 --- a/ext/ffi/tests/bug79532.phpt +++ b/ext/ffi/tests/bug79532.phpt @@ -21,7 +21,7 @@ if (PHP_OS_FAMILY !== 'Windows') { } } -$array = FFI::new("off_t[3]"); +$array = FFI::cdef()->new("off_t[3]"); $ffi->bug79532($array, 3); var_dump($array); ?> diff --git a/ext/ffi/tests/bug79749.phpt b/ext/ffi/tests/bug79749.phpt index 8047ed137f3..973eb3252d9 100644 --- a/ext/ffi/tests/bug79749.phpt +++ b/ext/ffi/tests/bug79749.phpt @@ -6,8 +6,8 @@ ffi type('int')); +var_dump((bool) FFI::cdef()->new('int')); ?> --EXPECT-- bool(true) diff --git a/ext/ffi/tests/deprecations.phpt b/ext/ffi/tests/deprecations.phpt new file mode 100644 index 00000000000..d62a214712d --- /dev/null +++ b/ext/ffi/tests/deprecations.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test calling the deprecated signature of FFI::new(), FFI::type(), FFI::cast() +--EXTENSIONS-- +ffi +--INI-- +ffi.enable=1 +--FILE-- +getMessage() . "\n"; +} +set_error_handler(null); + +var_dump($p1); + +$t1 = FFI::type("uint16_t[2]"); + +set_error_handler(function ($severity, $message, $file, $line) { + throw new Exception($message); +}); +try { + FFI::type("uint16_t[2]"); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +set_error_handler(null); + +$p = FFI::cast("uint8_t[2]", $p1); +set_error_handler(function ($severity, $message, $file, $line) { + throw new Exception($message); +}); +try { + FFI::cast("uint8_t[2]", $p1); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +?> +--EXPECTF-- +Deprecated: Calling FFI::new() statically is deprecated in %s on line %d +Calling FFI::new() statically is deprecated +object(FFI\CData:uint8_t[2])#1 (2) { + [0]=> + int(0) + [1]=> + int(0) +} + +Deprecated: Calling FFI::type() statically is deprecated in %s on line %d +Calling FFI::type() statically is deprecated + +Deprecated: Calling FFI::cast() statically is deprecated in %s on line %d +Calling FFI::cast() statically is deprecated diff --git a/ext/ffi/tests/gh7867.phpt b/ext/ffi/tests/gh7867.phpt index b85659aa705..72c30e8f335 100644 --- a/ext/ffi/tests/gh7867.phpt +++ b/ext/ffi/tests/gh7867.phpt @@ -6,19 +6,19 @@ ffi ffi.enable=1 --FILE-- new('char[26]'); FFI::memcpy($value, implode('', range('a', 'z')), 26); -$slice = FFI::new('char[4]'); +$slice = FFI::cdef()->new('char[4]'); echo 'cast from start' . PHP_EOL; FFI::memcpy($slice, $value, 4); -var_dump($value + 0, $slice, FFI::cast('char[4]', $value)); +var_dump($value + 0, $slice, FFI::cdef()->cast('char[4]', $value)); echo PHP_EOL; echo 'cast with offset' . PHP_EOL; FFI::memcpy($slice, $value + 4, 4); -var_dump($value + 4, $slice, FFI::cast('char[4]', $value + 4)); +var_dump($value + 4, $slice, FFI::cdef()->cast('char[4]', $value + 4)); echo PHP_EOL; ?> --EXPECTF-- diff --git a/ext/ffi/tests/gh9697.phpt b/ext/ffi/tests/gh9697.phpt index 0d73c16bda5..7d19480e694 100644 --- a/ext/ffi/tests/gh9697.phpt +++ b/ext/ffi/tests/gh9697.phpt @@ -6,7 +6,7 @@ ffi ffi.enable=1 --FILE-- new('int'); array_walk($x, function($x) { echo "test\n"; }); ?> DONE diff --git a/ext/standard/tests/array/array_sum_objects_operation_no_cast_FFI.phpt b/ext/standard/tests/array/array_sum_objects_operation_no_cast_FFI.phpt index a19e34f0b17..a43f27b1dd4 100644 --- a/ext/standard/tests/array/array_sum_objects_operation_no_cast_FFI.phpt +++ b/ext/standard/tests/array/array_sum_objects_operation_no_cast_FFI.phpt @@ -5,7 +5,7 @@ ffi --FILE-- new("int[2]"); $x[0] = 10; $x[1] = 25; diff --git a/ext/standard/tests/general_functions/bug77638_2.phpt b/ext/standard/tests/general_functions/bug77638_2.phpt index 589697011aa..c34f7a861a1 100644 --- a/ext/standard/tests/general_functions/bug77638_2.phpt +++ b/ext/standard/tests/general_functions/bug77638_2.phpt @@ -4,7 +4,7 @@ Bug #77638 (var_export'ing certain class instances segfaults) ffi --FILE-- new('int')); ?> --EXPECT-- \FFI\CData::__set_state(array(