# memory.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  $RCSfile: memory.h,v $
    00003  -------------------
    00004  cvs         : $Id: memory.h,v 1.5 2004/05/05 14:23:33 aquamaniac Exp $
    00005  begin       : Sat Jun 28 2003
    00006  copyright   : (C) 2003 by Martin Preuss
    00007  email       : martin@libchipcard.de
    00008
    00009  ***************************************************************************
    00010  *                                                                         *
    00011  *   This library is free software; you can redistribute it and/or         *
    00012  *   modify it under the terms of the GNU Lesser General Public            *
    00013  *   License as published by the Free Software Foundation; either          *
    00014  *   version 2.1 of the License, or (at your option) any later version.    *
    00015  *                                                                         *
    00016  *   This library is distributed in the hope that it will be useful,       *
    00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
    00019  *   Lesser General Public License for more details.                       *
    00020  *                                                                         *
    00021  *   You should have received a copy of the GNU Lesser General Public      *
    00022  *   License along with this library; if not, write to the Free Software   *
    00023  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
    00024  *   MA  02111-1307  USA                                                   *
    00025  *                                                                         *
    00026  ***************************************************************************/
    00027
    00028
    00029 #ifndef GWENHYWFAR_MEMORY_H
    00030 #define GWENHYWFAR_MEMORY_H
    00031
    00032 #include <gwenhywfar/gwenhywfarapi.h>
    00033 #include <gwenhywfar/types.h>
    00034 #include <gwenhywfar/error.h>
    00035 #include <stdio.h>
    00036 #include <stdlib.h>
    00037 #include <string.h>
    00038 #include <assert.h>
    00039
    00040
    00041
    00042 #ifdef __cplusplus
    00043 extern "C" {
    00044 #endif
    00045
    00046
    00047   /* this is taken from the system header file assert.h and
    00048    * and modified by me (Martin Preuss).
    00049    */
    00050 # if defined __cplusplus ? __GNUC_PREREQ (2, 6) : __GNUC_PREREQ (2, 4)
    00051 #   define GWEN_LOCATION_FUNCTION       __PRETTY_FUNCTION__
    00052 # else
    00053 #  if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
    00054 #   define GWEN_LOCATION_FUNCTION       __func__
    00055 #  else
    00056 #   define GWEN_LOCATION_FUNCTION       ((__const char *) "unknown function")
    00057 #  endif
    00058 # endif
    00059
    00060
    00061   GWENHYWFAR_API
    00062   GWEN_ERRORCODE GWEN_Memory_ModuleInit();
    00063
    00064   GWENHYWFAR_API
    00065   GWEN_ERRORCODE GWEN_Memory_ModuleFini();
    00066
    00067   GWENHYWFAR_API
    00068   void GWEN_Memory_Report();
    00069
    00070
    00071   GWENHYWFAR_API
    00072   void *GWEN_Memory_NewObject(void *p,
    00073                               const char *typeName,
    00074                               const char *function,
    00075                               const char *file,
    00076                               int line);
    00077
    00078   GWENHYWFAR_API
    00079   void GWEN_Memory_FreeObject(void *object,
    00080                               const char *function,
    00081                               const char *file,
    00082                               int line);
    00083
    00084   GWENHYWFAR_API
    00085   void GWEN_Memory_AttachObject(void *object,
    00086                                 const char *function,
    00087                                 const char *file,
    00088                                 int line);
    00089
    00090
    00091
    00092 #define GWEN_NEW_OBJECT(typ, varname) \
    00093   varname=(typ*)malloc(sizeof(typ));\
    00094   assert(varname); \
    00095   memset((void*)varname, 0, sizeof(typ));
    00096
    00097 #define GWEN_FREE_OBJECT(varname) \
    00098   free(varname)
    00099
    00100
    00101 #define GWEN_NEW(typ, function) \
    00102   ((typ*)GWEN_Memory_NewObject(function,\
    00103   __STRING(typ),\
    00104   GWEN_LOCATION_FUNCTION, \
    00105   __FILE__,\
    00106   __LINE__))
    00107
    00108 #define GWEN_FREE(varname) \
    00109   GWEN_Memory_FreeObject((void*)varname,\
    00110   GWEN_LOCATION_FUNCTION,\
    00111   __FILE__,\
    00112   __LINE__)
    00113
    00114 #define GWEN_ATTACH(varname) \
    00115   GWEN_Memory_AttachObject((void*)varname,\
    00116   GWEN_LOCATION_FUNCTION,\
    00117   __FILE__,\
    00118   __LINE__)
    00119
    00120
    00121 #ifdef __cplusplus
    00122 }
    00123 #endif
    00124
    00125
    00126 #endif /* GWENHYWFAR_MEMORY_H */
    00127