1 //: Update refcounts when copying addresses. 2 //: The top of the address layer has more on refcounts. 3 4 :(scenario refcounts) 5 def main [ 6 1:address:num <- copy 1000/unsafe 7 2:address:num <- copy 1:address:num 8 1:address:num <- copy 0 9 2:address:num <- copy 0 10 ] 11 +run: {1: ("address" "number")} <- copy {1000: "literal", "unsafe": ()} 12 +mem: incrementing refcount of 1000: 0 -> 1 13 +run: {2: ("address" "number")} <- copy {1: ("address" "number")} 14 +mem: incrementing refcount of 1000: 1 -> 2 15 +run: {1: ("address" "number")} <- copy {0: "literal"} 16 +mem: decrementing refcount of 1000: 2 -> 1 17 +run: {2: ("address" "number")} <- copy {0: "literal"} 18 +mem: decrementing refcount of 1000: 1 -> 0 19 20 :(before "End Globals") 21 //: escape hatch for a later layer 22 bool Update_refcounts_in_write_memory = true; 23 24 :(before "End write_memory(x) Special-cases") 25 if (Update_refcounts_in_write_memory) 26 update_any_refcounts(x, data); 27 28 :(code) 29 void update_any_refcounts(const reagent& canonized_x, const vector<double>& data) { 30 increment_any_refcounts(canonized_x, data); // increment first so we don't reclaim on x <- copy x 31 decrement_any_refcounts(canonized_x); 32 } 33 34 void increment_any_refcounts(const reagent& canonized_x, const vector<double>& data) { 35 if (is_mu_address(canonized_x)) { 36 assert(scalar(data)); 37 assert(!canonized_x.metadata.size); 38 increment_refcount(data.at(0)); 39 } 40 // End Increment Refcounts(canonized_x) 41 } 42 43 void increment_refcount(int new_address) { 44 assert(new_address >= 0); 45 if (new_address == 0) return; 46 int new_refcount = get_or_insert(Memory, new_address); 47 trace(9999, "mem") << "incrementing refcount of " << new_address << ": " << new_refcount << " -> " << new_refcount+1 << end(); 48 put#include <stdarg.h> #include <stddef.h> #include <setjmp.h> #include <cmocka.h> #include <stdlib.h> #include <string.h> #include <glib.h> #include "config/preferences.h" #include "ui/ui.h" #include "ui/stub_ui.h" #include "command/cmd_funcs.h" #define CMD_PRESENCE "/presence" void cmd_presence_shows_usage_when_bad_subcmd(void** state) { gchar* args[] = { "badcmd", NULL }; expect_string(cons_bad_cmd_usage, cmd, CMD_PRESENCE); gboolean result = cmd_presence(NULL, CMD_PRESENCE, args); assert_true(result); } void cmd_presence_shows_usage_when_bad_console_setting(void** state) { gchar* args[] = { "console", "badsetting", NULL }; expect_string(cons_bad_cmd_usage, cmd, CMD_PRESENCE); gboolean result = cmd_presence(NULL, CMD_PRESENCE, args); assert_true(result); } void cmd_presence_shows_usage_when_bad_chat_setting(void** state) { gchar* args[] = { "chat", "badsetting", NULL }; expect_string(cons_bad_cmd_usage, cmd, CMD_PRESENCE); gboolean result = cmd_presence(NULL, CMD_PRESENCE, args); assert_true(result); } void cmd_presence_shows_usage_when_bad_muc_setting(void** state) { gchar* args[] = { "muc", "badsetting", NULL }; expect_string(cons_bad_cmd_usage, cmd, CMD_PRESENCE); gboolean result = cmd_presence(NULL, CMD_PRESENCE, args); assert_true(result); } void cmd_presence_console_sets_all(void** state) { gchar* args[] = { "console", "all", NULL }; expect_cons_show("All presence updates will appear in the console."); gboolean result = cmd_presence(NULL, CMD_PRESENCE, args); char* setting = prefs_get_string(PREF_STATUSES_CONSOLE); assert_non_null(setting); assert_string_equal("all", setting); assert_true(result); g_free(setting); } void cmd_presence_console_sets_online(void** state) { gchar* args[] = { "console", "online", NULL }; expect_cons_show("Only online/offline presence updates will appear in the console."); gboolean result = cmd_presence(NULL, CMD_PRESENCE, args); char* setting = prefs_get_string(PREF_STATUSES_CONSOLE); assert_non_null(setting); assert_string_equal("online", setting); assert_true(result); g_free(setting); } void cmd_presence_console_sets_none(void** state) { gchar* args[] = { "console", "none", NULL }; expect_cons_show("Presence updates will not appear in the console."); gboolean result = cmd_presence(NULL, CMD_PRESENCE, args); char* setting = prefs_get_string(PREF_STATUSES_CONSOLE); assert_non_null(setting); assert_string_equal("none", setting); assert_true(result); g_free(setting); } void cmd_presence_chat_sets_all(void** state) { gchar* args[] = { "chat", "all", NULL }; expect_cons_show("All presence updates will appear in chat windows."); gboolean result = cmd_presence(NULL, CMD_PRESENCE, args); char* setting = prefs_get_string(PREF_STATUSES_CHAT); assert_non_null(setting); assert_string_equal("all", setting); assert_true(result); g_free(setting); } void cmd_presence_chat_sets_online(void** state) { gchar* args[] = { "chat", "online", NULL }; expect_cons_show("Only online/offline presence updates will appear in chat windows."); gboolean result = cmd_presence(NULL, CMD_PRESENCE, args); char* setting = prefs_get_string(PREF_STATUSES_CHAT); assert_non_null(setting); assert_string_equal("online", setting); assert_true(result); g_free(setting); } void cmd_presence_chat_sets_none(void** state) { gchar* args[] = { "chat", "none", NULL }; expect_cons_show("Presence updates will not appear in chat windows."); gboolean result = cmd_presence(NULL, CMD_PRESENCE, args); char* setting = prefs_get_string(PREF_STATUSES_CHAT); assert_non_null(setting); assert_string_equal("none", setting); assert_true(result); g_free(setting); } void cmd_presence_room_sets_all(void** state) { gchar* args[] = { "room", "all", NULL }; expect_cons_show("All presence updates will appear in chat room windows."); gboolean result = cmd_presence(NULL, CMD_PRESENCE, args); char* setting = prefs_get_string(PREF_STATUSES_MUC); assert_non_null(setting); assert_string_equal("all", setting); assert_true(result); g_free(setting); } void cmd_presence_room_sets_online(void** state) { gchar* args[] = { "room", "online", NULL }; expect_cons_show("Only join/leave presence updates will appear in chat room windows."); gboolean result = cmd_presence(NULL, CMD_PRESENCE, args); char* setting = prefs_get_string(PREF_STATUSES_MUC); assert_non_null(setting); assert_string_equal("online", setting); assert_true(result); g_free(setting); } void cmd_presence_room_sets_none(void** state) { gchar* args[] = { "room", "none", NULL }; expect_cons_show("Presence updates will not appear in chat room windows."); gboolean result = cmd_presence(NULL, CMD_PRESENCE, args); char* setting = prefs_get_string(PREF_STATUSES_MUC); assert_non_null(setting); assert_string_equal("none", setting); assert_true(result); g_free(setting); }