From 0dccbc80c6b9aa0ca73eb53394640e3c18fb56dc Mon Sep 17 00:00:00 2001 From: Pierre Tondereau Date: Tue, 16 May 2023 22:56:35 +0200 Subject: [PATCH 1/2] Upgrade bitflags to v2 --- Cargo.toml | 2 +- src/flags.rs | 21 ++++++++++++++------- src/types/zval.rs | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3451c7442a..c5e1f19f3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ categories = ["api-bindings"] exclude = ["/.github", "/.crates", "/guide"] [dependencies] -bitflags = "1.2.1" +bitflags = "2" parking_lot = "0.12.1" cfg-if = "1.0" once_cell = "1.8.0" diff --git a/src/flags.rs b/src/flags.rs index d65fb17a65..20378e62b5 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -28,6 +28,7 @@ use crate::error::{Error, Result}; bitflags! { /// Flags used for setting the type of Zval. + #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)] pub struct ZvalTypeFlags: u32 { const Undef = IS_UNDEF; const Null = IS_NULL; @@ -45,13 +46,13 @@ bitflags! { const Void = IS_VOID; const Ptr = IS_PTR; - const InternedStringEx = Self::String.bits; - const StringEx = Self::String.bits | Self::RefCounted.bits; - const ArrayEx = Self::Array.bits | Self::RefCounted.bits | Self::Collectable.bits; - const ObjectEx = Self::Object.bits | Self::RefCounted.bits | Self::Collectable.bits; - const ResourceEx = Self::Resource.bits | Self::RefCounted.bits; - const ReferenceEx = Self::Reference.bits | Self::RefCounted.bits; - const ConstantAstEx = Self::ConstantExpression.bits | Self::RefCounted.bits; + const InternedStringEx = Self::String.bits(); + const StringEx = Self::String.bits() | Self::RefCounted.bits(); + const ArrayEx = Self::Array.bits() | Self::RefCounted.bits() | Self::Collectable.bits(); + const ObjectEx = Self::Object.bits() | Self::RefCounted.bits() | Self::Collectable.bits(); + const ResourceEx = Self::Resource.bits() | Self::RefCounted.bits(); + const ReferenceEx = Self::Reference.bits() | Self::RefCounted.bits(); + const ConstantAstEx = Self::ConstantExpression.bits() | Self::RefCounted.bits(); const RefCounted = (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT); const Collectable = (IS_TYPE_COLLECTABLE << Z_TYPE_FLAGS_SHIFT); @@ -60,6 +61,7 @@ bitflags! { bitflags! { /// Flags for building classes. + #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)] pub struct ClassFlags: u32 { const Final = ZEND_ACC_FINAL; const Abstract = ZEND_ACC_ABSTRACT; @@ -91,6 +93,7 @@ bitflags! { bitflags! { /// Flags for building methods. + #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)] pub struct MethodFlags: u32 { const Public = ZEND_ACC_PUBLIC; const Protected = ZEND_ACC_PROTECTED; @@ -126,6 +129,7 @@ bitflags! { bitflags! { /// Flags for building properties. + #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)] pub struct PropertyFlags: u32 { const Public = ZEND_ACC_PUBLIC; const Protected = ZEND_ACC_PROTECTED; @@ -138,6 +142,7 @@ bitflags! { bitflags! { /// Flags for building constants. + #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)] pub struct ConstantFlags: u32 { const Public = ZEND_ACC_PUBLIC; const Protected = ZEND_ACC_PROTECTED; @@ -148,6 +153,7 @@ bitflags! { bitflags! { /// Flags for building module global constants. + #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)] pub struct GlobalConstantFlags: u32 { const CaseSensitive = CONST_CS; const Persistent = CONST_PERSISTENT; @@ -158,6 +164,7 @@ bitflags! { bitflags! { /// Represents the result of a function. + #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)] pub struct ZendResult: i32 { const Success = 0; const Failure = -1; diff --git a/src/types/zval.rs b/src/types/zval.rs index 6141043fb9..d45cdad79e 100644 --- a/src/types/zval.rs +++ b/src/types/zval.rs @@ -555,7 +555,7 @@ impl Zval { // SAFETY: If the value if refcounted (`self.u1.type_info & Z_TYPE_FLAGS_MASK`) // then it is valid to dereference `self.value.counted`. unsafe { - let flags = ZvalTypeFlags::from_bits_unchecked(self.u1.type_info); + let flags = ZvalTypeFlags::from_bits_retain(self.u1.type_info); if flags.contains(ZvalTypeFlags::RefCounted) { (*self.value.counted).gc.refcount += 1; } From 8828f8fc8cf563f7b52c79720f1ca21c5197ff7e Mon Sep 17 00:00:00 2001 From: Pierre Tondereau Date: Tue, 16 May 2023 23:02:33 +0200 Subject: [PATCH 2/2] Update cargo deps --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c5e1f19f3a..7f53894b23 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,9 @@ exclude = ["/.github", "/.crates", "/guide"] [dependencies] bitflags = "2" -parking_lot = "0.12.1" +parking_lot = "0.12" cfg-if = "1.0" -once_cell = "1.8.0" +once_cell = "1.17" anyhow = { version = "1", optional = true } ext-php-rs-derive = { version = "=0.10.0", path = "./crates/macros" }