The branch, master has been updated
       via  f74ae32 cast: make sure suncc sees a constant.
       via  be25ab9 cast: test/compile_fail-cast_static.c should fail without 
COMPOUND_LITERALS.
       via  3acce70 tdb2: fix prototype in tdb1 code.
      from  e36622f s4-upgradedns: Make sure the attribute exists before 
accessing it

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit f74ae3257a2edb9756d9f0442c1314306e936759
Author: Rusty Russell <[email protected]>
Date:   Thu Mar 29 14:58:33 2012 +1030

    cast: make sure suncc sees a constant.
    
    cast_const() et. al. are supposed to be a constant expression, so you can 
do things like:
        static char *p = cast_const(char *, (const char *)"hello");
    
    Unfortunately, a cast to intptr_t and arithmetic makes suncc reject it as
    a constant expression.  We need the cast, because (1) the expression could 
be
    a void *, so we can't just add to it, and (2) gcc complains with -Wcast-qual
    without it.
    
    So instead of adding BUILD_BUG_OR_ZERO, we use a ? :, which keeps everyone 
happy.
    
    Signed-off-by: Rusty Russell <[email protected]>
    (Imported from CCAN commit 74859ab18b10aaf990848e49d7789ff5c6cf96c6)
    
    Autobuild-User: Rusty Russell <[email protected]>
    Autobuild-Date: Thu Mar 29 08:18:57 CEST 2012 on sn-devel-104

commit be25ab9c8df2f96ee10929fdfee582935b2f0e06
Author: Rusty Russell <[email protected]>
Date:   Tue Mar 27 15:40:45 2012 +1030

    cast: test/compile_fail-cast_static.c should fail without COMPOUND_LITERALS.
    
    It still gave a warning on gcc, because casting a char to a char* gives a 
warning.  Not so on sun CC.
    
    Signed-off-by: Rusty Russell <[email protected]>
    (Imported from CCAN commit 6569a707d169a629e25e10710c760c8dc84525c7)

commit 3acce707a32a28c309133583b8cd1a554f19a8b3
Author: Rusty Russell <[email protected]>
Date:   Mon Mar 26 14:33:17 2012 +1030

    tdb2: fix prototype in tdb1 code.
    
    We were handing an int-returning function where we should hand an enum 
TDB_ERROR
    returning function.  Worse, it was returning 0/-1 instead of 0/TDB_ERR_*.
    
    Fortunately, it's only compared against success, but the Solaris compiler
    warns about it, and it's not correct anyway.
    
    Signed-off-by: Rusty Russell <[email protected]>

-----------------------------------------------------------------------

Summary of changes:
 lib/ccan/cast/cast.h                          |   20 ++++++++++++--------
 lib/ccan/cast/test/compile_fail-cast_static.c |   12 +++++++++---
 lib/ccan/cast/test/compile_ok-static.c        |   10 ++++++++++
 lib/tdb2/tdb1_tdb.c                           |   10 +++++-----
 4 files changed, 36 insertions(+), 16 deletions(-)
 create mode 100644 lib/ccan/cast/test/compile_ok-static.c


Changeset truncated at 500 lines:

diff --git a/lib/ccan/cast/cast.h b/lib/ccan/cast/cast.h
index b108b0c..1f3a7aa 100644
--- a/lib/ccan/cast/cast.h
+++ b/lib/ccan/cast/cast.h
@@ -15,8 +15,8 @@
  * only differs in signed/unsigned, not in type or const-ness.
  */
 #define cast_signed(type, expr)                                                
\
-       ((type)(expr)                                                   \
-        + BUILD_ASSERT_OR_ZERO(cast_sign_compatible(type, (expr))))
+       (0 ? BUILD_ASSERT_OR_ZERO(cast_sign_compatible(type, (expr))) : \
+        (type)(expr))
 
 /**
  * cast_const - remove a const qualifier from a pointer.
@@ -26,6 +26,10 @@
  * This ensures that you are only removing the const qualifier from an
  * expression.  The expression must otherwise match @type.
  *
+ * We cast via intptr_t to suppress gcc's -Wcast-qual (which SAMBA
+ * uses), and via the ? : so Sun CC doesn't complain about the result
+ * not being constant.
+ *
  * If @type is a pointer to a pointer, you must use cast_const2 (etc).
  *
  * Example:
@@ -40,8 +44,8 @@
  *     }
  */
 #define cast_const(type, expr)                                         \
-       ((type)((intptr_t)(expr)                                        \
-               + BUILD_ASSERT_OR_ZERO(cast_const_compat1((expr), type))))
+        (0 ? BUILD_ASSERT_OR_ZERO(cast_const_compat1((expr), type)) :   \
+         (type)(intptr_t)(expr))
 
 /**
  * cast_const2 - remove a const qualifier from a pointer to a pointer.
@@ -52,8 +56,8 @@
  * expression.  The expression must otherwise match @type.
  */
 #define cast_const2(type, expr)                                                
\
-       ((type)((intptr_t)(expr)                                        \
-               + BUILD_ASSERT_OR_ZERO(cast_const_compat2((expr), type))))
+        (0 ? BUILD_ASSERT_OR_ZERO(cast_const_compat2((expr), type)) :   \
+        (type)(intptr_t)(expr))
 
 /**
  * cast_const3 - remove a const from a pointer to a pointer to a pointer..
@@ -64,8 +68,8 @@
  * expression.  The expression must otherwise match @type.
  */
 #define cast_const3(type, expr)                                                
\
-       ((type)((intptr_t)(expr)                                        \
-               + BUILD_ASSERT_OR_ZERO(cast_const_compat3((expr), type))))
+        (0 ? BUILD_ASSERT_OR_ZERO(cast_const_compat3((expr), type)) :   \
+        (type)(intptr_t)(expr))
 
 
 /**
diff --git a/lib/ccan/cast/test/compile_fail-cast_static.c 
b/lib/ccan/cast/test/compile_fail-cast_static.c
index 0f9e478..a4ebf61 100644
--- a/lib/ccan/cast/test/compile_fail-cast_static.c
+++ b/lib/ccan/cast/test/compile_fail-cast_static.c
@@ -3,15 +3,21 @@
 
 int main(int argc, char *argv[])
 {
-       char c;
+       long c;
 #ifdef FAIL
        char *
 #else
-       long
+       char
 #endif
                x = 0;
 
-       c = cast_static(char, x);
+       c = cast_static(long, x);
        (void) c; /* Suppress unused-but-set-variable warning. */
        return 0;
 }
+
+#ifdef FAIL
+#if !HAVE_COMPOUND_LITERALS
+#error "Unfortunately we don't fail if cast_static without compound literals"
+#endif
+#endif
diff --git a/lib/ccan/cast/test/compile_ok-static.c 
b/lib/ccan/cast/test/compile_ok-static.c
new file mode 100644
index 0000000..98b667e
--- /dev/null
+++ b/lib/ccan/cast/test/compile_ok-static.c
@@ -0,0 +1,10 @@
+/* OpenIndiana's CC (aka suncc) has issues with constants: make sure
+ * we are one! */
+#include <ccan/cast/cast.h>
+
+static char *p = cast_const(char *, (const char *)"hello");
+
+int main(int argc, char *argv[])
+{
+       return p[0] == argv[0][0];
+}
diff --git a/lib/tdb2/tdb1_tdb.c b/lib/tdb2/tdb1_tdb.c
index 869672a..ae633ed 100644
--- a/lib/tdb2/tdb1_tdb.c
+++ b/lib/tdb2/tdb1_tdb.c
@@ -146,17 +146,17 @@ tdb1_off_t tdb1_find_lock_hash(struct tdb_context *tdb, 
TDB_DATA key, uint32_t h
 
 static TDB_DATA _tdb1_fetch(struct tdb_context *tdb, TDB_DATA key);
 
-static int tdb_update_hash_cmp(TDB_DATA key, TDB_DATA data, void *private_data)
+static enum TDB_ERROR tdb_update_hash_cmp(TDB_DATA key, TDB_DATA data, void 
*private_data)
 {
        TDB_DATA *dbuf = (TDB_DATA *)private_data;
 
        if (dbuf->dsize != data.dsize) {
-               return -1;
+               return TDB_ERR_EINVAL;
        }
        if (memcmp(dbuf->dptr, data.dptr, data.dsize) != 0) {
-               return -1;
+               return TDB_ERR_EINVAL;
        }
-       return 0;
+       return TDB_SUCCESS;
 }
 
 /* update an entry in place - this only works if the new data size
@@ -177,7 +177,7 @@ static int tdb1_update_hash(struct tdb_context *tdb, 
TDB_DATA key, uint32_t hash
        if (rec.key_len == key.dsize &&
            rec.data_len == dbuf.dsize &&
            rec.full_hash == hash &&
-           tdb1_parse_record(tdb, key, tdb_update_hash_cmp, &dbuf) == 0) {
+           tdb1_parse_record(tdb, key, tdb_update_hash_cmp, &dbuf) == 
TDB_SUCCESS) {
                        return 0;
        }
 


-- 
Samba Shared Repository

Reply via email to