Skip to content

Commit c365be7

Browse files
authored
Avoid PHP 8.3 FFI deprecations (fixes #226) (#231)
* Avoid PHP 8.3 FFI::cast deprecation * Avoid PHP 8.3 FFI::new deprecation * Run CI tests on PHP 8.3
1 parent 13ebba3 commit c365be7

File tree

10 files changed

+22
-19
lines changed

10 files changed

+22
-19
lines changed

Diff for: .github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
- php: '8.0'
1515
- php: '8.1'
1616
- php: '8.2'
17+
- php: '8.3'
1718

1819
steps:
1920
- name: Setup PHP

Diff for: src/Connection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ abstract class Connection extends VipsObject
1414

1515
public function __construct(\FFI\CData $pointer)
1616
{
17-
$this->pointer = \FFI::cast(FFI::ctypes('VipsConnection'), $pointer);
17+
$this->pointer = FFI::vips()->cast(FFI::ctypes('VipsConnection'), $pointer);
1818
parent::__construct($pointer);
1919
}
2020

Diff for: src/GObject.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ abstract class GObject
7474
*/
7575
public function __construct(CData $pointer)
7676
{
77-
$this->pointer = \FFI::cast(FFI::ctypes("GObject"), $pointer);
77+
$this->pointer = FFI::vips()->cast(FFI::ctypes("GObject"), $pointer);
7878
}
7979

8080
public function __destruct()
@@ -135,7 +135,7 @@ private static function getMarshaler(string $name, callable $callback): ?Closure
135135
$vi = FFI::gobject()->g_value_get_object(\FFI::addr($params[0]));
136136
FFI::gobject()->g_object_ref($vi);
137137
$image = new Image($vi);
138-
$pr = \FFI::cast(
138+
$pr = FFI::vips()->cast(
139139
FFI::ctypes('VipsProgress'),
140140
FFI::gobject()->g_value_get_pointer(\FFI::addr($params[1]))
141141
);

Diff for: src/GValue.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function set($value): void
147147
$value = [$value];
148148
}
149149
$n = count($value);
150-
$array = \FFI::new("int[$n]");
150+
$array = FFI::vips()->new("int[$n]");
151151
for ($i = 0; $i < $n; $i++) {
152152
$array[$i] = $value[$i];
153153
}
@@ -160,7 +160,7 @@ public function set($value): void
160160
$value = [$value];
161161
}
162162
$n = count($value);
163-
$array = \FFI::new("double[$n]");
163+
$array = FFI::vips()->new("double[$n]");
164164
for ($i = 0; $i < $n; $i++) {
165165
$array[$i] = $value[$i];
166166
}
@@ -187,7 +187,7 @@ public function set($value): void
187187
# we need to set the blob to a copy of the data that vips_lib
188188
# can own and free
189189
$n = strlen($value);
190-
$memory = \FFI::new("char[$n]", false, true);
190+
$memory = FFI::vips()->new("char[$n]", false, true);
191191
\FFI::memcpy($memory, $value, $n);
192192
FFI::vips()->
193193
vips_value_set_blob_free($this->pointer, $memory, $n);

Diff for: src/Image.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ class Image extends ImageAutodoc implements \ArrayAccess
500500
*/
501501
public function __construct(\FFI\CData $pointer)
502502
{
503-
$this->pointer = \FFI::cast(FFI::ctypes("VipsImage"), $pointer);
503+
$this->pointer = FFI::vips()->cast(FFI::ctypes("VipsImage"), $pointer);
504504
parent::__construct($pointer);
505505
}
506506

@@ -807,7 +807,7 @@ public static function newFromArray(
807807
$width = count($array[0]);
808808

809809
$n = $width * $height;
810-
$a = \FFI::new("double[$n]", true, true);
810+
$a = FFI::vips()->new("double[$n]", true, true);
811811
for ($y = 0; $y < $height; $y++) {
812812
for ($x = 0; $x < $width; $x++) {
813813
$a[$x + $y * $width] = $array[$y][$x];
@@ -921,7 +921,9 @@ public function newFromImage($value): Image
921921
*/
922922
public static function findLoadSource(Source $source): ?string
923923
{
924-
return FFI::vips()->vips_foreign_find_load_source(\FFI::cast(FFI::ctypes('VipsSource'), $source->pointer));
924+
return FFI::vips()->vips_foreign_find_load_source(
925+
FFI::vips()->cast(FFI::ctypes('VipsSource'), $source->pointer)
926+
);
925927
}
926928

927929
/**
@@ -1043,7 +1045,7 @@ public function writeToBuffer(string $suffix, array $options = []): string
10431045
*/
10441046
public function writeToMemory(): string
10451047
{
1046-
$p_size = \FFI::new("size_t[1]");
1048+
$p_size = FFI::vips()->new("size_t[1]");
10471049

10481050
$pointer = FFI::vips()->
10491051
vips_image_write_to_memory($this->pointer, $p_size);
@@ -1084,7 +1086,7 @@ public function writeToMemory(): string
10841086
*/
10851087
public function writeToArray(): array
10861088
{
1087-
$p_size = \FFI::new("size_t[1]");
1089+
$p_size = FFI::vips()->new("size_t[1]");
10881090

10891091
$pointer = FFI::vips()->
10901092
vips_image_write_to_memory($this->pointer, $p_size);
@@ -1095,7 +1097,7 @@ public function writeToArray(): array
10951097
// wrap pointer up as a C array of the right type
10961098
$type_name = FFI::ftypes($this->format);
10971099
$n = $this->width * $this->height * $this->bands;
1098-
$array = \FFI::cast("{$type_name}[$n]", $pointer);
1100+
$array = FFI::vips()->cast("{$type_name}[$n]", $pointer);
10991101

11001102
// copy to PHP memory as a flat array
11011103
$result = [];

Diff for: src/Interpolate.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Interpolate extends VipsObject
6262

6363
public function __construct(\FFI\CData $pointer)
6464
{
65-
$this->pointer = \FFI::cast(FFI::ctypes("VipsInterpolate"), $pointer);
65+
$this->pointer = FFI::vips()->cast(FFI::ctypes("VipsInterpolate"), $pointer);
6666

6767
parent::__construct($pointer);
6868
}

Diff for: src/Introspect.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function __construct($operation_name)
105105
$p_flags = FFI::vips()->new("int*[1]");
106106
$p_n_args = FFI::vips()->new("int[1]");
107107
$result = FFI::vips()->vips_object_get_args(
108-
\FFI::cast(FFI::ctypes("VipsObject"), $operation->pointer),
108+
FFI::vips()->cast(FFI::ctypes("VipsObject"), $operation->pointer),
109109
$p_names,
110110
$p_flags,
111111
$p_n_args

Diff for: src/Source.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Source extends Connection
1414

1515
public function __construct(\FFI\CData $pointer)
1616
{
17-
$this->pointer = \FFI::cast(FFI::ctypes('VipsSource'), $pointer);
17+
$this->pointer = FFI::vips()->cast(FFI::ctypes('VipsSource'), $pointer);
1818
parent::__construct($pointer);
1919
}
2020

@@ -67,7 +67,7 @@ public static function newFromMemory(string $data): self
6767
# we need to set the memory to a copy of the data that vips_lib
6868
# can own and free
6969
$n = strlen($data);
70-
$memory = \FFI::new("char[$n]", false, true);
70+
$memory = FFI::vips()->new("char[$n]", false, true);
7171
\FFI::memcpy($memory, $data, $n);
7272
$pointer = FFI::vips()->vips_source_new_from_memory($memory, $n);
7373

Diff for: src/Target.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Target extends Connection
1414

1515
public function __construct(\FFI\CData $pointer)
1616
{
17-
$this->pointer = \FFI::cast(FFI::ctypes('VipsTarget'), $pointer);
17+
$this->pointer = FFI::vips()->cast(FFI::ctypes('VipsTarget'), $pointer);
1818
parent::__construct($pointer);
1919
}
2020

Diff for: src/VipsObject.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ abstract class VipsObject extends GObject
6868

6969
public function __construct(\FFI\CData $pointer)
7070
{
71-
$this->pointer = \FFI::cast(FFI::ctypes("VipsObject"), $pointer);
72-
$this->gObject = \FFI::cast(FFI::ctypes("GObject"), $pointer);
71+
$this->pointer = FFI::vips()->cast(FFI::ctypes("VipsObject"), $pointer);
72+
$this->gObject = FFI::vips()->cast(FFI::ctypes("GObject"), $pointer);
7373

7474
parent::__construct($pointer);
7575
}

0 commit comments

Comments
 (0)