useful: Move close cleanup into ell/util.h
PATCH 1/2 useful: Move close cleanup into ell/util.h
--- ell/useful.h | 14 -------------- ell/util.h | 11 +++++++++++ 2 files changed, 11 insertions(+), 14 deletions(-)
ell/useful.h +0 -14
@@ -5,11 +5,6 @@* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include <unistd.h> -#include <errno.h> - -#include <ell/util.h> -#define align_len (len, boundary) (((len)+(boundary)-1) & ~((boundary)-1))#define likely (x) __builtin_expect(!!(x), 1)
@@ -70,15 +65,6 @@ static inline unsigned char bit_field(const unsigned char oct,#define _auto_ (func) \ __AUTODESTRUCT(func) -/* Enables declaring _auto_(close) int fd = <-1 or L_TFR(open(...))>; */ -inline __attribute__((always_inline))void close_cleanup (void *p) -{ -int fd = *(int *) p; - -if (fd >=0 ) -L_TFR (close (fd)); -} -/* * Trick the compiler into thinking that var might be changed somehow by * the asm
ell/util.h +11 -0
@@ -14,6 +14,8 @@#include <inttypes.h> #include <endian.h> #include <byteswap.h> +#include <unistd.h> +#include <errno.h> #include <sys/uio.h> #include <ell/cleanup.h>
@@ -314,6 +316,15 @@ const char *l_util_get_debugfs_path(void);while (__result ==-1L && errno ==EINTR ); \ __result; })) +/* Enables declaring _auto_(close) int fd = <-1 or L_TFR(open(...))>; */ +inline __attribute__((always_inline))void close_cleanup (void *p) +{ +int fd = *(int *) p; + +if (fd >=0 ) +L_TFR (close (fd)); +} +#define _L_IN_SET_CMP (val, type, cmp, ...) __extension__ ({ \ const type __v = (val); \ const typeof(__v) __elems[] = {__VA_ARGS__}; \
Signature · 1 line
2.43.0
PATCH 2/2 cleanup: Use _l_ preffix for all cleanup functions
Also while here, move the __AUTODESTRUCT macro to cleanup.h and prefix it with _L
--- ell/cleanup.h | 5 ++++- ell/useful.h | 5 +---- ell/util.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-)
ell/cleanup.h +4 -1
@@ -7,6 +7,9 @@#pragma once +#define __L_AUTODESTRUCT (func) \ + __attribute((cleanup(_l_ ## func ## _cleanup))) +#define DEFINE_CLEANUP_FUNC (func) \ inline __attribute__((always_inline)) \ - void func ## _cleanup(void *p) { func(*(void **) p); } + void _l_ ## func ## _cleanup(void *p) { func(*(void **) p); }
ell/useful.h +1 -4
@@ -59,11 +59,8 @@ static inline unsigned char bit_field(const unsigned char oct, _x / _d; \ }) -#define __AUTODESTRUCT (func) \ - __attribute((cleanup(func ## _cleanup))) -#define _auto_ (func) \ - __AUTODESTRUCT(func) + __L_AUTODESTRUCT(func)/* * Trick the compiler into thinking that var might be changed somehow by
ell/util.h +1 -1
@@ -317,7 +317,7 @@ const char *l_util_get_debugfs_path(void); __result; }))/* Enables declaring _auto_(close) int fd = <-1 or L_TFR(open(...))>; */ -inline __attribute__((always_inline))void close_cleanup (void *p) +inline __attribute__((always_inline))void _l_close_cleanup (void *p) {int fd = *(int *) p;
Signature · 1 line
2.43.0
Quoted 5 lines · Denis Kenzior
--- ell/useful.h | 14 -------------- ell/util.h | 11 +++++++++++ 2 files changed, 11 insertions(+), 14 deletions(-)
Both applied.