You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by ab...@apache.org on 2019/12/13 23:03:36 UTC

[kudu] 01/02: [util] a small clean-up on MAYBE_RETURN_FAILURE

This is an automated email from the ASF dual-hosted git repository.

abukor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit 5588a729c9769fad3a0ff6b1dfa4b8bb5c5505e0
Author: Alexey Serbin <al...@apache.org>
AuthorDate: Thu Dec 12 21:46:31 2019 -0800

    [util] a small clean-up on MAYBE_RETURN_FAILURE
    
    Updated MAYBE_RETURN_FAILURE macro to follow the 'do {...} while (0)'
    pattern so static code analyzers doesn't output warnings on an
    empty statements when encountering constructs like
    MAYBE_RETURN_FAILURE(...);
    
    This patch doesn't contain any functional modifications.
    
    Change-Id: Ieb9e172b4f2e1cfa712be08b9527f50bd0fe09e5
    Reviewed-on: http://gerrit.cloudera.org:8080/14899
    Tested-by: Alexey Serbin <as...@cloudera.com>
    Reviewed-by: Adar Dembo <ad...@cloudera.com>
    Reviewed-by: Andrew Wong <aw...@cloudera.com>
---
 src/kudu/util/env_posix.cc      |  2 +-
 src/kudu/util/fault_injection.h | 15 +++++++--------
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/kudu/util/env_posix.cc b/src/kudu/util/env_posix.cc
index cfe4b03..df29a32 100644
--- a/src/kudu/util/env_posix.cc
+++ b/src/kudu/util/env_posix.cc
@@ -125,7 +125,7 @@ typedef struct xfs_flock64 {
 #define MAYBE_RETURN_EIO(filename_expr, error_expr) do { \
   const string& f_ = (filename_expr); \
   MAYBE_RETURN_FAILURE(FLAGS_env_inject_eio, \
-      ShouldInject(f_, FLAGS_env_inject_eio_globs) ? (error_expr) : Status::OK()) \
+      ShouldInject(f_, FLAGS_env_inject_eio_globs) ? (error_expr) : Status::OK()); \
 } while (0)
 
 bool ShouldInject(const string& candidate, const string& glob_patterns) {
diff --git a/src/kudu/util/fault_injection.h b/src/kudu/util/fault_injection.h
index 7a71698..7e756c4 100644
--- a/src/kudu/util/fault_injection.h
+++ b/src/kudu/util/fault_injection.h
@@ -14,10 +14,9 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
-#ifndef KUDU_UTIL_FAULT_INJECTION_H
-#define KUDU_UTIL_FAULT_INJECTION_H
+#pragma once
 
-#include <stdint.h>
+#include <cstdint>
 
 #include "kudu/gutil/macros.h"
 #include "kudu/gutil/port.h"
@@ -52,9 +51,11 @@
 // With some probability, return the status described by 'status_expr'.
 // This will not evaluate 'status_expr' if 'fraction_flag' is zero.
 #define MAYBE_RETURN_FAILURE(fraction_flag, status_expr) \
-  if (kudu::fault_injection::MaybeTrue(fraction_flag)) { \
-    RETURN_NOT_OK((status_expr)); \
-  }
+  do { \
+    if (kudu::fault_injection::MaybeTrue(fraction_flag)) { \
+      RETURN_NOT_OK((status_expr)); \
+    } \
+  } while (false)
 
 // Implementation details below.
 // Use the MAYBE_FAULT macro instead.
@@ -92,7 +93,5 @@ inline void MaybeInjectFixedLatency(int32_t latency) {
   DoInjectFixedLatency(latency);
 }
 
-
 } // namespace fault_injection
 } // namespace kudu
-#endif /* KUDU_UTIL_FAULT_INJECTION_H */