Skip to content

Commit

Permalink
Disable ThinCursor debug checks by default.
Browse files Browse the repository at this point in the history
Summary: This breaks some internal tests. Make it opt-in at development time for now.

Differential Revision: D51876478

fbshipit-source-id: 2e844be044f48c2164fa71dc19131e5226172faa
  • Loading branch information
David Goldblatt authored and facebook-github-bot committed Dec 6, 2023
1 parent 4930436 commit 35bb384
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions folly/io/Cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ class ThinCursor;

namespace detail {

// This is very useful in development, but the size perturbation is currently
// causing some previously undetected bugs in unrelated projects to manifest in
// CI-breaking ways.
// TODO(davidgoldblatt): Fix this.
#define FOLLY_IO_CURSOR_BORROW_CHECKING 0
#if FOLLY_IO_CURSOR_BORROW_CHECKING
#define FOLLY_IO_CURSOR_BORROW_DCHECK DCHECK
#else
#define FOLLY_IO_CURSOR_BORROW_DCHECK(ignored)
#endif

template <class Derived, class BufType>
class CursorBase {
// Make all the templated classes friends for copy constructor.
Expand Down Expand Up @@ -810,7 +821,7 @@ class CursorBase {

protected:
void dcheckIntegrity() const {
DCHECK(!*borrowed());
FOLLY_IO_CURSOR_BORROW_DCHECK(!*borrowed());
DCHECK(crtBegin_ <= crtPos_ && crtPos_ <= crtEnd_);
DCHECK(crtBuf_ == nullptr || crtBegin_ == crtBuf_->data());
DCHECK(
Expand Down Expand Up @@ -877,7 +888,7 @@ class CursorBase {
// is set to the max of size_t
size_t remainingLen_{std::numeric_limits<size_t>::max()};

#ifndef NDEBUG
#if FOLLY_IO_CURSOR_BORROW_CHECKING
bool borrowed_ = false;
bool* borrowed() { return &borrowed_; }
const bool* borrowed() const { return &borrowed_; }
Expand Down Expand Up @@ -1083,12 +1094,12 @@ class Cursor : public detail::CursorBase<Cursor, const IOBuf> {
: detail::CursorBase<Cursor, const IOBuf>(cursor, len) {}

ThinCursor borrow() {
DCHECK(!std::exchange(*borrowed(), true));
FOLLY_IO_CURSOR_BORROW_DCHECK(!std::exchange(*borrowed(), true));
return {crtPos_, crtEnd_};
}

void unborrow(ThinCursor&& cursor) {
DCHECK(std::exchange(*borrowed(), false));
FOLLY_IO_CURSOR_BORROW_DCHECK(std::exchange(*borrowed(), false));
DCHECK_EQ(cursor.crtEnd_, crtEnd_);
crtPos_ = cursor.crtPos_;
}
Expand Down

0 comments on commit 35bb384

Please sign in to comment.