mem.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. (c) Copyright 2001-2009 The world wide DirectFB Open Source Community (directfb.org)
  3. (c) Copyright 2000-2004 Convergence (integrated media) GmbH
  4. All rights reserved.
  5. Written by Denis Oliver Kropp <dok@directfb.org>,
  6. Andreas Hundt <andi@fischlustig.de>,
  7. Sven Neumann <neo@directfb.org>,
  8. Ville Syrjälä <syrjala@sci.fi> and
  9. Claudio Ciccani <klan@users.sf.net>.
  10. This library is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU Lesser General Public
  12. License as published by the Free Software Foundation; either
  13. version 2 of the License, or (at your option) any later version.
  14. This library is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. Lesser General Public License for more details.
  18. You should have received a copy of the GNU Lesser General Public
  19. License along with this library; if not, write to the
  20. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. Boston, MA 02111-1307, USA.
  22. */
  23. #ifndef __DIRECT__MEM_H__
  24. #define __DIRECT__MEM_H__
  25. #include <stddef.h>
  26. #include <direct/build.h>
  27. void direct_print_memleaks( void );
  28. void direct_free ( const char *file, int line,
  29. const char *func, const char *what, void *mem );
  30. void *direct_malloc ( const char *file, int line,
  31. const char *func, size_t bytes );
  32. void *direct_calloc ( const char *file, int line,
  33. const char *func, size_t count, size_t bytes);
  34. void *direct_realloc( const char *file, int line,
  35. const char *func, const char *what, void *mem,
  36. size_t bytes );
  37. char *direct_strdup ( const char *file, int line,
  38. const char *func, const char *string );
  39. #if DIRECT_BUILD_DEBUG || defined(DIRECT_ENABLE_DEBUG) || defined(DIRECT_FORCE_DEBUG)
  40. #if !DIRECT_BUILD_DEBUGS
  41. #warning Building with debug, but library headers suggest that debug is not supported.
  42. #endif
  43. #define D_FREE(mem) direct_free( __FUNCTION__, __LINE__, __FUNCTION__, #mem, mem )
  44. #define D_MALLOC(bytes) direct_malloc( __FUNCTION__, __LINE__, __FUNCTION__, bytes )
  45. #define D_CALLOC(count,bytes) direct_calloc( __FUNCTION__, __LINE__, __FUNCTION__, count, bytes )
  46. #define D_REALLOC(mem,bytes) direct_realloc( __FUNCTION__, __LINE__, __FUNCTION__, #mem, mem, bytes )
  47. #define D_STRDUP(string) direct_strdup( __FUNCTION__, __LINE__, __FUNCTION__, string )
  48. #else
  49. #include <stdlib.h>
  50. #include <string.h>
  51. #define D_FREE free
  52. #define D_MALLOC malloc
  53. #define D_CALLOC calloc
  54. #define D_REALLOC realloc
  55. #define D_STRDUP strdup
  56. #endif
  57. #endif