1 #ifndef MP_MPDEBUG_H
2 #define MP_MPDEBUG_H
3 
4 
5 /*
6  * mpatrol
7  * A library for controlling and tracing dynamic memory allocations.
8  * Copyright (C) 1997-2002 Graeme S. Roy <graeme.roy@analog.com>
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library 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  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the Free
22  * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23  * MA 02111-1307, USA.
24  */
25 
26 
27 /*
28  * $Id: mpdebug.h,v 1.3 2002/01/08 20:13:59 graeme Exp $
29  */
30 
31 
32 #ifndef HAVE_MPATROL
33 #define HAVE_MPATROL 0
34 #endif /* HAVE_MPATROL */
35 
36 #ifndef HAVE_MPALLOC
37 #define HAVE_MPALLOC 0
38 #endif /* HAVE_MPALLOC */
39 
40 
41 #if HAVE_MPATROL
42 #include <mpatrol.h>
43 #else /* HAVE_MPATROL */
44 #include <stdlib.h>
45 #include <string.h>
46 #include <stdarg.h>
47 #ifdef __cplusplus
48 #include <new>
49 #endif /* __cplusplus */
50 #if HAVE_MPALLOC
51 #include <mpalloc.h>
52 #else /* HAVE_MPALLOC */
53 #include <stdio.h>
54 
55 typedef void *__mp_failhandler;
56 
57 #define MP_MALLOC(p, l, t) \
58     (((p = (t *) malloc((l) * sizeof(t))) != NULL) ? (t *) (p) : \
59      (t *) (fputs("out of memory\n", stderr), abort(), NULL))
60 #define MP_CALLOC(p, l, t) \
61     (((p = (t *) calloc((l), sizeof(t))) != NULL) ? (t *) (p) : \
62      (t *) (fputs("out of memory\n", stderr), abort(), NULL))
63 #define MP_STRDUP(p, s) \
64     (((p = (char *) strdup(s)) != NULL) ? (char *) (p) : \
65      (char *) (fputs("out of memory\n", stderr), abort(), NULL))
66 #define MP_REALLOC(p, l, t) \
67     (((p = (t *) realloc((p), (l) * sizeof(t))) != NULL) ? (t *) (p) : \
68      (t *) (fputs("out of memory\n", stderr), abort(), NULL))
69 #define MP_FREE(p) do { if (p) { free(p); p = NULL; } } while (0)
70 #define MP_FAILURE(f) ((__mp_failhandler) NULL)
71 #endif /* HAVE_MPALLOC */
72 #endif /* HAVE_MPATROL */
73 
74 
75 #endif /* MP_MPDEBUG_H */
76