source: azure_iot_hub/trunk/azure_iothub/c-utility/inc/azure_c_shared_utility/gballoc.h@ 389

Last change on this file since 389 was 389, checked in by coas-nagasima, 5 years ago

ビルドが通るよう更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 2.9 KB
Line 
1// Copyright (c) Microsoft. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4#ifndef GBALLOC_H
5#define GBALLOC_H
6
7#include "azure_c_shared_utility/umock_c_prod.h"
8
9#ifdef __cplusplus
10#include <cstddef>
11#include <cstdlib>
12extern "C"
13{
14#else
15#include <stddef.h>
16#include <stdlib.h>
17#endif
18
19// GB_USE_CUSTOM_HEAP disables the implementations in gballoc.c and
20// requires that an external library implement the gballoc_malloc family
21// declared here.
22#if defined(GB_USE_CUSTOM_HEAP)
23MOCKABLE_FUNCTION(, void*, gballoc_malloc, size_t, size);
24MOCKABLE_FUNCTION(, void*, gballoc_calloc, size_t, nmemb, size_t, size);
25MOCKABLE_FUNCTION(, void*, gballoc_realloc, void*, ptr, size_t, size);
26MOCKABLE_FUNCTION(, void, gballoc_free, void*, ptr);
27
28#define malloc gballoc_malloc
29#define calloc gballoc_calloc
30#define realloc gballoc_realloc
31#define free gballoc_free
32
33/* all translation units that need memory measurement need to have GB_MEASURE_MEMORY_FOR_THIS defined */
34/* GB_DEBUG_ALLOC is the switch that turns the measurement on/off, so that it is not on always */
35#elif defined(GB_DEBUG_ALLOC)
36
37MOCKABLE_FUNCTION(, int, gballoc_init);
38MOCKABLE_FUNCTION(, void, gballoc_deinit);
39MOCKABLE_FUNCTION(, void*, gballoc_malloc, size_t, size);
40MOCKABLE_FUNCTION(, void*, gballoc_calloc, size_t, nmemb, size_t, size);
41MOCKABLE_FUNCTION(, void*, gballoc_realloc, void*, ptr, size_t, size);
42MOCKABLE_FUNCTION(, void, gballoc_free, void*, ptr);
43
44MOCKABLE_FUNCTION(, size_t, gballoc_getMaximumMemoryUsed);
45MOCKABLE_FUNCTION(, size_t, gballoc_getCurrentMemoryUsed);
46MOCKABLE_FUNCTION(, size_t, gballoc_getAllocationCount);
47MOCKABLE_FUNCTION(, void, gballoc_resetMetrics);
48
49/* if GB_MEASURE_MEMORY_FOR_THIS is defined then we want to redirect memory allocation functions to gballoc_xxx functions */
50#ifdef GB_MEASURE_MEMORY_FOR_THIS
51/* Unfortunately this is still needed here for things to still compile when using _CRTDBG_MAP_ALLOC.
52That is because there is a rogue component (most likely CppUnitTest) including crtdbg. */
53#if defined(_CRTDBG_MAP_ALLOC) && defined(_DEBUG)
54#undef _malloc_dbg
55#undef _calloc_dbg
56#undef _realloc_dbg
57#undef _free_dbg
58#define _malloc_dbg(size, ...) gballoc_malloc(size)
59#define _calloc_dbg(nmemb, size, ...) gballoc_calloc(nmemb, size)
60#define _realloc_dbg(ptr, size, ...) gballoc_realloc(ptr, size)
61#define _free_dbg(ptr, ...) gballoc_free(ptr)
62#else
63#define malloc gballoc_malloc
64#define calloc gballoc_calloc
65#define realloc gballoc_realloc
66#define free gballoc_free
67#endif
68#endif
69
70#else /* GB_DEBUG_ALLOC */
71
72#define gballoc_init() 0
73#define gballoc_deinit() ((void)0)
74
75#define gballoc_getMaximumMemoryUsed() SIZE_MAX
76#define gballoc_getCurrentMemoryUsed() SIZE_MAX
77#define gballoc_getAllocationCount() SIZE_MAX
78#define gballoc_resetMetrics() ((void)0)
79
80#endif /* GB_DEBUG_ALLOC */
81
82#ifdef __cplusplus
83}
84#endif
85
86#endif /* GBALLOC_H */
Note: See TracBrowser for help on using the repository browser.