]> granicus.if.org Git - gc/commitdiff
Fix GC_register_disclaim_proc for leak-finding mode
authorIvan Maidanski <ivmai@mail.ru>
Thu, 29 Nov 2018 08:46:48 +0000 (11:46 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 29 Nov 2018 10:45:47 +0000 (13:45 +0300)
Issue #252 (bdwgc).

This makes the behavior of GC_register_disclaim_proc() and
GC_finalized_malloc() somewhat consistent with
GC_register_disappearing_link() and GC_register_finalizer() when
find-leak is on.  The documentation is updated accordingly.

* fnlz_mlc.c [ENABLE_DISCLAIM] (GC_finalized_disclaim): Add assertion
that GC_find_leak is off.
* fnlz_mlc.c [ENABLE_DISCLAIM] (GC_register_disclaim_proc): Do not
assign ok_disclaim_proc, ok_mark_unconditionally fields if GC_find_leak.
* include/gc_disclaim.h (GC_register_disclaim_proc,
GC_finalized_malloc): Refine comment about leak-find mode and GC_free
invocation.

fnlz_mlc.c
include/gc_disclaim.h

index 1e1a6ed0292f620eff113b3ea2cd495d426573f0..283566ee73b1fc1983dd7707f09d826e7e64b0a0 100644 (file)
@@ -45,6 +45,7 @@ STATIC int GC_CALLBACK GC_finalized_disclaim(void *obj)
         const struct GC_finalizer_closure *fc
                         = (struct GC_finalizer_closure *)(fc_word
                                         & ~(word)FINALIZER_CLOSURE_FLAG);
+        GC_ASSERT(!GC_find_leak);
         (*fc->proc)((word *)obj + 1, fc->cd);
     }
     return 0;
@@ -85,8 +86,11 @@ GC_API void GC_CALL GC_register_disclaim_proc(int kind, GC_disclaim_proc proc,
 {
     GC_ASSERT((unsigned)kind < MAXOBJKINDS);
     GC_ASSERT(NONNULL_ARG_NOT_NULL(proc));
-    GC_obj_kinds[kind].ok_disclaim_proc = proc;
-    GC_obj_kinds[kind].ok_mark_unconditionally = (GC_bool)mark_unconditionally;
+    if (!EXPECT(GC_find_leak, FALSE)) {
+        GC_obj_kinds[kind].ok_disclaim_proc = proc;
+        GC_obj_kinds[kind].ok_mark_unconditionally =
+                                        (GC_bool)mark_unconditionally;
+    }
 }
 
 GC_API GC_ATTR_MALLOC void * GC_CALL GC_finalized_malloc(size_t lb,
index 8123838ed48f0aab6230c2b025b3397b00ce8ab1..f2942cdb8b032a1700ffbd44cea27ca77ab5d740 100644 (file)
@@ -39,6 +39,8 @@ typedef int (GC_CALLBACK * GC_disclaim_proc)(void * /*obj*/);
 /* (including the referred closure object) will be protected from       */
 /* collection if "mark_from_all" is non-zero, but at the expense that   */
 /* long chains of objects will take many cycles to reclaim.             */
+/* Calls to GC_free() will free its argument without inquiring "proc".  */
+/* No-op in the leak-finding mode.                                      */
 GC_API void GC_CALL GC_register_disclaim_proc(int /*kind*/,
                                 GC_disclaim_proc /*proc*/,
                                 int /*mark_from_all*/) GC_ATTR_NONNULL(2);
@@ -60,6 +62,7 @@ struct GC_finalizer_closure {
 /* Note that GC_size (applied to such allocated object) returns a value */
 /* slightly bigger than the specified allocation size, and that GC_base */
 /* result points to a word prior to the start of the allocated object.  */
+/* The disclaim procedure is not invoked in the leak-finding mode.      */
 GC_API GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1) void * GC_CALL
         GC_finalized_malloc(size_t /*size*/,
                 const struct GC_finalizer_closure * /*fc*/) GC_ATTR_NONNULL(2);