1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use std::fmt::Debug;
use crate::{
ffi::{zend_refcounted_h, zend_string},
types::ZendObject,
};
pub type ZendRefcount = zend_refcounted_h;
impl Debug for ZendRefcount {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ZendRefcount")
.field("refcount", &self.refcount)
.finish()
}
}
pub trait PhpRc {
fn get_rc(&self) -> &ZendRefcount;
fn get_rc_mut(&mut self) -> &mut ZendRefcount;
fn get_count(&self) -> u32 {
self.get_rc().refcount
}
fn inc_count(&mut self) {
self.get_rc_mut().refcount += 1
}
fn dec_count(&mut self) {
self.get_rc_mut().refcount -= 1;
}
}
macro_rules! rc {
($($t: ty),*) => {
$(
impl PhpRc for $t {
fn get_rc(&self) -> &ZendRefcount {
&self.gc
}
fn get_rc_mut(&mut self) -> &mut ZendRefcount {
&mut self.gc
}
}
)*
};
}
rc!(ZendObject, zend_string);