summaryrefslogtreecommitdiffstats
path: root/src/pulse
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-06-17 03:07:42 +0200
committerLennart Poettering <lennart@poettering.net>2009-06-17 03:07:42 +0200
commit697b8de96fb988b7e7de24a549c4e77371a80847 (patch)
tree25ab5dc1e65b2c1ad6c7ddd95e9aa99c397cd409 /src/pulse
parent4f36cc76f25632212d1c661bd82780b2f938819d (diff)
malloc: implement pa_xrenew()
Diffstat (limited to 'src/pulse')
-rw-r--r--src/pulse/xmalloc.h13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/pulse/xmalloc.h b/src/pulse/xmalloc.h
index db20496f..f720d83f 100644
--- a/src/pulse/xmalloc.h
+++ b/src/pulse/xmalloc.h
@@ -88,9 +88,20 @@ static inline void* _pa_xnewdup_internal(const void *p, size_t n, size_t k) {
return pa_xmemdup(p, n*k);
}
-/** Same as pa_xnew() but set the memory to zero */
+/** Same as pa_xnew() but duplicate the specified data */
#define pa_xnewdup(type, p, n) ((type*) _pa_xnewdup_internal((p), (n), sizeof(type)))
+/** Internal helper for pa_xrenew() */
+static void* _pa_xrenew_internal(void *p, size_t n, size_t k) PA_GCC_MALLOC PA_GCC_ALLOC_SIZE2(2,3);
+
+static inline void* _pa_xrenew_internal(void *p, size_t n, size_t k) {
+ assert(n < INT_MAX/k);
+ return pa_xrealloc(p, n*k);
+}
+
+/** Reallocate n new structures of the specified type. */
+#define pa_xrenew(type, p, n) ((type*) _pa_xrenew_internal(p, (n), sizeof(type)))
+
PA_C_DECL_END
#endif