Skip to content

Use rb_len_t for String lengths - #1106

Open
hsbt wants to merge 5 commits into
masterfrom
claude/suspicious-mcnulty-cd6753
Open

hsbt wants to merge 5 commits into
masterfrom
claude/suspicious-mcnulty-cd6753

Conversation

@hsbt

@hsbt hsbt commented Oct 11, 2026

Copy link
Copy Markdown
Member

Ruby master added rb_len_t as the type of String and Array lengths. It is long everywhere today, and https://bugs.ruby-lang.org/issues/22400 proposes making it 64-bit on mswin, where long is 32-bit. A long that holds a string length there would truncate strings of 2GiB or more.

This changes the lengths the extension reads from RSTRING_LEN and RSTRING_GETMEM, the lengths it passes to String constructors, and the column of JSON::ParserError to rb_len_t. Rubies without HAVE_RB_LEN_T get a long typedef, so nothing changes there.

Generated with Claude Code

hsbt and others added 5 commits October 10, 2026 03:54
RSTRING_LEN returns rb_len_t on Ruby master, so the variables receiving it follow. Older Rubies get a long typedef and build as before.

https://bugs.ruby-lang.org/issues/22400

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The column is a character offset counted by rb_enc_strlen(), which returns rb_len_t. The line number stays long.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
These lengths come from pointer differences and go to functions that take rb_len_t, so they no longer pass through long on the way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ruby declares it with an rb_len_t count, and a mismatching definition fails builds where the fallback is compiled against those headers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An int index overflows on an Array longer than INT_MAX, which LP64 and now mswin can hold.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant