diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d855c50..d2f98cc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,7 +40,7 @@ jobs: strategy: fail-fast: false matrix: - php: ["PHP-8.5"] + php: ["PHP-8.5", "PHP-8.6"] rust: ["1.99.0"] php_zts: [true, false] php_debug: [true, false] @@ -108,7 +108,7 @@ jobs: strategy: fail-fast: false matrix: - php: ["PHP-8.5"] + php: ["PHP-8.5", "PHP-8.6"] rust: ["1.99.0"] php_zts: [true, false] php_debug: [true, false] diff --git a/Cargo.lock b/Cargo.lock index 2e2b535..b36c5e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -445,6 +445,7 @@ name = "rsphp" version = "0.1.2" dependencies = [ "bstr", + "rsphp-compat", "rsphp-macros-c", "rsphp-sys", ] @@ -456,6 +457,13 @@ dependencies = [ "bindgen", ] +[[package]] +name = "rsphp-compat" +version = "0.1.2" +dependencies = [ + "rsphp-sys", +] + [[package]] name = "rsphp-macros-c" version = "0.1.2" @@ -468,6 +476,7 @@ dependencies = [ name = "rsphp-macros-rs" version = "0.1.2" dependencies = [ + "rsphp-compat", "rsphp-macros-c", "rsphp-sys", ] diff --git a/Cargo.toml b/Cargo.toml index de6f729..59461d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -200,6 +200,7 @@ php-ast = "0.26.0" php-rs-parser = "0.26.0" regex = "1.13.1" rsphp-build-tools = { version = "0.1.2", path = "./crates/build-tools" } +rsphp-compat = { version = "0.1.2", path = "./crates/compat" } rsphp-macros-c = { version = "0.1.2", path = "./crates/macros-c" } rsphp-macros-rs = { version = "0.1.2", path = "./crates/macros-rs" } rsphp-stub-parser = { version = "0.1.2", path = "./crates/stub-parser" } @@ -210,6 +211,7 @@ walkdir = "2.5.0" [dependencies] bstr = { workspace = true, optional = true } +rsphp-compat = { workspace = true } rsphp-macros-c = { workspace = true } rsphp-sys = { workspace = true } diff --git a/README.md b/README.md index a1172d5..01f55f4 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ The primary `rsphp` crate contains utilities for use at runtime in PHP extensions. This workplace also includes the following crates: - `rsphp-build-tools` +- `rsphp-compat` - `rsphp-macros-c` - `rsphp-macros-rs` - `rsphp-stub-parser` @@ -30,6 +31,10 @@ testing. The `rsphp-sys` crate provides bindings for PHP's C ABI, and the `rsphp-build-tools` crate provides tools for generating those bindings. +The `rsphp-compat` crate provides compatability aliases for items with different +names across different PHP versions; these can be used to simplify supporting +multiple versions of PHP. + ## Argument information When using the `rsphp-stub-parser` crate for generating argument information diff --git a/crates/compat/Cargo.toml b/crates/compat/Cargo.toml new file mode 100644 index 0000000..7ea32c3 --- /dev/null +++ b/crates/compat/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "rsphp-compat" +description = "Compatability definitions for supporting multiple PHP versions in RSPHP extensions" +categories = ["development-tools"] +authors.workspace = true +edition.workspace = true +keywords.workspace = true +license.workspace = true +repository.workspace = true +rust-version.workspace = true +version.workspace = true + +[package.metadata.docs.rs] +# Show documentation for private items +rustdoc-args = ["--document-private-items"] + +[lints] +workspace = true + +[dependencies] +rsphp-sys = { workspace = true } + +[build-dependencies] +rsphp-sys = { workspace = true } diff --git a/crates/compat/README.md b/crates/compat/README.md new file mode 100644 index 0000000..ca2f612 --- /dev/null +++ b/crates/compat/README.md @@ -0,0 +1,6 @@ +# rsphp-compat + +Compatability aliases for supporting multiple versions of PHP in extensions, see +the main [rsphp] README for more information. + +[rsphp]: https://github.com/DanielEScherzer/rsphp diff --git a/crates/compat/build.rs b/crates/compat/build.rs new file mode 100644 index 0000000..8b46a92 --- /dev/null +++ b/crates/compat/build.rs @@ -0,0 +1,9 @@ +//! Build script for [`rsphp_compat`] that `php_is_86` if building for PHP 8.6. + +fn main() { + println!("cargo::rustc-check-cfg=cfg(php_is_86)"); + + if rsphp_sys::PHP_MAJOR_VERSION == 8 && rsphp_sys::PHP_MINOR_VERSION == 6 { + println!("cargo:rustc-cfg=php_is_86"); + } +} diff --git a/crates/compat/src/lib.rs b/crates/compat/src/lib.rs new file mode 100644 index 0000000..63ce68c --- /dev/null +++ b/crates/compat/src/lib.rs @@ -0,0 +1,11 @@ +//! Compatability aliases for things that change names in different PHP versions. + +#[cfg(not(php_is_86))] +mod php_85; +#[cfg(not(php_is_86))] +pub use php_85::*; + +#[cfg(php_is_86)] +mod php_86; +#[cfg(php_is_86)] +pub use php_86::*; diff --git a/crates/compat/src/php_85.rs b/crates/compat/src/php_85.rs new file mode 100644 index 0000000..7140f2c --- /dev/null +++ b/crates/compat/src/php_85.rs @@ -0,0 +1,8 @@ +//! Aliases for PHP 8.5. + +/// The result type. +pub type ZendResultType = rsphp_sys::zend_result; +/// A failure. +pub const ZEND_RESULT_FAILURE: ZendResultType = rsphp_sys::ZEND_RESULT_CODE::FAILURE; +/// A success. +pub const ZEND_RESULT_SUCCESS: ZendResultType = rsphp_sys::ZEND_RESULT_CODE::SUCCESS; diff --git a/crates/compat/src/php_86.rs b/crates/compat/src/php_86.rs new file mode 100644 index 0000000..d144204 --- /dev/null +++ b/crates/compat/src/php_86.rs @@ -0,0 +1,8 @@ +//! Aliases for PHP 8.6. + +/// The result type. +pub type ZendResultType = rsphp_sys::zend_result::Type; +/// A failure. +pub const ZEND_RESULT_FAILURE: ZendResultType = rsphp_sys::zend_result::FAILURE; +/// A success. +pub const ZEND_RESULT_SUCCESS: ZendResultType = rsphp_sys::zend_result::SUCCESS; diff --git a/crates/macros-c/build.rs b/crates/macros-c/build.rs index 241d834..9769abf 100644 --- a/crates/macros-c/build.rs +++ b/crates/macros-c/build.rs @@ -1,10 +1,12 @@ -//! Build script for [`rsphp_macros_rs`] that automatically sets `php_zend_zts` -//! if built with [`rsphp_sys::USING_ZST`] being `1`, and `php_zend_debug` if -//! built with [`rsphp_sys::ZEND_DEBUG`] being `1`. +//! Build script for [`rsphp_macros_rs`] that automatically sets +//! - `php_zend_zts` if built with [`rsphp_sys::USING_ZST`] being `1`. +//! - `php_zend_debug` if built with [`rsphp_sys::ZEND_DEBUG`] being `1`. +//! - `php_is_86` if built for PHP 8.6. fn main() { println!("cargo::rustc-check-cfg=cfg(php_zend_debug)"); println!("cargo::rustc-check-cfg=cfg(php_zend_zts)"); + println!("cargo::rustc-check-cfg=cfg(php_is_86)"); if rsphp_sys::ZEND_DEBUG == 1 { println!("cargo:rustc-cfg=php_zend_debug"); @@ -12,4 +14,7 @@ fn main() { if rsphp_sys::USING_ZTS == 1 { println!("cargo:rustc-cfg=php_zend_zts"); } + if rsphp_sys::PHP_MAJOR_VERSION == 8 && rsphp_sys::PHP_MINOR_VERSION == 6 { + println!("cargo:rustc-cfg=php_is_86"); + } } diff --git a/crates/macros-c/src/lib.rs b/crates/macros-c/src/lib.rs index 4055460..dbfe28e 100644 --- a/crates/macros-c/src/lib.rs +++ b/crates/macros-c/src/lib.rs @@ -21,9 +21,16 @@ mod zend_api; mod zend_closures; mod zend_compile; mod zend_constants; +mod zend_globals; mod zend_globals_macros; mod zend_hash; mod zend_ini; mod zend_object_handlers; mod zend_string; mod zend_types; + +#[cfg(any(doc, all(php_zend_zts, php_is_86)))] +pub use zend_globals::ZEND_CG_OFFSET; + +#[cfg(any(doc, all(php_zend_zts, php_is_86)))] +pub use zend_globals::ZEND_EG_OFFSET; diff --git a/crates/macros-c/src/tsrm.rs b/crates/macros-c/src/tsrm.rs index 668750b..5d9aaff 100644 --- a/crates/macros-c/src/tsrm.rs +++ b/crates/macros-c/src/tsrm.rs @@ -4,7 +4,44 @@ //! statically linked with PHP (i.e. that `ZEND_ENABLE_STATIC_TSRMLS_CACHE` is //! not enabled for ZTS builds). Thus, `ZEND_TSRMG` is an alias for TSRMG. -use crate::c_version; +use crate::{c_differences, c_version}; + +const _: () = { + assert!(size_of::() == 8, "usize should be 8 bytes"); +}; +const _: () = { + assert!(size_of::() == 8, "isize should be 8 bytes"); +}; +/// Get an aligned size for TSRM. +#[doc = c_version!( + "# define TSRM_ALIGNED_SIZE(size)", + "(((size) + INT64_C(15)) & ~INT64_C(15))" +)] +#[doc = c_differences!( + "The C version is defined differently for `SIZEOF_SIZE_T` being 4 or 8, we \ + assert that it is always 8. Only the C version for the size being 8 is \ + shown above." +)] +#[macro_export] +#[cfg(any(doc, php_zend_zts))] +macro_rules! TSRM_ALIGNED_SIZE { + ($size:expr) => {{ + #[expect( + clippy::cast_possible_wrap, + clippy::as_conversions, + reason = "Matches C code" + )] + let size: i64 = $size as i64; + let result_64: i64 = (size + 15_i64) & (!15_i64); + #[expect( + clippy::cast_possible_truncation, + clippy::as_conversions, + reason = "Matches C code, isize is 8 bytes" + )] + let result: isize = result_64 as isize; + result + }}; +} /// TSRM id unshuffling. #[doc = c_version!("#define TSRM_UNSHUFFLE_RSRC_ID(rsrc_id) ((rsrc_id)-1)")] @@ -78,7 +115,7 @@ macro_rules! TSRMG_FAST { /// Bulk lookup of an overall structure in the TSRM cache. #[doc = c_version!("#define TSRMG_FAST_BULK(offset, type) ((type) (((char*) tsrm_get_ls_cache())+(offset)))")] #[macro_export] -#[cfg(any(doc, php_zend_zts))] +#[cfg(any(doc, all(php_zend_zts, not(php_is_86))))] macro_rules! TSRMG_FAST_BULK { ($offset:expr, $ty:ty) => {{ // These are unsafe and so the macro is unsafe @@ -87,3 +124,15 @@ macro_rules! TSRMG_FAST_BULK { at_offset.cast::<$ty>() }}; } + +/// Bulk lookup of an overall structure in the TSRM cache. +#[macro_export] +#[cfg(all(not(doc), php_zend_zts, php_is_86))] +macro_rules! TSRMG_FAST_BULK { + ($offset:expr, $ty:ty) => {{ + // These are unsafe and so the macro is unsafe + let cache_base: *mut std::ffi::c_void = rsphp_sys::tsrm_get_ls_cache(); + let at_offset: *mut std::ffi::c_void = cache_base.byte_offset($offset); + at_offset.cast::<$ty>() + }}; +} diff --git a/crates/macros-c/src/utils.rs b/crates/macros-c/src/utils.rs index 4600dd6..e11e77c 100644 --- a/crates/macros-c/src/utils.rs +++ b/crates/macros-c/src/utils.rs @@ -1,12 +1,5 @@ /// Create a markdown string with the C version of a macro, for use in doc /// attributes. -#[cfg_attr( - all(not(doc), php_zend_zts), - expect( - unused_macro_rules, - reason = "ZTS/NTS variants documented on the NTS version" - ) -)] macro_rules! c_version { ($code:expr) => { c_version!(@overall c_version!(@code $code)) @@ -14,31 +7,76 @@ macro_rules! c_version { ($line1:literal, $line2:literal) => { c_version!(@overall c_version!(@code $line1, $line2)) }; - (NTS => $nts:literal, ZTS => $zts:literal,) => { + (85 => $code:literal, 86 => None,) => { c_version!( @overall concat!( - c_version!(@subsection "NTS" c_version!(@code $nts)), + c_version!(@subsection "PHP 8.5" c_version!(@code $code)), "\n\n", - c_version!(@subsection "ZTS" c_version!(@code $zts)), + c_version!(@subsection "PHP 8.6" "The corresponding C macro was removed.") ) ) }; - (NTS => [$nts1:literal, $nts2:literal,], ZTS => [$zts1:literal, $zts2:literal,],) => { + (85 => [$( $line85:literal, )+], 86 => None,) => { c_version!( @overall concat!( - c_version!(@subsection "NTS" c_version!(@code $nts1, $nts2)), + c_version!(@subsection "PHP 8.5" c_version!(@code $( $line85, )+ )), "\n\n", - c_version!(@subsection "ZTS" c_version!(@code $zts1, $zts2)), + c_version!(@subsection "PHP 8.6" "The corresponding C macro was removed.") + ) + ) + }; + (85 => [$( $line85:literal, )+], 86 => [$( $line86:literal, )+],) => { + c_version!( + @overall + concat!( + c_version!(@subsection "PHP 8.5" c_version!(@code $( $line85, )+ )), + "\n\n", + c_version!(@subsection "PHP 8.6" c_version!(@code $( $line86, )+ )) + ) + ) + }; + ( + 85 => [ + NTS => [$( $line85NTS:literal, )+], + ZTS => [$( $line85ZTS:literal, )+], + ], + 86 => [ + NTS => [$( $line86NTS:literal, )+], + ZTS => [$( $line86ZTS:literal, )+], + ], + ) => { + c_version!( + @overall + concat!( + c_version!( + @subsection + "PHP 8.5" + concat!( + c_version!(@subsubsection "NTS" c_version!(@code $( $line85NTS, )+ ) ), + "\n\n", + c_version!(@subsubsection "ZTS" c_version!(@code $( $line85ZTS, )+ ) ), + ) + ), + "\n\n", + c_version!( + @subsection + "PHP 8.6" + concat!( + c_version!(@subsubsection "NTS" c_version!(@code $( $line86NTS, )+ ) ), + "\n\n", + c_version!(@subsubsection "ZTS" c_version!(@code $( $line86ZTS, )+ ) ), + ) + ), ) ) }; - (@code $code:expr) => { + (@code $code:expr $(,)?) => { concat!("```c\n", $code, "\n", "```") }; - (@code $line1:literal, $line2:literal) => { + (@code $line1:literal, $line2:literal $(,)?) => { c_version!(@code concat!($line1, " \\", "\n", " ", $line2)) }; (@overall $contents:expr) => { @@ -47,6 +85,9 @@ macro_rules! c_version { (@subsection $label:literal $contents:expr) => { concat!("## ", $label, "\n", "\n", $contents) }; + (@subsubsection $label:literal $contents:expr) => { + concat!("### ", $label, "\n", "\n", $contents) + }; } /// Creates a markdown string with differences from the C version. diff --git a/crates/macros-c/src/zend_api.rs b/crates/macros-c/src/zend_api.rs index bc66140..39a22bf 100644 --- a/crates/macros-c/src/zend_api.rs +++ b/crates/macros-c/src/zend_api.rs @@ -13,6 +13,7 @@ macro_rules! ZEND_NS_NAME { /// Create a [`rsphp_sys::zend_function_entry`] for arg info for a function. #[doc = c_version!("#define ZEND_RAW_FENTRY(zend_name, name, arg_info, flags, frameless_function_infos, doc_comment) { zend_name, name, arg_info, (uint32_t) (sizeof(arg_info)/sizeof(struct _zend_internal_arg_info)-1), flags, frameless_function_infos, doc_comment },")] +#[cfg(any(doc, not(php_is_86)))] #[macro_export] macro_rules! ZEND_RAW_FENTRY { ($name:literal, NULL, $arginfo:expr, $flags:expr, $frameless_function_infos:expr, $doc_comment:expr) => { @@ -39,6 +40,34 @@ macro_rules! ZEND_RAW_FENTRY { }; } +/// Create a [`rsphp_sys::zend_function_entry`] for arg info for a function. +#[cfg(all(not(doc), php_is_86))] +#[macro_export] +macro_rules! ZEND_RAW_FENTRY { + ($name:literal, NULL, $arginfo:expr, $flags:expr, $frameless_function_infos:expr, $doc_comment:expr) => { + rsphp_sys::zend_function_entry { + fname: $crate::c_str!($name).as_ptr(), + handler: None, + arg_info: $arginfo.as_ptr(), + num_args: ($arginfo.len() - 1) as u32, + flags: $flags as u64, + frameless_function_infos: $frameless_function_infos, + doc_comment: $doc_comment, + } + }; + ($name:literal, $handler:expr, $arginfo:expr, $flags:expr, $frameless_function_infos:expr, $doc_comment:expr) => { + rsphp_sys::zend_function_entry { + fname: $crate::c_str!($name).as_ptr(), + handler: Some($handler), + arg_info: $arginfo.as_ptr(), + num_args: ($arginfo.len() - 1) as u32, + flags: $flags as u64, + frameless_function_infos: $frameless_function_infos, + doc_comment: $doc_comment, + } + }; +} + /// Create a [`rsphp_sys::zend_function_entry`] indicating the end of the function list. #[doc = c_version!("#define ZEND_FE_END { NULL, NULL, NULL, 0, 0, NULL, NULL }")] #[macro_export] @@ -451,7 +480,10 @@ macro_rules! CE_CONSTANTS_TABLE { } /// Initialize a [`rsphp_sys::zval`] to be an empty array. -#[doc = c_version!("#define array_init(arg) ZVAL_ARR((arg), zend_new_array(0))")] +#[doc = c_version!( + 85 => "#define array_init(arg) ZVAL_ARR((arg), zend_new_array(0))", + 86 => None, +)] #[macro_export] macro_rules! array_init { ($arg:expr) => { diff --git a/crates/macros-c/src/zend_compile.rs b/crates/macros-c/src/zend_compile.rs index 403cf52..656cc5f 100644 --- a/crates/macros-c/src/zend_compile.rs +++ b/crates/macros-c/src/zend_compile.rs @@ -18,8 +18,14 @@ macro_rules! OBJ_PROP { /// Identify the offset in bytes from a [`rsphp_sys::zend_object`] pointer to /// the property with the given offset number. #[doc = c_version!( - "#define OBJ_PROP_TO_OFFSET(num)", - "((uint32_t)(XtOffsetOf(zend_object, properties_table) + sizeof(zval) * (num)))" + 85 => [ + "#define OBJ_PROP_TO_OFFSET(num)", + "((uint32_t)(XtOffsetOf(zend_object, properties_table) + sizeof(zval) * (num)))", + ], + 86 => [ + "#define OBJ_PROP_TO_OFFSET(num)", + "((uint32_t)(offsetof(zend_object, properties_table) + sizeof(zval) * (num)))", + ], )] #[macro_export] macro_rules! OBJ_PROP_TO_OFFSET { diff --git a/crates/macros-c/src/zend_globals.rs b/crates/macros-c/src/zend_globals.rs new file mode 100644 index 0000000..a8a2806 --- /dev/null +++ b/crates/macros-c/src/zend_globals.rs @@ -0,0 +1,29 @@ +//! Macros corresponding to `zend_globals.h` in php/php-src. + +/// Compile time offset of compiler globals in the reserved region before the +/// cache pointer. +/// +/// Only defined for PHP 8.6, and only for ZTS. +/// +/// # C version +/// +/// ```c +/// # define ZEND_CG_OFFSET (-(ptrdiff_t) TSRM_ALIGNED_SIZE(sizeof(zend_compiler_globals))) +/// ``` +/// +/// Not actually a macro, but computed using macros that cannot be easily +/// reimplemented for use in bindgen. +#[cfg(any(doc, all(php_zend_zts, php_is_86)))] +pub const ZEND_CG_OFFSET: isize = + -crate::TSRM_ALIGNED_SIZE!(size_of::()); + +/// Compile time offset of executor globals in the reserved region before the +/// cache pointer. +/// +/// Only defined for PHP 8.6. +/// +/// Not actually a macro, but computed using macros that cannot be easily +/// reimplemented for use in bindgen. +#[cfg(any(doc, all(php_zend_zts, php_is_86)))] +pub const ZEND_EG_OFFSET: isize = + ZEND_CG_OFFSET - crate::TSRM_ALIGNED_SIZE!(size_of::()); diff --git a/crates/macros-c/src/zend_globals_macros.rs b/crates/macros-c/src/zend_globals_macros.rs index 59d26b8..0240529 100644 --- a/crates/macros-c/src/zend_globals_macros.rs +++ b/crates/macros-c/src/zend_globals_macros.rs @@ -8,8 +8,14 @@ use crate::c_version; /// Access a compiler global. #[doc = c_version!( - NTS => "#define CG(v) (compiler_globals.v)", - ZTS => "#define CG(v) ZEND_TSRMG_FAST(compiler_globals_offset, zend_compiler_globals *, v)", + 85 => [ + NTS => ["#define CG(v) (compiler_globals.v)",], + ZTS => ["#define CG(v) ZEND_TSRMG_FAST(compiler_globals_offset, zend_compiler_globals *, v)",], + ], + 86 => [ + NTS => ["#define CG(v) (compiler_globals.v)",], + ZTS => ["#define CG(v) ZEND_TSRMG_FAST(ZEND_CG_OFFSET, zend_compiler_globals *, v)",], + ], )] #[macro_export] #[cfg(any(doc, not(php_zend_zts)))] @@ -21,7 +27,7 @@ macro_rules! CG { /// Access a compiler global. #[macro_export] -#[cfg(all(not(doc), php_zend_zts))] +#[cfg(all(not(doc), php_zend_zts, not(php_is_86)))] macro_rules! CG { ($field:ident) => { unsafe { @@ -34,10 +40,31 @@ macro_rules! CG { }; } +/// Access a compiler global. +#[macro_export] +#[cfg(all(not(doc), php_zend_zts, php_is_86))] +macro_rules! CG { + ($field:ident) => { + unsafe { + $crate::TSRMG_FAST!( + rsphp_macros_c::ZEND_CG_OFFSET, + rsphp_sys::zend_compiler_globals, + $field + ) + } + }; +} + /// Access an executer global. #[doc = c_version!( - NTS => "#define EG(v) (executor_globals.v)", - ZTS => "#define EG(v) ZEND_TSRMG_FAST(executor_globals_offset, zend_executor_globals *, v)", + 85 => [ + NTS => ["#define EG(v) (executor_globals.v)",], + ZTS => ["#define EG(v) ZEND_TSRMG_FAST(executor_globals_offset, zend_executor_globals *, v)",], + ], + 86 => [ + NTS => ["#define EG(v) (executor_globals.v)",], + ZTS => ["#define EG(v) ZEND_TSRMG_FAST(ZEND_EG_OFFSET, zend_executor_globals *, v)",], + ], )] #[macro_export] #[cfg(any(doc, not(php_zend_zts)))] @@ -49,7 +76,7 @@ macro_rules! EG { /// Access an executer global. #[macro_export] -#[cfg(all(not(doc), php_zend_zts))] +#[cfg(all(not(doc), php_zend_zts, not(php_is_86)))] macro_rules! EG { ($field:ident) => { unsafe { @@ -61,3 +88,18 @@ macro_rules! EG { } }; } + +/// Access an executer global. +#[macro_export] +#[cfg(all(not(doc), php_zend_zts, php_is_86))] +macro_rules! EG { + ($field:ident) => { + unsafe { + $crate::TSRMG_FAST!( + rsphp_macros_c::ZEND_EG_OFFSET, + rsphp_sys::zend_executor_globals, + $field + ) + } + }; +} diff --git a/crates/macros-c/src/zend_ini.rs b/crates/macros-c/src/zend_ini.rs index 3102556..2bf0605 100644 --- a/crates/macros-c/src/zend_ini.rs +++ b/crates/macros-c/src/zend_ini.rs @@ -233,13 +233,25 @@ macro_rules! ZEND_INI_ENTRY { /// Set up an INI entry definition for a boolean option. #[doc = c_version!( - NTS => [ - "#define STD_ZEND_INI_BOOLEAN(name, default_value, modifiable, on_modify, property_name, struct_type, struct_ptr)", - "ZEND_INI_ENTRY3_EX(name, default_value, modifiable, on_modify, (void *) XtOffsetOf(struct_type, property_name), (void *) &struct_ptr, NULL, zend_ini_boolean_displayer_cb)", + 85 => [ + NTS => [ + "#define STD_ZEND_INI_BOOLEAN(name, default_value, modifiable, on_modify, property_name, struct_type, struct_ptr)", + "ZEND_INI_ENTRY3_EX(name, default_value, modifiable, on_modify, (void *) XtOffsetOf(struct_type, property_name), (void *) &struct_ptr, NULL, zend_ini_boolean_displayer_cb)", + ], + ZTS => [ + "#define STD_ZEND_INI_BOOLEAN(name, default_value, modifiable, on_modify, property_name, struct_type, struct_ptr)", + "ZEND_INI_ENTRY3_EX(name, default_value, modifiable, on_modify, (void *) XtOffsetOf(struct_type, property_name), (void *) &struct_ptr##_id, NULL, zend_ini_boolean_displayer_cb)", + ], ], - ZTS => [ - "#define STD_ZEND_INI_BOOLEAN(name, default_value, modifiable, on_modify, property_name, struct_type, struct_ptr)", - "ZEND_INI_ENTRY3_EX(name, default_value, modifiable, on_modify, (void *) XtOffsetOf(struct_type, property_name), (void *) &struct_ptr##_id, NULL, zend_ini_boolean_displayer_cb)", + 86 => [ + NTS => [ + "#define STD_ZEND_INI_BOOLEAN(name, default_value, modifiable, on_modify, property_name, struct_type, struct_ptr)", + "ZEND_INI_ENTRY3_EX(name, default_value, modifiable, on_modify, (void *) offsetof(struct_type, property_name), (void *) &struct_ptr, NULL, zend_ini_boolean_displayer_cb)", + ], + ZTS => [ + "#define STD_ZEND_INI_BOOLEAN(name, default_value, modifiable, on_modify, property_name, struct_type, struct_ptr)", + "ZEND_INI_ENTRY3_EX(name, default_value, modifiable, on_modify, (void *) offsetof(struct_type, property_name), (void *) &struct_ptr##_id, NULL, zend_ini_boolean_displayer_cb)", + ], ], )] #[macro_export] @@ -267,7 +279,11 @@ macro_rules! STD_ZEND_INI_BOOLEAN { } /// Get the current version of an INI value, as a [`rsphp_sys::zend_long`]. -#[doc = c_version!("#define INI_INT(name) zend_ini_long((name), strlen(name), 0)")] +#[doc = c_version!( + 85 => "#define INI_INT(name) zend_ini_long((name), strlen(name), 0)", + 86 => None, +)] +#[cfg(any(doc, not(php_is_86)))] #[macro_export] macro_rules! INI_INT { ($name:literal) => { @@ -282,8 +298,29 @@ macro_rules! INI_INT { } }; } + +/// Get the current version of an INI value, as a [`rsphp_sys::zend_long`]. +#[cfg(all(not(doc), php_is_86))] +#[macro_export] +macro_rules! INI_INT { + ($name:literal) => { + // SAFETY: per above + unsafe { + rsphp_sys::zend_ini_long( + $crate::c_str!($name).as_ptr(), + $crate::c_str!($name).count_bytes(), + false, + ) + } + }; +} + /// Get the current version of an INI value, as an f64. -#[doc = c_version!("#define INI_FLT(name) zend_ini_double((name), strlen(name), 0)")] +#[doc = c_version!( + 85 => "#define INI_FLT(name) zend_ini_double((name), strlen(name), 0)", + 86 => None, +)] +#[cfg(any(doc, not(php_is_86)))] #[macro_export] macro_rules! INI_FLT { ($name:literal) => { @@ -298,8 +335,29 @@ macro_rules! INI_FLT { } }; } + +/// Get the current version of an INI value, as an f64. +#[cfg(all(not(doc), php_is_86))] +#[macro_export] +macro_rules! INI_FLT { + ($name:literal) => { + // SAFETY: per above + unsafe { + rsphp_sys::zend_ini_double( + $crate::c_str!($name).as_ptr(), + $crate::c_str!($name).count_bytes(), + false, + ) + } + }; +} + /// Get the current version of an INI value, as a character pointer. -#[doc = c_version!("#define INI_STR(name) zend_ini_string_ex((name), strlen(name), 0, NULL)")] +#[doc = c_version!( + 85 => "#define INI_STR(name) zend_ini_string_ex((name), strlen(name), 0, NULL)", + 86 => None, +)] +#[cfg(any(doc, not(php_is_86)))] #[macro_export] macro_rules! INI_STR { ($name:literal) => { @@ -315,8 +373,29 @@ macro_rules! INI_STR { } }; } + +/// Get the current version of an INI value, as a character pointer. +#[cfg(all(not(doc), php_is_86))] +#[macro_export] +macro_rules! INI_STR { + ($name:literal) => { + // SAFETY: per above + unsafe { + rsphp_sys::zend_ini_string_ex( + $crate::c_str!($name).as_ptr(), + $crate::c_str!($name).count_bytes(), + false, + std::ptr::null_mut(), + ) + } + }; +} + /// Get the current version of an INI value, as a boolean. -#[doc = c_version!("#define INI_BOOL(name) ((bool) INI_INT(name))")] +#[doc = c_version!( + 85 => "#define INI_BOOL(name) ((bool) INI_INT(name))", + 86 => None, +)] #[macro_export] macro_rules! INI_BOOL { ($name:literal) => { @@ -325,7 +404,11 @@ macro_rules! INI_BOOL { } /// Get the original version of an INI value, as a [`rsphp_sys::zend_long`]. -#[doc = c_version!("#define INI_ORIG_INT(name) zend_ini_long((name), strlen(name), 1)")] +#[doc = c_version!( + 85 => "#define INI_ORIG_INT(name) zend_ini_long((name), strlen(name), 1)", + 86 => None, +)] +#[cfg(any(doc, not(php_is_86)))] #[macro_export] macro_rules! INI_ORIG_INT { ($name:literal) => { @@ -340,8 +423,29 @@ macro_rules! INI_ORIG_INT { } }; } + +/// Get the original version of an INI value, as a [`rsphp_sys::zend_long`]. +#[cfg(all(not(doc), php_is_86))] +#[macro_export] +macro_rules! INI_ORIG_INT { + ($name:literal) => { + // SAFETY: per above + unsafe { + rsphp_sys::zend_ini_long( + $crate::c_str!($name).as_ptr(), + $crate::c_str!($name).count_bytes(), + true, + ) + } + }; +} + /// Get the original version of an INI value, as an f64. -#[doc = c_version!("#define INI_ORIG_FLT(name) zend_ini_double((name), strlen(name), 1)")] +#[doc = c_version!( + 85 => "#define INI_ORIG_FLT(name) zend_ini_double((name), strlen(name), 1)", + 86 => None, +)] +#[cfg(any(doc, not(php_is_86)))] #[macro_export] macro_rules! INI_ORIG_FLT { ($name:literal) => { @@ -356,8 +460,29 @@ macro_rules! INI_ORIG_FLT { } }; } + +/// Get the original version of an INI value, as an f64. +#[cfg(all(not(doc), php_is_86))] +#[macro_export] +macro_rules! INI_ORIG_FLT { + ($name:literal) => { + // SAFETY: per above + unsafe { + rsphp_sys::zend_ini_double( + $crate::c_str!($name).as_ptr(), + $crate::c_str!($name).count_bytes(), + true, + ) + } + }; +} + /// Get the original version of an INI value, as a character pointer. -#[doc = c_version!("#define INI_ORIG_STR(name) zend_ini_string((name), strlen(name), 1)")] +#[doc = c_version!( + 85 => "#define INI_ORIG_STR(name) zend_ini_string((name), strlen(name), 1)", + 86 => None, +)] +#[cfg(any(doc, not(php_is_86)))] #[macro_export] macro_rules! INI_ORIG_STR { ($name:literal) => { @@ -372,8 +497,28 @@ macro_rules! INI_ORIG_STR { } }; } + +/// Get the original version of an INI value, as a character pointer. +#[cfg(all(not(doc), php_is_86))] +#[macro_export] +macro_rules! INI_ORIG_STR { + ($name:literal) => { + // SAFETY: per above + unsafe { + rsphp_sys::zend_ini_string( + $crate::c_str!($name).as_ptr(), + $crate::c_str!($name).count_bytes(), + true, + ) + } + }; +} + /// Get the original version of an INI value, as a boolean. -#[doc = c_version!("#define INI_ORIG_BOOL(name) ((bool) INI_ORIG_INT(name))")] +#[doc = c_version!( + 85 => "#define INI_ORIG_BOOL(name) ((bool) INI_ORIG_INT(name))", + 86 => None, +)] #[macro_export] macro_rules! INI_ORIG_BOOL { ($name:literal) => { diff --git a/crates/macros-c/src/zend_object_handlers.rs b/crates/macros-c/src/zend_object_handlers.rs index 32338eb..5ba3137 100644 --- a/crates/macros-c/src/zend_object_handlers.rs +++ b/crates/macros-c/src/zend_object_handlers.rs @@ -15,6 +15,8 @@ macro_rules! IS_VALID_PROPERTY_OFFSET { /// /// # C version /// +/// ## PHP 8.5 +/// /// ```c /// #define zend_free_trampoline(func) do { \ /// if ((func) == &EG(trampoline)) { \ @@ -25,6 +27,10 @@ macro_rules! IS_VALID_PROPERTY_OFFSET { /// } \ /// } while (0) /// ``` +/// +/// ## PHP 8.6 +/// +/// The corresponding C macro was removed. #[macro_export] macro_rules! zend_free_trampoline { ($func:expr) => {{ diff --git a/crates/macros-c/src/zend_string.rs b/crates/macros-c/src/zend_string.rs index 0aa7176..bce2bbd 100644 --- a/crates/macros-c/src/zend_string.rs +++ b/crates/macros-c/src/zend_string.rs @@ -21,7 +21,10 @@ macro_rules! ZSTR_LEN { } /// Check if a [`rsphp_sys::zend_string`] is interned. -#[doc = c_version!("#define ZSTR_IS_INTERNED(s) (GC_FLAGS(s) & IS_STR_INTERNED)")] +#[doc = c_version!( + 85 => "#define ZSTR_IS_INTERNED(s) (GC_FLAGS(s) & IS_STR_INTERNED)", + 86 => None, +)] #[macro_export] macro_rules! ZSTR_IS_INTERNED { ($s:expr) => { @@ -32,8 +35,11 @@ macro_rules! ZSTR_IS_INTERNED { /// Check if two [`rsphp_sys::zend_string`]s are equal in a case-insensitive /// manner. #[doc = c_version!( - "#define zend_string_equals_ci(s1, s2)", - "(ZSTR_LEN(s1) == ZSTR_LEN(s2) && !zend_binary_strcasecmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2)))" + 85 => [ + "#define zend_string_equals_ci(s1, s2)", + "(ZSTR_LEN(s1) == ZSTR_LEN(s2) && !zend_binary_strcasecmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2)))", + ], + 86 => None, )] #[macro_export] macro_rules! zend_string_equals_ci { @@ -49,7 +55,10 @@ macro_rules! zend_string_equals_ci { } /// Get a [`rsphp_sys::zend_string`] from a known string id. -#[doc = c_version!("#define ZSTR_KNOWN(idx) zend_known_strings[idx]")] +#[doc = c_version!( + 85 => "#define ZSTR_KNOWN(idx) zend_known_strings[idx]", + 86 => None, +)] #[macro_export] macro_rules! ZSTR_KNOWN { ($idx:expr) => {{ diff --git a/crates/macros-rs/Cargo.toml b/crates/macros-rs/Cargo.toml index 99f7611..2815a3d 100644 --- a/crates/macros-rs/Cargo.toml +++ b/crates/macros-rs/Cargo.toml @@ -18,6 +18,7 @@ rustdoc-args = ["--document-private-items"] workspace = true [dependencies] +rsphp-compat = { workspace = true } rsphp-macros-c = { workspace = true } rsphp-sys = { workspace = true } diff --git a/crates/macros-rs/src/zpp.rs b/crates/macros-rs/src/zpp.rs index 55c08d6..09e21f3 100644 --- a/crates/macros-rs/src/zpp.rs +++ b/crates/macros-rs/src/zpp.rs @@ -359,7 +359,7 @@ macro_rules! __impl__ZEND_PARSE_ARGS { $spec.as_ptr().cast::(), $( $processed_var ),+ ); - if result == rsphp_sys::ZEND_RESULT_CODE::FAILURE { + if result == rsphp_compat::ZEND_RESULT_FAILURE { rsphp_macros_c::RETURN_THROWS!(); } }; diff --git a/crates/stub-parser/src/verification.rs b/crates/stub-parser/src/verification.rs index f9ba568..83920d7 100644 --- a/crates/stub-parser/src/verification.rs +++ b/crates/stub-parser/src/verification.rs @@ -332,7 +332,7 @@ fn verify_registration( continue; }; let (_, fn_entry) = methods_and_names.remove(index); - if fn_entry.flags != expect_flags { + if fn_entry.flags != expect_flags.into() { errors.push(format!( "Registration of method {name} has wrong flags, expected {expect_flags}, found {}", fn_entry.flags diff --git a/crates/stub-parser/tests/bundled_panic_test.rs b/crates/stub-parser/tests/bundled_panic_test.rs index 6e00346..566003e 100644 --- a/crates/stub-parser/tests/bundled_panic_test.rs +++ b/crates/stub-parser/tests/bundled_panic_test.rs @@ -31,6 +31,7 @@ fn verify_walker(walker: WalkDir) -> Result<(), Box> { // zend_test splits the doc comment into two for one of the constants // listformatter.stub.php uses #if conditions to specify the definition // of IntlListFromatter::TYPE_AND and ::WIDTH_WIDE, + // similarly for rangeformatter skip!( "zend_builtin_functions", "zend_constants", @@ -38,6 +39,7 @@ fn verify_walker(walker: WalkDir) -> Result<(), Box> { "php_spl", "test", "listformatter", + "rangeformatter", ); let path = entry.into_path(); // We don't care about the actual result, just that .expect() does not diff --git a/crates/stub-parser/tests/verification-cases/interface_registration.expected b/crates/stub-parser/tests/verification-cases/interface_registration.expected index 10784f7..ad4cb6b 100644 --- a/crates/stub-parser/tests/verification-cases/interface_registration.expected +++ b/crates/stub-parser/tests/verification-cases/interface_registration.expected @@ -173,7 +173,7 @@ fn verify_registration( continue; }; let (_, fn_entry) = methods_and_names.remove(index); - if fn_entry.flags != expect_flags { + if fn_entry.flags != expect_flags.into() { errors.push(format!( "Registration of method {name} has wrong flags, expected {expect_flags}, found {}", fn_entry.flags diff --git a/crates/stub-parser/tests/verification-cases/method_attribs.expected b/crates/stub-parser/tests/verification-cases/method_attribs.expected index c52592f..7fc95a1 100644 --- a/crates/stub-parser/tests/verification-cases/method_attribs.expected +++ b/crates/stub-parser/tests/verification-cases/method_attribs.expected @@ -173,7 +173,7 @@ fn verify_registration( continue; }; let (_, fn_entry) = methods_and_names.remove(index); - if fn_entry.flags != expect_flags { + if fn_entry.flags != expect_flags.into() { errors.push(format!( "Registration of method {name} has wrong flags, expected {expect_flags}, found {}", fn_entry.flags diff --git a/crates/stub-parser/tests/verification-cases/methods.expected b/crates/stub-parser/tests/verification-cases/methods.expected index c48d6f6..9c9bbf0 100644 --- a/crates/stub-parser/tests/verification-cases/methods.expected +++ b/crates/stub-parser/tests/verification-cases/methods.expected @@ -173,7 +173,7 @@ fn verify_registration( continue; }; let (_, fn_entry) = methods_and_names.remove(index); - if fn_entry.flags != expect_flags { + if fn_entry.flags != expect_flags.into() { errors.push(format!( "Registration of method {name} has wrong flags, expected {expect_flags}, found {}", fn_entry.flags diff --git a/crates/stub-parser/tests/verification-cases/namespaced_semi.expected b/crates/stub-parser/tests/verification-cases/namespaced_semi.expected index 318a88d..6bc770f 100644 --- a/crates/stub-parser/tests/verification-cases/namespaced_semi.expected +++ b/crates/stub-parser/tests/verification-cases/namespaced_semi.expected @@ -175,7 +175,7 @@ fn verify_registration( continue; }; let (_, fn_entry) = methods_and_names.remove(index); - if fn_entry.flags != expect_flags { + if fn_entry.flags != expect_flags.into() { errors.push(format!( "Registration of method {name} has wrong flags, expected {expect_flags}, found {}", fn_entry.flags diff --git a/crates/sys/build.rs b/crates/sys/build.rs index e5e8c81..a67a910 100644 --- a/crates/sys/build.rs +++ b/crates/sys/build.rs @@ -71,6 +71,9 @@ fn main() { .blocklist_function("_mm_sad_epu8") .blocklist_function("_mm_movemask_epi8") .default_enum_style(EnumVariation::ModuleConsts) + .constified_enum("zend_class_type") + .constified_enum("zend_function_type") + .constified_enum("zpp_error") .merge_extern_blocks(true) // SLOW and didn't actually add anything // .clang_macro_fallback() diff --git a/example/rust-ext-demo/Cargo.lock b/example/rust-ext-demo/Cargo.lock index 83ba0c9..0355366 100644 --- a/example/rust-ext-demo/Cargo.lock +++ b/example/rust-ext-demo/Cargo.lock @@ -245,6 +245,7 @@ name = "rsphp" version = "0.1.2" dependencies = [ "bstr", + "rsphp-compat", "rsphp-macros-c", "rsphp-sys", ] @@ -256,12 +257,20 @@ dependencies = [ "bindgen", ] +[[package]] +name = "rsphp-compat" +version = "0.1.2" +dependencies = [ + "rsphp-sys", +] + [[package]] name = "rsphp-ext-demo" version = "0.1.0" dependencies = [ "bstr", "rsphp", + "rsphp-compat", "rsphp-macros-c", "rsphp-macros-rs", "rsphp-stub-parser", @@ -280,6 +289,7 @@ dependencies = [ name = "rsphp-macros-rs" version = "0.1.2" dependencies = [ + "rsphp-compat", "rsphp-macros-c", "rsphp-sys", ] diff --git a/example/rust-ext-demo/Cargo.toml b/example/rust-ext-demo/Cargo.toml index 644b826..0a0de51 100644 --- a/example/rust-ext-demo/Cargo.toml +++ b/example/rust-ext-demo/Cargo.toml @@ -6,6 +6,7 @@ edition = "2024" [dependencies] bstr = "1.13.1" rsphp = { path = "../../", features = [ "bstr" ] } +rsphp-compat = { path = "../../crates/compat" } rsphp-macros-c = { path = "../../crates/macros-c" } rsphp-macros-rs = { path = "../../crates/macros-rs" } rsphp-sys = { path = "../../crates/sys" } diff --git a/example/rust-ext-demo/build.rs b/example/rust-ext-demo/build.rs index 35d2c2d..a5f88da 100644 --- a/example/rust-ext-demo/build.rs +++ b/example/rust-ext-demo/build.rs @@ -8,10 +8,14 @@ use rsphp_stub_parser::generate_arginfo; )] fn main() { println!("cargo::rustc-check-cfg=cfg(php_zend_zts)"); + println!("cargo::rustc-check-cfg=cfg(php_is_86)"); if rsphp_sys::USING_ZTS == 1 { println!("cargo:rustc-cfg=php_zend_zts"); } + if rsphp_sys::PHP_MAJOR_VERSION == 8 && rsphp_sys::PHP_MINOR_VERSION == 6 { + println!("cargo:rustc-cfg=php_is_86"); + } println!("cargo::rerun-if-changed=src/rustdemo.stub.php"); println!("cargo::rerun-if-changed=src/opaquedata.stub.php"); diff --git a/example/rust-ext-demo/src/demo.rs b/example/rust-ext-demo/src/demo.rs index 2a2081f..9f8879d 100644 --- a/example/rust-ext-demo/src/demo.rs +++ b/example/rust-ext-demo/src/demo.rs @@ -1,13 +1,13 @@ use rsphp::extensions::ZendStringExt as _; +use rsphp_compat::{ZEND_RESULT_FAILURE, ZEND_RESULT_SUCCESS}; use rsphp_macros_c::{ RETURN_THROWS, Z_LVAL_P, Z_OBJ_P, Z_OBJCE_P, Z_STR_P, ZEND_FE_END, ZVAL_BOOL, ZVAL_STR, }; use rsphp_macros_rs::{ZEND_ME, ZEND_PARSE_PARAMETERS_NONE, ZEND_THIS}; use rsphp_sys::{ - ZEND_ACC_PUBLIC, ZEND_RESULT_CODE, zend_ce_arithmetic_error, zend_class_entry, - zend_enum_fetch_case_name, zend_execute_data, zend_function_entry, zend_object, - zend_parse_parameters, zend_read_property, zend_string, zend_string_init, zend_throw_exception, - zend_update_property_long, zval, + ZEND_ACC_PUBLIC, zend_ce_arithmetic_error, zend_class_entry, zend_enum_fetch_case_name, + zend_execute_data, zend_function_entry, zend_object, zend_parse_parameters, zend_read_property, + zend_string, zend_string_init, zend_throw_exception, zend_update_property_long, zval, }; use std::ffi::c_char; @@ -23,10 +23,10 @@ extern "C" fn RSDemoConstructor(execute_data: *mut zend_execute_data, _return_va &mut initial_value, ) }; - if result == ZEND_RESULT_CODE::FAILURE { + if result == ZEND_RESULT_FAILURE { RETURN_THROWS!(); } - assert_eq!(result, ZEND_RESULT_CODE::SUCCESS, "Must be success"); + assert_eq!(result, ZEND_RESULT_SUCCESS, "Must be success"); unsafe { zend_update_property_long( rs_demo_ptr, diff --git a/example/rust-ext-demo/src/ini_demo_arginfo.rs b/example/rust-ext-demo/src/ini_demo_arginfo.rs index 627c4e6..0087fcc 100644 --- a/example/rust-ext-demo/src/ini_demo_arginfo.rs +++ b/example/rust-ext-demo/src/ini_demo_arginfo.rs @@ -173,7 +173,7 @@ fn verify_registration( continue; }; let (_, fn_entry) = methods_and_names.remove(index); - if fn_entry.flags != expect_flags { + if fn_entry.flags != expect_flags.into() { errors.push(format!( "Registration of method {name} has wrong flags, expected {expect_flags}, found {}", fn_entry.flags diff --git a/example/rust-ext-demo/src/lib.rs b/example/rust-ext-demo/src/lib.rs index fd8302c..af057ce 100644 --- a/example/rust-ext-demo/src/lib.rs +++ b/example/rust-ext-demo/src/lib.rs @@ -2,6 +2,7 @@ use bstr::BStr; use rsphp::wrappers::{HashRepr, InfoTablePrinter}; +use rsphp_compat::{ZEND_RESULT_FAILURE, ZEND_RESULT_SUCCESS, ZendResultType}; use rsphp_macros_c::{ HT_IS_PACKED, RETURN_THROWS, Z_ARR_P, Z_DVAL_P, Z_LVAL_P, Z_OBJCE_P, Z_STR_P, Z_TYPE_P, ZEND_ADD_CALL_FLAG, ZEND_CALL_INFO, ZEND_DEL_CALL_FLAG, ZEND_FE_END, ZSTR_LEN, ZSTR_VAL, @@ -9,11 +10,10 @@ use rsphp_macros_c::{ }; use rsphp_macros_rs::{ZEND_FE, ZEND_PARSE_ARGS, ZEND_PARSE_PARAMETERS_NONE}; use rsphp_sys::{ - HashTable, ZEND_CALL_HAS_EXTRA_NAMED_PARAMS, ZEND_RESULT_CODE, display_ini_entries, - php_output_write, php_printf, php_var_dump, zend_class_entry, zend_execute_data, - zend_function_entry, zend_long, zend_module_entry, zend_parse_parameters, - zend_register_ini_entries_ex, zend_result, zend_string, zend_string_init, - zend_unregister_ini_entries_ex, zval, + HashTable, ZEND_CALL_HAS_EXTRA_NAMED_PARAMS, display_ini_entries, php_output_write, php_printf, + php_var_dump, zend_class_entry, zend_execute_data, zend_function_entry, zend_long, + zend_module_entry, zend_parse_parameters, zend_register_ini_entries_ex, zend_string, + zend_string_init, zend_unregister_ini_entries_ex, zval, }; use std::ffi::{c_char, c_int}; @@ -33,10 +33,13 @@ static mut properties_demo_ptr: *mut zend_class_entry = std::ptr::null_mut(); #[rustfmt::skip] #[expect(clippy::cast_possible_wrap, clippy::too_many_lines)] +#[cfg_attr(not(php_is_86), expect(clippy::useless_conversion, reason = "Needed for 8.6"))] mod rustdemo_arginfo; #[rustfmt::skip] +#[cfg_attr(not(php_is_86), expect(clippy::useless_conversion, reason = "Needed for 8.6"))] mod opaquedata_arginfo; #[rustfmt::skip] +#[cfg_attr(not(php_is_86), expect(clippy::useless_conversion, reason = "Needed for 8.6"))] mod ini_demo_arginfo; extern "C" fn my_module_info(entry: *mut zend_module_entry) { @@ -47,7 +50,7 @@ extern "C" fn my_module_info(entry: *mut zend_module_entry) { } } -extern "C" fn my_module_init(type_: c_int, module_number: c_int) -> zend_result { +extern "C" fn my_module_init(type_: c_int, module_number: c_int) -> ZendResultType { unsafe { rs_demo_ptr = rustdemo_arginfo::RSDemo::register_class(&class_RSDemo_methods); color_ptr = rustdemo_arginfo::Color::register_enum(enum_Color_methods); @@ -64,14 +67,14 @@ extern "C" fn my_module_init(type_: c_int, module_number: c_int) -> zend_result zend_register_ini_entries_ex(ini_demo::demo_ini_entries.as_ptr(), module_number, type_); } - ZEND_RESULT_CODE::SUCCESS + ZEND_RESULT_SUCCESS } -extern "C" fn my_module_shutdown(type_: c_int, module_number: c_int) -> zend_result { +extern "C" fn my_module_shutdown(type_: c_int, module_number: c_int) -> ZendResultType { unsafe { zend_unregister_ini_entries_ex(module_number, type_); } - ZEND_RESULT_CODE::SUCCESS + ZEND_RESULT_SUCCESS } extern "C" fn test1(exd: *mut zend_execute_data, _return_value: *mut zval) { @@ -93,10 +96,10 @@ extern "C" fn test2(execute_data: *mut zend_execute_data, return_value: *mut zva &mut str_len, ) }; - if result == ZEND_RESULT_CODE::FAILURE { + if result == ZEND_RESULT_FAILURE { RETURN_THROWS!(); } - assert_eq!(result, ZEND_RESULT_CODE::SUCCESS, "Must be success"); + assert_eq!(result, ZEND_RESULT_SUCCESS, "Must be success"); let str_slice: &[u8] = unsafe { std::slice::from_raw_parts(str_ptr.cast::(), str_len) }; let rust_str = BStr::new(str_slice); // CANNOT use CString since PHP strings can have null bytes in the middle @@ -119,10 +122,10 @@ extern "C" fn test3(execute_data: *mut zend_execute_data, return_value: *mut zva &mut str_ptr, ) }; - if result == ZEND_RESULT_CODE::FAILURE { + if result == ZEND_RESULT_FAILURE { RETURN_THROWS!(); } - assert_eq!(result, ZEND_RESULT_CODE::SUCCESS, "Must be success"); + assert_eq!(result, ZEND_RESULT_SUCCESS, "Must be success"); let str_slice: &[u8] = unsafe { std::slice::from_raw_parts((*str_ptr).val.as_ptr().cast::(), (*str_ptr).len) }; let rust_str = BStr::new(str_slice); @@ -238,7 +241,7 @@ extern "C" fn zpp_testing(execute_data: *mut zend_execute_data, return_value: *m &mut nullable_string_len, ) }; - if result == ZEND_RESULT_CODE::FAILURE { + if result == ZEND_RESULT_FAILURE { RETURN_THROWS!(); } let string_slice: &[u8] = @@ -360,7 +363,7 @@ extern "C" fn display_value(execute_data: *mut zend_execute_data, _return_value: let result = unsafe { zend_parse_parameters((*execute_data).This.u2.num_args, c"z".as_ptr(), &mut value) }; - if result == ZEND_RESULT_CODE::FAILURE { + if result == ZEND_RESULT_FAILURE { RETURN_THROWS!(); } let mut description = match unsafe { Z_TYPE_P!(value) } { diff --git a/example/rust-ext-demo/src/opaquedata.rs b/example/rust-ext-demo/src/opaquedata.rs index a067af4..c23b82f 100644 --- a/example/rust-ext-demo/src/opaquedata.rs +++ b/example/rust-ext-demo/src/opaquedata.rs @@ -1,9 +1,10 @@ +use rsphp_compat::{ZEND_RESULT_FAILURE, ZEND_RESULT_SUCCESS}; use rsphp_macros_c::{RETURN_THROWS, Z_OBJ_P, ZEND_FE_END, ZVAL_BOOL}; use rsphp_macros_rs::{ZEND_ME, ZEND_PARSE_PARAMETERS_NONE, ZEND_THIS}; use rsphp_sys::{ - ZEND_ACC_PUBLIC, ZEND_RESULT_CODE, object_properties_init, std_object_handlers, - zend_class_entry, zend_execute_data, zend_function_entry, zend_object, zend_object_alloc, - zend_object_handlers, zend_object_std_init, zend_parse_parameters, zval, + ZEND_ACC_PUBLIC, object_properties_init, std_object_handlers, zend_class_entry, + zend_execute_data, zend_function_entry, zend_object, zend_object_alloc, zend_object_handlers, + zend_object_std_init, zend_parse_parameters, zval, }; pub(crate) static mut opaquedata_ptr: *mut zend_class_entry = std::ptr::null_mut(); @@ -39,10 +40,10 @@ extern "C" fn OpaqueDataSetBool(execute_data: *mut zend_execute_data, _return_va let result = unsafe { zend_parse_parameters((*execute_data).This.u2.num_args, c"b".as_ptr(), &mut to_set) }; - if result == ZEND_RESULT_CODE::FAILURE { + if result == ZEND_RESULT_FAILURE { RETURN_THROWS!(); } - assert_eq!(result, ZEND_RESULT_CODE::SUCCESS, "Must be success"); + assert_eq!(result, ZEND_RESULT_SUCCESS, "Must be success"); let mut object = Z_OBJ_P!(unsafe { ZEND_THIS!(execute_data) }); let data = OpaqueDataObj::from_zend_obj_ptr(&mut object); data.opaque_bool = to_set; @@ -98,8 +99,10 @@ pub(crate) unsafe fn init_opaquedata_object_handlers() { &raw mut opaquedata_object_handlers, 1, ); - opaquedata_object_handlers.offset = - i32::try_from(std::mem::offset_of!(OpaqueDataObj, zo)).expect("Valid i32"); + opaquedata_object_handlers.offset = cfg_select! { + php_is_86 => std::mem::offset_of!(OpaqueDataObj, zo), + _ => i32::try_from(std::mem::offset_of!(OpaqueDataObj, zo)).expect("Valid i32") + }; } } diff --git a/example/rust-ext-demo/src/opaquedata_arginfo.rs b/example/rust-ext-demo/src/opaquedata_arginfo.rs index e6faff0..296ad3e 100644 --- a/example/rust-ext-demo/src/opaquedata_arginfo.rs +++ b/example/rust-ext-demo/src/opaquedata_arginfo.rs @@ -173,7 +173,7 @@ fn verify_registration( continue; }; let (_, fn_entry) = methods_and_names.remove(index); - if fn_entry.flags != expect_flags { + if fn_entry.flags != expect_flags.into() { errors.push(format!( "Registration of method {name} has wrong flags, expected {expect_flags}, found {}", fn_entry.flags diff --git a/example/rust-ext-demo/src/rustdemo_arginfo.rs b/example/rust-ext-demo/src/rustdemo_arginfo.rs index e9b4660..4674d47 100644 --- a/example/rust-ext-demo/src/rustdemo_arginfo.rs +++ b/example/rust-ext-demo/src/rustdemo_arginfo.rs @@ -176,7 +176,7 @@ fn verify_registration( continue; }; let (_, fn_entry) = methods_and_names.remove(index); - if fn_entry.flags != expect_flags { + if fn_entry.flags != expect_flags.into() { errors.push(format!( "Registration of method {name} has wrong flags, expected {expect_flags}, found {}", fn_entry.flags diff --git a/src/php_exceptions.rs b/src/php_exceptions.rs index 45aed9e..11a121a 100644 --- a/src/php_exceptions.rs +++ b/src/php_exceptions.rs @@ -1,10 +1,10 @@ use crate::stack_types::StackZendString; +use rsphp_compat::ZEND_RESULT_SUCCESS; use rsphp_macros_c::{CG, EG, Z_OBJ, ZSTR_KNOWN, ZVAL_LONG, ZVAL_STR}; use rsphp_sys::{ _zend_known_string_id::ZEND_STR_CODE, _zend_known_string_id::ZEND_STR_MESSAGE, E_ERROR, - ZEND_RESULT_CODE, instanceof_function, object_init_ex, zend_ce_error, zend_ce_throwable, - zend_class_entry, zend_error_noreturn, zend_throw_exception_internal, zend_update_property_ex, - zval, + instanceof_function, object_init_ex, zend_ce_error, zend_ce_throwable, zend_class_entry, + zend_error_noreturn, zend_throw_exception_internal, zend_update_property_ex, zval, }; /// Method holder for methods relating to throwing exceptions and errors. @@ -71,8 +71,7 @@ impl PHPExceptions { // zval pointer let result = unsafe { object_init_ex(&raw mut exception_zv, ce) }; assert_eq!( - ZEND_RESULT_CODE::SUCCESS, - result, + ZEND_RESULT_SUCCESS, result, "Exception object initialization must succeed" ); diff --git a/src/php_object.rs b/src/php_object.rs index 961cd41..2e32ba3 100644 --- a/src/php_object.rs +++ b/src/php_object.rs @@ -1,5 +1,6 @@ +use rsphp_compat::ZEND_RESULT_FAILURE; use rsphp_macros_c::Z_OBJ; -use rsphp_sys::{ZEND_RESULT_CODE, object_init_ex, zend_class_entry, zend_object, zval}; +use rsphp_sys::{object_init_ex, zend_class_entry, zend_object, zval}; use std::ptr::NonNull; /// Wrapper around a [`rsphp_sys::zend_object`] that is known to exist and @@ -37,7 +38,7 @@ impl PHPObject { // SAFETY: object_init_ex() is called correctly with a pointer to a // zval to initialize and non-null pointer to a class entry let result = unsafe { object_init_ex(&raw mut zval, class_type) }; - if result == ZEND_RESULT_CODE::FAILURE { + if result == ZEND_RESULT_FAILURE { return None; } let ptr = NonNull::new(Z_OBJ!(zval))?;