Test and Fix IOBuf Python Iterable on Fragmented Data
Summary: The Python chained `IOBuf` has undesirable behavior on cyclic pattern data. For example, when we have a data chain with ``` chain = make_chain([IOBuf(b"aaa"), IOBuf(b"aaaa")]) ``` `b"".join(chain)` will yield `b"aaa"` rather than `b"aaaaaaa"`. The root cause to this bug is because in the `__iter__` method of the Python `IOBuf`, the original code checks whether the circular chain has been traversed by the `!=` operator (`self != next`), which has been overridden by `__richcmp__` function. The rich comparator then invokes the comparator in C++, which compares the underlying data in a `IOBuf` chain rather than their reference locations. In the above example, therefore, `chain == chain.next` would return `True`. However, in `__iter__`, in order to check whether the traversal is back to the head of the chain, we should compare by reference rather value. Reviewed By: yfeldblum Differential Revision: D16589600 fbshipit-source-id: 3b03c4d502bdc385edca3502949be03440543a21
Showing
Please register or sign in to comment