Implement the core_move_up() routine for INDIRECT_CORE, needed for realloc_base
authorNick Downing <nick@ndcode.org>
Sun, 2 Jun 2019 02:17:06 +0000 (12:17 +1000)
committerNick Downing <nick@ndcode.org>
Sun, 2 Jun 2019 02:17:06 +0000 (12:17 +1000)
core.c
o.sh

diff --git a/core.c b/core.c
index 9cf74cb..df069bf 100644 (file)
--- a/core.c
+++ b/core.c
@@ -58,21 +58,25 @@ static void core_move(struct pool_item *item, int new_base) {
     core_table_mem[new_base + i] = core_table_mem[base + i];
     core_table_mem[base + i] = 0x55555555;
   }
-#endif
+#endif /* INDIRECT_CORE */
 }
 
-#ifndef INDIRECT_CORE
 static void core_move_up(struct pool_item *item, int new_limit) {
   int limit, blocks;
+#ifndef INDIRECT_CORE
   struct process *process;
   struct process_state state;
   int para;
+#else /* INDIRECT_CORE */
+  int i;
+#endif /* INDIRECT_CORE */
 
   limit = item->limit;
   blocks = limit - item->base;
  printf("core_move_up [%d,%d) to [%d,%d)\n", limit - blocks, limit, new_limit - blocks, new_limit);
   assert(new_limit >= limit || new_limit <= limit - blocks);
 
+#ifndef INDIRECT_CORE
 #if 0 // debugging
  core_copy_up(
   limit << BLOCK_PARAS_SHIFT,
@@ -98,8 +102,14 @@ static void core_move_up(struct pool_item *item, int new_limit) {
     state.core_paras
   );
 #endif
+#else /* INDIRECT_CORE */
+  blocks = -blocks;
+  for (i = -1; i >= blocks; --i) {
+    core_table_mem[new_limit + i] = core_table_mem[limit + i];
+    core_table_mem[limit + i] = 0x55555555;
+  }
+#endif /* INDIRECT_CORE */
 }
-#endif /* ! INDIRECT_CORE */
 
 #ifndef INDIRECT_CORE
 void core_init(int n_blocks)
@@ -116,11 +126,7 @@ void core_init(int n_blocks, int table_size)
     table_size,
 #endif /* INDIRECT_CORE */
     core_move,
-#ifndef INDIRECT_CORE
     core_move_up
-#else /* INDIRECT_CORE */
-    NULL
-#endif /* INDIRECT_CORE */
   );
 
 #ifdef INDIRECT_CORE
diff --git a/o.sh b/o.sh
index 5fca29f..5cec47d 100755 (executable)
--- a/o.sh
+++ b/o.sh
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 echo "generate test script"
-./process_test_gen 16 248 4096 32 false false >process_test.txt
+./process_test_gen 16 248 4096 32 true true >process_test.txt
 
 echo "run test script"
 ./process_test_run 16 64 192 8 384 384 <process_test.txt