Skip to content

TSLANG_ISSUES: 21, a C string result isn't copied when its .d.ts came through an import - #762

Merged
ASDAlexander77 merged 1 commit into
mainfrom
tslang-issue-21-c-string-copy
Oct 31, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
tslang-issue-21-c-string-copy

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Adds issue 21 to TSLANG_ISSUES.md. Documentation only; there is no compiler change here.

The bug: #575 copies a C function's string result. That copy is skipped when the declare function is in a .d.ts that a module the file imports also references.

Effect: the raw char* becomes a program string again.

  • Under -mm=gc, stored results share C's buffer.
  • Under -mm=rc, retaining one writes a count into C's memory and releasing it frees C's memory. This crashed native_ts_graphics's SampleGame on Android: "Scudo ERROR: misaligned pointer when deallocating".

The entry contains:

  • a four-file repro using strerror, run on pre-alpha111, with the right and wrong output;
  • the IR difference (no StringCopy; tsretv on the raw pointer);
  • where to look: isForeignCall in MLIRGenImpl.h checks the module the declaration was recorded with (MLIRGenFunctions.cpp:972);
  • a suggested regression test;
  • native_ts_graphics's workaround (template-literal copies, rtxpt_game: copy the strings C++ returns (SampleGame on Android, -mm=rc) native_ts_graphics#168), to remove once this is fixed.

🤖 Generated with Claude Code

… through an import

#575's copy of a C function's `string` result is skipped when the
`declare function` is in a .d.ts that an imported module also references
(isForeignCall checks the module the declaration was recorded with).
The raw char* then becomes a program string again: aliased buffers under
gc, C++ memory counted and freed under rc (native_ts_graphics's
SampleGame crashed on Android). Repro run on pre-alpha111, the IR,
where to look and a suggested regression test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit c750367 into main Oct 31, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the tslang-issue-21-c-string-copy branch October 31, 2026 13:03
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