Repository navigation
Conversation
operator+ on symbols kept raw pointers to the text of its arguments while allocating the result, which may run the garbage collector and move them. The text of the result then came from stale addresses. Rendering expressions goes through this operator for every term, so an expression could be displayed with damaged characters, for instance A14+^A+ followed by a line break in place of A14+A15+, depending on when a collection happened. Use gcutf8, as the same operator on text already does. Author & design: Jean Wilson Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
renderer::put(text, length) and its variant with a format read the source through a raw pointer while writing one character at a time. Each character written to the scratchpad may run the garbage collector and move the source, which is then read from the place where the output was just written. For instance, 'A' 'B' + was displayed as 'AAA'. Use gcutf8, as the rendering of text objects already does. Author & design: Jean Wilson Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Two places keep a raw pointer to text while the garbage collector may run and move it, so expressions can be displayed with damaged characters, depending on when a collection happens:
operator+on symbols,src/symbol.cc, holds raw pointers to its arguments while allocating the result. Rendering an expression goes through this operator for each term. The example suite gaveA14+^A+followed by a line break instead ofA14+A15+.renderer::put(text, length)and its variant with a format,src/renderer.cc, read the source through a raw pointer while writing one character at a time. Each character may run the collector. The source is then read from where the output was just written:'A' 'B' +gave'AAA', and'A' 'B' ↑gave'AAAAA'.operator+on text and the rendering of text objects already protect themselves against this. The first failure appeared on a branch that only adds library files, in the testNumerical evaluation of a sum with many terms.This is separate from #1858 and its fix #1868: the failure is the same with or without that fix.
Fix
Use
gcutf8in these places, astext.ccdoes. The fix inrenderer::putcovers all its callers.How I found it: forcing collections
Forcing a collection at every allocation exposes this kind of problem whatever the memory layout. I added this temporarily to
runtime::available(size_t)on the simulator, and it is not part of this PR:Then run the tests with
DB48X_GC_STRESS=5 ./db48x -H -Z -T'(symbolic)'. Many steps fail with "RPL command was not processed", simply because the run is so slow. What matters is anygotwith damaged text.AA 3=B÷3forA÷3=B÷3AAAforA+B,AAAAAforA↑Bcos (sin A)fortan (cos (sin A)), probably the previous result, because the test did not wait long enough; not verifiedThese forced runs stopped on their time limits after fewer than 35 steps of
symbolic. Other groups were not run this way, so similar problems may remain elsewhere. It may be worth doing a wider run, with longer test delays.Tests
gcutf8.Author & design: Jean Wilson
🤖 Generated with Claude Code