r23289: Provide support for GCC attributes _PURE_, _NONNULL_, _DEPRECATED_, _NORETURN...
authorJelmer Vernooij <jelmer@samba.org>
Fri, 1 Jun 2007 12:01:53 +0000 (12:01 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:53:08 +0000 (14:53 -0500)
(This used to be commit 44248f662f0b609dad6a7b437948f12d661a28f7)

source4/cluster/ctdb/common/ctdb_util.c
source4/include/includes.h
source4/lib/json/debug.c
source4/lib/json/linkhash.c
source4/lib/util/fault.c
source4/lib/util/util_str.c
source4/script/mkproto.pl

index 9a5e51bfa0bedfd60dd8a89a6540e962161621a4..49f7a55abff2714926154b50cb2e4a0d3b2f81fc 100644 (file)
@@ -52,7 +52,7 @@ void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...)
 /*
   a fatal internal error occurred - no hope for recovery
 */
-void ctdb_fatal(struct ctdb_context *ctdb, const char *msg)
+_NORETURN_ void ctdb_fatal(struct ctdb_context *ctdb, const char *msg)
 {
        DEBUG(0,("ctdb fatal error: %s\n", msg));
        fprintf(stderr, "ctdb fatal error: '%s'\n", msg);
index f1188e2aaf66a59a80d5ea2f7c6c709e9a0e97f6..1022b6554540e80c33c574744eb8b4439659e1de 100644 (file)
 #endif
 #endif
 
-#ifndef NORETURN_ATTRIBUTE
-#if (__GNUC__ >= 3)
-#define NORETURN_ATTRIBUTE __attribute__ ((noreturn))
+#ifndef _DEPRECATED_
+#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 )
+#define _DEPRECATED_ __attribute__ ((deprecated))
 #else
-#define NORETURN_ATTRIBUTE
+#define _DEPRECATED_
 #endif
 #endif
 
-/* mark smb_panic() as noreturn, so static analysers know that it is
-   used like abort */
-_PUBLIC_ void smb_panic(const char *why) NORETURN_ATTRIBUTE;
+#ifndef _WARN_UNUSED_RESULT_
+#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 )
+#define _WARN_UNUSED_RESULT_ __attribute__ ((warn_unused_result))
+#else
+#define _WARN_UNUSED_RESULT_
+#endif
+#endif
+
+#ifndef _NORETURN_
+#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 )
+#define _NORETURN_ __attribute__ ((noreturn))
+#else
+#define _NORETURN_
+#endif
+#endif
+
+#ifndef _PURE_
+#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1)
+#define _PURE_ __attribute__((pure))
+#else
+#define _PURE_
+#endif
+#endif
+
+#ifndef NONNULL
+#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1)
+#define NONNULL(param) param __attribute__((nonnull))
+#else
+#define NONNULL(param) param
+#endif
+#endif
 
 #include "system/time.h"
 #include "system/wait.h"
index eaa6fca33c99bdc10437145427eff0c92b6b86a2..a315b0e2a4c20b2d7a575c87b86756b84aa4e291 100644 (file)
@@ -41,7 +41,7 @@ extern void mc_set_syslog(int syslog)
   _syslog = syslog;
 }
 
-void mc_abort(const char *msg, ...)
+_NORETURN_ void mc_abort(const char *msg, ...)
 {
   va_list ap;
   va_start(ap, msg);
index 6cfc9a0ea6e4f633335184966439b57fa1a148c4..b04254b59703158066425c06089f0e31507463ca 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "linkhash.h"
 
-void lh_abort(const char *msg, ...)
+_NORETURN_ void lh_abort(const char *msg, ...)
 {
        va_list ap;
        va_start(ap, msg);
index c7d6b7ede65be2a5c0abe5e192cf636f757ee67e..86a0b61a769dc63e41930a98e30f3b66fc20c384 100644 (file)
@@ -118,7 +118,7 @@ _PUBLIC_ const char *panic_action = NULL;
 /**
  Something really nasty happened - panic !
 **/
-_PUBLIC_ void smb_panic(const char *why)
+_PUBLIC_ _NORETURN_ void smb_panic(const char *why)
 {
        int result;
 
index 86cd3176c511a69d961b40f03e254edf57556572..c088e26fe586c9dff818ba971c96e458757febdd 100644 (file)
 /**
  Trim the specified elements off the front and back of a string.
 **/
-_PUBLIC_ BOOL trim_string(char *s,const char *front,const char *back)
+_PUBLIC_ bool trim_string(char *s, const char *front, const char *back)
 {
-       BOOL ret = False;
+       bool ret = false;
        size_t front_len;
        size_t back_len;
        size_t len;
 
        /* Ignore null or empty strings. */
        if (!s || (s[0] == '\0'))
-               return False;
+               return false;
 
        front_len       = front? strlen(front) : 0;
        back_len        = back? strlen(back) : 0;
@@ -58,7 +58,7 @@ _PUBLIC_ BOOL trim_string(char *s,const char *front,const char *back)
                         * easily overlap. Found by valgrind. JRA. */
                        memmove(s, s+front_len, (len-front_len)+1);
                        len -= front_len;
-                       ret=True;
+                       ret=true;
                }
        }
        
@@ -66,7 +66,7 @@ _PUBLIC_ BOOL trim_string(char *s,const char *front,const char *back)
                while ((len >= back_len) && strncmp(s+len-back_len,back,back_len)==0) {
                        s[len-back_len]='\0';
                        len -= back_len;
-                       ret=True;
+                       ret=true;
                }
        }
        return ret;
@@ -75,7 +75,7 @@ _PUBLIC_ BOOL trim_string(char *s,const char *front,const char *back)
 /**
  Find the number of 'c' chars in a string
 **/
-_PUBLIC_ size_t count_chars(const char *s, char c)
+_PUBLIC_ _PURE_ size_t count_chars(const char *s, char c)
 {
        size_t count = 0;
 
@@ -218,7 +218,7 @@ _PUBLIC_ size_t strhex_to_str(char *p, size_t len, const char *strhex)
 /** 
  * Parse a hex string and return a data blob. 
  */
-_PUBLIC_ DATA_BLOB strhex_to_data_blob(const char *strhex) 
+_PUBLIC_ _PURE_ DATA_BLOB strhex_to_data_blob(const char *strhex) 
 {
        DATA_BLOB ret_blob = data_blob(NULL, strlen(strhex)/2+1);
 
index 1df53dffbbdfee9108db7e486ca424642e8e7782..ebdd8039912bedd75ad6ff7a5ca7ac08d92f78f1 100755 (executable)
@@ -180,7 +180,8 @@ sub process_file($$$)
                }
 
                next unless ( $is_public || $line =~ /
-                             (_DEPRECATED_ )?^(void|BOOL|bool|int|struct|char|const|\w+_[tT]\s|uint|unsigned|long|NTSTATUS|
+                             (_DEPRECATED_ |_NORETURN_ |_WARN_UNUSED_RESULT_ |_PURE_ )*^(
+                                 void|BOOL|bool|int|struct|char|const|\w+_[tT]\s|uint|unsigned|long|NTSTATUS|
                                  ADS_STATUS|enum\s.*\(|DATA_BLOB|WERROR|XFILE|FILE|DIR|
                              double|TDB_CONTEXT|TDB_DATA|TALLOC_CTX|NTTIME|FN_|init_module|
                              GtkWidget|GType|smb_ucs2_t|krb5_error_code)
@@ -224,6 +225,10 @@ if ($public_file ne $private_file) {
 }
 
 public("#ifndef _PUBLIC_\n#define _PUBLIC_\n#endif\n\n");
+public("#ifndef _PURE_\n#define _PURE_\n#endif\n\n");
+public("#ifndef _NORETURN_\n#define _NORETURN_\n#endif\n\n");
+public("#ifndef _DEPRECATED_\n#define _DEPRECATED_\n#endif\n\n");
+public("#ifndef _WARN_UNUSED_RESULT_\n#define _WARN_UNUSED_RESULT_\n#endif\n\n");
 
 process_file(\&public, \&private, $_) foreach (@ARGV);
 print_footer(\&public, $public_define);