Browse code

- added memory wrappers, allowing to use SR's built-in allocators by external libraries

bpi authored on 14/01/2010 23:12:48
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,44 @@
1
+#ifndef __PKG_WRAPPERS_H__
2
+#define __PKG_WRAPPERS_H__
3
+
4
+#include "mem.h"
5
+
6
+#if defined(PKG_MALLOC) || (defined(SHM_MEM) && defined(USE_SHM_MEM))
7
+static void *w_pkg_calloc(size_t nmemb, size_t size)
8
+{
9
+	void *slub;
10
+	size_t sz = nmemb * size;
11
+	if ((slub = pkg_malloc(sz)))
12
+		memset(slub, 0, sz);
13
+	return slub;
14
+}
15
+
16
+static void *w_pkg_malloc(size_t size)
17
+{
18
+	return pkg_malloc(size);
19
+}
20
+
21
+static void w_pkg_free(void *ptr)
22
+{
23
+	pkg_free(ptr);
24
+}
25
+
26
+static void *w_pkg_realloc(void *ptr, size_t size)
27
+{
28
+	return pkg_realloc(ptr, size);
29
+}
30
+
31
+/* shm, if ever needed */
32
+
33
+#else
34
+
35
+#	include <stdlib.h>
36
+
37
+#	define w_pkg_calloc		calloc
38
+#	define w_pkg_malloc		malloc
39
+#	define w_pkg_free		free
40
+#	define w_pkg_realloc	realloc
41
+
42
+#endif /* PKG_MALLOC || (SHM_MEM && USE_SHM_MEM) */
43
+
44
+#endif /* __PKG_WRAPPERS_H__ */