Skip to content

Commit 5021078

Browse files
authored
provide access to return_value, function's type, filename, line number (#217)
1 parent 7902372 commit 5021078

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

phper/src/functions.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,29 @@ impl ZFunc {
647647
}
648648
}
649649

650+
/// Get the type of the function (sys::ZEND_USER_FUNCTION,
651+
/// sys::ZEND_INTERNAL_FUNCTION, or sys::ZEND_EVAL_CODE).
652+
pub fn get_type(&self) -> u32 {
653+
unsafe { self.inner.type_ as u32 }
654+
}
655+
656+
/// For a user function or eval'd code, get the filename from op_array.
657+
pub fn get_filename(&self) -> Option<&ZStr> {
658+
unsafe {
659+
match u32::from(self.inner.type_) {
660+
ZEND_USER_FUNCTION | ZEND_EVAL_CODE => {
661+
let ptr = self.inner.op_array.filename;
662+
if ptr.is_null() {
663+
None
664+
} else {
665+
ZStr::try_from_ptr(ptr)
666+
}
667+
}
668+
_ => None,
669+
}
670+
}
671+
}
672+
650673
/// Get the function or method fully-qualified name.
651674
pub fn get_function_or_method_name(&self) -> ZString {
652675
unsafe {

phper/src/values.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,51 @@ impl ExecuteData {
130130
unsafe { ZFunc::from_mut_ptr(self.inner.func) }
131131
}
132132

133+
/// Gets the current opline line number if available. This represents the
134+
/// line number in the source code where the current operation is being
135+
/// executed.
136+
pub fn get_lineno(&self) -> Option<u32> {
137+
unsafe {
138+
match u32::from((*self.inner.func).type_) {
139+
ZEND_USER_FUNCTION | ZEND_EVAL_CODE => {
140+
let opline = self.inner.opline;
141+
if opline.is_null() {
142+
None
143+
} else {
144+
Some((*opline).lineno)
145+
}
146+
}
147+
_ => None,
148+
}
149+
}
150+
}
151+
152+
/// Gets associated return value.
153+
pub fn get_return_value(&self) -> Option<&ZVal> {
154+
unsafe {
155+
let val = self.inner.return_value;
156+
ZVal::try_from_ptr(val)
157+
}
158+
}
159+
160+
/// Gets mutable reference to associated return value.
161+
pub fn get_return_value_mut(&mut self) -> Option<&mut ZVal> {
162+
unsafe {
163+
let val = self.inner.return_value;
164+
ZVal::try_from_mut_ptr(val)
165+
}
166+
}
167+
168+
/// Gets associated return value pointer.
169+
pub fn get_return_value_mut_ptr(&mut self) -> *mut ZVal {
170+
self.inner.return_value as *mut ZVal
171+
}
172+
173+
/// Gets immutable pointer to associated return value.
174+
pub fn get_return_value_ptr(&self) -> *const ZVal {
175+
self.inner.return_value as *const ZVal
176+
}
177+
133178
/// Gets associated `$this` object if exists.
134179
pub fn get_this(&mut self) -> Option<&ZObj> {
135180
unsafe {

0 commit comments

Comments
 (0)