30 Commits
Author SHA1 Message Date
Goober5000 87189525e0 clean up check_sexp_syntax and improve caching
- Clean up `check_sexp_syntax` to use `eval_ship` (and incidentally `eval_wing` and `eval_prop`) rather than the old lookups.
- Disable SEXP node caching while FRED is running.  Also use smart pointers and fix a cache memory leak.
2026-08-27 14:21:30 -04:00
Goober5000andClaude Opus 4.8 bed228d264 avoid undefined behavior from UNREACHABLE on reachable code paths (#7555)
* avoid undefined behavior from UNREACHABLE on reachable code paths

UNREACHABLE expands to __assume(false) / __builtin_unreachable() in
release builds, which is undefined behavior if the code is ever actually
reached. Many UNREACHABLE sites only guard against unexpected-but-
possible runtime states (values from tables, mission/save files, network
packets, scripting, or user input), so reaching them should degrade
gracefully rather than invoke UB.

Replace UNREACHABLE with Assertion(false, ...) at all such sites. It
still pops an error in debug builds, but in release it is a harmless
no-op that simply falls through to the following code. Sites that are
genuinely unreachable by local invariants (e.g. a switch over a bounded
random number) are left as UNREACHABLE.

A few converted sites had no safe fall-through -- an uninitialized read,
null dereference, or null call would have followed -- so they also get a
minimal recovery: initialize the value, guard the dereference, return
early, or skip the offending item.

Where the converted site was a simple guard of the form
    if (x) { Assertion(false, ...); return; }
hoist the check onto the invariant instead:
    Assertion(!x, ...);
    if (x) { return; }
This states the expectation directly and shows the offending value in
the debug popup, while keeping the same graceful runtime degradation.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* addendum

After consultation with Lafiel, use UNREACHABLE in situations that are effectively impossible even if not provably impossible.  UNREACHABLE = "this shouldn't ever happen"; Assertion = "if this ever happens, it's a coding error".  Also fix a few other sites and change a couple to Warnings.

---------

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
2026-07-09 11:20:25 +09:00
Goober5000 ce31a33029 fix persistent variables and containers (#7192) 2026-03-13 08:16:28 -04:00
Goober5000 2e65831fa2 add int64 support to toolchain, and fix errors
Add `UINT64_T_ARG` and `INT64_T_ARG` macros for printf arguments, similar to `SIZE_T_ARG` and `PTRDIFF_T_ARG`.

In the process, fix some issues with the toolchain: in certain CI runs the toolchain headers were being #included multiple times, and certain CI runs produced collisions between clang definitions and gcc definitions.  Resolve these issues with `#pragma once` and preprocessor guards in the event of both gcc and clang being active.

Also remove toolchain.h from sexp_container.cpp since it is already #included via pstypes.h.
2025-05-21 23:32:35 -04:00
Joshua Glatt 19b849fd71 disallow all forms of add-to-map with a container used in special arg 2025-01-25 16:47:05 -08:00
Joshua Glatt 05e1a7a429 fix map container mutation issues 2025-01-25 16:08:49 -08:00
Birk Magnussen 7dd52a4214 Add scripting state that does not end mission 2023-11-05 22:04:23 +01:00
Sébastien Noel f149c36b44 Fix a few typos (#5598) 2023-10-24 20:33:45 -04:00
Joshua Glatt 86f458f01a Allow modifying map container data when the map is an argument (#4683)
* allow modifying map container data when the map is an argument

* skip past an invalid map key, avoid infinite loop
2022-09-21 08:11:17 +09:00
Joshua Glatt fa29b91e68 Disallow Replace Container Data with special argument list (#4392) 2022-06-14 21:03:11 -07:00
Joshua Glatt bd864baead Clean up list modifier code (#4363) 2022-06-10 17:31:25 -07:00
Joshua Glatt b893075efe Detect concurrent container modification (#4330)
* add node subtype for container names

* clean up and port changes to qtFRED

* fix parsing when container is the last argument

* fix serializing container name nodes

* fix parsing again

* disallow spaces in container names

* check for spaces and & chars while parsing container names

* early WIP for trying to get list containers of strings working as argument options

* indicate which SEXPs will be supported for now

* clean up

* add FRED/qtFRED support

* remove [in]validate-argument from supported SEXPs

* support map containers with string keys

* update FRED and qtFRED

* clean up

* update FRED help text

* revert some unneeded changes

* fix style

* remove added assertion

* backport useful changes from PR #4263 and then some

* clean up backport

* move condition_node evaluation outside of argument loop

* fix does_blank_of_op_support_container_args()

* fix assertion

* add OPF_DATA_OR_STR_CONTAINER and use restore old behavior of OPF_ANYTHING

* revert some unnecessary changes

* fix CI

* detect attempts to modify container while it is being used as special argument (WIP)

* evaluate conditional for each loop

* update placeholder text for new SEXP arg type

* finish/clean up
2022-06-05 08:47:51 -05:00
Joshua Glatt 1f625f3a7f Support using containers with random-multiple-of SEXP (#4326) 2022-06-03 17:09:24 -07:00
Joshua Glatt 6bfe6071d0 Add apply-container-filter SEXP (#4333) 2022-06-02 07:12:38 -07:00
Joshua Glatt 151bfd2f26 Support using string-valued containers in some when-argument SEXPs (#4305) 2022-06-01 07:57:15 -07:00
Joshua Glatt 84023002db Add for-container-data and for-map-container-keys SEXPs (#4296) 2022-05-26 21:39:14 -07:00
Joshua Glatt 3fb034ab7f Add container name subtype to Sexp_nodes (#4299) 2022-05-25 21:26:05 -07:00
Joshua Glatt c8ace18317 Add copy-container SEXP (#4291) 2022-05-23 08:55:27 -07:00
Goober5000 e534adf107 Merge pull request #4159 from Goober5000/test_replace
guard against off-by-one errors in replace_one and replace_all
2022-05-11 22:11:39 -04:00
Joshua Glatt e44456333e Fix clear-container SEXP (#4255) 2022-05-10 21:39:59 -07:00
Joshua Glatt 6f8e60eb17 SEXP containers, Part 8: Change SEXPs (#3862) 2022-05-08 20:15:59 -07:00
Joshua Glatt a654b61d0c SEXP containers, Part 7: Status SEXPs (#3861) 2022-05-08 08:15:59 -07:00
Goober5000 b404b137a0 guard against off-by-one errors in replace_one and replace_all
Also add some test cases for checking correct behavior.
2022-05-07 15:08:21 -04:00
Joshua Glatt 670665d0af SEXP containers, Part 6: FRED/qtFRED SEXP trees (#3852) 2022-05-01 20:27:39 -07:00
Joshua Glatt fe236b337f SEXP containers, Part 4: Text replacement (#3490) 2022-04-26 10:24:55 -07:00
Joshua Glatt c6ecf88aec karajorma's SEXP containers, Part 5: Sexp_nodes (#3495) 2021-12-24 17:49:36 -08:00
Joshua Glatt 16d75b981c karajorma's SEXP containers, Part 2: Persistence (#3462) 2021-10-11 18:58:00 -07:00
Joshua Glatt 7e4190b97e add any() and none() for ContainerType 2021-06-06 19:41:14 -07:00
Joshua Glatt f3773388b9 make ContainerType's '&' overload return ContainerType instead of bool 2021-06-06 11:35:54 -07:00
Joshua Glatt 552201884b karajorma's SEXP containers, Part 1: Definition, parsing, and saving (#3449) 2021-05-31 09:15:48 -07:00