Module: sip-router
Branch: bpintea/asi_binrpc2
Commit: e101ccf31f309726fb988a97d89a393f167b5f56
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=e101ccf…
Author: bpi <bpi(a)machine.office.iptego.net>
Committer: bpi <bpi(a)machine.office.iptego.net>
Date: Fri Jan 15 00:12:48 2010 +0100
- added memory wrappers, allowing to use SR's built-in allocators by external
libraries
---
mem/wrappers.h | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/mem/wrappers.h b/mem/wrappers.h
new file mode 100644
index 0000000..ab98679
--- /dev/null
+++ b/mem/wrappers.h
@@ -0,0 +1,44 @@
+#ifndef __PKG_WRAPPERS_H__
+#define __PKG_WRAPPERS_H__
+
+#include "mem.h"
+
+#if defined(PKG_MALLOC) || (defined(SHM_MEM) && defined(USE_SHM_MEM))
+static void *w_pkg_calloc(size_t nmemb, size_t size)
+{
+ void *slub;
+ size_t sz = nmemb * size;
+ if ((slub = pkg_malloc(sz)))
+ memset(slub, 0, sz);
+ return slub;
+}
+
+static void *w_pkg_malloc(size_t size)
+{
+ return pkg_malloc(size);
+}
+
+static void w_pkg_free(void *ptr)
+{
+ pkg_free(ptr);
+}
+
+static void *w_pkg_realloc(void *ptr, size_t size)
+{
+ return pkg_realloc(ptr, size);
+}
+
+/* shm, if ever needed */
+
+#else
+
+# include <stdlib.h>
+
+# define w_pkg_calloc calloc
+# define w_pkg_malloc malloc
+# define w_pkg_free free
+# define w_pkg_realloc realloc
+
+#endif /* PKG_MALLOC || (SHM_MEM && USE_SHM_MEM) */
+
+#endif /* __PKG_WRAPPERS_H__ */