*
*/
-#ifndef LIBVIRT_VIRALLOC_H
-# define LIBVIRT_VIRALLOC_H
+#pragma once
-# include "internal.h"
+#include "internal.h"
/* Return 1 if an array of N objects, each of size S, cannot exist due
to size arithmetic overflow. S must be positive and N must be
sizeof(ptrdiff_t) <= sizeof(size_t), so do not bother to test for
exactly-SIZE_MAX allocations on such hosts; this avoids a test and
branch when S is known to be 1. */
-# ifndef xalloc_oversized
-# define xalloc_oversized(n, s) \
+#ifndef xalloc_oversized
+# define xalloc_oversized(n, s) \
((size_t) (sizeof(ptrdiff_t) <= sizeof(size_t) ? -1 : -2) / (s) < (n))
-# endif
+#endif
*
* Returns -1 on failure (with OOM error reported), 0 on success
*/
-# define VIR_ALLOC(ptr) virAlloc(&(ptr), sizeof(*(ptr)), true, VIR_FROM_THIS, \
- __FILE__, __FUNCTION__, __LINE__)
+#define VIR_ALLOC(ptr) virAlloc(&(ptr), sizeof(*(ptr)), true, VIR_FROM_THIS, \
+ __FILE__, __FUNCTION__, __LINE__)
/**
* VIR_ALLOC_QUIET:
*
* Returns -1 on failure, 0 on success
*/
-# define VIR_ALLOC_QUIET(ptr) virAlloc(&(ptr), sizeof(*(ptr)), false, 0, NULL, NULL, 0)
+#define VIR_ALLOC_QUIET(ptr) virAlloc(&(ptr), sizeof(*(ptr)), false, 0, NULL, NULL, 0)
/**
* VIR_ALLOC_N:
*
* Returns -1 on failure (with OOM error reported), 0 on success
*/
-# define VIR_ALLOC_N(ptr, count) virAllocN(&(ptr), sizeof(*(ptr)), (count), true, \
- VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__)
+#define VIR_ALLOC_N(ptr, count) virAllocN(&(ptr), sizeof(*(ptr)), (count), true, \
+ VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__)
/**
* VIR_ALLOC_N_QUIET:
*
* Returns -1 on failure, 0 on success
*/
-# define VIR_ALLOC_N_QUIET(ptr, count) virAllocN(&(ptr), sizeof(*(ptr)), (count), \
- false, 0, NULL, NULL, 0)
+#define VIR_ALLOC_N_QUIET(ptr, count) virAllocN(&(ptr), sizeof(*(ptr)), (count), \
+ false, 0, NULL, NULL, 0)
/**
* VIR_REALLOC_N:
*
* Returns -1 on failure (with OOM error reported), 0 on success
*/
-# define VIR_REALLOC_N(ptr, count) virReallocN(&(ptr), sizeof(*(ptr)), (count), \
- true, VIR_FROM_THIS, __FILE__, \
- __FUNCTION__, __LINE__)
+#define VIR_REALLOC_N(ptr, count) virReallocN(&(ptr), sizeof(*(ptr)), (count), \
+ true, VIR_FROM_THIS, __FILE__, \
+ __FUNCTION__, __LINE__)
/**
* VIR_REALLOC_N_QUIET:
*
* Returns -1 on failure, 0 on success
*/
-# define VIR_REALLOC_N_QUIET(ptr, count) virReallocN(&(ptr), sizeof(*(ptr)), (count), \
- false, 0, NULL, NULL, 0)
+#define VIR_REALLOC_N_QUIET(ptr, count) virReallocN(&(ptr), sizeof(*(ptr)), (count), \
+ false, 0, NULL, NULL, 0)
/**
* VIR_EXPAND_N:
*
* Returns -1 on failure (with OOM error reported), 0 on success
*/
-# define VIR_EXPAND_N(ptr, count, add) \
+#define VIR_EXPAND_N(ptr, count, add) \
virExpandN(&(ptr), sizeof(*(ptr)), &(count), add, true, VIR_FROM_THIS, \
__FILE__, __FUNCTION__, __LINE__)
*
* Returns -1 on failure, 0 on success
*/
-# define VIR_EXPAND_N_QUIET(ptr, count, add) \
+#define VIR_EXPAND_N_QUIET(ptr, count, add) \
virExpandN(&(ptr), sizeof(*(ptr)), &(count), add, false, 0, NULL, NULL, 0)
/**
*
* Returns -1 on failure (with OOM error reported), 0 on success
*/
-# define VIR_RESIZE_N(ptr, alloc, count, add) \
+#define VIR_RESIZE_N(ptr, alloc, count, add) \
virResizeN(&(ptr), sizeof(*(ptr)), &(alloc), count, add, true, \
VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__)
*
* Returns -1 on failure, 0 on success
*/
-# define VIR_RESIZE_N_QUIET(ptr, alloc, count, add) \
+#define VIR_RESIZE_N_QUIET(ptr, alloc, count, add) \
virResizeN(&(ptr), sizeof(*(ptr)), &(alloc), count, add, \
false, 0, NULL, NULL, 0)
*
* No return value.
*/
-# define VIR_SHRINK_N(ptr, count, remove) \
+#define VIR_SHRINK_N(ptr, count, remove) \
virShrinkN(&(ptr), sizeof(*(ptr)), &(count), remove)
/**
* or evaluate to "1", and in the meantime check that we've actually
* added the correct &'s and/or *'s to the arguments. (Whew!)
*/
-# define VIR_TYPEMATCH(a, b) \
+#define VIR_TYPEMATCH(a, b) \
sizeof(char[2 * (sizeof(*(a) = *(b)) == sizeof(*(b))) - 1])
/**
*
* Returns -1 on failure (with OOM error reported), 0 on success
*/
-# define VIR_INSERT_ELEMENT(ptr, at, count, newelem) \
+#define VIR_INSERT_ELEMENT(ptr, at, count, newelem) \
virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \
VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, false, \
true, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__)
-# define VIR_INSERT_ELEMENT_COPY(ptr, at, count, newelem) \
+#define VIR_INSERT_ELEMENT_COPY(ptr, at, count, newelem) \
virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \
VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, false, \
true, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__)
-# define VIR_INSERT_ELEMENT_INPLACE(ptr, at, count, newelem) \
+#define VIR_INSERT_ELEMENT_INPLACE(ptr, at, count, newelem) \
virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \
VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, true, \
true, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__)
-# define VIR_INSERT_ELEMENT_COPY_INPLACE(ptr, at, count, newelem) \
+#define VIR_INSERT_ELEMENT_COPY_INPLACE(ptr, at, count, newelem) \
virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \
VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, true, \
true, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__)
/* Quiet version of macros above */
-# define VIR_INSERT_ELEMENT_QUIET(ptr, at, count, newelem) \
+#define VIR_INSERT_ELEMENT_QUIET(ptr, at, count, newelem) \
virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \
VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, false, \
false, 0, NULL, NULL, 0)
-# define VIR_INSERT_ELEMENT_COPY_QUIET(ptr, at, count, newelem) \
+#define VIR_INSERT_ELEMENT_COPY_QUIET(ptr, at, count, newelem) \
virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \
VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, false, \
false, 0, NULL, NULL, 0)
-# define VIR_INSERT_ELEMENT_INPLACE_QUIET(ptr, at, count, newelem) \
+#define VIR_INSERT_ELEMENT_INPLACE_QUIET(ptr, at, count, newelem) \
virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \
VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, true, \
false, 0, NULL, NULL, 0)
-# define VIR_INSERT_ELEMENT_COPY_INPLACE_QUIET(ptr, at, count, newelem) \
+#define VIR_INSERT_ELEMENT_COPY_INPLACE_QUIET(ptr, at, count, newelem) \
virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \
VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, true, \
false, 0, NULL, NULL, 0)
*
* Returns -1 on failure (with OOM error reported), 0 on success
*/
-# define VIR_APPEND_ELEMENT(ptr, count, newelem) \
+#define VIR_APPEND_ELEMENT(ptr, count, newelem) \
virInsertElementsN(&(ptr), sizeof(*(ptr)), -1, &(count), \
VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, false, \
true, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__)
-# define VIR_APPEND_ELEMENT_COPY(ptr, count, newelem) \
+#define VIR_APPEND_ELEMENT_COPY(ptr, count, newelem) \
virInsertElementsN(&(ptr), sizeof(*(ptr)), -1, &(count), \
VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, false, \
true, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__)
-# define VIR_APPEND_ELEMENT_INPLACE(ptr, count, newelem) \
+#define VIR_APPEND_ELEMENT_INPLACE(ptr, count, newelem) \
ignore_value(virInsertElementsN(&(ptr), sizeof(*(ptr)), -1, &(count), \
VIR_TYPEMATCH(ptr, &(newelem)), \
&(newelem), true, true, false, \
VIR_FROM_THIS, __FILE__, \
__FUNCTION__, __LINE__))
-# define VIR_APPEND_ELEMENT_COPY_INPLACE(ptr, count, newelem) \
+#define VIR_APPEND_ELEMENT_COPY_INPLACE(ptr, count, newelem) \
ignore_value(virInsertElementsN(&(ptr), sizeof(*(ptr)), -1, &(count), \
VIR_TYPEMATCH(ptr, &(newelem)), \
&(newelem), false, true, false, \
__FUNCTION__, __LINE__))
/* Quiet version of macros above */
-# define VIR_APPEND_ELEMENT_QUIET(ptr, count, newelem) \
+#define VIR_APPEND_ELEMENT_QUIET(ptr, count, newelem) \
virInsertElementsN(&(ptr), sizeof(*(ptr)), -1, &(count), \
VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, false, \
false, 0, NULL, NULL, 0)
-# define VIR_APPEND_ELEMENT_COPY_QUIET(ptr, count, newelem) \
+#define VIR_APPEND_ELEMENT_COPY_QUIET(ptr, count, newelem) \
virInsertElementsN(&(ptr), sizeof(*(ptr)), -1, &(count), \
VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, false, \
false, 0, NULL, NULL, 0)
*
* Returns -1 on failure, 0 on success
*/
-# define VIR_DELETE_ELEMENT(ptr, at, count) \
+#define VIR_DELETE_ELEMENT(ptr, at, count) \
virDeleteElementsN(&(ptr), sizeof(*(ptr)), at, &(count), 1, false)
-# define VIR_DELETE_ELEMENT_INPLACE(ptr, at, count) \
+#define VIR_DELETE_ELEMENT_INPLACE(ptr, at, count) \
virDeleteElementsN(&(ptr), sizeof(*(ptr)), at, &(count), 1, true)
/**
* arithmetic overflow in the allocation size. The check is
* essentially the same as that in gnulib's xalloc_oversized.
*/
-# define VIR_ALLOC_VAR_OVERSIZED(M, N, S) ((((size_t)-1) - (M)) / (S) < (N))
+#define VIR_ALLOC_VAR_OVERSIZED(M, N, S) ((((size_t)-1) - (M)) / (S) < (N))
/**
* VIR_ALLOC_VAR:
*
* Returns -1 on failure (with OOM error reported), 0 on success
*/
-# define VIR_ALLOC_VAR(ptr, type, count) \
+#define VIR_ALLOC_VAR(ptr, type, count) \
virAllocVar(&(ptr), sizeof(*(ptr)), sizeof(type), (count), true, \
VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__)
*
* Returns -1 on failure, 0 on success
*/
-# define VIR_ALLOC_VAR_QUIET(ptr, type, count) \
+#define VIR_ALLOC_VAR_QUIET(ptr, type, count) \
virAllocVar(&(ptr), sizeof(*(ptr)), sizeof(type), (count), false, 0, NULL, NULL, 0)
/**
* integer type, all while evaluating ptr only once. This gives us
* extra compiler safety when compiling under gcc.
*/
-# define VIR_FREE(ptr) virFree(1 ? (void *) &(ptr) : (ptr))
+#define VIR_FREE(ptr) virFree(1 ? (void *) &(ptr) : (ptr))
/**
*
* This macro is safe to use on arguments with side effects.
*/
-# define VIR_DISPOSE_N(ptr, count) virDispose(1 ? (void *) &(ptr) : (ptr), 0, \
+#define VIR_DISPOSE_N(ptr, count) virDispose(1 ? (void *) &(ptr) : (ptr), 0, \
sizeof(*(ptr)), &(count))
*
* This macro is not safe to be used on arguments with side effects.
*/
-# define VIR_DISPOSE_STRING(ptr) virDisposeString(&(ptr))
+#define VIR_DISPOSE_STRING(ptr) virDisposeString(&(ptr))
/**
* VIR_AUTODISPOSE_STR:
* the string variable declared with it by calling virDisposeString
* when the variable goes out of scope.
*/
-# define VIR_AUTODISPOSE_STR \
+#define VIR_AUTODISPOSE_STR \
__attribute__((cleanup(virDisposeString))) char *
/**
*
* This macro is safe to be used on arguments with side effects.
*/
-# define VIR_DISPOSE(ptr) virDispose(1 ? (void *) &(ptr) : (ptr), 1, \
- sizeof(*(ptr)), NULL)
+#define VIR_DISPOSE(ptr) virDispose(1 ? (void *) &(ptr) : (ptr), 1, \
+ sizeof(*(ptr)), NULL)
void virAllocTestInit(void);
* the variable declared with it by calling virFree
* when the variable goes out of scope.
*/
-# define VIR_AUTOFREE(type) __attribute__((cleanup(virFree))) type
-
-#endif /* LIBVIRT_VIRALLOC_H */
+#define VIR_AUTOFREE(type) __attribute__((cleanup(virFree))) type