Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions phper/src/arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use phper_alloc::ToRefOwned;
use std::{
fmt::{self, Debug},
marker::PhantomData,
mem::ManuallyDrop,
mem::{ManuallyDrop, MaybeUninit},
ops::Deref,
ptr::null_mut,
};
Expand Down Expand Up @@ -335,8 +335,10 @@ impl ZArr {

impl Drop for ZArr {
fn drop(&mut self) {
let mut val = MaybeUninit::<zval>::uninit();
unsafe {
zend_array_destroy(self.as_mut_ptr());
phper_zval_arr(val.as_mut_ptr().cast(), self.as_mut_ptr());
phper_zval_ptr_dtor(val.as_mut_ptr());
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/src/arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// See the Mulan PSL v2 for more details.

use phper::{
alloc::ToRefOwned,
arrays::{InsertKey, IterKey, ZArray},
modules::Module,
objects::{ZObj, ZObject},
Expand All @@ -30,6 +31,16 @@ pub fn integrate(module: &mut Module) {
let bar = a2.get("bar").unwrap();
let bar = bar.as_z_str().unwrap().to_str().unwrap();

{
let mut arr1 = ZArray::with_capacity(4);
let mut arr2 = arr1.to_ref_owned();
arr2.insert((), "1");
arr2.insert((), "2");
arr2.insert((), "3");
arr2.insert((), "4");
arr2.insert((), "5");
}

Ok(format!("{} {}", val, bar))
},
);
Expand Down
Loading