about summary refs log tree commit diff stats
path: root/043space.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-08-16 17:03:27 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-08-16 17:03:27 -0700
commit78a12c9d706f6197d3710ece04e9bd8d4eebe713 (patch)
tree3951e166cb933c608eeb1a233e7a218497870751 /043space.cc
parent19695cc7ca16d9129ed3ef2b46bf3460452dd6db (diff)
downloadmu-78a12c9d706f6197d3710ece04e9bd8d4eebe713.tar.gz
3202 - bugfix: 'start-running' and refcounts
When you pass an ingredient to a recipe using 'start-running' it mostly
behaves identically to performing a regular function call. However, if
the calling function completed before the new routine had a chance to
run, the ingredients passed in ran the risk of being reclaimed.

In response, let's always increment refcounts at the time of a function
call rather than when the ingredients are read inside the callee.

Now the summary of commit 3197 is modified to this:

  Update refcounts of products after every instruction, EXCEPT:

    a) when instruction is a non-primitive and the callee starts with
    'local-scope' (because it's already not decremented in 'return')

  OR:

    b) when instruction is primitive 'next-ingredient' or
    'next-ingredient-without-typechecking'
Diffstat (limited to '043space.cc')
-rw-r--r--043space.cc4
1 files changed, 2 insertions, 2 deletions
diff --git a/043space.cc b/043space.cc
index 9ee280d8..3a37dc1d 100644
--- a/043space.cc
+++ b/043space.cc
@@ -282,12 +282,12 @@ Update_refcounts_in_write_memory = true;
 :(code)
 bool should_update_refcounts_in_write_memory() {
   const instruction& inst = current_instruction();
+  // End should_update_refcounts_in_write_memory Special-cases For Primitives
   if (inst.operation < MAX_PRIMITIVE_RECIPES) return true;
   if (!contains_key(Recipe, inst.operation)) return true;
   const recipe& caller = get(Recipe, inst.operation);
   if (caller.steps.empty()) return true;
-  // if the recipe doesn't begin with 'local-scope', always update refcounts
-  return caller.steps.at(0).old_name != "local-scope";
+  return caller.steps.at(0).old_name != "local-scope";  // callees that call local-scope are already dealt with before return
 }
 
 bool caller_uses_product(int product_index) {