Skip to content

Commit

Permalink
fix: circular dependency in qlist
Browse files Browse the repository at this point in the history
fixes #4294

Signed-off-by: Roman Gershman <[email protected]>
  • Loading branch information
romange committed Dec 12, 2024
1 parent b37287b commit a4d1bff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/core/qlist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ string QList::Pop(Where where) {

/* The head and tail should never be compressed */
DCHECK(node->encoding != QUICKLIST_NODE_ENCODING_LZF);
DCHECK(head_->prev->next == nullptr);

string res;
if (ABSL_PREDICT_FALSE(QL_NODE_IS_PLAIN(node))) {
Expand All @@ -390,6 +391,7 @@ string QList::Pop(Where where) {
}
DelPackedIndex(node, pos);
}
DCHECK(head_->prev->next == nullptr);
return res;
}

Expand Down Expand Up @@ -479,11 +481,13 @@ bool QList::PushSentinel(string_view value, Where where) {
if (len_ == 1) { // sanity check
DCHECK_EQ(malloc_size_, orig->sz);
}
DCHECK(head_->prev->next == nullptr);
return false;
}

quicklistNode* node = CreateFromSV(QUICKLIST_NODE_CONTAINER_PACKED, value);
InsertNode(orig, node, opt);
DCHECK(head_->prev->next == nullptr);
return true;
}

Expand Down Expand Up @@ -837,7 +841,7 @@ quicklistNode* QList::ListpackMerge(quicklistNode* a, quicklistNode* b) {
void QList::DelNode(quicklistNode* node) {
if (node->next)
node->next->prev = node->prev;
if (node->prev)
if (node != head_) // For head, node->prev is tail, and its next should point to NULL.
node->prev->next = node->next;

if (node == head_) {
Expand Down
9 changes: 9 additions & 0 deletions src/core/qlist_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,15 @@ TEST_F(QListTest, CompressionPlain) {
EXPECT_EQ(500, i);
}

TEST_F(QListTest, LargeValues) {
string val(100000, 'a');
ql_.Push(val, QList::HEAD);
ql_.Push(val, QList::HEAD);
ql_.Pop(QList::HEAD);
auto items = ToItems();
EXPECT_THAT(items, ElementsAre(val));
}

using FillCompress = tuple<int, unsigned>;

class PrintToFillCompress {
Expand Down

0 comments on commit a4d1bff

Please sign in to comment.