From 38cbba0457e637cc4e5410fb29a7964c2dfc40c0 Mon Sep 17 00:00:00 2001 From: Joe Hoyle Date: Wed, 19 Jul 2023 15:30:49 +0200 Subject: [PATCH] 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 dada00e..cb389cb 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 ba889d7..9793e3e 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_ }) + } +}