From: Ivan Maidanski Date: Mon, 15 Oct 2018 20:54:57 +0000 (+0300) Subject: New API function to get size of object debug header X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=85e3083ff;p=gc New API function to get size of object debug header GC_get_debug_header_size() is exported in addition to GC_debug_header_size variable. The usage of the latter is deprecated. * dbg_mlc.c [CPPCHECK] (GC_start_debugging_inner): Call GC_noop1(GC_debug_header_size) to suppress a cppcheck warning about unused symbol. * dbg_mlc.c (GC_debug_header_size): Add const. * dbg_mlc.c (GC_get_debug_header_size): New API function definition. * include/gc_config_macros.h (GC_ATTR_CONST): New macro. * include/gc_mark.h (GC_debug_header_size): Add GC_ATTR_DEPRECATED and const; update comment. * include/gc_mark.h (GC_get_debug_header_size): New API public const function declaration; move the comment from GC_debug_header_size. * include/gc_mark.h (GC_USR_PTR_FROM_BASE): Use GC_get_debug_header_size() instead of GC_debug_header_size. --- diff --git a/dbg_mlc.c b/dbg_mlc.c index 4d547c15..a8bd8154 100644 --- a/dbg_mlc.c +++ b/dbg_mlc.c @@ -489,9 +489,16 @@ GC_INNER void GC_start_debugging_inner(void) GC_print_heap_obj = GC_debug_print_heap_obj_proc; GC_debugging_started = TRUE; GC_register_displacement_inner((word)sizeof(oh)); +# if defined(CPPCHECK) + GC_noop1(GC_debug_header_size); +# endif } -size_t GC_debug_header_size = sizeof(oh); +const size_t GC_debug_header_size = sizeof(oh); + +GC_API size_t GC_CALL GC_get_debug_header_size(void) { + return sizeof(oh); +} GC_API void GC_CALL GC_debug_register_displacement(size_t offset) { diff --git a/include/gc_config_macros.h b/include/gc_config_macros.h index d656e01e..b999316d 100644 --- a/include/gc_config_macros.h +++ b/include/gc_config_macros.h @@ -276,6 +276,14 @@ # endif #endif +#ifndef GC_ATTR_CONST +# if GC_GNUC_PREREQ(4, 0) +# define GC_ATTR_CONST __attribute__((__const__)) +# else +# define GC_ATTR_CONST /* empty */ +# endif +#endif + #ifndef GC_ATTR_DEPRECATED # ifdef GC_BUILD # undef GC_ATTR_DEPRECATED diff --git a/include/gc_mark.h b/include/gc_mark.h index b5201cb7..ecc6c8a7 100644 --- a/include/gc_mark.h +++ b/include/gc_mark.h @@ -152,12 +152,17 @@ GC_API struct GC_ms_entry * GC_CALL GC_mark_and_push(void * /* obj */, (GC_word)(obj) <= (GC_word)GC_greatest_plausible_heap_addr ? \ GC_mark_and_push(obj, msp, lim, src) : (msp)) -GC_API size_t GC_debug_header_size; - /* The size of the header added to objects allocated through */ - /* the GC_debug routines. */ - /* Defined as a variable so that client mark procedures don't */ - /* need to be recompiled for collector version changes. */ -#define GC_USR_PTR_FROM_BASE(p) ((void *)((char *)(p) + GC_debug_header_size)) +/* The size of the header added to objects allocated through the */ +/* GC_debug routines. Defined as a function so that client mark */ +/* procedures do not need to be recompiled for the collector library */ +/* version changes. */ +GC_API GC_ATTR_CONST size_t GC_CALL GC_get_debug_header_size(void); +#define GC_USR_PTR_FROM_BASE(p) \ + ((void *)((char *)(p) + GC_get_debug_header_size())) + +/* The same but defined as a variable. Exists only for the backward */ +/* compatibility. */ +GC_API GC_ATTR_DEPRECATED const size_t GC_debug_header_size; /* And some routines to support creation of new "kinds", e.g. with */ /* custom mark procedures, by language runtimes. */