Skip to content

Commit 8dc9881

Browse files
committed
Fix Object clone bug.
1 parent 374d0da commit 8dc9881

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

phper-sys/php_wrapper.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ void phper_zval_obj(zval *z, zend_object *o) {
116116
ZVAL_OBJ(z, o);
117117
}
118118

119+
#if PHP_VERSION_ID < 80000
119120
static zend_string *phper_zend_string_concat3(
120121
const char *str1, size_t str1_len,
121122
const char *str2, size_t str2_len,
@@ -131,6 +132,7 @@ static zend_string *phper_zend_string_concat3(
131132

132133
return res;
133134
}
135+
#endif
134136

135137
zend_string *phper_get_function_or_method_name(const zend_function *func) {
136138
#if PHP_VERSION_ID >= 80000

phper/src/classes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::{
44
errors::ClassNotFoundError,
5-
functions::{Argument, Callable, FunctionEntity, FunctionEntry, Method},
5+
functions::{Argument, FunctionEntity, FunctionEntry, Method},
66
objects::Object,
77
sys::*,
88
utils::ensure_end_with_zero,

phper/src/functions.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
//! Apis relate to [crate::sys::zend_function_entry].
22
3-
use std::{mem::zeroed, os::raw::c_char, sync::atomic::AtomicPtr};
3+
use std::{mem::zeroed, os::raw::c_char};
44

55
use crate::{
6-
alloc::EBox,
7-
classes::ClassEntry,
86
errors::ArgumentCountError,
97
objects::Object,
108
strings::ZendString,
119
sys::*,
1210
utils::ensure_end_with_zero,
1311
values::{ExecuteData, SetVal, Val},
1412
};
15-
use std::{marker::PhantomData, mem::transmute, slice::from_raw_parts, str, str::Utf8Error};
13+
use std::{marker::PhantomData, str::Utf8Error};
1614

1715
pub(crate) trait Callable {
1816
fn call(&self, execute_data: &mut ExecuteData, arguments: &mut [Val], return_value: &mut Val);
@@ -122,7 +120,7 @@ impl FunctionEntity {
122120
let translator = CallableTranslator {
123121
callable: self.handler.as_ref(),
124122
};
125-
let mut last_arg_info: zend_internal_arg_info = translator.internal_arg_info;
123+
let last_arg_info: zend_internal_arg_info = translator.internal_arg_info;
126124
infos.push(last_arg_info);
127125

128126
zend_function_entry {

phper/src/modules.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::{
44
c_str_ptr,
55
classes::{ClassEntity, Classifiable},
6-
functions::{Argument, Callable, Function, FunctionEntity},
6+
functions::{Argument, Function, FunctionEntity},
77
ini::{IniEntity, IniValue, Policy, StrPtrBox},
88
sys::*,
99
utils::ensure_end_with_zero,

phper/src/objects.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
sys::*,
88
values::Val,
99
};
10-
use std::{marker::PhantomData, mem::zeroed, ptr::null_mut};
10+
use std::{marker::PhantomData, ptr::null_mut};
1111

1212
/// Wrapper of [crate::sys::zend_object].
1313
#[repr(transparent)]
@@ -60,7 +60,7 @@ impl<T> Object<T> {
6060
}
6161
#[cfg(phper_major_version = "7")]
6262
{
63-
let mut zv = zeroed::<zval>();
63+
let mut zv = std::mem::zeroed::<zval>();
6464
phper_zval_obj(&mut zv, self.as_ptr() as *mut _);
6565
zend_read_property(
6666
self.inner.ce,
@@ -92,7 +92,7 @@ impl<T> Object<T> {
9292
}
9393
#[cfg(phper_major_version = "7")]
9494
{
95-
let mut zv = zeroed::<zval>();
95+
let mut zv = std::mem::zeroed::<zval>();
9696
phper_zval_obj(&mut zv, self.as_mut_ptr());
9797
zend_update_property(
9898
self.inner.ce,
@@ -107,7 +107,19 @@ impl<T> Object<T> {
107107

108108
pub fn clone_obj(&self) -> EBox<Self> {
109109
unsafe {
110-
let new_obj = zend_objects_clone_obj(self.as_ptr() as *mut _).cast();
110+
let new_obj = {
111+
#[cfg(phper_major_version = "8")]
112+
{
113+
zend_objects_clone_obj(self.as_ptr() as *mut _).cast()
114+
}
115+
#[cfg(phper_major_version = "7")]
116+
{
117+
let mut zv = std::mem::zeroed::<zval>();
118+
phper_zval_obj(&mut zv, self.as_ptr() as *mut _);
119+
zend_objects_clone_obj(&mut zv).cast()
120+
}
121+
};
122+
111123
EBox::from_raw(new_obj)
112124
}
113125
}

0 commit comments

Comments
 (0)