two small prep commits from the imds PR (#41316)

They are not directly IMDS stuff, and should be easy to merge ahead.
This commit is contained in:
Luca Boccassi
2026-03-25 12:54:23 +00:00
committed by GitHub
3 changed files with 22 additions and 13 deletions
+14
View File
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include "assert-util.h"
#include "cleanup-fundamental.h" /* IWYU pragma: export */
typedef void (*free_func_t)(void *p);
@@ -89,3 +90,16 @@ typedef void* (*mfree_func_t)(void *p);
#define DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(type, name, free_func) \
DEFINE_PUBLIC_TRIVIAL_REF_FUNC(type, name); \
DEFINE_PUBLIC_TRIVIAL_UNREF_FUNC(type, name, free_func);
typedef void (*void_func_t)(void);
static inline void dispatch_void_func(void_func_t *f) {
assert(f);
assert(*f);
(*f)();
}
/* Inspired by Go's "defer" construct, but much more basic. This basically just calls a void function when
* the current scope is left. Doesn't do function parameters (i.e. no closures). */
#define DEFER_VOID_CALL(x) _DEFER_VOID_CALL(UNIQ, x)
#define _DEFER_VOID_CALL(uniq, x) _unused_ _cleanup_(dispatch_void_func) void_func_t UNIQ_T(defer, uniq) = (x)
-13
View File
@@ -205,16 +205,3 @@ static inline size_t size_add(size_t x, size_t y) {
for (typeof(entry) _va_sentinel_[1] = {}, _entries_[] = { __VA_ARGS__ __VA_OPT__(,) _va_sentinel_[0] }, *_current_ = _entries_; \
((long)(_current_ - _entries_) < (long)(ELEMENTSOF(_entries_) - 1)) && ({ entry = *_current_; true; }); \
_current_++)
typedef void (*void_func_t)(void);
static inline void dispatch_void_func(void_func_t *f) {
assert(f);
assert(*f);
(*f)();
}
/* Inspired by Go's "defer" construct, but much more basic. This basically just calls a void function when
* the current scope is left. Doesn't do function parameters (i.e. no closures). */
#define DEFER_VOID_CALL(x) _DEFER_VOID_CALL(UNIQ, x)
#define _DEFER_VOID_CALL(uniq, x) _unused_ _cleanup_(dispatch_void_func) void_func_t UNIQ_T(defer, uniq) = (x)
+8
View File
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "iovec-util.h"
#include "memory-util.h"
#include "tests.h"
TEST(iovec_memcmp) {
@@ -67,4 +68,11 @@ TEST(iovec_append) {
assert_se(iovec_memcmp(&iov, &IOVEC_MAKE_STRING("waldoquuxp")) == 0);
}
TEST(iovec_make_byte) {
struct iovec x = IOVEC_MAKE_BYTE('x');
ASSERT_EQ(x.iov_len, 1U);
ASSERT_EQ(memcmp_nn(x.iov_base, x.iov_len, "x", 1), 0);
}
DEFINE_TEST_MAIN(LOG_INFO);