• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * ngtcp2
3  *
4  * Copyright (c) 2017 ngtcp2 contributors
5  * Copyright (c) 2014 nghttp2 contributors
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26 #ifndef NGTCP2_MEM_H
27 #define NGTCP2_MEM_H
28 
29 #ifdef HAVE_CONFIG_H
30 #  include <config.h>
31 #endif /* HAVE_CONFIG_H */
32 
33 #include <ngtcp2/ngtcp2.h>
34 
35 /* Convenient wrapper functions to call allocator function in
36    |mem|. */
37 #ifndef MEMDEBUG
38 void *ngtcp2_mem_malloc(const ngtcp2_mem *mem, size_t size);
39 
40 void ngtcp2_mem_free(const ngtcp2_mem *mem, void *ptr);
41 
42 void *ngtcp2_mem_calloc(const ngtcp2_mem *mem, size_t nmemb, size_t size);
43 
44 void *ngtcp2_mem_realloc(const ngtcp2_mem *mem, void *ptr, size_t size);
45 #else /* MEMDEBUG */
46 void *ngtcp2_mem_malloc_debug(const ngtcp2_mem *mem, size_t size,
47                               const char *func, const char *file, size_t line);
48 
49 #  define ngtcp2_mem_malloc(MEM, SIZE)                                         \
50     ngtcp2_mem_malloc_debug((MEM), (SIZE), __func__, __FILE__, __LINE__)
51 
52 void ngtcp2_mem_free_debug(const ngtcp2_mem *mem, void *ptr, const char *func,
53                            const char *file, size_t line);
54 
55 #  define ngtcp2_mem_free(MEM, PTR)                                            \
56     ngtcp2_mem_free_debug((MEM), (PTR), __func__, __FILE__, __LINE__)
57 
58 void *ngtcp2_mem_calloc_debug(const ngtcp2_mem *mem, size_t nmemb, size_t size,
59                               const char *func, const char *file, size_t line);
60 
61 #  define ngtcp2_mem_calloc(MEM, NMEMB, SIZE)                                  \
62     ngtcp2_mem_calloc_debug((MEM), (NMEMB), (SIZE), __func__, __FILE__,        \
63                             __LINE__)
64 
65 void *ngtcp2_mem_realloc_debug(const ngtcp2_mem *mem, void *ptr, size_t size,
66                                const char *func, const char *file, size_t line);
67 
68 #  define ngtcp2_mem_realloc(MEM, PTR, SIZE)                                   \
69     ngtcp2_mem_realloc_debug((MEM), (PTR), (SIZE), __func__, __FILE__, __LINE__)
70 #endif /* MEMDEBUG */
71 
72 #endif /* NGTCP2_MEM_H */
73