Skip to content

Commit

Permalink
fix: Host Functions of PHP 7.4 (#23)
Browse files Browse the repository at this point in the history
Fixes issue #22 that causes host
functions with arguments to not work on PHP 7.4.
See issue for context.
  • Loading branch information
oatmael authored Jul 3, 2024
1 parent 6ab7293 commit ac61e14
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
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

0 comments on commit ac61e14

Please sign in to comment.