From: Ivan Maidanski Date: Tue, 22 Apr 2014 21:28:32 +0000 (+0400) Subject: Fix MS VC redefinition warning for functions declared with GC_ATTR_MALLOC X-Git-Tag: gc7_6_0~270 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=36aa13da6c202b354537c08fa909f7bf122b420f;p=gc Fix MS VC redefinition warning for functions declared with GC_ATTR_MALLOC * dbg_mlc.c (GC_debug_malloc, GC_debug_malloc_ignore_off_page, GC_debug_malloc_atomic_ignore_off_page, GC_debug_malloc_stubborn, GC_debug_malloc_atomic, GC_debug_strdup, GC_debug_strndup, GC_debug_wcsdup, GC_debug_malloc_uncollectable, GC_debug_malloc_atomic_uncollectable, GC_debug_generic_or_special_malloc, GC_debug_malloc_replacement): Add GC_ATTR_MALLOC attribute to API function definition (to avoid MS VC warning about redefinition of a symbol previously declared with __declspec). * fnlz_mlc.c (GC_finalized_malloc): Likewise. * gcj_mlc.c (GC_gcj_malloc, GC_debug_gcj_malloc, GC_gcj_malloc_ignore_off_page): Likewise. * malloc.c (GC_generic_malloc, GC_malloc_atomic, GC_malloc, GC_malloc_uncollectable): Likewise. * mallocx.c (GC_generic_or_special_malloc, GC_generic_malloc_ignore_off_page, GC_malloc_ignore_off_page, GC_malloc_atomic_ignore_off_page, GC_malloc_many, GC_memalign, GC_malloc_atomic_uncollectable, GC_strdup, GC_strndup, GC_wcsdup): Likewise. * stubborn.c (GC_malloc_stubborn): Likewise. * thread_local_alloc.c (GC_malloc, GC_malloc_atomic, GC_gcj_malloc): Likewise. * typd_mlc.c (GC_malloc_explicitly_typed, GC_malloc_explicitly_typed_ignore_off_page, GC_calloc_explicitly_typed): Likewise. --- diff --git a/dbg_mlc.c b/dbg_mlc.c index da4b86f3..fef1a251 100644 --- a/dbg_mlc.c +++ b/dbg_mlc.c @@ -506,7 +506,8 @@ GC_API void GC_CALL GC_debug_register_displacement(size_t offset) # endif #endif /* GC_ADD_CALLER */ -GC_API void * GC_CALL GC_debug_malloc(size_t lb, GC_EXTRA_PARAMS) +GC_API GC_ATTR_MALLOC void * GC_CALL GC_debug_malloc(size_t lb, + GC_EXTRA_PARAMS) { void * result; @@ -531,8 +532,8 @@ GC_API void * GC_CALL GC_debug_malloc(size_t lb, GC_EXTRA_PARAMS) return (GC_store_debug_info(result, (word)lb, s, i)); } -GC_API void * GC_CALL GC_debug_malloc_ignore_off_page(size_t lb, - GC_EXTRA_PARAMS) +GC_API GC_ATTR_MALLOC void * GC_CALL + GC_debug_malloc_ignore_off_page(size_t lb, GC_EXTRA_PARAMS) { void * result = GC_malloc_ignore_off_page(lb + DEBUG_BYTES); @@ -548,8 +549,8 @@ GC_API void * GC_CALL GC_debug_malloc_ignore_off_page(size_t lb, return (GC_store_debug_info(result, (word)lb, s, i)); } -GC_API void * GC_CALL GC_debug_malloc_atomic_ignore_off_page(size_t lb, - GC_EXTRA_PARAMS) +GC_API GC_ATTR_MALLOC void * GC_CALL + GC_debug_malloc_atomic_ignore_off_page(size_t lb, GC_EXTRA_PARAMS) { void * result = GC_malloc_atomic_ignore_off_page(lb + DEBUG_BYTES); @@ -624,7 +625,8 @@ STATIC void * GC_debug_generic_malloc(size_t lb, int knd, GC_EXTRA_PARAMS) #endif /* DBG_HDRS_ALL */ #ifdef STUBBORN_ALLOC - GC_API void * GC_CALL GC_debug_malloc_stubborn(size_t lb, GC_EXTRA_PARAMS) + GC_API GC_ATTR_MALLOC void * GC_CALL GC_debug_malloc_stubborn(size_t lb, + GC_EXTRA_PARAMS) { void * result = GC_malloc_stubborn(lb + DEBUG_BYTES); @@ -673,7 +675,8 @@ STATIC void * GC_debug_generic_malloc(size_t lb, int knd, GC_EXTRA_PARAMS) #else /* !STUBBORN_ALLOC */ - GC_API void * GC_CALL GC_debug_malloc_stubborn(size_t lb, GC_EXTRA_PARAMS) + GC_API GC_ATTR_MALLOC void * GC_CALL GC_debug_malloc_stubborn(size_t lb, + GC_EXTRA_PARAMS) { return GC_debug_malloc(lb, OPT_RA s, i); } @@ -685,7 +688,8 @@ STATIC void * GC_debug_generic_malloc(size_t lb, int knd, GC_EXTRA_PARAMS) const void * p GC_ATTR_UNUSED) {} #endif /* !STUBBORN_ALLOC */ -GC_API void * GC_CALL GC_debug_malloc_atomic(size_t lb, GC_EXTRA_PARAMS) +GC_API GC_ATTR_MALLOC void * GC_CALL GC_debug_malloc_atomic(size_t lb, + GC_EXTRA_PARAMS) { void * result = GC_malloc_atomic(lb + DEBUG_BYTES); @@ -701,7 +705,8 @@ GC_API void * GC_CALL GC_debug_malloc_atomic(size_t lb, GC_EXTRA_PARAMS) return (GC_store_debug_info(result, (word)lb, s, i)); } -GC_API char * GC_CALL GC_debug_strdup(const char *str, GC_EXTRA_PARAMS) +GC_API GC_ATTR_MALLOC char * GC_CALL GC_debug_strdup(const char *str, + GC_EXTRA_PARAMS) { char *copy; size_t lb; @@ -723,8 +728,8 @@ GC_API char * GC_CALL GC_debug_strdup(const char *str, GC_EXTRA_PARAMS) return copy; } -GC_API char * GC_CALL GC_debug_strndup(const char *str, size_t size, - GC_EXTRA_PARAMS) +GC_API GC_ATTR_MALLOC char * GC_CALL GC_debug_strndup(const char *str, + size_t size, GC_EXTRA_PARAMS) { char *copy; size_t len = strlen(str); /* str is expected to be non-NULL */ @@ -745,7 +750,8 @@ GC_API char * GC_CALL GC_debug_strndup(const char *str, size_t size, #ifdef GC_REQUIRE_WCSDUP # include /* for wcslen() */ - GC_API wchar_t * GC_CALL GC_debug_wcsdup(const wchar_t *str, GC_EXTRA_PARAMS) + GC_API GC_ATTR_MALLOC wchar_t * GC_CALL GC_debug_wcsdup(const wchar_t *str, + GC_EXTRA_PARAMS) { size_t lb = (wcslen(str) + 1) * sizeof(wchar_t); wchar_t *copy = GC_debug_malloc_atomic(lb, OPT_RA s, i); @@ -760,8 +766,8 @@ GC_API char * GC_CALL GC_debug_strndup(const char *str, size_t size, } #endif /* GC_REQUIRE_WCSDUP */ -GC_API void * GC_CALL GC_debug_malloc_uncollectable(size_t lb, - GC_EXTRA_PARAMS) +GC_API GC_ATTR_MALLOC void * GC_CALL GC_debug_malloc_uncollectable(size_t lb, + GC_EXTRA_PARAMS) { void * result = GC_malloc_uncollectable(lb + UNCOLLECTABLE_DEBUG_BYTES); @@ -778,8 +784,8 @@ GC_API void * GC_CALL GC_debug_malloc_uncollectable(size_t lb, } #ifdef ATOMIC_UNCOLLECTABLE - GC_API void * GC_CALL GC_debug_malloc_atomic_uncollectable(size_t lb, - GC_EXTRA_PARAMS) + GC_API GC_ATTR_MALLOC void * GC_CALL + GC_debug_malloc_atomic_uncollectable(size_t lb, GC_EXTRA_PARAMS) { void * result = GC_malloc_atomic_uncollectable(lb + UNCOLLECTABLE_DEBUG_BYTES); @@ -941,8 +947,8 @@ GC_API void * GC_CALL GC_debug_realloc(void * p, size_t lb, GC_EXTRA_PARAMS) return(result); } -GC_API void * GC_CALL GC_debug_generic_or_special_malloc(size_t lb, int knd, - GC_EXTRA_PARAMS) +GC_API GC_ATTR_MALLOC void * GC_CALL + GC_debug_generic_or_special_malloc(size_t lb, int knd, GC_EXTRA_PARAMS) { switch (knd) { # ifdef STUBBORN_ALLOC @@ -1247,7 +1253,7 @@ GC_API void GC_CALL GC_debug_register_finalizer_ignore_self #endif /* !GC_NO_FINALIZATION */ -GC_API void * GC_CALL GC_debug_malloc_replacement(size_t lb) +GC_API GC_ATTR_MALLOC void * GC_CALL GC_debug_malloc_replacement(size_t lb) { return GC_debug_malloc(lb, GC_DBG_EXTRAS); } diff --git a/fnlz_mlc.c b/fnlz_mlc.c index 23735bdb..5eb168a3 100644 --- a/fnlz_mlc.c +++ b/fnlz_mlc.c @@ -81,7 +81,7 @@ GC_API void GC_CALL GC_register_disclaim_proc(int kind, GC_disclaim_proc proc, STATIC void * GC_core_finalized_malloc(size_t lb, const struct GC_finalizer_closure *fclos) #else - GC_API void * GC_CALL GC_finalized_malloc(size_t lb, + GC_API GC_ATTR_MALLOC void * GC_CALL GC_finalized_malloc(size_t lb, const struct GC_finalizer_closure *fclos) #endif { @@ -125,7 +125,7 @@ GC_API void GC_CALL GC_register_disclaim_proc(int kind, GC_disclaim_proc proc, } #ifdef THREAD_LOCAL_ALLOC - GC_API void * GC_CALL GC_finalized_malloc(size_t client_lb, + GC_API GC_ATTR_MALLOC void * GC_CALL GC_finalized_malloc(size_t client_lb, const struct GC_finalizer_closure *fclos) { size_t lb = client_lb + sizeof(void *); diff --git a/gcj_mlc.c b/gcj_mlc.c index c2aee253..195a215a 100644 --- a/gcj_mlc.c +++ b/gcj_mlc.c @@ -159,7 +159,7 @@ static void maybe_finalize(void) GC_INNER void * GC_core_gcj_malloc(size_t lb, void * ptr_to_struct_containing_descr) #else - GC_API void * GC_CALL GC_gcj_malloc(size_t lb, + GC_API GC_ATTR_MALLOC void * GC_CALL GC_gcj_malloc(size_t lb, void * ptr_to_struct_containing_descr) #endif { @@ -204,7 +204,7 @@ static void maybe_finalize(void) /* Similar to GC_gcj_malloc, but add debug info. This is allocated */ /* with GC_gcj_debug_kind. */ -GC_API void * GC_CALL GC_debug_gcj_malloc(size_t lb, +GC_API GC_ATTR_MALLOC void * GC_CALL GC_debug_gcj_malloc(size_t lb, void * ptr_to_struct_containing_descr, GC_EXTRA_PARAMS) { void * result; @@ -232,7 +232,7 @@ GC_API void * GC_CALL GC_debug_gcj_malloc(size_t lb, } /* There is no THREAD_LOCAL_ALLOC for GC_gcj_malloc_ignore_off_page(). */ -GC_API void * GC_CALL GC_gcj_malloc_ignore_off_page(size_t lb, +GC_API GC_ATTR_MALLOC void * GC_CALL GC_gcj_malloc_ignore_off_page(size_t lb, void * ptr_to_struct_containing_descr) { ptr_t op; diff --git a/malloc.c b/malloc.c index 58aa55ab..a4dd437f 100644 --- a/malloc.c +++ b/malloc.c @@ -167,7 +167,7 @@ GC_INNER void * GC_generic_malloc_inner_ignore_off_page(size_t lb, int k) size_t GC_dbg_collect_at_malloc_min_lb = (GC_COLLECT_AT_MALLOC); #endif -GC_API void * GC_CALL GC_generic_malloc(size_t lb, int k) +GC_API GC_ATTR_MALLOC void * GC_CALL GC_generic_malloc(size_t lb, int k) { void * result; DCL_LOCK_STATE; @@ -225,7 +225,7 @@ GC_API void * GC_CALL GC_generic_malloc(size_t lb, int k) #ifdef THREAD_LOCAL_ALLOC GC_INNER void * GC_core_malloc_atomic(size_t lb) #else - GC_API void * GC_CALL GC_malloc_atomic(size_t lb) + GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_atomic(size_t lb) #endif { void *op; @@ -254,7 +254,7 @@ GC_API void * GC_CALL GC_generic_malloc(size_t lb, int k) #ifdef THREAD_LOCAL_ALLOC GC_INNER void * GC_core_malloc(size_t lb) #else - GC_API void * GC_CALL GC_malloc(size_t lb) + GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc(size_t lb) #endif { void *op; @@ -286,7 +286,7 @@ GC_API void * GC_CALL GC_generic_malloc(size_t lb, int k) } /* Allocate lb bytes of pointerful, traced, but not collectible data. */ -GC_API void * GC_CALL GC_malloc_uncollectable(size_t lb) +GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_uncollectable(size_t lb) { void *op; size_t lg; diff --git a/mallocx.c b/mallocx.c index 6cbcf6c1..b559371c 100644 --- a/mallocx.c +++ b/mallocx.c @@ -56,7 +56,8 @@ GC_API int GC_CALL GC_get_kind_and_size(const void * p, size_t * psize) return hhdr -> hb_obj_kind; } -GC_API void * GC_CALL GC_generic_or_special_malloc(size_t lb, int knd) +GC_API GC_ATTR_MALLOC void * GC_CALL GC_generic_or_special_malloc(size_t lb, + int knd) { switch(knd) { # ifdef STUBBORN_ALLOC @@ -143,8 +144,7 @@ GC_API void * GC_CALL GC_realloc(void * p, size_t lb) } } else { /* grow */ - void * result = - GC_generic_or_special_malloc((word)lb, obj_kind); + void * result = GC_generic_or_special_malloc((word)lb, obj_kind); if (result == 0) return(0); BCOPY(p, result, sz); @@ -176,7 +176,8 @@ void * realloc(void * p, size_t lb) /* Allocate memory such that only pointers to near the */ /* beginning of the object are considered. */ /* We avoid holding allocation lock while we clear the memory. */ -GC_API void * GC_CALL GC_generic_malloc_ignore_off_page(size_t lb, int k) +GC_API GC_ATTR_MALLOC void * GC_CALL + GC_generic_malloc_ignore_off_page(size_t lb, int k) { void *result; size_t lg; @@ -227,12 +228,13 @@ GC_API void * GC_CALL GC_generic_malloc_ignore_off_page(size_t lb, int k) } } -GC_API void * GC_CALL GC_malloc_ignore_off_page(size_t lb) +GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_ignore_off_page(size_t lb) { return GC_generic_malloc_ignore_off_page(lb, NORMAL); } -GC_API void * GC_CALL GC_malloc_atomic_ignore_off_page(size_t lb) +GC_API GC_ATTR_MALLOC void * GC_CALL + GC_malloc_atomic_ignore_off_page(size_t lb) { return GC_generic_malloc_ignore_off_page(lb, PTRFREE); } @@ -442,7 +444,7 @@ GC_API void GC_CALL GC_generic_malloc_many(size_t lb, int k, void **result) /* Note that the "atomic" version of this would be unsafe, since the */ /* links would not be seen by the collector. */ -GC_API void * GC_CALL GC_malloc_many(size_t lb) +GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_many(size_t lb) { void *result; @@ -455,7 +457,7 @@ GC_API void * GC_CALL GC_malloc_many(size_t lb) /* Debug version is tricky and currently missing. */ #include -GC_API void * GC_CALL GC_memalign(size_t align, size_t lb) +GC_API GC_ATTR_MALLOC void * GC_CALL GC_memalign(size_t align, size_t lb) { size_t new_lb; size_t offset; @@ -514,7 +516,8 @@ GC_API int GC_CALL GC_posix_memalign(void **memptr, size_t align, size_t lb) /* Allocate lb bytes of pointer-free, untraced, uncollectible data */ /* This is normally roughly equivalent to the system malloc. */ /* But it may be useful if malloc is redefined. */ - GC_API void * GC_CALL GC_malloc_atomic_uncollectable(size_t lb) + GC_API GC_ATTR_MALLOC void * GC_CALL + GC_malloc_atomic_uncollectable(size_t lb) { void *op; size_t lg; @@ -564,7 +567,7 @@ GC_API int GC_CALL GC_posix_memalign(void **memptr, size_t align, size_t lb) /* provide a version of strdup() that uses the collector to allocate the copy of the string */ -GC_API char * GC_CALL GC_strdup(const char *s) +GC_API GC_ATTR_MALLOC char * GC_CALL GC_strdup(const char *s) { char *copy; size_t lb; @@ -580,7 +583,7 @@ GC_API char * GC_CALL GC_strdup(const char *s) return copy; } -GC_API char * GC_CALL GC_strndup(const char *str, size_t size) +GC_API GC_ATTR_MALLOC char * GC_CALL GC_strndup(const char *str, size_t size) { char *copy; size_t len = strlen(str); /* str is expected to be non-NULL */ @@ -601,7 +604,7 @@ GC_API char * GC_CALL GC_strndup(const char *str, size_t size) #ifdef GC_REQUIRE_WCSDUP # include /* for wcslen() */ - GC_API wchar_t * GC_CALL GC_wcsdup(const wchar_t *str) + GC_API GC_ATTR_MALLOC wchar_t * GC_CALL GC_wcsdup(const wchar_t *str) { size_t lb = (wcslen(str) + 1) * sizeof(wchar_t); wchar_t *copy = GC_malloc_atomic(lb); diff --git a/stubborn.c b/stubborn.c index 82f11389..cc5d08ae 100644 --- a/stubborn.c +++ b/stubborn.c @@ -24,7 +24,7 @@ void GC_dirty(ptr_t p); - GC_API void * GC_CALL GC_malloc_stubborn(size_t lb) + GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_stubborn(size_t lb) { return(GC_malloc(lb)); } @@ -40,7 +40,7 @@ #else /* !MANUAL_VDB */ - GC_API void * GC_CALL GC_malloc_stubborn(size_t lb) + GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_stubborn(size_t lb) { return(GC_malloc(lb)); } diff --git a/thread_local_alloc.c b/thread_local_alloc.c index a35b0c3f..8d184f51 100644 --- a/thread_local_alloc.c +++ b/thread_local_alloc.c @@ -144,7 +144,7 @@ GC_INNER void GC_destroy_thread_local(GC_tlfs p) GC_bool GC_is_thread_tsd_valid(void *tsd); #endif -GC_API void * GC_CALL GC_malloc(size_t bytes) +GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc(size_t bytes) { size_t granules = ROUNDED_UP_GRANULES(bytes); void *tsd; @@ -181,7 +181,7 @@ GC_API void * GC_CALL GC_malloc(size_t bytes) return result; } -GC_API void * GC_CALL GC_malloc_atomic(size_t bytes) +GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_atomic(size_t bytes) { size_t granules = ROUNDED_UP_GRANULES(bytes); void *tsd; @@ -237,7 +237,7 @@ GC_API void * GC_CALL GC_malloc_atomic(size_t bytes) /* incremental GC should be enabled before we fork a second thread. */ /* Unlike the other thread local allocation calls, we assume that the */ /* collector has been explicitly initialized. */ -GC_API void * GC_CALL GC_gcj_malloc(size_t bytes, +GC_API GC_ATTR_MALLOC void * GC_CALL GC_gcj_malloc(size_t bytes, void * ptr_to_struct_containing_descr) { if (EXPECT(GC_incremental, FALSE)) { diff --git a/typd_mlc.c b/typd_mlc.c index 1c546ed7..30646a48 100644 --- a/typd_mlc.c +++ b/typd_mlc.c @@ -581,7 +581,8 @@ GC_API GC_descr GC_CALL GC_make_descriptor(const GC_word * bm, size_t len) } } -GC_API void * GC_CALL GC_malloc_explicitly_typed(size_t lb, GC_descr d) +GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_explicitly_typed(size_t lb, + GC_descr d) { ptr_t op; size_t lg; @@ -615,8 +616,8 @@ GC_API void * GC_CALL GC_malloc_explicitly_typed(size_t lb, GC_descr d) return((void *) op); } -GC_API void * GC_CALL GC_malloc_explicitly_typed_ignore_off_page(size_t lb, - GC_descr d) +GC_API GC_ATTR_MALLOC void * GC_CALL + GC_malloc_explicitly_typed_ignore_off_page(size_t lb, GC_descr d) { ptr_t op; size_t lg; @@ -650,8 +651,8 @@ GC_API void * GC_CALL GC_malloc_explicitly_typed_ignore_off_page(size_t lb, return((void *) op); } -GC_API void * GC_CALL GC_calloc_explicitly_typed(size_t n, size_t lb, - GC_descr d) +GC_API GC_ATTR_MALLOC void * GC_CALL GC_calloc_explicitly_typed(size_t n, + size_t lb, GC_descr d) { ptr_t op; size_t lg;