Skip to content

fix(macOS): 0 mapped reads on Apple Silicon (libc++ stringbuf::setbuf is a no-op)#2691

Open
BenjaminDEMAILLE wants to merge 1 commit into
alexdobin:masterfrom
BenjaminDEMAILLE:fix/macos-libcxx-0reads
Open

fix(macOS): 0 mapped reads on Apple Silicon (libc++ stringbuf::setbuf is a no-op)#2691
BenjaminDEMAILLE wants to merge 1 commit into
alexdobin:masterfrom
BenjaminDEMAILLE:fix/macos-libcxx-0reads

Conversation

@BenjaminDEMAILLE

Copy link
Copy Markdown

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 char buffers by calling stringStream.rdbuf()->pubsetbuf(buffer, size) in ReadAlignChunk.cpp.

std::basic_stringbuf::setbuf is 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 into chunkIn but the istringstream reads nothing, and the SAM ostringstream writes 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++):

char buf[64]; std::istringstream s; s.rdbuf()->pubsetbuf(buf, 64);

Fix

Add ExtBufStreambuf, a small std::streambuf that explicitly adopts a caller-owned fixed buffer (setg/setp + seekoff/seekpos), and back readInStream / chunkOutBAMstream with plain istream/ostream over 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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

STAR returns 0 mapped reads (installed via Homebrew & Conda)

1 participant