fix(macOS): 0 mapped reads on Apple Silicon (libc++ stringbuf::setbuf is a no-op)#2691
Open
BenjaminDEMAILLE wants to merge 1 commit into
Open
fix(macOS): 0 mapped reads on Apple Silicon (libc++ stringbuf::setbuf is a no-op)#2691BenjaminDEMAILLE wants to merge 1 commit into
BenjaminDEMAILLE wants to merge 1 commit into
Conversation
STAR read input reads and wrote SAM/BAM records zero-copy through pre-allocated char buffers via stringStream.rdbuf()->pubsetbuf(buf, size). basic_stringbuf::setbuf is implementation-defined: libstdc++ adopts the external buffer, but libc++ (clang/macOS) ignores it. The native macOS/arm64 build therefore compiled and ran with exit 0 but read 0 input reads and produced empty SAM/BAM output. Add ExtBufStreambuf, a std::streambuf that explicitly adopts a caller-owned fixed buffer (setg/setp plus seekoff/seekpos), and back readInStream and chunkOutBAMstream with plain istream/ostream over it. Behavior is now identical on every standard library, zero-copy is preserved. Verified on native arm64: 5/5 synthetic reads map uniquely to the expected positions (previously 0). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Jun 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On macOS / Apple Silicon, STAR 2.7.11b completes without error but reports 0 input reads and produces no alignments (see #2632, and the duplicate symptom reported by several users; reverting to 2.7.10b "works"). Linux is unaffected.
Root cause
STAR reads input reads and writes SAM/BAM records zero-copy through pre-allocated
charbuffers by callingstringStream.rdbuf()->pubsetbuf(buffer, size)inReadAlignChunk.cpp.std::basic_stringbuf::setbufis implementation-defined: libstdc++ (Linux/GCC) adopts the external buffer, but libc++ (clang/macOS) ignores it. The conda-forge/Homebrew builds compile with clang/libc++, so the streams stay empty: reads are scanned intochunkInbut theistringstreamreads nothing, and the SAMostringstreamwrites nowhere. This is why it regressed when the macOS package toolchain moved to clang.Minimal reproducer (prints empty on libc++, the buffer content on libstdc++):
Fix
Add
ExtBufStreambuf, a smallstd::streambufthat explicitly adopts a caller-owned fixed buffer (setg/setp+seekoff/seekpos), and backreadInStream/chunkOutBAMstreamwith plainistream/ostreamover it. Behavior is now identical on every standard library and zero-copy is preserved. Linux/libstdc++ behavior is unchanged.Verification
Built native arm64 (
make STARforMac CXX=clang++) on Apple Silicon; a synthetic genome + reads now map 5/5 (previously 0). No change on Linux.Closes #2632.
Part of a small series adding first-class macOS / Apple Silicon support.
🤖 Generated with Claude Code