From f696b8ddcf4ea365f4e1090883bd58eef1b28ed8 Mon Sep 17 00:00:00 2001 From: Yoram Date: Tue, 12 Nov 2024 14:09:35 +0100 Subject: [PATCH 01/14] Allow optional variadic arguments for methods/functions --- crates/macros/src/function.rs | 2 +- src/types/zval.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/macros/src/function.rs b/crates/macros/src/function.rs index 670d32fedc..6fe52995a2 100644 --- a/crates/macros/src/function.rs +++ b/crates/macros/src/function.rs @@ -188,7 +188,7 @@ pub fn build_arg_parser<'a>( None }); - if rest_optional && !arg.nullable && arg.default.is_none() { + if rest_optional && !arg.nullable && arg.default.is_none() && !arg.variadic { bail!( "Parameter `{}` must be a variant of `Option` or have a default value as it is optional.", arg.name diff --git a/src/types/zval.rs b/src/types/zval.rs index d2381d5bb4..cbccad7590 100644 --- a/src/types/zval.rs +++ b/src/types/zval.rs @@ -718,3 +718,18 @@ impl<'a> FromZvalMut<'a> for &'a mut Zval { Some(zval) } } + +impl<'a> FromZvalMut<'a> for &'a [&'a Zval] { + const TYPE: DataType = DataType::Array; + + fn from_zval_mut(zval: &'a mut Zval) -> Option { + // Check if the input Zval is an array and convert it into a slice of references + if let Some(a) = zval.array(){ + // Collect references to each element in the array + let slice: Vec<&'a Zval> = a.values().collect(); + Some(Box::leak(slice.into_boxed_slice())) + } else { + None + } + } +} From 0d1176556d4860da113bd94e6d5ae45e51c7e30d Mon Sep 17 00:00:00 2001 From: Yoram Date: Thu, 14 Nov 2024 16:37:22 +0100 Subject: [PATCH 02/14] apply code style format --- src/types/zval.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/zval.rs b/src/types/zval.rs index cbccad7590..0ccb44d1ac 100644 --- a/src/types/zval.rs +++ b/src/types/zval.rs @@ -724,7 +724,7 @@ impl<'a> FromZvalMut<'a> for &'a [&'a Zval] { fn from_zval_mut(zval: &'a mut Zval) -> Option { // Check if the input Zval is an array and convert it into a slice of references - if let Some(a) = zval.array(){ + if let Some(a) = zval.array() { // Collect references to each element in the array let slice: Vec<&'a Zval> = a.values().collect(); Some(Box::leak(slice.into_boxed_slice())) From 60e2ba2dc04c72183e7ab70cf55b4026cb111084 Mon Sep 17 00:00:00 2001 From: Yoram Date: Thu, 5 Dec 2024 12:12:13 +0100 Subject: [PATCH 03/14] added tests and fix minor bugs --- src/types/zval.rs | 9 +++++--- tests/src/integration/variadic_args.php | 27 +++++++++++++++++++++++ tests/src/integration/variadic_args.rs | 4 ++++ tests/src/lib.rs | 29 ++++++++++++++++++++++++- 4 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 tests/src/integration/variadic_args.php create mode 100644 tests/src/integration/variadic_args.rs diff --git a/src/types/zval.rs b/src/types/zval.rs index 0ccb44d1ac..b8a819d5df 100644 --- a/src/types/zval.rs +++ b/src/types/zval.rs @@ -723,13 +723,16 @@ impl<'a> FromZvalMut<'a> for &'a [&'a Zval] { const TYPE: DataType = DataType::Array; fn from_zval_mut(zval: &'a mut Zval) -> Option { + let mut slice: Vec<&'a Zval> = Vec::new(); + // Check if the input Zval is an array and convert it into a slice of references if let Some(a) = zval.array() { // Collect references to each element in the array - let slice: Vec<&'a Zval> = a.values().collect(); - Some(Box::leak(slice.into_boxed_slice())) + slice = a.values().collect(); } else { - None + slice.push(zval); } + + Some(Box::leak(slice.into_boxed_slice())) } } diff --git a/tests/src/integration/variadic_args.php b/tests/src/integration/variadic_args.php new file mode 100644 index 0000000000..4b73d52784 --- /dev/null +++ b/tests/src/integration/variadic_args.php @@ -0,0 +1,27 @@ +getMessage()); +// } diff --git a/tests/src/integration/variadic_args.rs b/tests/src/integration/variadic_args.rs new file mode 100644 index 0000000000..b868f45576 --- /dev/null +++ b/tests/src/integration/variadic_args.rs @@ -0,0 +1,4 @@ +#[test] +fn test_variadic_optional_args() { + assert!(crate::integration::run_php("variadic_args.php")); +} diff --git a/tests/src/lib.rs b/tests/src/lib.rs index 237c08ef05..b31a964475 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -1,5 +1,9 @@ #![cfg_attr(windows, feature(abi_vectorcall))] -use ext_php_rs::{binary::Binary, prelude::*, types::ZendObject, types::Zval}; +use ext_php_rs::{ + binary::Binary, + prelude::*, + types::{ZendObject, Zval}, +}; use std::collections::HashMap; #[php_function] @@ -72,6 +76,28 @@ pub fn test_callable(call: ZendCallable, a: String) -> Zval { call.try_call(vec![&a]).expect("Failed to call function") } +// Rust type &[&Zval] must be converted because to Vec because of +// lifetime hell. +#[php_function(optional = "params")] +pub fn test_variadic_optional_args(params: &[&Zval]) -> Vec { + params.iter().map(|x| x.shallow_clone()).collect() +} + +#[php_function] +pub fn test_variadic_args(params: &[&Zval]) -> Vec { + params.iter().map(|x| x.shallow_clone()).collect() +} + +// Rust type &[&Zval] must be converted because to Vec because +// of lifetime hell... #[php_function] does not support lifetime. +// error1: error[E0261]: use of undeclared lifetime name `'a` +// error2: lifetime `'a` is missing in item created through this procedural +// macro #[php_function] +// pub fn test_variadic_optional2_args<'a>(params: &'a [&'a Zval]) -> &'a [&'a +// Zval] { println!("Hiero: {:#?}", params); +// params +// } + #[php_class] pub struct TestClass { string: String, @@ -184,4 +210,5 @@ mod integration { mod object; mod string; mod types; + mod variadic_args; } From d2c34fd57924abda1812da63aad2caa4d5bdf398 Mon Sep 17 00:00:00 2001 From: Yoram Date: Thu, 5 Dec 2024 12:44:19 +0100 Subject: [PATCH 04/14] added optional variadic arguments example in docs and added directly passed arguments tests --- guide/src/macros/function.md | 13 +++++++++++++ tests/src/integration/variadic_args.php | 14 ++++++++++++++ tests/src/lib.rs | 24 ++++++++++++++++++++++-- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/guide/src/macros/function.md b/guide/src/macros/function.md index 4538180f86..64281a1fd3 100644 --- a/guide/src/macros/function.md +++ b/guide/src/macros/function.md @@ -108,14 +108,27 @@ the `...$args` syntax. # use ext_php_rs::prelude::*; # use ext_php_rs::types::Zval; /// This can be called from PHP as `add(1, 2, 3, 4, 5)` +/// note: it requires to set numbers with one or arguments #[php_function] pub fn add(number: u32, numbers:&[&Zval]) -> u32 { + println!("Extra numbers: {:?}", numbers); + // numbers is a slice of 4 Zvals all of type long + number +} + +/// Having optional numbers can be done like: +/// This can be called from PHP as `add(1)`, with no addional numbers given +#[php_function(optional = "numbers")] +pub fn add(number: u32, numbers:&[&Zval]) -> u32 { + println!("Optional numbers: {:?}", numbers); // numbers is a slice of 4 Zvals all of type long number } # fn main() {} ``` +Checkout more example in our [tests](https://github.com/davidcole1340/ext-php-rs/tree/master/tests/src/integration/variadic_args.php) location. + ## Returning `Result` You can also return a `Result` from the function. The error variant will be diff --git a/tests/src/integration/variadic_args.php b/tests/src/integration/variadic_args.php index 4b73d52784..2e3d163806 100644 --- a/tests/src/integration/variadic_args.php +++ b/tests/src/integration/variadic_args.php @@ -25,3 +25,17 @@ // } catch (ArgumentCountError $e) { // var_dump($e->getMessage()); // } + +// Values directly passed +test_variadic_add_optional(1, 2, 3); // 1 + +$count = test_variadic_add_optional(11); // 11 +assert($count === 11, 'Allow only one argument'); + +$numbers = test_variadic_add_required(1, 2, 3, 4); +assert($numbers === [1, 2, 3, 4], 'Must return a array of numbers'); + +$types = test_variadic_all_types('a', 1, ['abc', 'def', 0.01], true, new stdClass); +assert(gettype(end($types[2])) === 'double', 'Type of argument 2 and its last element should be a float of 0.01'); +assert($types[3], 'Arg 4 should be boolean true'); +assert($types[4] instanceof stdClass, 'Last argument is an instance of an StdClass'); diff --git a/tests/src/lib.rs b/tests/src/lib.rs index b31a964475..255fea1ff5 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -88,13 +88,33 @@ pub fn test_variadic_args(params: &[&Zval]) -> Vec { params.iter().map(|x| x.shallow_clone()).collect() } +#[php_function(optional = "numbers")] +pub fn test_variadic_add_optional(number: u32, numbers:&[&Zval]) -> u32 { + println!("Optional numbers: {:?}", numbers); + // numbers is a slice of 4 Zvals all of type long + number +} + +#[php_function] +pub fn test_variadic_add_required(numbers:&[&Zval]) -> Vec { + // numbers is a slice of 4 Zvals all of type long + // *numbers[0].as_number() + numbers.iter().map(|x| x.shallow_clone()).collect() +} + +#[php_function(optional = "everything")] +pub fn test_variadic_all_types(everything: &[&Zval]) -> Vec { + everything.iter().map(|x| x.shallow_clone()).collect() +} + // Rust type &[&Zval] must be converted because to Vec because // of lifetime hell... #[php_function] does not support lifetime. // error1: error[E0261]: use of undeclared lifetime name `'a` // error2: lifetime `'a` is missing in item created through this procedural // macro #[php_function] -// pub fn test_variadic_optional2_args<'a>(params: &'a [&'a Zval]) -> &'a [&'a -// Zval] { println!("Hiero: {:#?}", params); +// pub fn test_variadic_optional_args<'a>(params: &'a [&'a Zval]) -> &'a [&'a +// Zval] { +// println!("Params: {:#?}", params); // params // } From a66c8b4e57a835ce6d1920fdd37bdc5b4cb95b17 Mon Sep 17 00:00:00 2001 From: Yoram Date: Fri, 6 Dec 2024 08:55:28 +0100 Subject: [PATCH 05/14] cs fix --- tests/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/src/lib.rs b/tests/src/lib.rs index 255fea1ff5..9fa7b00781 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -89,14 +89,14 @@ pub fn test_variadic_args(params: &[&Zval]) -> Vec { } #[php_function(optional = "numbers")] -pub fn test_variadic_add_optional(number: u32, numbers:&[&Zval]) -> u32 { +pub fn test_variadic_add_optional(number: u32, numbers: &[&Zval]) -> u32 { println!("Optional numbers: {:?}", numbers); // numbers is a slice of 4 Zvals all of type long number } #[php_function] -pub fn test_variadic_add_required(numbers:&[&Zval]) -> Vec { +pub fn test_variadic_add_required(numbers: &[&Zval]) -> Vec { // numbers is a slice of 4 Zvals all of type long // *numbers[0].as_number() numbers.iter().map(|x| x.shallow_clone()).collect() From 623b14f241f8973606247f187c72a9b49b502249 Mon Sep 17 00:00:00 2001 From: Yoram Date: Fri, 6 Dec 2024 10:26:15 +0100 Subject: [PATCH 06/14] change name of example func --- guide/src/macros/function.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guide/src/macros/function.md b/guide/src/macros/function.md index 64281a1fd3..f3f32d678f 100644 --- a/guide/src/macros/function.md +++ b/guide/src/macros/function.md @@ -119,7 +119,7 @@ pub fn add(number: u32, numbers:&[&Zval]) -> u32 { /// Having optional numbers can be done like: /// This can be called from PHP as `add(1)`, with no addional numbers given #[php_function(optional = "numbers")] -pub fn add(number: u32, numbers:&[&Zval]) -> u32 { +pub fn add_optional(number: u32, numbers:&[&Zval]) -> u32 { println!("Optional numbers: {:?}", numbers); // numbers is a slice of 4 Zvals all of type long number From fbeb8fd7654d2d9b6bb5ca196ebe7d4d83066327 Mon Sep 17 00:00:00 2001 From: Yoram Date: Mon, 9 Dec 2024 16:01:53 +0100 Subject: [PATCH 07/14] Remove comments and unnecessary code --- tests/src/integration/variadic_args.php | 5 ----- tests/src/lib.rs | 15 --------------- 2 files changed, 20 deletions(-) diff --git a/tests/src/integration/variadic_args.php b/tests/src/integration/variadic_args.php index 2e3d163806..4855bdcd5d 100644 --- a/tests/src/integration/variadic_args.php +++ b/tests/src/integration/variadic_args.php @@ -20,11 +20,6 @@ // Must have arguments.. so catch ArgumentCountError errors! assert_exception_thrown('test_variadic_args'); -// try { -// $args = test_variadic_args(); -// } catch (ArgumentCountError $e) { -// var_dump($e->getMessage()); -// } // Values directly passed test_variadic_add_optional(1, 2, 3); // 1 diff --git a/tests/src/lib.rs b/tests/src/lib.rs index 9fa7b00781..40d3d68b77 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -90,15 +90,11 @@ pub fn test_variadic_args(params: &[&Zval]) -> Vec { #[php_function(optional = "numbers")] pub fn test_variadic_add_optional(number: u32, numbers: &[&Zval]) -> u32 { - println!("Optional numbers: {:?}", numbers); - // numbers is a slice of 4 Zvals all of type long number } #[php_function] pub fn test_variadic_add_required(numbers: &[&Zval]) -> Vec { - // numbers is a slice of 4 Zvals all of type long - // *numbers[0].as_number() numbers.iter().map(|x| x.shallow_clone()).collect() } @@ -107,17 +103,6 @@ pub fn test_variadic_all_types(everything: &[&Zval]) -> Vec { everything.iter().map(|x| x.shallow_clone()).collect() } -// Rust type &[&Zval] must be converted because to Vec because -// of lifetime hell... #[php_function] does not support lifetime. -// error1: error[E0261]: use of undeclared lifetime name `'a` -// error2: lifetime `'a` is missing in item created through this procedural -// macro #[php_function] -// pub fn test_variadic_optional_args<'a>(params: &'a [&'a Zval]) -> &'a [&'a -// Zval] { -// println!("Params: {:#?}", params); -// params -// } - #[php_class] pub struct TestClass { string: String, From 2792a0958afa0af82012b163e23a7b61925398e1 Mon Sep 17 00:00:00 2001 From: Yoram Date: Wed, 11 Dec 2024 10:46:56 +0100 Subject: [PATCH 08/14] unused params for example --- tests/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/lib.rs b/tests/src/lib.rs index 40d3d68b77..0469d7f453 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -89,7 +89,7 @@ pub fn test_variadic_args(params: &[&Zval]) -> Vec { } #[php_function(optional = "numbers")] -pub fn test_variadic_add_optional(number: u32, numbers: &[&Zval]) -> u32 { +pub fn test_variadic_add_optional(number: u32, _numbers: &[&Zval]) -> u32 { number } From d278e306f5ba99768a8c5e06b4277c33259810fd Mon Sep 17 00:00:00 2001 From: Yoram Date: Wed, 15 Jan 2025 11:39:24 +0100 Subject: [PATCH 09/14] fix: issue after pulling master --- src/zend/handlers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zend/handlers.rs b/src/zend/handlers.rs index 7e88a7e053..02439b035b 100644 --- a/src/zend/handlers.rs +++ b/src/zend/handlers.rs @@ -239,7 +239,7 @@ impl ZendObjectHandlers { val.get(self_, &mut zv)?; #[allow(clippy::unnecessary_mut_passed)] - if zend_is_true(&mut zv) == 1 { + if zend_is_true(&mut zv) { return Ok(1); } } From a54954c538124d54a9be0ffcf55bc6c96b97b6fd Mon Sep 17 00:00:00 2001 From: Yoram Date: Wed, 15 Jan 2025 11:51:36 +0100 Subject: [PATCH 10/14] fix: missing fields for FunctionEntry --- src/builders/function.rs | 11 +++++++++-- src/zend/function.rs | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/builders/function.rs b/src/builders/function.rs index 60eddcc962..d8bc36433c 100644 --- a/src/builders/function.rs +++ b/src/builders/function.rs @@ -5,7 +5,10 @@ use crate::{ types::Zval, zend::{ExecuteData, FunctionEntry, ZendType}, }; -use std::{ffi::CString, mem, ptr}; +use std::{ + ffi::{c_char, CString}, + mem, ptr, +}; /// Function representation in Rust. #[cfg(not(windows))] @@ -54,7 +57,9 @@ impl<'a> FunctionBuilder<'a> { }), arg_info: ptr::null(), num_args: 0, - flags: 0, // TBD? + flags: 0, + frameless_function_infos: ptr::null(), + doc_comment: "".as_ptr() as *const c_char, }, args: vec![], n_req: None, @@ -79,6 +84,8 @@ impl<'a> FunctionBuilder<'a> { arg_info: ptr::null(), num_args: 0, flags: MethodFlags::Abstract.bits(), + frameless_function_infos: ptr::null(), + doc_comment: "".as_ptr() as *const c_char, }, args: vec![], n_req: None, diff --git a/src/zend/function.rs b/src/zend/function.rs index 6e6dd1a39e..d9dceed49a 100644 --- a/src/zend/function.rs +++ b/src/zend/function.rs @@ -38,6 +38,10 @@ impl FunctionEntry { arg_info: ptr::null(), num_args: 0, flags: 0, + frameless_function_infos: ptr::null(), + doc_comment: "".as_ptr() as *const c_char, + // pub frameless_function_infos: *const zend_frameless_function_info, + // pub doc_comment: *const ::std::os::raw::c_char, } } From 2f9a321daf0d95e68c1787f8033ffcd37e3a1a21 Mon Sep 17 00:00:00 2001 From: Yoram Date: Wed, 15 Jan 2025 12:27:48 +0100 Subject: [PATCH 11/14] added PHP8.4 --- build.rs | 10 ++++++++-- src/builders/function.rs | 4 ++++ src/zend/function.rs | 4 ++-- src/zend/handlers.rs | 6 ++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/build.rs b/build.rs index bcaabb4161..ee15bb55d0 100644 --- a/build.rs +++ b/build.rs @@ -16,7 +16,7 @@ use bindgen::RustTarget; use impl_::Provider; const MIN_PHP_API_VER: u32 = 20200930; -const MAX_PHP_API_VER: u32 = 20230831; +const MAX_PHP_API_VER: u32 = 20240924; pub trait PHPProvider<'a>: Sized { /// Create a new PHP provider. @@ -230,7 +230,9 @@ fn check_php_version(info: &PHPInfo) -> Result<()> { const PHP_83_API_VER: u32 = 20230831; - println!("cargo::rustc-check-cfg=cfg(php80, php81, php82, php83, php_zts, php_debug, docs)"); + const PHP_84_API_VER: u32 = 20240924; + + println!("cargo::rustc-check-cfg=cfg(php80, php81, php82, php83, php84, php_zts, php_debug, docs)"); println!("cargo:rustc-cfg=php80"); if (PHP_81_API_VER..PHP_82_API_VER).contains(&version) { @@ -245,6 +247,10 @@ fn check_php_version(info: &PHPInfo) -> Result<()> { println!("cargo:rustc-cfg=php83"); } + if version >= PHP_84_API_VER { + println!("cargo:rustc-cfg=php84"); + } + Ok(()) } diff --git a/src/builders/function.rs b/src/builders/function.rs index d8bc36433c..c67762d475 100644 --- a/src/builders/function.rs +++ b/src/builders/function.rs @@ -58,7 +58,9 @@ impl<'a> FunctionBuilder<'a> { arg_info: ptr::null(), num_args: 0, flags: 0, + #[cfg(php84)] frameless_function_infos: ptr::null(), + #[cfg(php84)] doc_comment: "".as_ptr() as *const c_char, }, args: vec![], @@ -84,7 +86,9 @@ impl<'a> FunctionBuilder<'a> { arg_info: ptr::null(), num_args: 0, flags: MethodFlags::Abstract.bits(), + #[cfg(php84)] frameless_function_infos: ptr::null(), + #[cfg(php84)] doc_comment: "".as_ptr() as *const c_char, }, args: vec![], diff --git a/src/zend/function.rs b/src/zend/function.rs index d9dceed49a..60b3e9320b 100644 --- a/src/zend/function.rs +++ b/src/zend/function.rs @@ -38,10 +38,10 @@ impl FunctionEntry { arg_info: ptr::null(), num_args: 0, flags: 0, + #[cfg(php84)] frameless_function_infos: ptr::null(), + #[cfg(php84)] doc_comment: "".as_ptr() as *const c_char, - // pub frameless_function_infos: *const zend_frameless_function_info, - // pub doc_comment: *const ::std::os::raw::c_char, } } diff --git a/src/zend/handlers.rs b/src/zend/handlers.rs index 02439b035b..da1a3d064c 100644 --- a/src/zend/handlers.rs +++ b/src/zend/handlers.rs @@ -238,10 +238,16 @@ impl ZendObjectHandlers { let mut zv = Zval::new(); val.get(self_, &mut zv)?; + #[cfg(php84)] #[allow(clippy::unnecessary_mut_passed)] if zend_is_true(&mut zv) { return Ok(1); } + + #[cfg(not(php84))] + if zend_is_true(&mut zv) == 1 { + return Ok(1); + } } } // From 71c9a4597c43fe91d45ae8e1a9c5762cabc47021 Mon Sep 17 00:00:00 2001 From: Yoram Date: Wed, 22 Jan 2025 11:29:15 +0100 Subject: [PATCH 12/14] fix: tests --- tests/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/lib.rs b/tests/src/lib.rs index 0469d7f453..ac07764da5 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -88,7 +88,7 @@ pub fn test_variadic_args(params: &[&Zval]) -> Vec { params.iter().map(|x| x.shallow_clone()).collect() } -#[php_function(optional = "numbers")] +#[php_function(optional = "_numbers")] pub fn test_variadic_add_optional(number: u32, _numbers: &[&Zval]) -> u32 { number } From 692c6bdf505af7a95186e04ec8962423ab90930a Mon Sep 17 00:00:00 2001 From: Yoram Date: Wed, 22 Jan 2025 11:35:29 +0100 Subject: [PATCH 13/14] clippy --- build.rs | 4 +++- src/zend/function.rs | 4 ++-- src/zend/handlers.rs | 21 ++++++++++++--------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/build.rs b/build.rs index ee15bb55d0..5232564972 100644 --- a/build.rs +++ b/build.rs @@ -232,7 +232,9 @@ fn check_php_version(info: &PHPInfo) -> Result<()> { const PHP_84_API_VER: u32 = 20240924; - println!("cargo::rustc-check-cfg=cfg(php80, php81, php82, php83, php84, php_zts, php_debug, docs)"); + println!( + "cargo::rustc-check-cfg=cfg(php80, php81, php82, php83, php84, php_zts, php_debug, docs)" + ); println!("cargo:rustc-cfg=php80"); if (PHP_81_API_VER..PHP_82_API_VER).contains(&version) { diff --git a/src/zend/function.rs b/src/zend/function.rs index 60b3e9320b..a16ea1e61a 100644 --- a/src/zend/function.rs +++ b/src/zend/function.rs @@ -39,9 +39,9 @@ impl FunctionEntry { num_args: 0, flags: 0, #[cfg(php84)] - frameless_function_infos: ptr::null(), + doc_comment: ptr::null(), #[cfg(php84)] - doc_comment: "".as_ptr() as *const c_char, + frameless_function_infos: ptr::null(), } } diff --git a/src/zend/handlers.rs b/src/zend/handlers.rs index da1a3d064c..d8f8ac148e 100644 --- a/src/zend/handlers.rs +++ b/src/zend/handlers.rs @@ -238,15 +238,18 @@ impl ZendObjectHandlers { let mut zv = Zval::new(); val.get(self_, &mut zv)?; - #[cfg(php84)] - #[allow(clippy::unnecessary_mut_passed)] - if zend_is_true(&mut zv) { - return Ok(1); - } - - #[cfg(not(php84))] - if zend_is_true(&mut zv) == 1 { - return Ok(1); + cfg_if::cfg_if! { + if #[cfg(php84)] { + #[allow(clippy::unnecessary_mut_passed)] + if zend_is_true(&mut zv) { + return Ok(1); + } + } else { + #[allow(clippy::unnecessary_mut_passed)] + if zend_is_true(&mut zv) == 1 { + return Ok(1); + } + } } } } From 5e6954c25a9f3ffcf303af3dceff262719e01bad Mon Sep 17 00:00:00 2001 From: Yoram Date: Wed, 22 Jan 2025 11:38:00 +0100 Subject: [PATCH 14/14] consistency and fmt --- src/builders/function.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/builders/function.rs b/src/builders/function.rs index c67762d475..99f74f7e2d 100644 --- a/src/builders/function.rs +++ b/src/builders/function.rs @@ -5,10 +5,7 @@ use crate::{ types::Zval, zend::{ExecuteData, FunctionEntry, ZendType}, }; -use std::{ - ffi::{c_char, CString}, - mem, ptr, -}; +use std::{ffi::CString, mem, ptr}; /// Function representation in Rust. #[cfg(not(windows))] @@ -57,11 +54,11 @@ impl<'a> FunctionBuilder<'a> { }), arg_info: ptr::null(), num_args: 0, - flags: 0, + flags: 0, // TBD? #[cfg(php84)] - frameless_function_infos: ptr::null(), + doc_comment: ptr::null(), #[cfg(php84)] - doc_comment: "".as_ptr() as *const c_char, + frameless_function_infos: ptr::null(), }, args: vec![], n_req: None, @@ -87,9 +84,9 @@ impl<'a> FunctionBuilder<'a> { num_args: 0, flags: MethodFlags::Abstract.bits(), #[cfg(php84)] - frameless_function_infos: ptr::null(), + doc_comment: ptr::null(), #[cfg(php84)] - doc_comment: "".as_ptr() as *const c_char, + frameless_function_infos: ptr::null(), }, args: vec![], n_req: None,