Specify register_disclaim_proc and finalized_malloc argument as non-null
authorIvan Maidanski <ivmai@mail.ru>
Thu, 13 Sep 2018 06:31:11 +0000 (09:31 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 18 Sep 2018 21:37:38 +0000 (00:37 +0300)
Also, a check is added that the actual finalizer closure pointer does
not have FINALIZER_CLOSURE_FLAG set.

* fnlz_mlc.c (GC_register_disclaim_proc): Add assertion that proc is
non-null.
* fnlz_mlc.c (GC_finalized_malloc): Add assertions that fclos argument
is non-null and that fclos itself does not have FINALIZER_CLOSURE_FLAG
set.
* include/gc_disclaim.h (GC_register_disclaim_proc,
GC_finalized_malloc): Add GC_ATTR_NONNULL for the pointer argument.

fnlz_mlc.c
include/gc_disclaim.h

index 17c73ae..3d6244a 100644 (file)
@@ -78,6 +78,7 @@ GC_API void GC_CALL GC_register_disclaim_proc(int kind, GC_disclaim_proc proc,
                                               int mark_unconditionally)
 {
     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;
 }
@@ -88,6 +89,8 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_finalized_malloc(size_t lb,
     word *op;
 
     GC_ASSERT(GC_finalized_kind != 0);
+    GC_ASSERT(NONNULL_ARG_NOT_NULL(fclos));
+    GC_ASSERT(((word)fclos & FINALIZER_CLOSURE_FLAG) == 0);
     op = (word *)GC_malloc_kind(SIZET_SAT_ADD(lb, sizeof(word)),
                                 GC_finalized_kind);
     if (EXPECT(NULL == op, FALSE))
index b720977..7f5ffb1 100644 (file)
@@ -39,8 +39,8 @@ typedef int (GC_CALLBACK * GC_disclaim_proc)(void * /*obj*/);
 /* but at the expense that long chains of objects will take many cycles */
 /* to reclaim.                                                          */
 GC_API void GC_CALL GC_register_disclaim_proc(int /*kind*/,
-                                              GC_disclaim_proc /*proc*/,
-                                              int /*mark_from_all*/);
+                                GC_disclaim_proc /*proc*/,
+                                int /*mark_from_all*/) GC_ATTR_NONNULL(2);
 
 /* The finalizer closure used by GC_finalized_malloc.                   */
 struct GC_finalizer_closure {
@@ -57,7 +57,7 @@ struct GC_finalizer_closure {
 /* result points to a word prior to the start of the allocated object.  */
 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*/);
+                const struct GC_finalizer_closure * /*fc*/) GC_ATTR_NONNULL(2);
 
 #ifdef __cplusplus
   } /* extern "C" */