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