From 6261e04dfd6c843b87823f07bfa5954086e2795d Mon Sep 17 00:00:00 2001 From: Xenira <1288524+Xenira@users.noreply.github.com> Date: Tue, 22 Oct 2024 20:43:43 +0200 Subject: [PATCH] fix(cfg): unified php version cfg Refs: #331 --- build.rs | 7 +++++-- src/builders/class.rs | 2 +- src/flags.rs | 6 +++--- src/zend/globals.rs | 22 +++++++++++----------- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/build.rs b/build.rs index bcaabb416..f262af9e5 100644 --- a/build.rs +++ b/build.rs @@ -231,13 +231,16 @@ 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)"); - 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"); } diff --git a/src/builders/class.rs b/src/builders/class.rs index 922453690..3abf91016 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 da3a6844c..aa2208543 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/globals.rs b/src/zend/globals.rs index decd4957b..2c9c84cb3 100644 --- a/src/zend/globals.rs +++ b/src/zend/globals.rs @@ -10,18 +10,18 @@ use parking_lot::{const_rwlock, RwLock, RwLockReadGuard, RwLockWriteGuard}; use crate::boxed::ZBox; use crate::exception::PhpResult; -#[cfg(php80)] -use crate::ffi::_zend_hash_find_known_hash; -#[cfg(php82)] +#[cfg(not(any(php80, php81)))] use crate::ffi::zend_atomic_bool_store; use crate::ffi::{ - _sapi_module_struct, _zend_executor_globals, _zend_string, executor_globals, - ext_php_rs_executor_globals, ext_php_rs_file_globals, ext_php_rs_process_globals, - ext_php_rs_sapi_globals, ext_php_rs_sapi_module, php_core_globals, php_file_globals, - sapi_globals_struct, sapi_header_struct, sapi_headers_struct, sapi_request_info, - zend_ini_entry, zend_is_auto_global, TRACK_VARS_COOKIE, TRACK_VARS_ENV, TRACK_VARS_FILES, - TRACK_VARS_GET, TRACK_VARS_POST, TRACK_VARS_SERVER, + _sapi_module_struct, _zend_executor_globals, executor_globals, ext_php_rs_executor_globals, + ext_php_rs_file_globals, ext_php_rs_process_globals, ext_php_rs_sapi_globals, + ext_php_rs_sapi_module, php_core_globals, php_file_globals, sapi_globals_struct, + sapi_header_struct, sapi_headers_struct, sapi_request_info, zend_ini_entry, + zend_is_auto_global, TRACK_VARS_COOKIE, TRACK_VARS_ENV, TRACK_VARS_FILES, TRACK_VARS_GET, + TRACK_VARS_POST, TRACK_VARS_SERVER, }; +#[cfg(php80)] +use crate::ffi::{_zend_hash_find_known_hash, _zend_string}; #[cfg(not(php80))] use crate::ffi::{ _zend_known_string_id_ZEND_STR_AUTOGLOBAL_REQUEST, zend_hash_find_known_hash, @@ -161,7 +161,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); } @@ -174,7 +174,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); }