Skip to content

Commit a7ff478

Browse files
robarnoldEric Holk
authored andcommitted
---
yaml --- r: 3545 b: refs/heads/master c: 02a5949 h: refs/heads/master i: 3543: 9511681 v: v3
1 parent 6729259 commit a7ff478

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 73cc624e8e326f54eb0ea8bff70388d62dccd3cb
2+
refs/heads/master: 02a5949abaa4e888ecb470023ea2f29cd6bde43b

trunk/src/rt/rust_internal.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,18 @@ static intptr_t const CONST_REFCOUNT = 0x7badface;
9797
static size_t const BUF_BYTES = 2048;
9898

9999
// Every reference counted object should derive from this base class.
100+
// Or use this macro. The macro is preferred as the base class will be
101+
// disappearing.
100102

101-
template <typename T> struct rc_base {
102-
intptr_t ref_count;
103-
104-
void ref() {
105-
++ref_count;
106-
}
103+
#define RUST_REFCOUNTED(T) \
104+
RUST_REFCOUNTED_WITH_DTOR(T, delete (T*)this)
105+
#define RUST_REFCOUNTED_WITH_DTOR(T, dtor) \
106+
intptr_t ref_count; \
107+
void ref() { ++ref_count; } \
108+
void deref() { if (--ref_count == 0) { dtor; } }
107109

108-
void deref() {
109-
if (--ref_count == 0) {
110-
delete (T*)this;
111-
}
112-
}
110+
template <typename T> struct rc_base {
111+
RUST_REFCOUNTED(T)
113112

114113
rc_base();
115114
~rc_base();

0 commit comments

Comments
 (0)