Skip to content

Commit

Permalink
Apply data offset for list-of-pointers at access time rather than Lis…
Browse files Browse the repository at this point in the history
…tReader creation time.

Baking this offset into `ptr` reduced ops needed at access time but made the interpretation of `ptr` inconsistent depending on what type of list was expected.
  • Loading branch information
kentonv committed Nov 23, 2022
1 parent 1a679ce commit 25d34c6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 0 additions & 4 deletions c++/src/capnp/layout.c++
Original file line number Diff line number Diff line change
Expand Up @@ -2360,10 +2360,6 @@ struct WireHelpers {
break;

case ElementSize::POINTER:
// We expected a list of pointers but got a list of structs. Assuming the first field
// in the struct is the pointer we were looking for, we want to munge the pointer to
// point at the first element's pointer section.
ptr += tag->structRef.dataSize.get();
KJ_REQUIRE(tag->structRef.ptrCount.get() > ZERO * POINTERS,
"Schema mismatch: Expected a pointer list, but got a list of data-only "
"structs.") {
Expand Down
6 changes: 5 additions & 1 deletion c++/src/capnp/layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -1227,8 +1227,12 @@ inline Void ListReader::getDataElement<Void>(ElementCount index) const {
}

inline PointerReader ListReader::getPointerElement(ElementCount index) const {
// If the list elements have data sections we need to skip those. Note that for pointers to be
// present at all (which already must be true if we get here), then `structDataSize` must be a
// whole number of words, so we don't have to worry about unaligned reads here.
auto offset = structDataSize / BITS_PER_BYTE;
return PointerReader(segment, capTable, reinterpret_cast<const WirePointer*>(
ptr + upgradeBound<uint64_t>(index) * step / BITS_PER_BYTE), nestingLimit);
ptr + offset + upgradeBound<uint64_t>(index) * step / BITS_PER_BYTE), nestingLimit);
}

// -------------------------------------------------------------------
Expand Down

0 comments on commit 25d34c6

Please sign in to comment.