ngtcp2_mem.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #ifdef HAVE_CONFIG_H
  29. # include <config.h>
  30. #endif /* defined(HAVE_CONFIG_H) */
  31. #include <ngtcp2/ngtcp2.h>
  32. /* Convenient wrapper functions to call allocator function in
  33. |mem|. */
  34. #ifndef MEMDEBUG
  35. void *ngtcp2_mem_malloc(const ngtcp2_mem *mem, size_t size);
  36. void ngtcp2_mem_free(const ngtcp2_mem *mem, void *ptr);
  37. void *ngtcp2_mem_calloc(const ngtcp2_mem *mem, size_t nmemb, size_t size);
  38. void *ngtcp2_mem_realloc(const ngtcp2_mem *mem, void *ptr, size_t size);
  39. #else /* defined(MEMDEBUG) */
  40. void *ngtcp2_mem_malloc_debug(const ngtcp2_mem *mem, size_t size,
  41. const char *func, const char *file, size_t line);
  42. # define ngtcp2_mem_malloc(MEM, SIZE) \
  43. ngtcp2_mem_malloc_debug((MEM), (SIZE), __func__, __FILE__, __LINE__)
  44. void ngtcp2_mem_free_debug(const ngtcp2_mem *mem, void *ptr, const char *func,
  45. const char *file, size_t line);
  46. # define ngtcp2_mem_free(MEM, PTR) \
  47. ngtcp2_mem_free_debug((MEM), (PTR), __func__, __FILE__, __LINE__)
  48. void *ngtcp2_mem_calloc_debug(const ngtcp2_mem *mem, size_t nmemb, size_t size,
  49. const char *func, const char *file, size_t line);
  50. # define ngtcp2_mem_calloc(MEM, NMEMB, SIZE) \
  51. ngtcp2_mem_calloc_debug((MEM), (NMEMB), (SIZE), __func__, __FILE__, \
  52. __LINE__)
  53. void *ngtcp2_mem_realloc_debug(const ngtcp2_mem *mem, void *ptr, size_t size,
  54. const char *func, const char *file, size_t line);
  55. # define ngtcp2_mem_realloc(MEM, PTR, SIZE) \
  56. ngtcp2_mem_realloc_debug((MEM), (PTR), (SIZE), __func__, __FILE__, __LINE__)
  57. #endif /* defined(MEMDEBUG) */
  58. #endif /* !defined(NGTCP2_MEM_H) */