From f51073404517406dfbc9f8bfc57e7fb9c4720029 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 26 Sep 2024 09:10:21 +0200 Subject: [PATCH 1/4] drop EXPERIMENTAL (as ext is stable) --- EXPERIMENTAL | 0 package.xml | 1 - 2 files changed, 1 deletion(-) delete mode 100644 EXPERIMENTAL diff --git a/EXPERIMENTAL b/EXPERIMENTAL deleted file mode 100644 index e69de29..0000000 diff --git a/package.xml b/package.xml index 365f176..290fd7b 100644 --- a/package.xml +++ b/package.xml @@ -46,7 +46,6 @@ - From d33a7fb61574bafd97c1a1f60a213aa4471bc205 Mon Sep 17 00:00:00 2001 From: Jack Date: Wed, 19 Feb 2025 21:02:05 +0000 Subject: [PATCH 2/4] Allow forcing floats to be encoded as F32 --- msgpack.c | 5 +++++ msgpack_class.c | 10 ++++++++++ msgpack_class.h | 1 + msgpack_pack.c | 6 +++++- php_msgpack.h | 1 + tests/029.phpt | 1 + tests/141.phpt | 25 +++++++++++++++++++++++++ tests/142.phpt | 23 +++++++++++++++++++++++ tests/143.phpt | 25 +++++++++++++++++++++++++ 9 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 tests/141.phpt create mode 100644 tests/142.phpt create mode 100644 tests/143.phpt diff --git a/msgpack.c b/msgpack.c index 4e3124d..fcda164 100644 --- a/msgpack.c +++ b/msgpack.c @@ -55,6 +55,9 @@ STD_PHP_INI_BOOLEAN( STD_PHP_INI_BOOLEAN( "msgpack.use_str8_serialization", "1", PHP_INI_ALL, OnUpdateBool, use_str8_serialization, zend_msgpack_globals, msgpack_globals) +STD_PHP_INI_BOOLEAN( + "msgpack.force_f32", "0", PHP_INI_ALL, OnUpdateBool, + force_f32, zend_msgpack_globals, msgpack_globals) PHP_INI_END() #if HAVE_PHP_SESSION @@ -115,6 +118,8 @@ static ZEND_MINIT_FUNCTION(msgpack) /* {{{ */ { MSGPACK_CLASS_OPT_PHPONLY, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MESSAGEPACK_OPT_ASSOC", MSGPACK_CLASS_OPT_ASSOC, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("MESSAGEPACK_OPT_FORCE_F32", + MSGPACK_CLASS_OPT_FORCE_F32, CONST_CS | CONST_PERSISTENT); return SUCCESS; } diff --git a/msgpack_class.c b/msgpack_class.c index 243d5ad..f8d162a 100644 --- a/msgpack_class.c +++ b/msgpack_class.c @@ -11,6 +11,7 @@ typedef struct { long php_only; zend_bool assoc; zend_object object; + zend_bool force_f32; } php_msgpack_base_t; typedef struct { @@ -178,6 +179,7 @@ static void php_msgpack_unpacker_free(zend_object *object) /* {{{ */ { static ZEND_METHOD(msgpack, __construct) /* {{{ */ { zend_bool 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(), "|b", &php_only) == FAILURE) { @@ -186,6 +188,7 @@ static ZEND_METHOD(msgpack, __construct) /* {{{ */ { base->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/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/tests/029.phpt b/tests/029.phpt index e1656b2..4635c39 100644 --- a/tests/029.phpt +++ b/tests/029.phpt @@ -51,6 +51,7 @@ header Version => %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 From 99ae6ab47476725101e1338a9f68fd8f3f48dc40 Mon Sep 17 00:00:00 2001 From: Andreas Wahlen Date: Fri, 18 Jul 2025 15:50:27 +0200 Subject: [PATCH 3/4] Add PHP stub file --- msgpack-stub.php | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 msgpack-stub.php 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 @@ + Date: Tue, 26 Aug 2025 13:42:51 +0200 Subject: [PATCH 4/4] ci & pie --- .github/workflows/ci.yml | 78 ++++++++++++++++++++---------- composer.json | 12 +++++ scripts/gen_github_workflow_ci.php | 10 ++-- 3 files changed, 68 insertions(+), 32 deletions(-) create mode 100644 composer.json 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/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/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