diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2018-11-29 11:46:48 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2018-11-29 11:46:48 +0300 |
commit | 328509d459ee420c839e51acac12aa1d71d829a5 (patch) | |
tree | baedc308f0f1f9aabeaf45692487ea14d31b5785 | |
parent | 945afca717982db4363e6241a5da80a5999afed2 (diff) | |
download | bdwgc-328509d459ee420c839e51acac12aa1d71d829a5.tar.gz |
Fix GC_register_disclaim_proc for leak-finding mode
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.
-rw-r--r-- | fnlz_mlc.c | 8 | ||||
-rw-r--r-- | include/gc_disclaim.h | 3 |
2 files changed, 9 insertions, 2 deletions
@@ -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, diff --git a/include/gc_disclaim.h b/include/gc_disclaim.h index 8123838e..f2942cdb 100644 --- a/include/gc_disclaim.h +++ b/include/gc_disclaim.h @@ -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); |