/******************************************************************************/
/* BP le 19/01/98 */
/* */
/* Ensemble de routines pour aider au debuggage sur des allocations memoires */
/* Fichier : GestMem.h */
/* */
/*Copyright (C) 1998 Bruno Pean */
/* EISTI Av du Parc, 950111 CERGY FRANCE */
/* */
/*This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program; if not, write to the Free Software */
/* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* */
/******************************************************************************/
/******************************************************************************/
#include <stdlib.h>
#ifndef ABORT_FCT
/****************************************************************/
/* Par defaut si un ecrasemnt est detecte on appelle la */
/* Fonction abort() */
/* L'utilisateur peut definir une fonction qui peut etre */
/* Appelee a la place de abort */
/* Pour ce faire il doit ecrire une fonction sans parametre */
/* et sans retour */
/* et definir ABORT_FCT avec le nom de sa fonction */
/* Exemple : void Rien(void) {} */
/* #define ABORT_FCT Rien */
/****************************************************************/
#define ABORT_FCT abort
#endif /* ABORT_FCT */
#ifndef VERSION_FINALE
/****************************************************************/
/* Si VERSION_FINALE est defini, alors le programme fait */
/* appel au fonction malloc, calloc, realloc, et free */
/* de la libc standart */
/* l'appel de la fonction TesterMemoire est alors */
/* neutralise */
/****************************************************************/
#ifndef TFILL_ALLOC_SECOURS
/****************************************************************/
/* TFILL_ALLOC_SECOURS est le nombre d'octets en plus des */
/* octets de controle qui sont allloues en plus de la demande */
/* de l'utilisateur de facon a limiter la casse si un ecrasement*/
/* survenait */
/* Ce nombre est fixé par defaut a 50 */
/* Pour modifier cette valeur, il suffit de definir */
/* TFILL_ALLOC_SECOURS avec une valeur */
/* ex : #define TFILL_ALLOC_SECOURS 10 */
/****************************************************************/
#define TFILL_ALLOC_SECOURS 50
#endif /* TFILL_ALLOC_SECOURS */
/****************************************************************/
/* Surcharche des fonctions pour recuperer le source et la ligne*/
/****************************************************************/
#define MyMalloc(a) _MyMalloc(a,__FILE__,__LINE__,TFILL_ALLOC_SECOURS )
#define MyRealloc(a,b) _MyRealloc(a,b,__FILE__,__LINE__,\
TFILL_ALLOC_SECOURS,ABORT_FCT )
#define MyCalloc(a,b) _MyCalloc(a,b,__FILE__,__LINE__,TFILL_ALLOC_SECOURS )
#define MyFree(a) {_MyFree(a,__FILE__,__LINE__,ABORT_FCT);a=NULL;}
#define TesterMemoire() _TesterMemoire(__FILE__,__LINE__,ABORT_FCT)
#define free(x) MyFree(x)
#define malloc(x) MyMalloc(x)
#define calloc(x,y) MyCalloc(x,y)
#define realloc(x,y) MyRealloc(x,y)
#else
#define TesterMemoire()
#endif /* VERSION_FINALE */
/****************************************************************/
/* Prototypes des fonctions */
/****************************************************************/
void * _MyMalloc(int n,char * Source, int Ligne,int TFill);
void * _MyRealloc(void * Ptr,int n,char * Source, int Ligne,int TFill,
void (*AbortFct)(void));
void * _MyCalloc(int a,int b,char * Source, int Ligne,int TFill);
void _MyFree( void * Ptr, char * Source, int Ligne,
void (*AbortFct)(void));
void _TesterMemoire(char * Source,int Ligne,void (*AbortFct)(void));