]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
Replace some runtime assertions with compile-time assertions
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Thu, 11 Sep 2014 11:55:52 +0000 (12:55 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Mon, 15 Sep 2014 11:22:23 +0000 (12:22 +0100)
This requires a little bit of code re-ordering, because
_DBUS_STATIC_ASSERT can appear anywhere that a variable declaration
would be valid, i.e. not after executable code.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83767
Reviewed-by: Alban Crequy <alban.crequy@collabora.co.uk>
dbus/dbus-errors.c
dbus/dbus-hash.c
dbus/dbus-marshal-basic.c
dbus/dbus-message.c
dbus/dbus-signature.c
dbus/dbus-string.c
dbus/dbus-sysdeps-unix.c

index a0571a50e07d5828e00350e2c23887a6f661deb1..5d8f194e3c51a0e652b71459e68f60abde0596f2 100644 (file)
@@ -189,9 +189,9 @@ dbus_error_init (DBusError *error)
 {
   DBusRealError *real;
 
-  _dbus_return_if_fail (error != NULL);
+  _DBUS_STATIC_ASSERT (sizeof (DBusError) == sizeof (DBusRealError));
 
-  _dbus_assert (sizeof (DBusError) == sizeof (DBusRealError));
+  _dbus_return_if_fail (error != NULL);
 
   real = (DBusRealError *)error;
   
index c80835aaafe0fe8d38b2fe8131899f8df8eb8650..8f7d04bbf17a9e7c60c9c47b888d215c6ae48064 100644 (file)
@@ -519,7 +519,7 @@ _dbus_hash_iter_init (DBusHashTable *table,
 {
   DBusRealHashIter *real;
   
-  _dbus_assert (sizeof (DBusHashIter) == sizeof (DBusRealHashIter));
+  _DBUS_STATIC_ASSERT (sizeof (DBusHashIter) == sizeof (DBusRealHashIter));
   
   real = (DBusRealHashIter*) iter;
 
@@ -544,7 +544,7 @@ _dbus_hash_iter_next (DBusHashIter  *iter)
 {
   DBusRealHashIter *real;
   
-  _dbus_assert (sizeof (DBusHashIter) == sizeof (DBusRealHashIter));
+  _DBUS_STATIC_ASSERT (sizeof (DBusHashIter) == sizeof (DBusRealHashIter));
   
   real = (DBusRealHashIter*) iter;
 
@@ -746,7 +746,7 @@ _dbus_hash_iter_lookup (DBusHashTable *table,
   DBusHashEntry *entry;
   DBusHashEntry **bucket;
   
-  _dbus_assert (sizeof (DBusHashIter) == sizeof (DBusRealHashIter));
+  _DBUS_STATIC_ASSERT (sizeof (DBusHashIter) == sizeof (DBusRealHashIter));
   
   real = (DBusRealHashIter*) iter;
 
index eafc2a9ad71862427e386c5a7885b27273424c65..9bb5b761ac1f239708d71a8cb4455c510aa886c3 100644 (file)
@@ -599,7 +599,7 @@ marshal_2_octets (DBusString   *str,
   dbus_bool_t retval;
   int orig_len;
 
-  _dbus_assert (sizeof (value) == 2);
+  _DBUS_STATIC_ASSERT (sizeof (value) == 2);
 
   if (byte_order != DBUS_COMPILER_BYTE_ORDER)
     value = DBUS_UINT16_SWAP_LE_BE (value);
@@ -628,7 +628,7 @@ marshal_4_octets (DBusString   *str,
   dbus_bool_t retval;
   int orig_len;
 
-  _dbus_assert (sizeof (value) == 4);
+  _DBUS_STATIC_ASSERT (sizeof (value) == 4);
 
   if (byte_order != DBUS_COMPILER_BYTE_ORDER)
     value = DBUS_UINT32_SWAP_LE_BE (value);
@@ -657,7 +657,7 @@ marshal_8_octets (DBusString    *str,
   dbus_bool_t retval;
   int orig_len;
 
-  _dbus_assert (sizeof (value) == 8);
+  _DBUS_STATIC_ASSERT (sizeof (value) == 8);
 
   swap_8_octets (&value, byte_order);
 
index 78df75583dc8788dd2230dbd61d2affc7082f6f1..203a01641edc20ff586354eec6bdfafc074233f2 100644 (file)
@@ -2024,7 +2024,7 @@ _dbus_message_iter_init_common (DBusMessage         *message,
                                 DBusMessageRealIter *real,
                                 int                  iter_type)
 {
-  _dbus_assert (sizeof (DBusMessageRealIter) <= sizeof (DBusMessageIter));
+  _DBUS_STATIC_ASSERT (sizeof (DBusMessageRealIter) <= sizeof (DBusMessageIter));
 
   /* Since the iterator will read or write who-knows-what from the
    * message, we need to get in the right byte order
index 8a4701c9eb1cc7262d6155ad0e4d6a801966c7c9..6f1521b10df62b1cc4f6e8be02697524bbf3c98d 100644 (file)
@@ -428,7 +428,7 @@ _dbus_signature_test (void)
   const char *sig;
   dbus_bool_t boolres;
 
-  _dbus_assert (sizeof (DBusSignatureIter) >= sizeof (DBusSignatureRealIter));
+  _DBUS_STATIC_ASSERT (sizeof (DBusSignatureIter) >= sizeof (DBusSignatureRealIter));
 
   sig = "";
   _dbus_assert (dbus_signature_validate (sig, NULL));
index 2001074084f336bfa47222c47650b665fa902de3..15cff9c6f3ee576e7459eacd8eccdc61b15dab99 100644 (file)
@@ -133,11 +133,11 @@ _dbus_string_init_preallocated (DBusString *str,
                                 int         allocate_size)
 {
   DBusRealString *real;
-  
+
+  _DBUS_STATIC_ASSERT (sizeof (DBusString) == sizeof (DBusRealString));
+
   _dbus_assert (str != NULL);
 
-  _dbus_assert (sizeof (DBusString) == sizeof (DBusRealString));
-  
   real = (DBusRealString*) str;
 
   /* It's very important not to touch anything
index 170d8650e59fbd0934bf7783f8357013343a61cc..acff89e37cac2e72562da26e883b56a96d03a099 100644 (file)
@@ -1660,18 +1660,18 @@ _dbus_read_credentials_socket  (int              client_fd,
   } cmsg;
 #endif
 
-  uid_read = DBUS_UID_UNSET;
-  pid_read = DBUS_PID_UNSET;
-
-  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
   /* The POSIX spec certainly doesn't promise this, but
    * we need these assertions to fail as soon as we're wrong about
    * it so we can do the porting fixups
    */
-  _dbus_assert (sizeof (pid_t) <= sizeof (dbus_pid_t));
-  _dbus_assert (sizeof (uid_t) <= sizeof (dbus_uid_t));
-  _dbus_assert (sizeof (gid_t) <= sizeof (dbus_gid_t));
+  _DBUS_STATIC_ASSERT (sizeof (pid_t) <= sizeof (dbus_pid_t));
+  _DBUS_STATIC_ASSERT (sizeof (uid_t) <= sizeof (dbus_uid_t));
+  _DBUS_STATIC_ASSERT (sizeof (gid_t) <= sizeof (dbus_gid_t));
+
+  uid_read = DBUS_UID_UNSET;
+  pid_read = DBUS_PID_UNSET;
+
+  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
 
   _dbus_credentials_clear (credentials);
 
@@ -2352,9 +2352,9 @@ _dbus_credentials_add_from_current_process (DBusCredentials *credentials)
    * we need these assertions to fail as soon as we're wrong about
    * it so we can do the porting fixups
    */
-  _dbus_assert (sizeof (pid_t) <= sizeof (dbus_pid_t));
-  _dbus_assert (sizeof (uid_t) <= sizeof (dbus_uid_t));
-  _dbus_assert (sizeof (gid_t) <= sizeof (dbus_gid_t));
+  _DBUS_STATIC_ASSERT (sizeof (pid_t) <= sizeof (dbus_pid_t));
+  _DBUS_STATIC_ASSERT (sizeof (uid_t) <= sizeof (dbus_uid_t));
+  _DBUS_STATIC_ASSERT (sizeof (gid_t) <= sizeof (dbus_gid_t));
 
   if (!_dbus_credentials_add_pid(credentials, _dbus_getpid()))
     return FALSE;