From 34d524327db0b8d345f2ddac13346d9ad29cd571 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 16 Feb 2024 19:03:12 +0300 Subject: [PATCH] Use GC_debug_generic_or_special_malloc in GC_debug_realloc (refactoring) * dbg_mlc.c (GC_register_describe_type_fn): Rename kind argument to k. * dbg_mlc.c (GC_print_obj): Rename kind local variable to k. * dbg_mlc.c (GC_debug_realloc): Call GC_debug_generic_or_special_malloc instead of GC_debug_malloc[_atomic][_uncollectable]() and GC_debug_generic_malloc(). --- dbg_mlc.c | 40 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/dbg_mlc.c b/dbg_mlc.c index 259e57f41..ead29c435 100644 --- a/dbg_mlc.c +++ b/dbg_mlc.c @@ -330,11 +330,11 @@ static void *store_debug_info(void *p, size_t lb, STATIC GC_describe_type_fn GC_describe_type_fns[MAXOBJKINDS] = {0}; -GC_API void GC_CALL GC_register_describe_type_fn(int kind, +GC_API void GC_CALL GC_register_describe_type_fn(int k, GC_describe_type_fn fn) { - GC_ASSERT((unsigned)kind < MAXOBJKINDS); - GC_describe_type_fns[kind] = fn; + GC_ASSERT((unsigned)k < MAXOBJKINDS); + GC_describe_type_fns[k] = fn; } #define GET_OH_LINENUM(ohdr) ((int)(ohdr)->oh_int) @@ -354,7 +354,7 @@ STATIC void GC_print_obj(ptr_t p) oh * ohdr = (oh *)GC_base(p); ptr_t q; hdr * hhdr; - int kind; + int k; const char *kind_str; char buffer[GC_TYPE_DESCR_LEN + 1]; @@ -367,16 +367,16 @@ STATIC void GC_print_obj(ptr_t p) /* Print a type description for the object whose client-visible */ /* address is q. */ hhdr = GC_find_header(q); - kind = hhdr -> hb_obj_kind; - if (0 != GC_describe_type_fns[kind] && GC_is_marked(ohdr)) { + k = hhdr -> hb_obj_kind; + if (GC_describe_type_fns[k] != 0 && GC_is_marked(ohdr)) { /* This should preclude free list objects except with */ /* thread-local allocation. */ buffer[GC_TYPE_DESCR_LEN] = 0; - (GC_describe_type_fns[kind])(q, buffer); + (GC_describe_type_fns[k])(q, buffer); GC_ASSERT(buffer[GC_TYPE_DESCR_LEN] == 0); kind_str = buffer; } else { - switch(kind) { + switch (k) { case PTRFREE: kind_str = "PTRFREE"; break; @@ -410,7 +410,7 @@ STATIC void GC_print_obj(ptr_t p) (void *)((ptr_t)ohdr + sizeof(oh)), ohdr->oh_string, GET_OH_LINENUM(ohdr) /*, */ COMMA_IFNOT_SHORTDBG_HDRS((unsigned long)ohdr->oh_sz), - kind, (unsigned long)hhdr->hb_descr); + k, (unsigned long)(hhdr -> hb_descr)); } PRINT_CALL_CHAIN(ohdr); } @@ -857,26 +857,8 @@ GC_API void * GC_CALL GC_debug_realloc(void * p, size_t lb, GC_EXTRA_PARAMS) return GC_realloc(p, lb); } hhdr = HDR(base); - switch (hhdr -> hb_obj_kind) { - case NORMAL: - result = GC_debug_malloc(lb, OPT_RA s, i); - break; - case PTRFREE: - result = GC_debug_malloc_atomic(lb, OPT_RA s, i); - break; - case UNCOLLECTABLE: - result = GC_debug_malloc_uncollectable(lb, OPT_RA s, i); - break; -# ifdef GC_ATOMIC_UNCOLLECTABLE - case AUNCOLLECTABLE: - result = GC_debug_malloc_atomic_uncollectable(lb, OPT_RA s, i); - break; -# endif - default: - result = GC_debug_generic_malloc(lb, hhdr -> hb_obj_kind, OPT_RA s, i); - break; - } - + result = GC_debug_generic_or_special_malloc(lb, hhdr -> hb_obj_kind, + OPT_RA s, i); if (result != NULL) { size_t old_sz; # ifdef SHORT_DBG_HDRS