Skip to content

Commit ec0308f

Browse files
committed
refactor(cfg): use distinct cfg for php version
Refs: #334
1 parent 59721e4 commit ec0308f

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

build.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,6 @@ fn check_php_version(info: &PHPInfo) -> Result<()> {
221221
// introduced in PHP 8.1).
222222
//
223223
// PHP 8.0 is the baseline - no feature flags will be introduced here.
224-
//
225-
// The PHP version cfg flags should also stack - if you compile on PHP 8.2 you
226-
// should get both the `php81` and `php82` flags.
227224
const PHP_81_API_VER: u32 = 20210902;
228225

229226
const PHP_82_API_VER: u32 = 20220829;
@@ -235,17 +232,20 @@ fn check_php_version(info: &PHPInfo) -> Result<()> {
235232
println!(
236233
"cargo::rustc-check-cfg=cfg(php80, php81, php82, php83, php84, php_zts, php_debug, docs)"
237234
);
238-
println!("cargo:rustc-cfg=php80");
235+
236+
if version < PHP_81_API_VER {
237+
println!("cargo:rustc-cfg=php80");
238+
}
239239

240240
if (PHP_81_API_VER..PHP_82_API_VER).contains(&version) {
241241
println!("cargo:rustc-cfg=php81");
242242
}
243243

244-
if version >= PHP_82_API_VER {
244+
if (PHP_82_API_VER..PHP_83_API_VER).contains(&version) {
245245
println!("cargo:rustc-cfg=php82");
246246
}
247247

248-
if version >= PHP_83_API_VER {
248+
if (PHP_83_API_VER..PHP_84_API_VER).contains(&version) {
249249
println!("cargo:rustc-cfg=php83");
250250
}
251251

src/builders/class.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl ClassBuilder {
247247
// disable serialization if the class has an associated object
248248
if self.object_override.is_some() {
249249
cfg_if::cfg_if! {
250-
if #[cfg(any(php81, php82))] {
250+
if #[cfg(not(php80))] {
251251
class.ce_flags |= ClassFlags::NotSerializable.bits();
252252
} else {
253253
class.serialize = Some(crate::ffi::zend_class_serialize_deny);

src/flags.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use bitflags::bitflags;
44

5-
#[cfg(not(php82))]
5+
#[cfg(any(php80, php81))]
66
use crate::ffi::ZEND_ACC_REUSE_GET_ITERATOR;
77
use crate::ffi::{
88
CONST_CS, CONST_DEPRECATED, CONST_NO_FILE_CACHE, CONST_PERSISTENT, E_COMPILE_ERROR,
@@ -84,14 +84,14 @@ bitflags! {
8484
const ConstantsUpdated = ZEND_ACC_CONSTANTS_UPDATED;
8585
const NoDynamicProperties = ZEND_ACC_NO_DYNAMIC_PROPERTIES;
8686
const HasStaticInMethods = ZEND_HAS_STATIC_IN_METHODS;
87-
#[cfg(not(php82))]
87+
#[cfg(any(php80, php81))]
8888
const ReuseGetIterator = ZEND_ACC_REUSE_GET_ITERATOR;
8989
const ResolvedParent = ZEND_ACC_RESOLVED_PARENT;
9090
const ResolvedInterfaces = ZEND_ACC_RESOLVED_INTERFACES;
9191
const UnresolvedVariance = ZEND_ACC_UNRESOLVED_VARIANCE;
9292
const NearlyLinked = ZEND_ACC_NEARLY_LINKED;
9393

94-
#[cfg(any(php81,php82))]
94+
#[cfg(not(php80))]
9595
const NotSerializable = crate::ffi::ZEND_ACC_NOT_SERIALIZABLE;
9696
}
9797
}

src/zend/_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl ZendType {
8383
flags |= _ZEND_TYPE_NULLABLE_BIT
8484
}
8585
cfg_if::cfg_if! {
86-
if #[cfg(php83)] {
86+
if #[cfg(not(any(php80, php81, php82)))] {
8787
flags |= crate::ffi::_ZEND_TYPE_LITERAL_NAME_BIT
8888
} else {
8989
flags |= crate::ffi::_ZEND_TYPE_NAME_BIT

src/zend/globals.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use parking_lot::{const_rwlock, RwLock, RwLockReadGuard, RwLockWriteGuard};
1010

1111
use crate::boxed::ZBox;
1212
use crate::exception::PhpResult;
13-
#[cfg(php82)]
13+
#[cfg(not(any(php80, php81)))]
1414
use crate::ffi::zend_atomic_bool_store;
1515
use crate::ffi::{
1616
_sapi_module_struct, _zend_executor_globals, ext_php_rs_executor_globals,
@@ -154,7 +154,7 @@ impl ExecutorGlobals {
154154
/// set with [`crate::ffi::zend_interrupt_function`].
155155
pub fn request_interrupt(&mut self) {
156156
cfg_if::cfg_if! {
157-
if #[cfg(php82)] {
157+
if #[cfg(not(any(php80, php81)))] {
158158
unsafe {
159159
zend_atomic_bool_store(&mut self.vm_interrupt, true);
160160
}
@@ -167,7 +167,7 @@ impl ExecutorGlobals {
167167
/// Cancel a requested an interrupt of the PHP VM.
168168
pub fn cancel_interrupt(&mut self) {
169169
cfg_if::cfg_if! {
170-
if #[cfg(php82)] {
170+
if #[cfg(not(any(php80, php81)))] {
171171
unsafe {
172172
zend_atomic_bool_store(&mut self.vm_interrupt, false);
173173
}

0 commit comments

Comments
 (0)