Skip to content

Commit 34beeb5

Browse files
committed
Update objects api.
1 parent ce11ae3 commit 34beeb5

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

examples/hello/tests/php/test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
]);
3030

3131
$foo = new FooClass();
32-
assert_eq($foo->getFoo(), "100");
32+
assert_eq($foo->getFoo(), 100);
3333

3434
$foo->setFoo("Hello");
3535
assert_eq($foo->getFoo(), "Hello");

phper-sys/php_wrapper.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,7 @@ const zend_object_handlers *phper_z_obj_ht_p(const zval *zv) {
317317
zend_object *phper_z_obj_p(const zval *zv) {
318318
return Z_OBJ_P(zv);
319319
}
320+
321+
uint32_t phper_z_addref_p(zval *zv) {
322+
return Z_ADDREF_P(zv);
323+
}

phper/src/objects.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,14 @@ impl ZObj {
5555
&mut self.inner
5656
}
5757

58-
pub unsafe fn as_state<T>(&self) -> &T {
59-
todo!()
60-
// let eo = ExtendObject::fetch(&self.inner);
61-
// eo.state.downcast_ref().unwrap()
58+
pub unsafe fn as_state<T: 'static>(&self) -> &T {
59+
let eo = ExtendObject::fetch(&self.inner);
60+
eo.state.downcast_ref().unwrap()
6261
}
6362

64-
pub unsafe fn as_mut_state<T>(&mut self) -> &mut T {
65-
todo!()
66-
// let eo = ExtendObject::fetch_mut(&mut self.inner);
67-
// eo.state.downcast_mut().unwrap()
63+
pub unsafe fn as_mut_state<T: 'static>(&mut self) -> &mut T {
64+
let eo = ExtendObject::fetch_mut(&mut self.inner);
65+
eo.state.downcast_mut().unwrap()
6866
}
6967

7068
pub fn get_class(&self) -> &ClassEntry {
@@ -188,13 +186,12 @@ impl ToRefOwned for ZObj {
188186
type Owned = ZObject;
189187

190188
fn to_ref_owned(&mut self) -> Self::Owned {
191-
let mut dst = ZVal::default();
192-
let mut src = ZVal::default();
189+
let mut val = ZVal::default();
193190

194191
unsafe {
195-
phper_zval_obj(src.as_mut_ptr(), self.as_mut_ptr());
196-
phper_zval_copy(dst.as_mut_ptr(), src.as_mut_ptr());
197-
ZObject::from_raw(dst.as_mut_z_obj().unwrap().as_mut_ptr())
192+
phper_zval_obj(val.as_mut_ptr(), self.as_mut_ptr());
193+
phper_z_addref_p(val.as_mut_ptr());
194+
ZObject::from_raw(val.as_mut_z_obj().unwrap().as_mut_ptr())
198195
}
199196
}
200197
}

0 commit comments

Comments
 (0)