+/* Reset the alloc_region. This indicates that it's safe to call
+ * gc_alloc_new_region() on it, and impossible to allocate space from
+ * until gc_alloc_new_region() is called on it. (The reset values are
+ * chosen so that attempts to allocate space from it will fail
+ * (because free_pointer == end_addr) and cause gc_alloc_new_region()
+ * to be called before retrying.) */
+void
+reset_alloc_region(struct alloc_region *alloc_region)
+{
+ alloc_region->first_page = 0;
+ alloc_region->last_page = -1;
+ alloc_region->start_addr =
+ alloc_region->free_pointer =
+ alloc_region->end_addr =
+ page_address(0);
+ /* REMOVEME: last-ditch sanity check for postcondition */
+ gc_assert(alloc_region_is_completely_reset(alloc_region));
+}
+
+/* Does *alloc_region look exactly like it does after
+ * reset_alloc_region() has munged it? */
+int
+alloc_region_is_completely_reset(struct alloc_region *alloc_region)
+{
+ return
+ alloc_region->first_page == 0
+ && alloc_region->last_page == -1
+ && alloc_region->start_addr == alloc_region->free_pointer
+ && alloc_region->free_pointer == alloc_region->end_addr;
+}
+
+/* Is *alloc_region in a state which it could only have gotten into by
+ * having reset_alloc_region() munge it, as it does in preparation for
+ * having gc_alloc_new_region() operate on it? I.e. are at least some
+ * key fields distinctively munged, even if some others aren't?
+ *
+ * This test is different from alloc_region_is_completely_reset(). In
+ * particular, if you reset the region, and then accidentally scribble
+ * on some of its fields, this test will be true while the other test
+ * is false. Around sbcl-0.6.12.8, merging the Alpha patches, this
+ * difference became important because of some problems with the
+ * global current_region_free_pointer being used to scribble on
+ * alloc_region.free_pointer after the alloc_region had been reset and
+ * before gc_alloc_new_region() was called. */
+int
+alloc_region_looks_reset(struct alloc_region *alloc_region)
+{
+ return
+ alloc_region->first_page == 0
+ && alloc_region->last_page == -1;
+}
+
+/* (should only be needed for debugging or assertion failure reporting) */
+void
+fprint_alloc_region(FILE *file, struct alloc_region *alloc_region)
+{
+ fprintf(file,
+ "alloc_region *0x%0lx:
+ first_page=0x%08lx, last_page=0x%08lx,
+ start_addr=0x%08lx, free_pointer=0x%08lx, end_addr=0x%08lx\n",
+ (unsigned long)alloc_region,
+ (unsigned long)alloc_region->first_page,
+ (unsigned long)alloc_region->last_page,
+ (unsigned long)alloc_region->start_addr,
+ (unsigned long)alloc_region->free_pointer,
+ (unsigned long)alloc_region->end_addr);
+}
+
+