1 /*
2 * mpatrol
3 * A library for controlling and tracing dynamic memory allocations.
4 * Copyright (C) 1997-2002 Graeme S. Roy <graeme.roy@analog.com>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19 * MA 02111-1307, USA.
20 */
21
22
23 /*
24 * Release version of uninitialised memory allocation function. This is used
25 * by the version of MP_MALLOC() that is defined in mpalloc.h and will call a
26 * failure handler function instead of returning NULL.
27 */
28
29
30 #include "config.h"
31 #include "mpalloc.h"
32
33
34 #if MP_IDENT_SUPPORT
35 #ident "$Id: mpmalloc.c,v 1.6 2002/01/08 20:13:59 graeme Exp $"
36 #else /* MP_IDENT_SUPPORT */
37 static MP_CONST MP_VOLATILE char *mpmalloc_id = "$Id: mpmalloc.c,v 1.6 2002/01/08 20:13:59 graeme Exp $";
38 #endif /* MP_IDENT_SUPPORT */
39
40
41 #ifdef __cplusplus
42 extern "C"
43 {
44 #endif /* __cplusplus */
45
46
47 extern __mp_failhandler __mp_failure;
48
49
50 /* Allocate an uninitialised memory block of a given size and abort on failure.
51 */
52
53 MP_API
54 void *
__mp_xmalloc(size_t l,MP_CONST char * s,MP_CONST char * t,unsigned long u,MP_CONST char * g,size_t h)55 __mp_xmalloc(size_t l, MP_CONST char *s, MP_CONST char *t, unsigned long u,
56 MP_CONST char *g, size_t h)
57 {
58 void *p;
59
60 if (l == 0)
61 if (h != 0)
62 l = h;
63 else
64 l = 1;
65 if ((p = malloc(l)) == NULL)
66 {
67 if (__mp_failure != NULL)
68 __mp_failure(l, s, t, u, g, h);
69 abort();
70 }
71 return p;
72 }
73
74
75 #ifdef __cplusplus
76 }
77 #endif /* __cplusplus */
78