Skip to content

Commit a961b1f

Browse files
committed
Compact versions.
1 parent 909f205 commit a961b1f

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

phper-sys/php_wrapper.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,13 @@ void phper_zval_str(zval *zv, zend_string *s) {
263263
}
264264

265265
zend_array *phper_zend_new_array(uint32_t size) {
266+
#if PHP_VERSION_ID >= 70300
266267
return zend_new_array(size);
268+
#else
269+
HashTable *ht = emalloc(sizeof(HashTable));
270+
zend_hash_init(ht, size, NULL, ZVAL_PTR_DTOR, 0);
271+
return ht;
272+
#endif
267273
}
268274

269275
zend_array *phper_zend_array_dup(zend_array *source) {

phper/src/objects.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,16 +238,27 @@ impl ZObject {
238238
impl Clone for ZObject {
239239
fn clone(&self) -> Self {
240240
unsafe {
241-
let ptr = {
242-
let mut zv = ZVal::default();
241+
Self::from_raw({
242+
let mut zv = ManuallyDrop::new(ZVal::default());
243243
phper_zval_obj(zv.as_mut_ptr(), self.as_ptr() as *mut _);
244244
let handlers = phper_z_obj_ht_p(zv.as_ptr());
245+
246+
let ptr = {
247+
#[cfg(phper_major_version = "7")]
248+
{
249+
zv.as_mut_ptr()
250+
}
251+
#[cfg(phper_major_version = "8")]
252+
{
253+
self.as_ptr() as *mut _
254+
}
255+
};
256+
245257
match (*handlers).clone_obj {
246-
Some(clone_obj) => clone_obj(zv.as_mut_ptr()),
247-
None => zend_objects_clone_obj(zv.as_mut_ptr()),
258+
Some(clone_obj) => clone_obj(ptr),
259+
None => zend_objects_clone_obj(ptr),
248260
}
249-
};
250-
Self::from_raw(ptr)
261+
})
251262
}
252263
}
253264
}

0 commit comments

Comments
 (0)