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

fix: Host Functions of PHP 7.4 #23

Merged
merged 6 commits into from
Jul 3, 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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
php: ['8.3']
php: ['8.3', '7.4']
steps:
- name: Checkout sources
uses: actions/checkout@v3
Expand All @@ -28,4 +28,4 @@ jobs:
fail-fast: true
- name: Test PHP SDK
run: |
make test
make test
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ prepare:
composer install

test: prepare
php vendor/bin/phpunit ./tests --display-deprecations --display-warnings
php vendor/bin/phpunit ./tests
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
"scripts": {},
"scripts-descriptions": {},
"require-dev": {
"phpunit/phpunit": "^10"
"phpunit/phpunit": "^9"
}
}
16 changes: 14 additions & 2 deletions src/HostFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ class ExtismValType
public const V128 = 4;
public const FUNC_REF = 5;
public const EXTERN_REF = 6;

public const VAL_TYPE_MAP = [
0 => 'ExtismValType_I32',
1 => 'ExtismValType_I64',
2 => 'ExtismValType_F32',
3 => 'ExtismValType_F64',
4 => 'ExtismValType_V128',
5 => 'ExtismValType_Func_Ref',
6 => 'ExtismValType_Extern_Ref',
];
}

class HostFunction
Expand Down Expand Up @@ -52,13 +62,15 @@ function __construct(string $name, array $inputTypes, array $outputTypes, callab
$inputs = [];

for ($i = 0; $i < count($inputTypes); $i++) {
$inputs[$i] = $this->lib->ffi->cast("ExtismValType", $inputTypes[$i]);
$enum = ExtismValType::VAL_TYPE_MAP[$inputTypes[$i]];
$inputs[$i] = $this->lib->ffi->$enum;
}

$outputs = [];

for ($i = 0; $i < count($outputTypes); $i++) {
$outputs[$i] = $this->lib->ffi->cast("ExtismValType", $outputTypes[$i]);
$enum = ExtismValType::VAL_TYPE_MAP[$outputTypes[$i]];
$outputs[$i] = $this->lib->ffi->$enum;
}

$func = function ($handle, $inputs, $n_inputs, $outputs, $n_outputs, $data) use ($callback, $lib, $arguments, $offset) {
Expand Down
Loading