From 38cbba0457e637cc4e5410fb29a7964c2dfc40c0 Mon Sep 17 00:00:00 2001 From: Joe Hoyle Date: Wed, 19 Jul 2023 15:30:49 +0200 Subject: [PATCH 1/3] Add function type helper function Follow up to #254 --- src/zend/ex.rs | 12 ++++++++++++ src/zend/function.rs | 13 ++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/zend/ex.rs b/src/zend/ex.rs index dada00e0c8..cb389cb2e7 100644 --- a/src/zend/ex.rs +++ b/src/zend/ex.rs @@ -6,6 +6,8 @@ use crate::{ types::{ZendClassObject, ZendObject, Zval}, }; +use super::function::Function; + /// Execute data passed when a function is called from PHP. /// /// This generally contains things related to the call, including but not @@ -194,6 +196,16 @@ impl ExecuteData { self.This.object_mut() } + /// Attempt to retrieve the function that is being called. + pub fn function(&self) -> Option<&Function> { + unsafe { self.func.as_ref() } + } + + /// Attempt to retrieve the previous execute data on the call stack. + pub fn previous(&self) -> Option<&Self> { + unsafe { self.prev_execute_data.as_ref() } + } + /// Translation of macro `ZEND_CALL_ARG(call, n)` /// zend_compile.h:578 /// diff --git a/src/zend/function.rs b/src/zend/function.rs index ba889d775f..9793e3e05c 100644 --- a/src/zend/function.rs +++ b/src/zend/function.rs @@ -2,7 +2,10 @@ use std::{fmt::Debug, os::raw::c_char, ptr}; -use crate::ffi::zend_function_entry; +use crate::{ + ffi::{zend_function, zend_function_entry}, + flags::FunctionType, +}; /// A Zend function entry. pub type FunctionEntry = zend_function_entry; @@ -36,3 +39,11 @@ impl FunctionEntry { Box::into_raw(Box::new(self)) } } + +pub type Function = zend_function; + +impl Function { + pub fn type_(&self) -> FunctionType { + FunctionType::from(unsafe { self.type_ }) + } +} From 05eb9fc3eafba1325f44965822d9aed91b7e8789 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 24 Nov 2023 13:32:15 +0100 Subject: [PATCH 2/3] Use better name --- src/zend/function.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zend/function.rs b/src/zend/function.rs index 234fb625cc..d4aa20b500 100644 --- a/src/zend/function.rs +++ b/src/zend/function.rs @@ -50,7 +50,7 @@ impl FunctionEntry { pub type Function = zend_function; impl Function { - pub fn type_(&self) -> FunctionType { + pub fn function_type(&self) -> FunctionType { FunctionType::from(unsafe { self.type_ }) } From 10d5f3a41a9d02b93bd0afe7df4493e83cc1ce4b Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 24 Nov 2023 13:38:56 +0100 Subject: [PATCH 3/3] Fmt --- src/zend/function.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/zend/function.rs b/src/zend/function.rs index d4aa20b500..6e6dd1a39e 100644 --- a/src/zend/function.rs +++ b/src/zend/function.rs @@ -9,7 +9,8 @@ use crate::{ zend_call_known_function, zend_fetch_function_str, zend_function, zend_function_entry, zend_hash_str_find_ptr_lc, }, - types::Zval, flags::FunctionType, + flags::FunctionType, + types::Zval, }; use super::ClassEntry;