Add new header for collecting utility macros
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 25 Feb 2008 09:02:07 +0000 (11:02 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 25 Feb 2008 09:02:07 +0000 (11:02 +0200)
- atm consists of portability wrappers to various gcc extensions like
  __attribute__() to provide additional warnings and checks
- copied from glib to avoid an extra build dependency just for the silly
  macros, renamed to avoid namespace clashing

Makefile.am
preinstall.am
rpmio/rpmutil.h [new file with mode: 0644]

index e97a6d5..99304b9 100644 (file)
@@ -50,6 +50,7 @@ pkginclude_HEADERS += rpmio/rpmsq.h
 pkginclude_HEADERS += rpmio/rpmstring.h
 pkginclude_HEADERS += rpmio/rpmsw.h
 pkginclude_HEADERS += rpmio/rpmfileutil.h
+pkginclude_HEADERS += rpmio/rpmutil.h
 
 pkginclude_HEADERS += rpmdb/header.h
 pkginclude_HEADERS += rpmdb/rpmdb.h
index 0ef8b71..07d67a3 100644 (file)
@@ -42,6 +42,10 @@ include/rpm/rpmfileutil.h: rpmio/rpmfileutil.h include/rpm/$(dirstamp)
        $(INSTALL_DATA) $(top_srcdir)/rpmio/rpmfileutil.h include/rpm/rpmfileutil.h
 BUILT_SOURCES += include/rpm/rpmfileutil.h
 CLEANFILES += include/rpm/rpmfileutil.h
+include/rpm/rpmutil.h: rpmio/rpmutil.h include/rpm/$(dirstamp)
+       $(INSTALL_DATA) $(top_srcdir)/rpmio/rpmutil.h include/rpm/rpmutil.h
+BUILT_SOURCES += include/rpm/rpmutil.h
+CLEANFILES += include/rpm/rpmutil.h
 include/rpm/header.h: rpmdb/header.h include/rpm/$(dirstamp)
        $(INSTALL_DATA) $(top_srcdir)/rpmdb/header.h include/rpm/header.h
 BUILT_SOURCES += include/rpm/header.h
diff --git a/rpmio/rpmutil.h b/rpmio/rpmutil.h
new file mode 100644 (file)
index 0000000..325ee0e
--- /dev/null
@@ -0,0 +1,95 @@
+#ifndef _RPMUTIL_H
+#define _RPMUTIL_H
+
+/*
+ * Miscellanous utility macros:
+ * - portability wrappers for various gcc extensions like __attribute__()
+ * - ...
+ *
+ * Copied from glib, names replaced to avoid clashing with glib.
+ *
+ */
+
+/* Here we provide RPM_GNUC_EXTENSION as an alias for __extension__,
+ * where this is valid. This allows for warningless compilation of
+ * "long long" types even in the presence of '-ansi -pedantic'. 
+ */
+#if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
+#  define RPM_GNUC_EXTENSION __extension__
+#else
+#  define RPM_GNUC_EXTENSION
+#endif
+
+/* Provide macros to feature the GCC function attribute.
+ */
+#if    __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
+#define RPM_GNUC_PURE                            \
+  __attribute__((__pure__))
+#define RPM_GNUC_MALLOC                        \
+  __attribute__((__malloc__))
+#else
+#define RPM_GNUC_PURE
+#define RPM_GNUC_MALLOC
+#endif
+
+#if     __GNUC__ >= 4
+#define RPM_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
+#else
+#define RPM_GNUC_NULL_TERMINATED
+#endif
+
+#if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
+#define RPM_GNUC_PRINTF( format_idx, arg_idx )    \
+  __attribute__((__format__ (__printf__, format_idx, arg_idx)))
+#define RPM_GNUC_SCANF( format_idx, arg_idx )     \
+  __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
+#define RPM_GNUC_FORMAT( arg_idx )                \
+  __attribute__((__format_arg__ (arg_idx)))
+#define RPM_GNUC_NORETURN                         \
+  __attribute__((__noreturn__))
+#define RPM_GNUC_CONST                            \
+  __attribute__((__const__))
+#define RPM_GNUC_UNUSED                           \
+  __attribute__((__unused__))
+#define RPM_GNUC_NO_INSTRUMENT                 \
+  __attribute__((__no_instrument_function__))
+#else   /* !__GNUC__ */
+#define RPM_GNUC_PRINTF( format_idx, arg_idx )
+#define RPM_GNUC_SCANF( format_idx, arg_idx )
+#define RPM_GNUC_FORMAT( arg_idx )
+#define RPM_GNUC_NORETURN
+#define RPM_GNUC_CONST
+#define RPM_GNUC_UNUSED
+#define RPM_GNUC_NO_INSTRUMENT
+#endif  /* !__GNUC__ */
+
+#if    __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
+#define RPM_GNUC_DEPRECATED                            \
+  __attribute__((__deprecated__))
+#else
+#define RPM_GNUC_DEPRECATED
+#endif /* __GNUC__ */
+
+#if     __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
+#  define RPM_GNUC_MAY_ALIAS __attribute__((may_alias))
+#else
+#  define RPM_GNUC_MAY_ALIAS
+#endif
+
+#if    __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+#define RPM_GNUC_WARN_UNUSED_RESULT            \
+  __attribute__((warn_unused_result))
+#else
+#define RPM_GNUC_WARN_UNUSED_RESULT
+#endif /* __GNUC__ */
+
+/* Guard C code in headers, while including them from C++ */
+#ifdef  __cplusplus
+# define RPM_BEGIN_DECLS  extern "C" {
+# define RPM_END_DECLS    }
+#else
+# define RPM_BEGIN_DECLS
+# define RPM_END_DECLS
+#endif
+
+#endif /* _RPMUTIL_H */