Skip to content

Commit 794a982

Browse files
committed
use a smart pointer within WeakPointer
the static analyzer no longer analyzes WeakPointer, and as such there's no reason to restrict the use of a smart pointer. Ephemerons still need a disguised pointer, unfortunately.
1 parent a9f33c1 commit 794a982

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

include/clasp/gctools/gcweak.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,8 @@ struct WeakPointer {
8989
void store_no_lock(core::T_sp); // ditto.
9090
void store(core::T_sp);
9191
void fixupInternalsForSnapshotSaveLoad(snapshotSaveLoad::Fixup*);
92-
public: // has to be public for precise GC reasons even though it's not scanned?
93-
// This is a Tagged rather than a T_sp because something in gc_boot seems to
94-
// check for T_sps in atomic (pointerless) objects. Rather than lie harder we
95-
// can just do this and build a T_sp from it as required.
96-
Tagged _value;
92+
private:
93+
core::T_sp _value;
9794
#ifdef USE_BOEHM
9895
// flag needed to disambiguate fixnum 0 from splatted pointer
9996
bool _splattablep = false;

src/gctools/gcweak.cc

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ THE SOFTWARE.
3434
namespace gctools {
3535

3636
#ifdef USE_BOEHM
37-
WeakPointer::WeakPointer(core::T_sp o) : _value(o.tagged_()) {
37+
WeakPointer::WeakPointer(core::T_sp o) : _value(o) {
3838
if (o.objectp()) { // pointer, so we're actually weak
3939
_splattablep = true;
4040
// note: deregistered automatically if the weak pointer itself is dealloc'd
@@ -45,8 +45,8 @@ WeakPointer::WeakPointer(core::T_sp o) : _value(o.tagged_()) {
4545
void* WeakPointer::value_helper(void* data) {
4646
value_helper_s* vhsp = (value_helper_s*)data;
4747
if (vhsp->wp->_value || !vhsp->wp->_splattablep) // not splatted
48-
// construct a T_sp in the result
49-
vhsp->result.emplace(vhsp->wp->_value);
48+
// put a T_sp in the result
49+
vhsp->result = vhsp->wp->_value;
5050
// otherwise, leave the result default constructed (no T_sp)
5151
return nullptr; // unused
5252
}
@@ -59,11 +59,11 @@ std::optional<core::T_sp> WeakPointer::value() const {
5959
}
6060
std::optional<core::T_sp> WeakPointer::value_no_lock() const {
6161
if (_value || !_splattablep)
62-
return core::T_sp(_value);
62+
return _value;
6363
else return std::nullopt;
6464
}
6565
void WeakPointer::store_no_lock(core::T_sp o) {
66-
_value = o.tagged_();
66+
_value = o;
6767
_splattablep = o.objectp();
6868
// links set up in fixupInternals below.
6969
}
@@ -76,31 +76,30 @@ void WeakPointer::store(core::T_sp o) {
7676
_splattablep = false;
7777
GC_unregister_disappearing_link((void**)&_value);
7878
}
79-
_value = o.tagged_();
79+
_value = o;
8080
}
8181

8282
void WeakPointer::fixupInternalsForSnapshotSaveLoad(snapshotSaveLoad::Fixup* fixup) {
8383
if (snapshotSaveLoad::operation(fixup) == snapshotSaveLoad::LoadOp) {
8484
// We do this later rather than in store_no_lock because register/deregister
8585
// unconditionally grab a lock. This is a bit of a KLUDGE.
86-
core::T_sp o(_value);
87-
if (o.objectp()) {
86+
if (_value.objectp()) {
8887
_splattablep = true;
8988
// Implicitly removes any previous registration, per boehm docs.
90-
GC_general_register_disappearing_link((void**)&_value, &*o);
89+
GC_general_register_disappearing_link((void**)&_value, &*_value);
9190
} else {
9291
_splattablep = false;
9392
GC_unregister_disappearing_link((void**)&_value);
9493
}
9594
}
9695
}
9796
#else // not-actually-weak pointers - TODO for your other GC!
98-
WeakPointer::WeakPointer(core::T_sp o) : _value(o.tagged_()) {}
97+
WeakPointer::WeakPointer(core::T_sp o) : _value(o) {}
9998

10099
// always valid
101-
std::optional<core::T_sp> WeakPointer::value() const { return core::T_sp(_value); }
100+
std::optional<core::T_sp> WeakPointer::value() const { return _value; }
102101
std::optional<core::T_sp> WeakPointer::value_no_lock() const { return value(); }
103-
void WeakPointer::store_no_lock(core::T_sp o) { _value = o.tagged_(); }
102+
void WeakPointer::store_no_lock(core::T_sp o) { _value = o; }
104103
void WeakPointer::store(core::T_sp o) { store_no_lock(o); }
105104
void WeakPointer::fixupInternalsForSnapshotSaveLoad(snapshotSaveLoad::Fixup*) {}
106105
#endif

0 commit comments

Comments
 (0)