aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorGertjan van den Burg <gertjanvandenburg@gmail.com>2016-05-09 21:10:45 +0200
committerGertjan van den Burg <gertjanvandenburg@gmail.com>2016-05-09 21:10:45 +0200
commitf2c8d1beffe88fd0a8e23ecb350ab22a3259c185 (patch)
tree15c35b70693d4033f0db8b4830b137e24d541d4e /include
parentuse stdbool instead of bool typedef (diff)
downloadgensvm-f2c8d1beffe88fd0a8e23ecb350ab22a3259c185.tar.gz
gensvm-f2c8d1beffe88fd0a8e23ecb350ab22a3259c185.zip
Add functions for safe memory allocation
Diffstat (limited to 'include')
-rw-r--r--include/gensvm_memory.h26
-rw-r--r--include/globals.h11
2 files changed, 30 insertions, 7 deletions
diff --git a/include/gensvm_memory.h b/include/gensvm_memory.h
new file mode 100644
index 0000000..bc4aae9
--- /dev/null
+++ b/include/gensvm_memory.h
@@ -0,0 +1,26 @@
+/**
+ * @file gensvm_memory.h
+ * @author Gertjan van den Burg
+ * @date May, 2016
+ * @brief Global definitions
+ *
+ */
+
+#ifndef GENSVM_MEMORY_H
+#define GENSVM_MEMORY_H
+
+#define Calloc(type, size) \
+ mycalloc(__FILE__, __LINE__, size, sizeof(type))
+#define Malloc(type, size) \
+ mymalloc(__FILE__, __LINE__, (size)*sizeof(type))
+#define Realloc(var, type, size) \
+ myrealloc(__FILE__, __LINE__, (size)*sizeof(type), var)
+#define Memset(var, type, size) \
+ memset(var, 0, (size)*sizeof(type))
+
+void *mycalloc(const char *file, int line, unsigned long size,
+ size_t typesize);
+void *mymalloc(const char *file, int line, unsigned long size);
+void *myrealloc(const char *file, int line, unsigned long size, void *var);
+
+#endif
diff --git a/include/globals.h b/include/globals.h
index eab1d9f..becde35 100644
--- a/include/globals.h
+++ b/include/globals.h
@@ -6,9 +6,8 @@
*
* @details
* This header file contains defines and includes which are used in many
- * parts of the program. Most notable are the Calloc, Malloc and Memset
- * defines, which are commonly used to allocate memory. These functions
- * are shorthands for their lowercase counterparts.
+ * parts of the program. Most notably, it includes the gensvm_memory.h header
+ * which defines functions for safe memory allocation.
*
* Furthermore, a maximum and minimum function are defined here. These
* functions have their own include guards, to ensure potential linked
@@ -24,11 +23,9 @@
#include <stdbool.h>
#include <string.h>
-#define MAX_LINE_LENGTH 1024
+#include "gensvm_memory.h"
-#define Calloc(type, n) (type *)calloc((n), sizeof(type))
-#define Malloc(type, n) (type *)malloc((n)*sizeof(type))
-#define Memset(var, type, n) memset(var, 0, (n)*sizeof(type))
+#define MAX_LINE_LENGTH 1024
#ifndef MIN_MAX_DEFINE
#define MIN_MAX_DEFINE