($INBOX_DIR/description missing)
 help / color / mirror / Atom feed
From: Denis Kenzior <denkenz@gmail.com>
To: ell@lists.linux.dev
Cc: Denis Kenzior <denkenz@gmail.com>
Subject: [PATCH] cleanup: Promote _auto_ to public API
Date: Tue, 30 Jan 2024 13:44:29 -0600	[thread overview]
Message-ID: <20240130194453.805041-1-denkenz@gmail.com> (raw)

Move this out of useful.h which is not installed by default and requires
special build time hacks into cleanup.h, which is installed as part of
public headers / api.
---
 ell/cleanup.h |  6 ++++++
 ell/useful.h  | 20 --------------------
 ell/util.h    | 11 +++++++++++
 3 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/ell/cleanup.h b/ell/cleanup.h
index 337c8ad5d753..220240bdd4cf 100644
--- a/ell/cleanup.h
+++ b/ell/cleanup.h
@@ -10,3 +10,9 @@
 #define DEFINE_CLEANUP_FUNC(func)			\
 	inline __attribute__((always_inline))		\
 	void func ## _cleanup(void *p) { func(*(void **) p); }
+
+#define __AUTODESTRUCT(func)				\
+	__attribute((cleanup(func ## _cleanup)))
+
+#define _auto_(func)					\
+	__AUTODESTRUCT(func)
diff --git a/ell/useful.h b/ell/useful.h
index 5a4a5eba091c..a3d5ad916bd8 100644
--- a/ell/useful.h
+++ b/ell/useful.h
@@ -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)
@@ -64,21 +59,6 @@ static inline unsigned char bit_field(const unsigned char oct,
 	_x / _d;					\
 })
 
-#define __AUTODESTRUCT(func)				\
-	__attribute((cleanup(func ## _cleanup)))
-
-#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
diff --git a/ell/util.h b/ell/util.h
index 5dfc35c89ea6..daec4024fdfa 100644
--- a/ell/util.h
+++ b/ell/util.h
@@ -15,6 +15,8 @@
 #include <endian.h>
 #include <byteswap.h>
 #include <sys/uio.h>
+#include <errno.h>
+#include <unistd.h>
 #include <ell/cleanup.h>
 
 #ifdef __cplusplus
@@ -437,6 +439,15 @@ int l_safe_atox32(const char *s, uint32_t *out_u);
 int l_safe_atox16(const char *s, uint16_t *out_u);
 int l_safe_atox8(const char *s, uint8_t *out_u);
 
+/* 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));
+}
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.43.0


                 reply	other threads:[~2024-01-30 19:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240130194453.805041-1-denkenz@gmail.com \
    --to=denkenz@gmail.com \
    --cc=ell@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).