Convert xml-protected spaces to real spaces
[odt2txt.git] / mem.h
blobb74056eac12a722bd4318a60b2720f7b072cfcd5
1 /*
2 * mem.c: memory allocation wrappers with a few simple checks
4 * Copyright (c) 2002-2009 Dennis Stosberg <dennis@stosberg.net>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License,
8 * version 2 as published by the Free Software Foundation
9 */
11 #ifndef MEM_H
12 #define MEM_H
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <stdarg.h>
18 #include <assert.h>
20 #ifdef MEMDEBUG
22 /**
23 * A container to keep the information about allocated memory.
25 typedef struct {
26 void *addr;
27 size_t size;
28 const char *file;
29 int line;
30 } MEMINFO;
32 #define yfree(p) yfree_dbg(p, __FILE__, __LINE__)
33 void yfree_dbg(void *p, const char *file, int line);
35 #define ymalloc(size) ymalloc_dbg(size, __FILE__, __LINE__)
36 void *ymalloc_dbg(size_t size, const char *file, int line);
38 #define ycalloc(num, size) ymalloc_dbg(num, size, __FILE__, __LINE__)
39 void *ycalloc_dbg(size_t number, size_t size, const char *file, int line);
41 #define yrealloc(p, size) yrealloc_dbg(p, size, __FILE__, __LINE__)
42 void *yrealloc_dbg(void *p, size_t size, const char *file, int line);
44 #else
45 #define yfree(p) free(p)
46 #define ymalloc(size) malloc(size)
47 #define ycalloc(num, size) calloc(num, size);
48 #define yrealloc(p, size) realloc(p, size);
49 #endif
51 #endif /* MEM_H */