Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid PHP 8.3 FFI deprecations (fixes #226) #231

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
- php: '8.0'
- php: '8.1'
- php: '8.2'
- php: '8.3'

steps:
- name: Setup PHP
Expand Down
2 changes: 1 addition & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class Connection extends VipsObject

public function __construct(\FFI\CData $pointer)
{
$this->pointer = \FFI::cast(FFI::ctypes('VipsConnection'), $pointer);
$this->pointer = FFI::vips()->cast(FFI::ctypes('VipsConnection'), $pointer);
parent::__construct($pointer);
}

Expand Down
4 changes: 2 additions & 2 deletions src/GObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ abstract class GObject
*/
public function __construct(CData $pointer)
{
$this->pointer = \FFI::cast(FFI::ctypes("GObject"), $pointer);
$this->pointer = FFI::vips()->cast(FFI::ctypes("GObject"), $pointer);
}

public function __destruct()
Expand Down Expand Up @@ -135,7 +135,7 @@ private static function getMarshaler(string $name, callable $callback): ?Closure
$vi = FFI::gobject()->g_value_get_object(\FFI::addr($params[0]));
FFI::gobject()->g_object_ref($vi);
$image = new Image($vi);
$pr = \FFI::cast(
$pr = FFI::vips()->cast(
FFI::ctypes('VipsProgress'),
FFI::gobject()->g_value_get_pointer(\FFI::addr($params[1]))
);
Expand Down
6 changes: 3 additions & 3 deletions src/GValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function set($value): void
$value = [$value];
}
$n = count($value);
$array = \FFI::new("int[$n]");
$array = FFI::vips()->new("int[$n]");
for ($i = 0; $i < $n; $i++) {
$array[$i] = $value[$i];
}
Expand All @@ -160,7 +160,7 @@ public function set($value): void
$value = [$value];
}
$n = count($value);
$array = \FFI::new("double[$n]");
$array = FFI::vips()->new("double[$n]");
for ($i = 0; $i < $n; $i++) {
$array[$i] = $value[$i];
}
Expand All @@ -187,7 +187,7 @@ public function set($value): void
# we need to set the blob to a copy of the data that vips_lib
# can own and free
$n = strlen($value);
$memory = \FFI::new("char[$n]", false, true);
$memory = FFI::vips()->new("char[$n]", false, true);
\FFI::memcpy($memory, $value, $n);
FFI::vips()->
vips_value_set_blob_free($this->pointer, $memory, $n);
Expand Down
14 changes: 8 additions & 6 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ class Image extends ImageAutodoc implements \ArrayAccess
*/
public function __construct(\FFI\CData $pointer)
{
$this->pointer = \FFI::cast(FFI::ctypes("VipsImage"), $pointer);
$this->pointer = FFI::vips()->cast(FFI::ctypes("VipsImage"), $pointer);
parent::__construct($pointer);
}

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

$n = $width * $height;
$a = \FFI::new("double[$n]", true, true);
$a = FFI::vips()->new("double[$n]", true, true);
for ($y = 0; $y < $height; $y++) {
for ($x = 0; $x < $width; $x++) {
$a[$x + $y * $width] = $array[$y][$x];
Expand Down Expand Up @@ -921,7 +921,9 @@ public function newFromImage($value): Image
*/
public static function findLoadSource(Source $source): ?string
{
return FFI::vips()->vips_foreign_find_load_source(\FFI::cast(FFI::ctypes('VipsSource'), $source->pointer));
return FFI::vips()->vips_foreign_find_load_source(
FFI::vips()->cast(FFI::ctypes('VipsSource'), $source->pointer)
);
}

/**
Expand Down Expand Up @@ -1016,7 +1018,7 @@ public function writeToBuffer(string $suffix, array $options = []): string
*/
public function writeToMemory(): string
{
$p_size = \FFI::new("size_t[1]");
$p_size = FFI::vips()->new("size_t[1]");

$pointer = FFI::vips()->
vips_image_write_to_memory($this->pointer, $p_size);
Expand Down Expand Up @@ -1057,7 +1059,7 @@ public function writeToMemory(): string
*/
public function writeToArray(): array
{
$p_size = \FFI::new("size_t[1]");
$p_size = FFI::vips()->new("size_t[1]");

$pointer = FFI::vips()->
vips_image_write_to_memory($this->pointer, $p_size);
Expand All @@ -1068,7 +1070,7 @@ public function writeToArray(): array
// wrap pointer up as a C array of the right type
$type_name = FFI::ftypes($this->format);
$n = $this->width * $this->height * $this->bands;
$array = \FFI::cast("{$type_name}[$n]", $pointer);
$array = FFI::vips()->cast("{$type_name}[$n]", $pointer);

// copy to PHP memory as a flat array
$result = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Interpolate.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Interpolate extends VipsObject

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

parent::__construct($pointer);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Introspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function __construct($operation_name)
$p_flags = FFI::vips()->new("int*[1]");
$p_n_args = FFI::vips()->new("int[1]");
$result = FFI::vips()->vips_object_get_args(
\FFI::cast(FFI::ctypes("VipsObject"), $operation->pointer),
FFI::vips()->cast(FFI::ctypes("VipsObject"), $operation->pointer),
$p_names,
$p_flags,
$p_n_args
Expand Down
4 changes: 2 additions & 2 deletions src/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Source extends Connection

public function __construct(\FFI\CData $pointer)
{
$this->pointer = \FFI::cast(FFI::ctypes('VipsSource'), $pointer);
$this->pointer = FFI::vips()->cast(FFI::ctypes('VipsSource'), $pointer);
parent::__construct($pointer);
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Target extends Connection

public function __construct(\FFI\CData $pointer)
{
$this->pointer = \FFI::cast(FFI::ctypes('VipsTarget'), $pointer);
$this->pointer = FFI::vips()->cast(FFI::ctypes('VipsTarget'), $pointer);
parent::__construct($pointer);
}

Expand Down
4 changes: 2 additions & 2 deletions src/VipsObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ abstract class VipsObject extends GObject

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

parent::__construct($pointer);
}
Expand Down
Loading