Skip to content

Commit

Permalink
Merge pull request #259 from davidcole1340/function-helper
Browse files Browse the repository at this point in the history
Add function type helper function
  • Loading branch information
danog authored Nov 24, 2023
2 parents 3f50e7e + 10d5f3a commit 80e448c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/zend/ex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
///
Expand Down
5 changes: 5 additions & 0 deletions src/zend/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
zend_call_known_function, zend_fetch_function_str, zend_function, zend_function_entry,
zend_hash_str_find_ptr_lc,
},
flags::FunctionType,
types::Zval,
};

Expand Down Expand Up @@ -50,6 +51,10 @@ impl FunctionEntry {
pub type Function = zend_function;

impl Function {
pub fn function_type(&self) -> FunctionType {
FunctionType::from(unsafe { self.type_ })
}

pub fn try_from_function(name: &str) -> Option<Self> {
unsafe {
let res = zend_fetch_function_str(name.as_ptr() as *const c_char, name.len());
Expand Down

0 comments on commit 80e448c

Please sign in to comment.