Live mod options: keep a value only after a callback accepts

Review (#602): psx_mod_set_option_live stored the new value before any
callback ran, so a refusal ("nothing changes until next start") still
changed what psx_mod_option_value answered. The value is visible to the
callbacks while they run and is rolled back unless one accepts. New
test_mod_runtime case: a refusing callback leaves the running value as is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shokunin
2026-10-09 00:27:06 -07:00
parent 0a59b3fd58
commit 57bcbcf075
2 changed files with 26 additions and 4 deletions
+12 -1
View File
@@ -318,6 +318,7 @@ int iso_read_cdda_sector(void*,uint32_t,uint8_t*,int);
static int big_ram_activations;
static int option_changed_hits = 0;
static std::string option_changed_value;
static int option_changed_refuse = 0; /* 1 = the plugin answers "next start" */
static int test_option_changed(const char* option_id, const char* value) {
char cur[32];
option_changed_hits++;
@@ -326,7 +327,7 @@ static int test_option_changed(const char* option_id, const char* value) {
psx_mod_current_option_value("size", cur, sizeof(cur)) == 1)
option_changed_value = cur;
(void)value;
return 1;
return option_changed_refuse ? 0 : 1;
}
static void test_big_ram_activation(void) {
big_ram_activations++;
@@ -1111,6 +1112,16 @@ int main(int argc, char** argv) {
check(psx_mod_option_value("runtime.ram", "big-ram", "size", value, sizeof(value)) == 1 &&
std::string(value) == "four",
"a live override must answer later reads");
/* A callback that refuses ("nothing changes until next start") must
* leave the value the session runs with untouched. */
option_changed_refuse = 1;
check(psx_mod_set_option_live("runtime.ram", "big-ram", "size", "two") == 0 &&
option_changed_hits == 2,
"a refused live set reports refused after asking the plugin");
check(psx_mod_option_value("runtime.ram", "big-ram", "size", value, sizeof(value)) == 1 &&
std::string(value) == "four",
"a refused live set must not change the value later reads see");
option_changed_refuse = 0;
check(psx_mod_set_option_live("runtime.ram", "no-such-feature", "size", "x") == 0,
"features outside the plan are not live-settable");
check(psx_mod_save_selection() == 1, "saving the selection mid-session must succeed");