-
Notifications
You must be signed in to change notification settings - Fork 18
/
mem.h
51 lines (41 loc) · 1.33 KB
/
mem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* mem.c: memory allocation wrappers with a few simple checks
*
* Copyright (c) 2002-2009 Dennis Stosberg <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License,
* version 2 as published by the Free Software Foundation
*/
#ifndef MEM_H
#define MEM_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <assert.h>
#ifdef MEMDEBUG
/**
* A container to keep the information about allocated memory.
*/
typedef struct {
void *addr;
size_t size;
const char *file;
int line;
} MEMINFO;
#define yfree(p) yfree_dbg(p, __FILE__, __LINE__)
void yfree_dbg(void *p, const char *file, int line);
#define ymalloc(size) ymalloc_dbg(size, __FILE__, __LINE__)
void *ymalloc_dbg(size_t size, const char *file, int line);
#define ycalloc(num, size) ymalloc_dbg(num, size, __FILE__, __LINE__)
void *ycalloc_dbg(size_t number, size_t size, const char *file, int line);
#define yrealloc(p, size) yrealloc_dbg(p, size, __FILE__, __LINE__)
void *yrealloc_dbg(void *p, size_t size, const char *file, int line);
#else
#define yfree(p) free(p)
#define ymalloc(size) malloc(size)
#define ycalloc(num, size) calloc(num, size);
#define yrealloc(p, size) realloc(p, size);
#endif
#endif /* MEM_H */