diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0c88f03..7ee06db 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: enable_debug: "yes" enable_maintainer_zts: "yes" enable_session: "yes" - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v2 with: @@ -42,7 +42,7 @@ jobs: enable_debug: "yes" enable_maintainer_zts: "yes" enable_session: "yes" - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v2 with: @@ -70,7 +70,7 @@ jobs: enable_debug: "yes" enable_maintainer_zts: "yes" enable_session: "yes" - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v2 with: @@ -98,7 +98,35 @@ jobs: enable_debug: "yes" enable_maintainer_zts: "yes" enable_session: "yes" - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - name: Install + run: | + sudo apt-get install -y \ + php-cli \ + php-pear \ + re2c + - name: Prepare + run: | + make -f scripts/ci/Makefile php || make -f scripts/ci/Makefile clean php + - name: Build + run: | + make -f scripts/ci/Makefile ext PECL=msgpack + - name: Test + run: | + make -f scripts/ci/Makefile test + + old-matrix-4: + name: php-8.3-debug-nozts + env: + PHP: "8.3" + enable_debug: "yes" + enable_maintainer_zts: "yes" + enable_session: "yes" + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v2 with: @@ -127,7 +155,7 @@ jobs: enable_debug: "yes" enable_zts: "yes" enable_session: "yes" - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v2 with: @@ -149,11 +177,11 @@ jobs: make -f scripts/ci/Makefile test cur-none-0: - name: php-8.3-nodebug-nozts + name: php-8.4-nodebug-nozts env: - PHP: "8.3" + PHP: "8.4" enable_session: "no" - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v2 with: @@ -175,13 +203,13 @@ jobs: make -f scripts/ci/Makefile test cur-dbg-zts-0: - name: php-8.3-debug-zts + name: php-8.4-debug-zts env: - PHP: "8.3" + PHP: "8.4" enable_debug: "yes" enable_zts: "yes" enable_session: "yes" - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v2 with: @@ -203,13 +231,13 @@ jobs: make -f scripts/ci/Makefile test cur-dbg-zts-1: - name: php-8.3-nodebug-zts + name: php-8.4-nodebug-zts env: - PHP: "8.3" + PHP: "8.4" enable_debug: "no" enable_zts: "yes" enable_session: "yes" - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v2 with: @@ -231,13 +259,13 @@ jobs: make -f scripts/ci/Makefile test cur-dbg-zts-2: - name: php-8.3-debug-nozts + name: php-8.4-debug-nozts env: - PHP: "8.3" + PHP: "8.4" enable_debug: "yes" enable_zts: "no" enable_session: "yes" - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v2 with: @@ -259,13 +287,13 @@ jobs: make -f scripts/ci/Makefile test cur-dbg-zts-3: - name: php-8.3-nodebug-nozts + name: php-8.4-nodebug-nozts env: - PHP: "8.3" + PHP: "8.4" enable_debug: "no" enable_zts: "no" enable_session: "yes" - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v2 with: @@ -287,13 +315,13 @@ jobs: make -f scripts/ci/Makefile test cur-cov-0: - name: php-8.3-nodebug-nozts + name: php-8.4-nodebug-nozts env: CFLAGS: "-O0 -g --coverage" CXXFLAGS: "-O0 -g --coverage" - PHP: "8.3" + PHP: "8.4" enable_session: "yes" - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v2 with: @@ -315,7 +343,5 @@ jobs: make -f scripts/ci/Makefile test - name: Coverage if: success() - run: | - cd .libs - bash <(curl -s https://codecov.io/bash) -X xcode -X coveragepy + uses: codecov/codecov-action@v5 diff --git a/EXPERIMENTAL b/EXPERIMENTAL deleted file mode 100644 index e69de29..0000000 diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..b207404 --- /dev/null +++ b/composer.json @@ -0,0 +1,12 @@ +{ + "name": "msgpack/msgpack-php", + "type": "php-ext", + "license": "BSD-3-Clause", + "description": "MessagePack serialization API", + "require": { + "php": ">= 7.0.0" + }, + "php-ext": { + "extension-name": "msgpack" + } +} diff --git a/msgpack-stub.php b/msgpack-stub.php new file mode 100644 index 0000000..10de4a7 --- /dev/null +++ b/msgpack-stub.php @@ -0,0 +1,48 @@ +php_only = php_only; base->assoc = assoc; + base->force_f32 = force_f32; } /* }}} */ @@ -205,6 +208,9 @@ static ZEND_METHOD(msgpack, setOption) /* {{{ */ { case MSGPACK_CLASS_OPT_ASSOC: base->assoc = i_zend_is_true(value); break; + case MSGPACK_CLASS_OPT_FORCE_F32: + base->force_f32 = i_zend_is_true(value); + break; default: MSGPACK_WARNING("[msgpack] (MessagePack::setOption) " "error setting msgpack option"); @@ -221,6 +227,7 @@ static ZEND_METHOD(msgpack, pack) /* {{{ */ { smart_str buf = {0}; int php_only = MSGPACK_G(php_only); zend_bool assoc = MSGPACK_G(assoc); + zend_bool force_f32 = MSGPACK_G(force_f32); php_msgpack_base_t *base = Z_MSGPACK_BASE_P(getThis()); if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", ¶meter) == FAILURE) { @@ -229,11 +236,13 @@ static ZEND_METHOD(msgpack, pack) /* {{{ */ { MSGPACK_G(php_only) = base->php_only; MSGPACK_G(assoc) = base->assoc; + MSGPACK_G(force_f32) = base->force_f32; php_msgpack_serialize(&buf, parameter); MSGPACK_G(php_only) = php_only; MSGPACK_G(assoc) = assoc; + MSGPACK_G(force_f32) = force_f32; if (buf.s) { smart_str_0(&buf); ZVAL_STR(return_value, buf.s); @@ -512,6 +521,7 @@ void msgpack_init_class() /* {{{ */ { zend_declare_class_constant_long(msgpack_ce, ZEND_STRS("OPT_PHPONLY") - 1, MSGPACK_CLASS_OPT_PHPONLY); zend_declare_class_constant_long(msgpack_ce, ZEND_STRS("OPT_ASSOC") - 1, MSGPACK_CLASS_OPT_ASSOC); + zend_declare_class_constant_long(msgpack_ce, ZEND_STRS("OPT_FORCE_F32") - 1, MSGPACK_CLASS_OPT_FORCE_F32); /* unpacker */ INIT_CLASS_ENTRY(ce, "MessagePackUnpacker", msgpack_unpacker_methods); diff --git a/msgpack_class.h b/msgpack_class.h index 3dcbf40..b86d3ce 100644 --- a/msgpack_class.h +++ b/msgpack_class.h @@ -4,6 +4,7 @@ #define MSGPACK_CLASS_OPT_PHPONLY -1001 #define MSGPACK_CLASS_OPT_ASSOC -1002 +#define MSGPACK_CLASS_OPT_FORCE_F32 -1003 void msgpack_init_class(); diff --git a/msgpack_pack.c b/msgpack_pack.c index cfbea5c..57887c1 100644 --- a/msgpack_pack.c +++ b/msgpack_pack.c @@ -589,7 +589,11 @@ void msgpack_serialize_zval(smart_str *buf, zval *val, HashTable *var_hash) /* { msgpack_pack_long(buf, zval_get_long(val_noref)); break; case IS_DOUBLE: - msgpack_pack_double(buf, Z_DVAL_P(val_noref)); + if (MSGPACK_G(force_f32)) { + msgpack_pack_float(buf, (float) Z_DVAL_P(val_noref)); + } else { + msgpack_pack_double(buf, Z_DVAL_P(val_noref)); + } break; case IS_STRING: msgpack_serialize_string(buf, Z_STRVAL_P(val_noref), Z_STRLEN_P(val_noref)); diff --git a/package.xml b/package.xml index 365f176..290fd7b 100644 --- a/package.xml +++ b/package.xml @@ -46,7 +46,6 @@ - diff --git a/php_msgpack.h b/php_msgpack.h index 2a6ac82..b164094 100644 --- a/php_msgpack.h +++ b/php_msgpack.h @@ -26,6 +26,7 @@ ZEND_BEGIN_MODULE_GLOBALS(msgpack) zend_bool assoc; zend_bool illegal_key_insert; zend_bool use_str8_serialization; + zend_bool force_f32; struct { void *var_hash; unsigned level; diff --git a/scripts/gen_github_workflow_ci.php b/scripts/gen_github_workflow_ci.php index 81afb6f..d47fd47 100755 --- a/scripts/gen_github_workflow_ci.php +++ b/scripts/gen_github_workflow_ci.php @@ -24,11 +24,11 @@ function jobname(string $id, array $env) : string { return sprintf("php-%s-%s-%s", $env["PHP"], yesno($env, "debug"), yesno($env, "zts")); } $gen = include __DIR__ . "/ci/gen-matrix.php"; -$cur = "8.3"; +$cur = "8.4"; $job = $gen->github([ "old-matrix" => [ // most useful for all additional versions except current - "PHP" => ["7.4", "8.0", "8.1", "8.2"], + "PHP" => ["7.4", "8.0", "8.1", "8.2", "8.3"], "enable_debug" => "yes", "enable_maintainer_zts" => "yes", "enable_session" => "yes", @@ -70,7 +70,7 @@ function jobname(string $id, array $env) : string { printf(" %s: \"%s\"\n", $key, $val); } ?> - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v2 with: @@ -93,9 +93,7 @@ function jobname(string $id, array $env) : string { - name: Coverage if: success() - run: | - cd .libs - bash <(curl -s https://codecov.io/bash) -X xcode -X coveragepy + uses: codecov/codecov-action@v5 %s Directive => Local Value => Master Value msgpack.assoc => %s => %s msgpack.error_display => %s => %s +msgpack.force_f32 => Off => Off msgpack.illegal_key_insert => %s => %s msgpack.php_only => %s => %s msgpack.use_str8_serialization => %s => %s diff --git a/tests/141.phpt b/tests/141.phpt new file mode 100644 index 0000000..3db3701 --- /dev/null +++ b/tests/141.phpt @@ -0,0 +1,25 @@ +--TEST-- +Check for f32 serialisation +--SKIPIF-- +--FILE-- +setOption(\MessagePack::OPT_FORCE_F32, true); + + $serialized = $packer->pack($variable); + + echo $type, PHP_EOL; + echo bin2hex($serialized), PHP_EOL; +} + +test('double: 123.456', 123.456); +?> +--EXPECT-- +double: 123.456 +ca42f6e979 diff --git a/tests/142.phpt b/tests/142.phpt new file mode 100644 index 0000000..1ed8fee --- /dev/null +++ b/tests/142.phpt @@ -0,0 +1,23 @@ +--TEST-- +Check for f32 serialisation +--SKIPIF-- +--INI-- +msgpack.force_f32 = 1 +--FILE-- + +--EXPECT-- +double: 123.456 +ca42f6e979 diff --git a/tests/143.phpt b/tests/143.phpt new file mode 100644 index 0000000..b231192 --- /dev/null +++ b/tests/143.phpt @@ -0,0 +1,25 @@ +--TEST-- +Check for f32 serialisation +--SKIPIF-- +--INI-- +msgpack.force_f32 = 1 +--FILE-- +pack($variable); + + echo $type, PHP_EOL; + echo bin2hex($serialized), PHP_EOL; +} + +test('double: 123.456', 123.456); +?> +--EXPECT-- +double: 123.456 +ca42f6e979