File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -215,7 +215,7 @@ class core::impl {
215
215
}
216
216
}
217
217
218
- ~frame () {
218
+ void close () {
219
219
if (is_array) {
220
220
if (!bson_append_array_end (parent, &bson)) {
221
221
throw bsoncxx::exception{error_code::k_cannot_end_appending_array};
Original file line number Diff line number Diff line change 23
23
namespace bsoncxx {
24
24
BSONCXX_INLINE_NAMESPACE_BEGIN
25
25
26
+ // Note: This stack is only intended for use with the 'frame' type in
27
+ // builder core.cpp.
26
28
template <typename T, std::size_t size>
27
29
class stack {
28
30
public:
29
31
stack () : _bucket_index(0 ), _bucket_size(size), _is_empty(true ) {}
30
32
31
33
~stack () {
32
34
while (!empty ()) {
33
- pop_back ();
35
+ // If you are using a stack<core::impl::frame> inside a
36
+ // builder::core object, then either one of two things is
37
+ // true:
38
+ //
39
+ // 1) core::impl::is_viewable is true, so the stack is
40
+ // empty, we aren't going to get here.
41
+ //
42
+ // OR
43
+ //
44
+ // 2) The stack isn't empty, so the builder wasn't in a
45
+ // viewable state when we were destroying its internal
46
+ // stack. We have a partially constructed but
47
+ // un-observable BSON document. We don't need to call
48
+ // close, which might fail. Just call _dec to properly
49
+ // invoke the non-failing frame destructor.
50
+ _dec ();
34
51
}
35
52
36
53
while (!_buckets.empty ()) {
@@ -59,6 +76,7 @@ class stack {
59
76
}
60
77
61
78
void pop_back () {
79
+ _get_ptr ()->close ();
62
80
_dec ();
63
81
}
64
82
You can’t perform that action at this time.
0 commit comments