Repository navigation
runtime, ipl: fix array allocation crashes and window-close event loops - #694
Merged
Merged
Conversation
Closing a window with the window manager's close button made programs built on the IPL event loops stop with run-time error 142: the window reports the close event (-11) and is then closed, but evmux(), GetEvents() and the dialog loop went back to Event() on it. gpxtest did this for both its main window and its dialog, under X11 as well as SDL. - evmux() and GetEvents() now return once their window is closed, so a program whose main ends with the event loop exits normally. Handlers still see the close event first (GetEvents passes it to the missed and all callbacks as before). - Dialogs open their window with inputmask=c and treat the close button as a press of their Cancel button, or of the default button if there is no Cancel (Notice() returns "Okay"); so Dialog(), TextDialog() and friends return a button name as usual. tests/graphics/gpxtest.icn carries its own copies of evmux and vdialog and gets the same changes. Signed-off-by: Jafar Al-Gharaibeh <[email protected]>
array(n, x), and list(n, x) when x is a number, allocate an array block and then a list header that points at it. The array block is not reachable until then, so no collection may run between the two: room for both has to be reserved first. array() reserved it using n, the number of arguments, instead of num, the number of elements, so array(16, 0.0) reserved room for 2 elements; list() reserved nothing. When the header did not fit, a collection lost the array block, and alclisthdr() wrote the header's address into whatever block had taken its place, or put the header inside the array's old space. Programs that make many small arrays (the 3D viewer's matrices) failed later with memory violations, overwritten list headers, or numbers read back as strings. Reserve for the whole array in both. In array(), keep num and the size as words, and reject a negative or overflowing size instead of building a list from a truncated one: array(-1, 1.0) made a list of size -1, and array(2^40, 1.0) an empty list. Signed-off-by: Jafar Al-Gharaibeh <[email protected]>
collect() does nothing until the interpreter has started, which it tells by sp being NULL. With threads, sp and the other interpreter registers are fields of &main's co-expression block, which comes from malloc() and was never cleared; the interpreter sets them only when it starts. An allocation before then that needed a collection (the co-expression queues, with a small BLKSIZE) found sp set to garbage, and collect() walked an interpreter stack that did not exist. Clear the registers when &main's block is set up. Signed-off-by: Jafar Al-Gharaibeh <[email protected]>
alcintarray() and alcrealarray() computed the block size in an int. Past 2GB it wrapped negative, and AlcBlk() then moved the free pointer backwards over live blocks, so list(n, 2.5) or array(n, 2.5) with more than about 268 million elements crashed. Use a uword, and give an empty array a whole block instead of one smaller than its header. Signed-off-by: Jafar Al-Gharaibeh <[email protected]>
[High impact] The PR appears safe to merge; both previous findings are fixed. SummaryFixes array allocation crashes and stops event loops after windows close.
Both previous findings are fixed. No new issues were found in the changes since the last review. Reviews (2) · Last reviewed commit: "runtime: size array blocks as words" · Reviewed by Greptile |
Jafaral
force-pushed
the
runtime-ipl-fixes
branch
from
November 2, 2026 19:16
85fbe82 to
376d37a
Compare
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.
No description provided.