From 5e0f8722dd3fcaeefcd880582195a8f146ba673b Mon Sep 17 00:00:00 2001 From: Joe Hoyle Date: Wed, 19 Jul 2023 11:04:06 +0200 Subject: [PATCH 1/3] Add function type_() method This helps with handling zend_functions as they can be internal, user or eval. --- docsrs_bindings.rs | 3 +++ src/flags.rs | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/docsrs_bindings.rs b/docsrs_bindings.rs index 1888949c3..d15f56f65 100644 --- a/docsrs_bindings.rs +++ b/docsrs_bindings.rs @@ -91,6 +91,9 @@ pub const ZEND_ACC_GENERATOR: u32 = 16777216; pub const ZEND_ACC_DONE_PASS_TWO: u32 = 33554432; pub const ZEND_ACC_HEAP_RT_CACHE: u32 = 67108864; pub const ZEND_ACC_STRICT_TYPES: u32 = 2147483648; +pub const ZEND_INTERNAL_FUNCTION: u32 = 1; +pub const ZEND_USER_FUNCTION: u32 = 2; +pub const ZEND_EVAL_CODE: u32 = 4; pub const ZEND_ISEMPTY: u32 = 1; pub const _ZEND_SEND_MODE_SHIFT: u32 = 25; pub const _ZEND_IS_VARIADIC_BIT: u32 = 134217728; diff --git a/src/flags.rs b/src/flags.rs index 2dcdb6a89..26fbfd475 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -21,7 +21,7 @@ use crate::ffi::{ ZEND_ACC_RESOLVED_PARENT, ZEND_ACC_RETURN_REFERENCE, ZEND_ACC_STATIC, ZEND_ACC_STRICT_TYPES, ZEND_ACC_TOP_LEVEL, ZEND_ACC_TRAIT, ZEND_ACC_TRAIT_CLONE, ZEND_ACC_UNRESOLVED_VARIANCE, ZEND_ACC_USES_THIS, ZEND_ACC_USE_GUARDS, ZEND_ACC_VARIADIC, ZEND_HAS_STATIC_IN_METHODS, - Z_TYPE_FLAGS_SHIFT, _IS_BOOL, + Z_TYPE_FLAGS_SHIFT, _IS_BOOL, ZEND_INTERNAL_FUNCTION, ZEND_USER_FUNCTION, ZEND_EVAL_CODE, }; use std::{convert::TryFrom, fmt::Display}; @@ -193,6 +193,24 @@ bitflags! { const UserDeprecated = E_USER_DEPRECATED; } } +#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)] +pub enum FunctionType { + Internal, + User, + Eval, +} + +impl From for FunctionType { + #[allow(clippy::bad_bit_mask)] + fn from(value: u8) -> Self { + match value as _ { + ZEND_INTERNAL_FUNCTION => Self::Internal, + ZEND_USER_FUNCTION => Self::User, + ZEND_EVAL_CODE => Self::Eval, + _ => panic!("Unknown function type: {}", value), + } + } +} /// Valid data types for PHP. #[repr(C, u8)] From 1c55640a3e0cd22a555fac021d1cc3f654b3b2bd Mon Sep 17 00:00:00 2001 From: Joe Hoyle Date: Wed, 19 Jul 2023 12:15:59 +0200 Subject: [PATCH 2/3] Add allowed bindings --- allowed_bindings.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/allowed_bindings.rs b/allowed_bindings.rs index b1e2748fb..26604dd89 100644 --- a/allowed_bindings.rs +++ b/allowed_bindings.rs @@ -217,6 +217,9 @@ bind! { _ZEND_TYPE_NULLABLE_BIT, ts_rsrc_id, _ZEND_TYPE_NAME_BIT, + ZEND_INTERNAL_FUNCTION, + ZEND_USER_FUNCTION, + ZEND_EVAL_CODE, zval_ptr_dtor, zend_refcounted_h, zend_is_true, From a8ac0501796068c77f114c805f479babb1e87cb9 Mon Sep 17 00:00:00 2001 From: Joe Hoyle Date: Wed, 19 Jul 2023 12:27:56 +0200 Subject: [PATCH 3/3] fmt --- src/builders/module.rs | 3 ++- src/flags.rs | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/builders/module.rs b/src/builders/module.rs index 01bc9e4eb..ee2b219fd 100644 --- a/src/builders/module.rs +++ b/src/builders/module.rs @@ -131,7 +131,8 @@ impl ModuleBuilder { /// This function can be useful if you need to do any final cleanup at the /// very end of a request, after all other resources have been released. For /// example, if your extension creates any persistent resources that last - /// beyond a single request, you could use this function to clean those up. # Arguments + /// beyond a single request, you could use this function to clean those up. + /// # Arguments /// /// * `func` - The function to be called when shutdown is requested. pub fn post_deactivate_function(mut self, func: extern "C" fn() -> i32) -> Self { diff --git a/src/flags.rs b/src/flags.rs index 26fbfd475..d2fbc37ba 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -20,8 +20,9 @@ use crate::ffi::{ ZEND_ACC_PROMOTED, ZEND_ACC_PROTECTED, ZEND_ACC_PUBLIC, ZEND_ACC_RESOLVED_INTERFACES, ZEND_ACC_RESOLVED_PARENT, ZEND_ACC_RETURN_REFERENCE, ZEND_ACC_STATIC, ZEND_ACC_STRICT_TYPES, ZEND_ACC_TOP_LEVEL, ZEND_ACC_TRAIT, ZEND_ACC_TRAIT_CLONE, ZEND_ACC_UNRESOLVED_VARIANCE, - ZEND_ACC_USES_THIS, ZEND_ACC_USE_GUARDS, ZEND_ACC_VARIADIC, ZEND_HAS_STATIC_IN_METHODS, - Z_TYPE_FLAGS_SHIFT, _IS_BOOL, ZEND_INTERNAL_FUNCTION, ZEND_USER_FUNCTION, ZEND_EVAL_CODE, + ZEND_ACC_USES_THIS, ZEND_ACC_USE_GUARDS, ZEND_ACC_VARIADIC, ZEND_EVAL_CODE, + ZEND_HAS_STATIC_IN_METHODS, ZEND_INTERNAL_FUNCTION, ZEND_USER_FUNCTION, Z_TYPE_FLAGS_SHIFT, + _IS_BOOL, }; use std::{convert::TryFrom, fmt::Display};