From ec0308fbee50b2d691546c742e766a229fdb0ca1 Mon Sep 17 00:00:00 2001 From: Xenira <1288524+Xenira@users.noreply.github.com> Date: Thu, 28 Nov 2024 21:56:13 +0100 Subject: [PATCH] refactor(cfg): use distinct cfg for php version Refs: #334 --- build.rs | 12 ++++++------ src/builders/class.rs | 2 +- src/flags.rs | 6 +++--- src/zend/_type.rs | 2 +- src/zend/globals.rs | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/build.rs b/build.rs index 5232564972..af1239a307 100644 --- a/build.rs +++ b/build.rs @@ -221,9 +221,6 @@ fn check_php_version(info: &PHPInfo) -> Result<()> { // introduced in PHP 8.1). // // PHP 8.0 is the baseline - no feature flags will be introduced here. - // - // The PHP version cfg flags should also stack - if you compile on PHP 8.2 you - // should get both the `php81` and `php82` flags. const PHP_81_API_VER: u32 = 20210902; const PHP_82_API_VER: u32 = 20220829; @@ -235,17 +232,20 @@ fn check_php_version(info: &PHPInfo) -> Result<()> { println!( "cargo::rustc-check-cfg=cfg(php80, php81, php82, php83, php84, php_zts, php_debug, docs)" ); - println!("cargo:rustc-cfg=php80"); + + if version < PHP_81_API_VER { + println!("cargo:rustc-cfg=php80"); + } if (PHP_81_API_VER..PHP_82_API_VER).contains(&version) { println!("cargo:rustc-cfg=php81"); } - if version >= PHP_82_API_VER { + if (PHP_82_API_VER..PHP_83_API_VER).contains(&version) { println!("cargo:rustc-cfg=php82"); } - if version >= PHP_83_API_VER { + if (PHP_83_API_VER..PHP_84_API_VER).contains(&version) { println!("cargo:rustc-cfg=php83"); } diff --git a/src/builders/class.rs b/src/builders/class.rs index 9224536906..3abf910165 100644 --- a/src/builders/class.rs +++ b/src/builders/class.rs @@ -247,7 +247,7 @@ impl ClassBuilder { // disable serialization if the class has an associated object if self.object_override.is_some() { cfg_if::cfg_if! { - if #[cfg(any(php81, php82))] { + if #[cfg(not(php80))] { class.ce_flags |= ClassFlags::NotSerializable.bits(); } else { class.serialize = Some(crate::ffi::zend_class_serialize_deny); diff --git a/src/flags.rs b/src/flags.rs index da3a6844c8..aa22085434 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -2,7 +2,7 @@ use bitflags::bitflags; -#[cfg(not(php82))] +#[cfg(any(php80, php81))] use crate::ffi::ZEND_ACC_REUSE_GET_ITERATOR; use crate::ffi::{ CONST_CS, CONST_DEPRECATED, CONST_NO_FILE_CACHE, CONST_PERSISTENT, E_COMPILE_ERROR, @@ -84,14 +84,14 @@ bitflags! { const ConstantsUpdated = ZEND_ACC_CONSTANTS_UPDATED; const NoDynamicProperties = ZEND_ACC_NO_DYNAMIC_PROPERTIES; const HasStaticInMethods = ZEND_HAS_STATIC_IN_METHODS; - #[cfg(not(php82))] + #[cfg(any(php80, php81))] const ReuseGetIterator = ZEND_ACC_REUSE_GET_ITERATOR; const ResolvedParent = ZEND_ACC_RESOLVED_PARENT; const ResolvedInterfaces = ZEND_ACC_RESOLVED_INTERFACES; const UnresolvedVariance = ZEND_ACC_UNRESOLVED_VARIANCE; const NearlyLinked = ZEND_ACC_NEARLY_LINKED; - #[cfg(any(php81,php82))] + #[cfg(not(php80))] const NotSerializable = crate::ffi::ZEND_ACC_NOT_SERIALIZABLE; } } diff --git a/src/zend/_type.rs b/src/zend/_type.rs index 7718514497..825ee2bba9 100644 --- a/src/zend/_type.rs +++ b/src/zend/_type.rs @@ -83,7 +83,7 @@ impl ZendType { flags |= _ZEND_TYPE_NULLABLE_BIT } cfg_if::cfg_if! { - if #[cfg(php83)] { + if #[cfg(not(any(php80, php81, php82)))] { flags |= crate::ffi::_ZEND_TYPE_LITERAL_NAME_BIT } else { flags |= crate::ffi::_ZEND_TYPE_NAME_BIT diff --git a/src/zend/globals.rs b/src/zend/globals.rs index 21ba29c8c6..6fa6aa44f3 100644 --- a/src/zend/globals.rs +++ b/src/zend/globals.rs @@ -10,7 +10,7 @@ use parking_lot::{const_rwlock, RwLock, RwLockReadGuard, RwLockWriteGuard}; use crate::boxed::ZBox; use crate::exception::PhpResult; -#[cfg(php82)] +#[cfg(not(any(php80, php81)))] use crate::ffi::zend_atomic_bool_store; use crate::ffi::{ _sapi_module_struct, _zend_executor_globals, ext_php_rs_executor_globals, @@ -154,7 +154,7 @@ impl ExecutorGlobals { /// set with [`crate::ffi::zend_interrupt_function`]. pub fn request_interrupt(&mut self) { cfg_if::cfg_if! { - if #[cfg(php82)] { + if #[cfg(not(any(php80, php81)))] { unsafe { zend_atomic_bool_store(&mut self.vm_interrupt, true); } @@ -167,7 +167,7 @@ impl ExecutorGlobals { /// Cancel a requested an interrupt of the PHP VM. pub fn cancel_interrupt(&mut self) { cfg_if::cfg_if! { - if #[cfg(php82)] { + if #[cfg(not(any(php80, php81)))] { unsafe { zend_atomic_bool_store(&mut self.vm_interrupt, false); }