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_4_2~29 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=66d3375e520b996168b3e2f83bc1c6d32453693f;p=gc Fix MS VC redefinition warning for functions declared with GC_ATTR_MALLOC (Apply commit 36aa13d from 'master' branch.) * 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. Conflicts: dbg_mlc.c mallocx.c --- diff --git a/dbg_mlc.c b/dbg_mlc.c index a0423e97..f805473f 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); @@ -607,7 +608,8 @@ GC_API void * GC_CALL GC_debug_malloc_atomic_ignore_off_page(size_t lb, #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); @@ -656,7 +658,8 @@ GC_API void * GC_CALL GC_debug_malloc_atomic_ignore_off_page(size_t lb, #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); } @@ -668,7 +671,8 @@ GC_API void * GC_CALL GC_debug_malloc_atomic_ignore_off_page(size_t lb, 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); @@ -684,7 +688,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; @@ -706,8 +711,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 */ @@ -728,7 +733,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); @@ -743,8 +749,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); @@ -761,8 +767,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); @@ -1207,7 +1213,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 0dad28a6..84b4eda6 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 { @@ -127,7 +127,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 78950e25..9be948b9 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 { @@ -206,7 +206,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; @@ -234,7 +234,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 4983cdfe..8405faf6 100644 --- a/malloc.c +++ b/malloc.c @@ -168,7 +168,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; @@ -226,7 +226,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; @@ -256,7 +256,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; @@ -289,7 +289,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; void **opp; diff --git a/mallocx.c b/mallocx.c index 7fcaa5c2..6a183f38 100644 --- a/mallocx.c +++ b/mallocx.c @@ -134,8 +134,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); @@ -167,7 +166,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; @@ -218,12 +218,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((void *)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((void *)GC_generic_malloc_ignore_off_page(lb, PTRFREE)); } @@ -433,7 +434,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; GC_generic_malloc_many((lb + EXTRA_BYTES + GRANULE_BYTES-1) @@ -446,7 +447,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; @@ -505,7 +506,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; void **opp; @@ -557,7 +559,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; @@ -573,7 +575,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 */ @@ -594,7 +596,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 00f78ce5..b164f522 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; ptr_t * opp; @@ -617,8 +618,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; ptr_t * opp; @@ -654,8 +655,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; ptr_t * opp;