Skip to content

runtime, ipl: fix array allocation crashes and window-close event loops - #694

Merged
Jafaral merged 4 commits into
uniconproject:masterfrom
Jafaral:runtime-ipl-fixes
Nov 2, 2026
Merged

Jafaral merged 4 commits into
uniconproject:masterfrom
Jafaral:runtime-ipl-fixes

Conversation

@Jafaral

@Jafaral Jafaral commented Nov 2, 2026

Copy link
Copy Markdown
Member

No description provided.

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]>
@greptile-apps

greptile-apps Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge; both previous findings are fixed.

Summary

Fixes array allocation crashes and stops event loops after windows close.

  • Array creation reserves its storage safely and supports larger sizes.
  • Startup collection skips the main stack until it is ready.
  • Graphics event loops return when their window closes.
  • Dialog close buttons now choose a button or cancel.

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

Comment thread src/runtime/fstruct.r Resolved
Comment thread ipl/gprocs/vdialog.icn Resolved
@Jafaral
Jafaral merged commit b9f0fdd into uniconproject:master Nov 2, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant