From fb9721bd73ead6675ae16830797e483a900d4fe0 Mon Sep 17 00:00:00 2001 From: jmjoy Date: Mon, 29 Jun 2026 16:11:12 +0800 Subject: [PATCH 1/4] Revert materialize_missing feature, refactor CI workflow --- .github/workflows/release-plz.yml | 21 +++--- phper-sys/php_wrapper.c | 4 - phper/src/errors.rs | 22 ------ phper/src/modules.rs | 3 +- phper/src/values.rs | 50 +------------ tests/integration/src/execute_data.rs | 77 -------------------- tests/integration/src/lib.rs | 2 - tests/integration/tests/php/execute_data.php | 42 ----------- 8 files changed, 11 insertions(+), 210 deletions(-) diff --git a/.github/workflows/release-plz.yml b/.github/workflows/release-plz.yml index 796fab7a..b3b2026e 100644 --- a/.github/workflows/release-plz.yml +++ b/.github/workflows/release-plz.yml @@ -31,23 +31,24 @@ jobs: if: ${{ github.repository_owner == 'phper-framework' }} permissions: contents: write + pull-requests: read steps: - - name: Checkout repository - uses: actions/checkout@v4 + - &checkout + name: Checkout repository + uses: actions/checkout@v6 with: fetch-depth: 0 - - name: Install Rust toolchain + persist-credentials: false + - &install-rust + name: Install Rust toolchain uses: dtolnay/rust-toolchain@stable - - name: Install libclang run: sudo apt-get install -y llvm-18-dev libclang-18-dev - - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: 7.4 tools: php-config - - name: Run release-plz uses: release-plz/action@v0.5 with: @@ -68,12 +69,8 @@ jobs: group: release-plz-${{ github.ref }} cancel-in-progress: false steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@stable + - *checkout + - *install-rust - name: Run release-plz uses: release-plz/action@v0.5 with: diff --git a/phper-sys/php_wrapper.c b/phper-sys/php_wrapper.c index 7fd23c46..1f015ed8 100644 --- a/phper-sys/php_wrapper.c +++ b/phper-sys/php_wrapper.c @@ -463,10 +463,6 @@ uint32_t phper_zend_call_num_args(const zend_execute_data *execute_data) { return ZEND_CALL_NUM_ARGS(execute_data); } -void phper_zend_set_call_num_args(zend_execute_data *execute_data, uint32_t num) { - ZEND_CALL_NUM_ARGS(execute_data) = num; -} - uint32_t phper_zend_call_info(zend_execute_data *execute_data) { return ZEND_CALL_INFO(execute_data); } diff --git a/phper/src/errors.rs b/phper/src/errors.rs index 1adac966..32b83432 100644 --- a/phper/src/errors.rs +++ b/phper/src/errors.rs @@ -46,7 +46,6 @@ macro_rules! throwable_delegate { Self::InitializeObject(e) => Throwable::$method(e), Self::ExpectType(e) => Throwable::$method(e), Self::NotImplementThrowable(e) => Throwable::$method(e), - Self::CallArg(e) => Throwable::$method(e), } }; // For `&mut self` methods (to_object). @@ -62,7 +61,6 @@ macro_rules! throwable_delegate { Self::InitializeObject(e) => Throwable::$method(e), Self::ExpectType(e) => Throwable::$method(e), Self::NotImplementThrowable(e) => Throwable::$method(e), - Self::CallArg(e) => Throwable::$method(e), } }; } @@ -250,9 +248,6 @@ pub enum Error { #[error(transparent)] NotImplementThrowable(#[from] NotImplementThrowableError), - /// Call argument index out of bounds. - #[error(transparent)] - CallArg(#[from] CallArgError), } impl Error { @@ -388,23 +383,6 @@ impl Throwable for ThrowObject { } } -/// Call argument index out of bounds. -#[derive(Debug, thiserror::Error, Constructor)] -#[error( - "call arg index {index} out of bounds: must be in [0, {declared_len}) (declared_len = \ - {declared_len})" -)] -pub struct CallArgError { - index: usize, - declared_len: usize, -} - -impl Throwable for CallArgError { - fn get_class(&self) -> &ClassEntry { - type_error_class() - } -} - /// Expect type is not the actual type. #[derive(Debug, thiserror::Error, Constructor)] #[error("type error: must be of type {expect_type}, {actual_type} given")] diff --git a/phper/src/modules.rs b/phper/src/modules.rs index d6975e69..96ec8f2a 100644 --- a/phper/src/modules.rs +++ b/phper/src/modules.rs @@ -257,8 +257,7 @@ impl Module { /// access. /// /// Unlike [`add_function`], the handler receives `&mut ExecuteData` - /// alongside `&mut [ZVal]`, enabling methods like - /// [`materialize_missing`](crate::values::ExecuteData::materialize_missing). + /// alongside `&mut [ZVal]`. pub fn add_function_with_execute_data( &mut self, name: impl Into, handler: F, ) -> &mut FunctionEntity diff --git a/phper/src/values.rs b/phper/src/values.rs index 0c83f66e..3fb05980 100644 --- a/phper/src/values.rs +++ b/phper/src/values.rs @@ -13,7 +13,7 @@ use crate::{ arrays::{ZArr, ZArray}, classes::ClassEntry, - errors::{CallArgError, ExpectTypeError}, + errors::ExpectTypeError, functions::{ZFunc, call_internal}, objects::{StateObject, ZObj, ZObject}, references::ZRef, @@ -242,56 +242,8 @@ impl ExecuteData { } } - /// Fills missing optional parameters with their default values. - /// - /// `defaults` is the full list of default values for **all** optional - /// parameters of the function. Already-provided optional arguments are - /// skipped automatically. - /// - /// `num_args` is updated to reflect the new count. - /// - /// # Errors - /// - /// Returns [`CallArgError`] if the total after filling would not match - /// `common_num_args()`. - pub fn materialize_missing( - &mut self, defaults: impl IntoIterator, - ) -> crate::Result<()> { - let declared_len = self.common_num_args() as usize; - let required_len = self.common_required_num_args(); - let passed_len = self.num_args(); - - if passed_len >= declared_len { - return Ok(()); - } - - let execute_data_ptr = self.as_mut_ptr(); - let provided_optionals = passed_len.saturating_sub(required_len); - let mut i = passed_len; - for mut default in defaults.into_iter().skip(provided_optionals) { - if i >= declared_len { - return Err(CallArgError::new(i, declared_len).into()); - } - unsafe { - phper_zend_init_call_arg( - execute_data_ptr, - i.try_into().unwrap(), - default.as_mut_ptr(), - ); - } - i += 1; - } - - if i != declared_len { - return Err(CallArgError::new(i, declared_len).into()); - } - unsafe { - phper_zend_set_call_num_args(execute_data_ptr, i.try_into().unwrap()); - } - Ok(()) - } } /// Wrapper of [zval]. diff --git a/tests/integration/src/execute_data.rs b/tests/integration/src/execute_data.rs index be26a499..e69de29b 100644 --- a/tests/integration/src/execute_data.rs +++ b/tests/integration/src/execute_data.rs @@ -1,77 +0,0 @@ -// Copyright (c) 2022 PHPER Framework Team -// PHPER is licensed under Mulan PSL v2. -// You can use this software according to the terms and conditions of the Mulan -// PSL v2. You may obtain a copy of Mulan PSL v2 at: -// http://license.coscl.org.cn/MulanPSL2 -// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY -// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO -// NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. -// See the Mulan PSL v2 for more details. - -use phper::{functions::Argument, modules::Module, values::ZVal}; - -pub fn integrate(module: &mut Module) { - register_two_optionals(module); - register_no_optionals(module); - register_exceed_error(module); - register_insufficient_error(module); -} - -fn register_two_optionals(module: &mut Module) { - module - .add_function_with_execute_data( - "materialize_missing_two_optionals", - |execute_data, _arguments| -> phper::Result { - execute_data.materialize_missing([ZVal::from(42), ZVal::from("hello")])?; - let a = execute_data.get_parameter(0).expect_long()?; - let b = execute_data.get_parameter(1).expect_z_str()?.to_str()?; - let c = execute_data.get_parameter(2).expect_long()?; - let d = execute_data.get_parameter(3).expect_z_str()?.to_str()?; - Ok(format!("{}, {}, {}, {}", a, b, c, d)) - }, - ) - .arguments([ - Argument::new("a"), - Argument::new("b"), - Argument::new("c").optional(), - Argument::new("d").optional(), - ]); -} - -fn register_no_optionals(module: &mut Module) { - module - .add_function_with_execute_data( - "materialize_missing_no_optionals", - |execute_data, _arguments| -> phper::Result { - execute_data.materialize_missing([])?; - let a = execute_data.get_parameter(0).expect_long()?; - let b = execute_data.get_parameter(1).expect_z_str()?.to_str()?; - Ok(format!("{}, {}", a, b)) - }, - ) - .arguments([Argument::new("a"), Argument::new("b")]); -} - -fn register_exceed_error(module: &mut Module) { - module - .add_function_with_execute_data( - "materialize_missing_exceed_error", - |execute_data, _arguments| -> phper::Result { - execute_data.materialize_missing([ZVal::from(1), ZVal::from(2), ZVal::from(3)])?; - Ok("ok".to_owned()) - }, - ) - .arguments([Argument::new("a").optional(), Argument::new("b").optional()]); -} - -fn register_insufficient_error(module: &mut Module) { - module - .add_function_with_execute_data( - "materialize_missing_insufficient_error", - |execute_data, _arguments| -> phper::Result { - execute_data.materialize_missing(std::iter::empty())?; - Ok("ok".to_owned()) - }, - ) - .arguments([Argument::new("a").optional(), Argument::new("b").optional()]); -} diff --git a/tests/integration/src/lib.rs b/tests/integration/src/lib.rs index ec3b9e8a..c653edd2 100644 --- a/tests/integration/src/lib.rs +++ b/tests/integration/src/lib.rs @@ -16,7 +16,6 @@ mod classes; mod constants; mod enums; mod errors; -mod execute_data; mod functions; mod ini; mod macros; @@ -47,7 +46,6 @@ pub fn get_module() -> Module { ini::integrate(&mut module); macros::integrate(&mut module); errors::integrate(&mut module); - execute_data::integrate(&mut module); references::integrate(&mut module); typehints::integrate(&mut module); #[cfg(all(phper_major_version = "8", not(phper_minor_version = "0")))] diff --git a/tests/integration/tests/php/execute_data.php b/tests/integration/tests/php/execute_data.php index 0669d0e0..e69de29b 100644 --- a/tests/integration/tests/php/execute_data.php +++ b/tests/integration/tests/php/execute_data.php @@ -1,42 +0,0 @@ - Date: Mon, 29 Jun 2026 22:30:47 +0800 Subject: [PATCH 2/4] Fmt --- phper/src/errors.rs | 1 - phper/src/values.rs | 3 --- 2 files changed, 4 deletions(-) diff --git a/phper/src/errors.rs b/phper/src/errors.rs index 32b83432..dd8504c9 100644 --- a/phper/src/errors.rs +++ b/phper/src/errors.rs @@ -247,7 +247,6 @@ pub enum Error { /// Failed when the object isn't implement PHP `Throwable`. #[error(transparent)] NotImplementThrowable(#[from] NotImplementThrowableError), - } impl Error { diff --git a/phper/src/values.rs b/phper/src/values.rs index 3fb05980..05f2f5a4 100644 --- a/phper/src/values.rs +++ b/phper/src/values.rs @@ -241,9 +241,6 @@ impl ExecuteData { ZVal::from_mut_ptr(val) } } - - - } /// Wrapper of [zval]. From b0b893615d382d4f2d241d39ef408e9d64cd86e3 Mon Sep 17 00:00:00 2001 From: jmjoy Date: Mon, 29 Jun 2026 22:41:08 +0800 Subject: [PATCH 3/4] Remove empty test files for execute_data --- tests/integration/src/execute_data.rs | 0 tests/integration/tests/php/execute_data.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/integration/src/execute_data.rs delete mode 100644 tests/integration/tests/php/execute_data.php diff --git a/tests/integration/src/execute_data.rs b/tests/integration/src/execute_data.rs deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/integration/tests/php/execute_data.php b/tests/integration/tests/php/execute_data.php deleted file mode 100644 index e69de29b..00000000 From 9cc21d5552a2d650b3375b8ba9c1c0a392606d7b Mon Sep 17 00:00:00 2001 From: jmjoy Date: Mon, 29 Jun 2026 22:53:27 +0800 Subject: [PATCH 4/4] Fix --- tests/integration/tests/cli.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/integration/tests/cli.rs b/tests/integration/tests/cli.rs index 7f6ca807..d675c98a 100644 --- a/tests/integration/tests/cli.rs +++ b/tests/integration/tests/cli.rs @@ -92,8 +92,3 @@ fn test_typehints() { fn test_enums() { test_php_script(&*DYLIB_PATH, TESTS_PHP_DIR.join("enums.php")); } - -#[test] -fn test_execute_data() { - test_php_script(&*DYLIB_PATH, TESTS_PHP_DIR.join("execute_data.php")); -}