Skip to content

Commit 5e848fa

Browse files
committed
Modify execute data.
1 parent dde27c4 commit 5e848fa

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

phper-sys/php_wrapper.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,11 @@ bool phper_z_refcounted_p(zval *zval_ptr) {
198198
return Z_REFCOUNTED_P(zval_ptr);
199199
}
200200

201-
zval *phper_execute_data_call_arg(zend_execute_data *execute_data, int index) {
201+
zval *phper_zend_call_var_num(zend_execute_data *execute_data, int index) {
202+
return ZEND_CALL_VAR_NUM(execute_data, index);
203+
}
204+
205+
zval *phper_zend_call_arg(zend_execute_data *execute_data, int index) {
202206
return ZEND_CALL_ARG(execute_data, index);
203207
}
204208

@@ -351,3 +355,7 @@ zval *phper_zend_symtable_str_find(HashTable *ht, const char *str, size_t len) {
351355
bool phper_zend_symtable_str_exists(HashTable *ht, const char *str, size_t len) {
352356
return zend_symtable_str_exists(ht, str, len) != 0;
353357
}
358+
359+
uint32_t phper_zend_num_args(const zend_execute_data *execute_data) {
360+
return ZEND_NUM_ARGS();
361+
}

phper/src/values.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,25 @@ pub struct ExecuteData {
3838
}
3939

4040
impl ExecuteData {
41+
/// # Safety
42+
///
43+
/// Create from raw pointer.
44+
#[inline]
45+
pub unsafe fn from_ptr<'a>(ptr: *const zend_execute_data) -> &'a Self {
46+
(ptr as *const Self).as_ref().expect("ptr should't be null")
47+
}
48+
49+
#[inline]
50+
pub fn as_ptr(&self) -> *const zend_execute_data {
51+
&self.inner
52+
}
53+
4154
/// # Safety
4255
///
4356
/// Create from raw pointer.
4457
#[inline]
4558
pub unsafe fn from_mut_ptr<'a>(ptr: *mut zend_execute_data) -> &'a mut Self {
46-
&mut *(ptr as *mut Self)
59+
(ptr as *mut Self).as_mut().expect("ptr should't be null")
4760
}
4861

4962
#[inline]
@@ -55,32 +68,29 @@ impl ExecuteData {
5568
///
5669
/// Get value from union.
5770
#[inline]
58-
pub unsafe fn common_num_args(&self) -> u32 {
59-
(*self.inner.func).common.num_args
71+
pub fn common_num_args(&self) -> u32 {
72+
unsafe { (*self.inner.func).common.num_args }
6073
}
6174

6275
/// # Safety
6376
///
6477
/// Get value from union.
6578
#[inline]
66-
pub unsafe fn common_required_num_args(&self) -> u16 {
67-
(*self.inner.func).common.required_num_args as u16
79+
pub fn common_required_num_args(&self) -> u16 {
80+
unsafe { (*self.inner.func).common.required_num_args as u16 }
6881
}
6982

7083
/// # Safety
7184
///
7285
/// Get value from union.
7386
#[inline]
74-
pub unsafe fn common_arg_info(&self) -> *mut zend_arg_info {
75-
(*self.inner.func).common.arg_info
87+
pub fn common_arg_info(&self) -> *mut zend_arg_info {
88+
unsafe { (*self.inner.func).common.arg_info }
7689
}
7790

78-
/// # Safety
79-
///
80-
/// Get value from union.
8191
#[inline]
82-
pub unsafe fn num_args(&self) -> u16 {
83-
self.inner.This.u2.num_args as u16
92+
pub fn num_args(&self) -> usize {
93+
unsafe { phper_zend_num_args(self.as_ptr()).try_into().unwrap() }
8494
}
8595

8696
/// # Safety
@@ -103,14 +113,14 @@ impl ExecuteData {
103113
let num_args = self.num_args();
104114
let mut arguments = vec![zeroed::<zval>(); num_args as usize];
105115
if num_args > 0 {
106-
_zend_get_parameters_array_ex(num_args.into(), arguments.as_mut_ptr());
116+
_zend_get_parameters_array_ex(num_args.try_into().unwrap(), arguments.as_mut_ptr());
107117
}
108118
transmute(arguments)
109119
}
110120

111121
pub fn get_parameter(&mut self, index: usize) -> &mut ZVal {
112122
unsafe {
113-
let val = phper_execute_data_call_arg(self.as_mut_ptr(), index as c_int);
123+
let val = phper_zend_call_arg(self.as_mut_ptr(), index as c_int);
114124
ZVal::from_mut_ptr(val)
115125
}
116126
}

0 commit comments

Comments
 (0)