summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHan-Wen Nienhuys <hanwen@lilypond.org>2008-09-09 23:08:16 -0300
committerHan-Wen Nienhuys <hanwen@lilypond.org>2008-09-09 23:08:16 -0300
commit7ddb9baf80744f0ea4810c35b465d96f48338750 (patch)
tree7827a68cb9a524b33936703b113140e452b60c76
parenta8db4a59c898598cc55dd3bd86a6fd8618721d10 (diff)
downloadguile-7ddb9baf80744f0ea4810c35b465d96f48338750.tar.gz
Cleanup mark-during-GC debug checks.
* libguile/__scm.h (SCM_DEBUG): add SCM_DEBUG_MARKING_API * libguile/gc.h (SCM_SET_GC_MARK): depending on SCM_DEBUG_MARKING_API crash if someone is touching markbits outside regular hours. Rename ensure_marking() to scm_i_ensure_marking(). * libguile/inline.h (scm_double_cell, scm_cell): only set mark bits for debugging if SCM_DEBUG_MARKING_API is unset * libguile/gc-mark.c: Issue deprecation warning if we are marking outside of the GC mark phase.
-rw-r--r--libguile/__scm.h8
-rw-r--r--libguile/gc-mark.c9
-rw-r--r--libguile/gc.c5
-rw-r--r--libguile/gc.h13
-rw-r--r--libguile/inline.h9
5 files changed, 35 insertions, 9 deletions
diff --git a/libguile/__scm.h b/libguile/__scm.h
index 30077fd46..d486b69bf 100644
--- a/libguile/__scm.h
+++ b/libguile/__scm.h
@@ -197,6 +197,14 @@
#define SCM_DEBUG 0
#endif
+/* For debugging purposes: define this is to ensure nobody is using
+ * the mark bits outside of the marking phase. This is meant for
+ * debugging purposes only.
+ */
+#ifndef SCM_DEBUG_MARKING_API
+#define SCM_DEBUG_MARKING_API 0
+#endif
+
/* If SCM_DEBUG_CELL_ACCESSES is set to 1, cell accesses will perform
* exhaustive parameter checking: It will be verified that cell parameters
* actually point to a valid heap cell. Note: If this option is enabled,
diff --git a/libguile/gc-mark.c b/libguile/gc-mark.c
index d72caf1ac..c334c1075 100644
--- a/libguile/gc-mark.c
+++ b/libguile/gc-mark.c
@@ -165,12 +165,19 @@ scm_gc_mark (SCM ptr)
if (SCM_GC_MARK_P (ptr))
return;
+ if (!scm_i_marking)
+ {
+ static const char msg[]
+ = "Should only call scm_gc_mark() during GC.";
+ scm_c_issue_deprecation_warning (msg);
+ }
+
SCM_SET_GC_MARK (ptr);
scm_gc_mark_dependencies (ptr);
}
void
-ensure_marking (void)
+scm_i_ensure_marking (void)
{
assert (scm_i_marking);
}
diff --git a/libguile/gc.c b/libguile/gc.c
index a0b3080f7..f3ef585a9 100644
--- a/libguile/gc.c
+++ b/libguile/gc.c
@@ -143,7 +143,7 @@ scm_assert_cell_valid (SCM cell)
*/
if (scm_expensive_debug_cell_accesses_p)
scm_i_expensive_validation_check (cell);
-
+#if (SCM_DEBUG_MARKING_API == 0)
if (!SCM_GC_MARK_P (cell))
{
fprintf (stderr,
@@ -153,7 +153,8 @@ scm_assert_cell_valid (SCM cell)
(unsigned long) SCM_UNPACK (cell));
abort ();
}
-
+#endif /* SCM_DEBUG_MARKING_API */
+
scm_i_cell_validation_already_running = 0; /* re-enable */
}
}
diff --git a/libguile/gc.h b/libguile/gc.h
index 3bdc3cc3c..fbd971036 100644
--- a/libguile/gc.h
+++ b/libguile/gc.h
@@ -156,9 +156,16 @@ typedef unsigned long scm_t_c_bvec_long;
/* testing and changing GC marks */
#define SCM_GC_MARK_P(x) SCM_GC_CELL_GET_BIT (x)
-void ensure_marking(void);
-#define SCM_SET_GC_MARK(x) SCM_GC_CELL_SET_BIT (x)
-#define SCM_CLEAR_GC_MARK(x) SCM_GC_CELL_CLEAR_BIT (x)
+SCM_INTERNAL void scm_i_ensure_marking(void);
+
+#if (SCM_DEBUG_MARKING_API == 1)
+#define SCM_I_ENSURE_MARKING scm_i_ensure_marking(),
+#else
+#define SCM_I_ENSURE_MARKING
+#endif
+
+#define SCM_SET_GC_MARK(x) SCM_I_ENSURE_MARKING SCM_GC_CELL_SET_BIT (x)
+#define SCM_CLEAR_GC_MARK(x) SCM_I_ENSURE_MARKING SCM_GC_CELL_CLEAR_BIT (x)
/* Low level cell data accessing macros. These macros should only be used
* from within code related to garbage collection issues, since they will
diff --git a/libguile/inline.h b/libguile/inline.h
index a9b3dc544..f3c76b5e2 100644
--- a/libguile/inline.h
+++ b/libguile/inline.h
@@ -134,12 +134,14 @@ scm_cell (scm_t_bits car, scm_t_bits cdr)
}
}
+#if (SCM_DEBUG_MARKING_API == 0)
/*
Always set mark. Otherwise cells that are alloced before
scm_debug_cell_accesses_p is toggled seem invalid.
*/
SCM_SET_GC_MARK (z);
-
+#endif /* SCM_DEBUG_MARKING_API */
+
/*
TODO: figure out if this use of mark bits is valid with
threading. What if another thread is doing GC at this point
@@ -202,10 +204,11 @@ scm_double_cell (scm_t_bits car, scm_t_bits cbr,
abort();
}
}
-
+#if (SCM_DEBUG_MARKING_API == 0)
/* see above. */
SCM_SET_GC_MARK (z);
-
+#endif /* SCM_DEBUG_MARKING_API */
+
#endif
/* When this function is inlined, it's possible that the last