Skip to content

An Opaque out of an any is as wide as the value in the box - #789

Merged
ASDAlexander77 merged 1 commit into
mainfrom
any-opaque-box-size
Nov 8, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
any-opaque-box-size

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

<Opaque><any>0 read 8 bytes out of a box holding a 4-byte s32, so the padding after the value became the pointer's high bytes.

Fix (AnyLogic::UnboxAny): when the result type is Opaque, the unbox reads the box's recorded size (ANY_SIZE) and keeps that many bytes, zero-extended. The 8-byte read stays inside the box, because the data field starts 8-aligned. Every other unbox, including classes and strings, keeps its plain load.

Tests

  • New 00any_to_opaque_narrow.ts, in all four models, JIT and compiled. It checks that <Opaque><any>0 is null after the heap has been dirtied, and that u8, u16, s32 and u64 values keep their exact bit patterns.
  • Linux (WSL), without the fix: the test fails in rc, none and own. With the fix: it passes in all four models, and so does 00tslang_issue_29_pthread.ts.
  • Windows: the full ctest passes (6758 tests). On Windows the new test passes either way, so Linux CI is what actually guards it.

🤖 Generated with Claude Code

`<Opaque><any>0` read 8 bytes out of a box holding a 4-byte s32: the padding
after it became the pointer's high bytes. Only a zeroing allocator (the
collector) left it 0; under -mm=rc, none and own on Linux the "null" pointer
was garbage, and pthread_create crashed on it as its attribute argument.

Unboxing to Opaque now reads the box's recorded size and keeps that many
bytes, zero-extended. Other unboxes are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 2674714 into main Nov 8, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the any-opaque-box-size branch November 8, 2026 22:00
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