about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-04-20 20:01:34 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-04-20 20:01:34 -0700
commit2db8bed570552cdf363711d2f49b0adaae63c6b5 (patch)
treec15b31543d84d3705952da9604feccf684ace42d
parent6abdff2707bbe9d7df8b8d7eb08bb3c4ea75ab59 (diff)
downloadmu-2db8bed570552cdf363711d2f49b0adaae63c6b5.tar.gz
2849
-rw-r--r--037new.cc24
-rw-r--r--076duplex_list.mu2
2 files changed, 23 insertions, 3 deletions
diff --git a/037new.cc b/037new.cc
index edf9a548..ec30fee1 100644
--- a/037new.cc
+++ b/037new.cc
@@ -25,6 +25,7 @@
 //: minimize memory use, be sure to reset allocated addresses to 0 when you're
 //: done with them.
 
+//: interlude {
 //: To help you distinguish addresses that point at allocations, 'new' returns
 //: type address:shared:___. Think of 'shared' as a generic container that
 //: contains one extra field: the refcount. However, lookup operations will
@@ -34,7 +35,7 @@
 type_ordinal shared = put(Type_ordinal, "shared", Next_type_ordinal++);
 get_or_insert(Type, shared).name = "shared";
 :(before "End Drop Address In lookup_memory(x)")
-if (x.type->name == "shared") {
+if (x.type->name == "shared" && x.value != 0) {
   trace(9999, "mem") << "skipping refcount at " << x.value << end();
   x.set_value(x.value+1);  // skip refcount
   drop_from_type(x, "shared");
@@ -44,6 +45,27 @@ if (r.type->name == "shared") {
   drop_from_type(r, "shared");
 }
 
+:(code)
+void test_lookup_shared_address() {
+  reagent x("*x:address:shared:number");
+  x.set_value(34);  // unsafe
+  put(Memory, 34, 1000);
+  lookup_memory(x);
+  CHECK_TRACE_CONTENTS("mem: skipping refcount at 1000");
+  CHECK_EQ(x.value, 1001);
+}
+
+void test_lookup_shared_address_skip_zero() {
+  reagent x("*x:address:shared:number");
+  x.set_value(34);  // unsafe
+  put(Memory, 34, 0);
+  lookup_memory(x);
+  CHECK_TRACE_DOESNT_CONTAIN("mem: skipping refcount at 0");
+  CHECK_EQ(x.value, 0);
+}
+
+//: } end interlude
+
 :(scenarios run)
 :(scenario new)
 # call new two times with identical arguments; you should get back different results
diff --git a/076duplex_list.mu b/076duplex_list.mu
index d8c33c91..d6970916 100644
--- a/076duplex_list.mu
+++ b/076duplex_list.mu
@@ -460,8 +460,6 @@ scenario remove-range-to-end [
     5:address:shared:duplex-list:character <- next 1:address:shared:duplex-list:character
     6:character <- get *5:address:shared:duplex-list:character, value:offset
     7:address:shared:duplex-list:character <- next 5:address:shared:duplex-list:character
-    8:character <- get *7:address:shared:duplex-list:character, value:offset
-    9:address:shared:duplex-list:character <- next 7:address:shared:duplex-list:character
   ]
   memory-should-contain [
     4 <- 13