mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
build: Assume __attribute__((cleanup)) always works
All recent compilers support this (except MS compilers which we don't care about). Assume it is supported. We test it in ./configure and hard fail if it doesn't work. We still define HAVE_ATTRIBUTE_CLEANUP but you can now assume it is always defined and don't have to check it.
This commit is contained in:
2
common
2
common
Submodule common updated: b6e703dccb...01c5322606
@@ -93,11 +93,7 @@ extern char *read_whole_file (const char *filename, size_t *size_r);
|
||||
extern char *mountable_to_string (const mountable_t *mountable);
|
||||
extern void cleanup_free_mountable (mountable_t *mountable);
|
||||
|
||||
#ifdef HAVE_ATTRIBUTE_CLEANUP
|
||||
#define CLEANUP_FREE_MOUNTABLE __attribute__((cleanup(cleanup_free_mountable)))
|
||||
#else
|
||||
#define CLEANUP_FREE_MOUNTABLE
|
||||
#endif
|
||||
|
||||
/* cleanups.c */
|
||||
/* These functions are used internally by the CLEANUP_* macros.
|
||||
@@ -106,13 +102,8 @@ extern void cleanup_free_mountable (mountable_t *mountable);
|
||||
extern void cleanup_aug_close (void *ptr);
|
||||
extern void cleanup_free_stringsbuf (void *ptr);
|
||||
|
||||
#ifdef HAVE_ATTRIBUTE_CLEANUP
|
||||
#define CLEANUP_AUG_CLOSE __attribute__((cleanup(cleanup_aug_close)))
|
||||
#define CLEANUP_FREE_STRINGSBUF __attribute__((cleanup(cleanup_free_stringsbuf)))
|
||||
#else
|
||||
#define CLEANUP_AUG_CLOSE
|
||||
#define CLEANUP_FREE_STRINGSBUF
|
||||
#endif
|
||||
|
||||
/* mount.c */
|
||||
extern int is_root_mounted (void);
|
||||
|
||||
@@ -32,13 +32,8 @@
|
||||
|
||||
#include "ignore-value.h"
|
||||
|
||||
#ifdef HAVE_ATTRIBUTE_CLEANUP
|
||||
#define CLEANUP_BIND_STATE __attribute__((cleanup(free_bind_state)))
|
||||
#define CLEANUP_RESOLVER_STATE __attribute__((cleanup(free_resolver_state)))
|
||||
#else
|
||||
#define CLEANUP_BIND_STATE
|
||||
#define CLEANUP_RESOLVER_STATE
|
||||
#endif
|
||||
|
||||
struct bind_state {
|
||||
bool mounted;
|
||||
|
||||
@@ -39,12 +39,8 @@
|
||||
|
||||
#include <yara.h>
|
||||
|
||||
#ifdef HAVE_ATTRIBUTE_CLEANUP
|
||||
#define CLEANUP_DESTROY_YARA_COMPILER \
|
||||
__attribute__((cleanup(cleanup_destroy_yara_compiler)))
|
||||
#else
|
||||
#define CLEANUP_DESTROY_YARA_COMPILER
|
||||
#endif
|
||||
|
||||
struct write_callback_data {
|
||||
int fd;
|
||||
@@ -208,10 +204,6 @@ compile_rules_file (const char *rules_path)
|
||||
}
|
||||
|
||||
err:
|
||||
#ifndef HAVE_ATTRIBUTE_CLEANUP
|
||||
yr_compiler_destroy (compiler);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -817,7 +817,6 @@ and generate_client_structs_cleanups_h () =
|
||||
#ifndef GUESTFS_STRUCTS_CLEANUPS_H_
|
||||
#define GUESTFS_STRUCTS_CLEANUPS_H_
|
||||
|
||||
#ifdef HAVE_ATTRIBUTE_CLEANUP
|
||||
";
|
||||
|
||||
List.iter (
|
||||
@@ -828,16 +827,7 @@ and generate_client_structs_cleanups_h () =
|
||||
pr " __attribute__((cleanup(guestfs_int_cleanup_free_%s_list)))\n" name
|
||||
) structs;
|
||||
|
||||
pr "#else /* !HAVE_ATTRIBUTE_CLEANUP */\n";
|
||||
|
||||
List.iter (
|
||||
fun { s_name = name } ->
|
||||
pr "#define CLEANUP_FREE_%s\n" (String.uppercase_ascii name);
|
||||
pr "#define CLEANUP_FREE_%s_LIST\n" (String.uppercase_ascii name)
|
||||
) structs;
|
||||
|
||||
pr "\
|
||||
#endif /* !HAVE_ATTRIBUTE_CLEANUP */
|
||||
|
||||
/* These functions are used internally by the CLEANUP_* macros.
|
||||
* Don't call them directly.
|
||||
|
||||
@@ -127,8 +127,6 @@ let generate_daemon_stubs actions () =
|
||||
args_passed_to_daemon in
|
||||
|
||||
if args_passed_to_daemon <> [] then (
|
||||
pr "#ifdef HAVE_ATTRIBUTE_CLEANUP\n";
|
||||
pr "\n";
|
||||
pr "#define CLEANUP_XDR_FREE_%s_ARGS \\\n" uc_name;
|
||||
pr " __attribute__((cleanup(cleanup_xdr_free_%s_args)))\n" name;
|
||||
pr "\n";
|
||||
@@ -140,9 +138,6 @@ let generate_daemon_stubs actions () =
|
||||
name;
|
||||
pr "}\n";
|
||||
pr "\n";
|
||||
pr "#else /* !HAVE_ATTRIBUTE_CLEANUP */\n";
|
||||
pr "#define CLEANUP_XDR_FREE_%s_ARGS\n" uc_name;
|
||||
pr "#endif /* !HAVE_ATTRIBUTE_CLEANUP */\n";
|
||||
pr "\n"
|
||||
);
|
||||
|
||||
@@ -1315,7 +1310,6 @@ let generate_daemon_structs_cleanups_h () =
|
||||
#ifndef GUESTFS_DAEMON_STRUCTS_CLEANUPS_H_
|
||||
#define GUESTFS_DAEMON_STRUCTS_CLEANUPS_H_
|
||||
|
||||
#ifdef HAVE_ATTRIBUTE_CLEANUP
|
||||
";
|
||||
|
||||
List.iter (
|
||||
@@ -1326,16 +1320,7 @@ let generate_daemon_structs_cleanups_h () =
|
||||
pr " __attribute__((cleanup(cleanup_free_int_%s_list)))\n" name
|
||||
) structs;
|
||||
|
||||
pr "#else /* !HAVE_ATTRIBUTE_CLEANUP */\n";
|
||||
|
||||
List.iter (
|
||||
fun { s_name = name } ->
|
||||
pr "#define CLEANUP_FREE_%s\n" (String.uppercase_ascii name);
|
||||
pr "#define CLEANUP_FREE_%s_LIST\n" (String.uppercase_ascii name)
|
||||
) structs;
|
||||
|
||||
pr "\
|
||||
#endif /* !HAVE_ATTRIBUTE_CLEANUP */
|
||||
|
||||
/* These functions are used internally by the CLEANUP_* macros.
|
||||
* Don't call them directly.
|
||||
|
||||
@@ -661,11 +661,7 @@ extern void guestfs_int_end_stringsbuf (guestfs_h *g, struct stringsbuf *sb);
|
||||
|
||||
extern void guestfs_int_free_stringsbuf (struct stringsbuf *sb);
|
||||
|
||||
#ifdef HAVE_ATTRIBUTE_CLEANUP
|
||||
#define CLEANUP_FREE_STRINGSBUF __attribute__((cleanup(guestfs_int_cleanup_free_stringsbuf)))
|
||||
#else
|
||||
#define CLEANUP_FREE_STRINGSBUF
|
||||
#endif
|
||||
extern void guestfs_int_cleanup_free_stringsbuf (struct stringsbuf *sb);
|
||||
|
||||
/* proto.c */
|
||||
@@ -785,11 +781,7 @@ extern int guestfs_int_cmd_pipe_run (struct command *cmd, const char *mode);
|
||||
extern int guestfs_int_cmd_pipe_wait (struct command *cmd);
|
||||
extern char *guestfs_int_cmd_get_pipe_errors (struct command *cmd);
|
||||
|
||||
#ifdef HAVE_ATTRIBUTE_CLEANUP
|
||||
#define CLEANUP_CMD_CLOSE __attribute__((cleanup(guestfs_int_cleanup_cmd_close)))
|
||||
#else
|
||||
#define CLEANUP_CMD_CLOSE
|
||||
#endif
|
||||
extern void guestfs_int_cleanup_cmd_close (struct command **);
|
||||
|
||||
/* launch-*.c constructors */
|
||||
|
||||
@@ -43,7 +43,6 @@
|
||||
#include "guestfs-internal.h"
|
||||
#include "guestfs-internal-actions.h"
|
||||
|
||||
#ifdef HAVE_ATTRIBUTE_CLEANUP
|
||||
#define CLEANUP_JSON_T_DECREF __attribute__((cleanup(cleanup_json_t_decref)))
|
||||
|
||||
static void
|
||||
@@ -52,10 +51,6 @@ cleanup_json_t_decref (void *ptr)
|
||||
json_decref (* (json_t **) ptr);
|
||||
}
|
||||
|
||||
#else
|
||||
#define CLEANUP_JSON_T_DECREF
|
||||
#endif
|
||||
|
||||
static json_t *get_json_output (guestfs_h *g, const char *filename);
|
||||
static int qemu_img_supports_U_option (guestfs_h *g);
|
||||
static void set_child_rlimits (struct command *);
|
||||
|
||||
@@ -97,7 +97,6 @@ xmlBufferDetach (xmlBufferPtr buf)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ATTRIBUTE_CLEANUP
|
||||
#define CLEANUP_VIRSECRETFREE __attribute__((cleanup(cleanup_virSecretFree)))
|
||||
|
||||
static void
|
||||
@@ -108,10 +107,6 @@ cleanup_virSecretFree (void *ptr)
|
||||
virSecretFree (secret_obj);
|
||||
}
|
||||
|
||||
#else /* !HAVE_ATTRIBUTE_CLEANUP */
|
||||
#define CLEANUP_VIRSECRETFREE
|
||||
#endif
|
||||
|
||||
/* List used to store a mapping of secret to libvirt secret UUID. */
|
||||
struct secret {
|
||||
char *secret;
|
||||
|
||||
@@ -46,7 +46,6 @@
|
||||
#include "guestfs-internal.h"
|
||||
#include "guestfs_protocol.h"
|
||||
|
||||
#ifdef HAVE_ATTRIBUTE_CLEANUP
|
||||
#define CLEANUP_JSON_T_DECREF __attribute__((cleanup(cleanup_json_t_decref)))
|
||||
|
||||
static void
|
||||
@@ -55,10 +54,6 @@ cleanup_json_t_decref (void *ptr)
|
||||
json_decref (* (json_t **) ptr);
|
||||
}
|
||||
|
||||
#else
|
||||
#define CLEANUP_JSON_T_DECREF
|
||||
#endif
|
||||
|
||||
struct qemu_data {
|
||||
int generation; /* MEMO_GENERATION read from qemu.stat */
|
||||
uint64_t prev_size; /* Size of qemu binary when cached. */
|
||||
|
||||
@@ -109,15 +109,12 @@ main (int argc, char *argv[])
|
||||
AC_MSG_RESULT([yes])
|
||||
AC_DEFINE([HAVE_ATTRIBUTE_CLEANUP],[1],[Define to 1 if '__attribute__((cleanup(...)))' works with this compiler.])
|
||||
],[
|
||||
AC_MSG_WARN(
|
||||
AC_MSG_ERROR(
|
||||
['__attribute__((cleanup(...)))' does not work.
|
||||
|
||||
You may not be using a sufficiently recent version of GCC or CLANG, or
|
||||
you may be using a C compiler which does not support this attribute,
|
||||
or the configure test may be wrong.
|
||||
|
||||
The code will still compile, but is likely to leak memory and other
|
||||
resources when it runs.])])
|
||||
or the configure test may be wrong.])])
|
||||
dnl restore CFLAGS
|
||||
CFLAGS="${acx_nbdkit_save_CFLAGS}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user