]> granicus.if.org Git - libvpx/commitdiff
add static_assert.h
authorJames Zern <jzern@google.com>
Sat, 18 Jan 2020 07:15:19 +0000 (23:15 -0800)
committerJames Zern <jzern@google.com>
Sat, 18 Jan 2020 07:17:46 +0000 (23:17 -0800)
unify COMPILE_TIME_ASSERT definitions and rename to VPX_STATIC_ASSERT

Change-Id: Id51150c204e0c4eaf355ee45b20915113209d524

vp8/vp8_cx_iface.c
vp9/vp9_cx_iface.c
vpx_ports/static_assert.h [new file with mode: 0644]
vpx_ports/vpx_ports.mk

index 07ea52c053b52edaa3e76ae8c820259c7ce7716f..8f7617abf9c033223cb719d813e093821c3fd1c7 100644 (file)
@@ -16,6 +16,7 @@
 #include "vpx/internal/vpx_codec_internal.h"
 #include "vpx_version.h"
 #include "vpx_mem/vpx_mem.h"
+#include "vpx_ports/static_assert.h"
 #include "vpx_ports/system_state.h"
 #include "vpx_ports/vpx_once.h"
 #include "vpx_util/vpx_timestamp.h"
@@ -131,22 +132,6 @@ static vpx_codec_err_t update_error_state(
     if (!!((p)->memb) != (p)->memb) ERROR(#memb " expected boolean"); \
   } while (0)
 
-#if defined(_MSC_VER)
-#define COMPILE_TIME_ASSERT(boolexp)              \
-  do {                                            \
-    char compile_time_assert[(boolexp) ? 1 : -1]; \
-    (void)compile_time_assert;                    \
-  } while (0)
-#else /* !_MSC_VER */
-#define COMPILE_TIME_ASSERT(boolexp)                         \
-  do {                                                       \
-    struct {                                                 \
-      unsigned int compile_time_assert : (boolexp) ? 1 : -1; \
-    } compile_time_assert;                                   \
-    (void)compile_time_assert;                               \
-  } while (0)
-#endif /* _MSC_VER */
-
 static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
                                        const vpx_codec_enc_cfg_t *cfg,
                                        const struct vp8_extracfg *vp8_cfg,
@@ -751,8 +736,8 @@ static void pick_quickcompress_mode(vpx_codec_alg_priv_t *ctx,
     /* Convert duration parameter from stream timebase to microseconds */
     uint64_t duration_us;
 
-    COMPILE_TIME_ASSERT(TICKS_PER_SEC > 1000000 &&
-                        (TICKS_PER_SEC % 1000000) == 0);
+    VPX_STATIC_ASSERT(TICKS_PER_SEC > 1000000 &&
+                      (TICKS_PER_SEC % 1000000) == 0);
 
     duration_us = duration * (uint64_t)ctx->timestamp_ratio.num /
                   (ctx->timestamp_ratio.den * (TICKS_PER_SEC / 1000000));
index baea0ece1931a41f572881bcc9137e1d847b194d..0709c642872bb334af94b6c15ae34a02b6aefbec 100644 (file)
@@ -15,6 +15,7 @@
 #include "vpx/vpx_encoder.h"
 #include "vpx_dsp/psnr.h"
 #include "vpx_ports/vpx_once.h"
+#include "vpx_ports/static_assert.h"
 #include "vpx_ports/system_state.h"
 #include "vpx_util/vpx_timestamp.h"
 #include "vpx/internal/vpx_codec_internal.h"
@@ -160,22 +161,6 @@ static vpx_codec_err_t update_error_state(
     if (!!((p)->memb) != (p)->memb) ERROR(#memb " expected boolean"); \
   } while (0)
 
-#if defined(_MSC_VER)
-#define COMPILE_TIME_ASSERT(boolexp)              \
-  do {                                            \
-    char compile_time_assert[(boolexp) ? 1 : -1]; \
-    (void)compile_time_assert;                    \
-  } while (0)
-#else  // !_MSC_VER
-#define COMPILE_TIME_ASSERT(boolexp)                         \
-  do {                                                       \
-    struct {                                                 \
-      unsigned int compile_time_assert : (boolexp) ? 1 : -1; \
-    } compile_time_assert;                                   \
-    (void)compile_time_assert;                               \
-  } while (0)
-#endif  // _MSC_VER
-
 static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
                                        const vpx_codec_enc_cfg_t *cfg,
                                        const struct vp9_extracfg *extra_cfg) {
@@ -968,8 +953,8 @@ static void pick_quickcompress_mode(vpx_codec_alg_priv_t *ctx,
         // Convert duration parameter from stream timebase to microseconds.
         uint64_t duration_us;
 
-        COMPILE_TIME_ASSERT(TICKS_PER_SEC > 1000000 &&
-                            (TICKS_PER_SEC % 1000000) == 0);
+        VPX_STATIC_ASSERT(TICKS_PER_SEC > 1000000 &&
+                          (TICKS_PER_SEC % 1000000) == 0);
 
         duration_us = duration * (uint64_t)ctx->timestamp_ratio.num /
                       (ctx->timestamp_ratio.den * (TICKS_PER_SEC / 1000000));
diff --git a/vpx_ports/static_assert.h b/vpx_ports/static_assert.h
new file mode 100644 (file)
index 0000000..f632d9f
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ *  Copyright (c) 2020 The WebM project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef VPX_VPX_PORTS_STATIC_ASSERT_H_
+#define VPX_VPX_PORTS_STATIC_ASSERT_H_
+
+#if defined(_MSC_VER)
+#define VPX_STATIC_ASSERT(boolexp)              \
+  do {                                          \
+    char vpx_static_assert[(boolexp) ? 1 : -1]; \
+    (void)vpx_static_assert;                    \
+  } while (0)
+#else  // !_MSC_VER
+#define VPX_STATIC_ASSERT(boolexp)                         \
+  do {                                                     \
+    struct {                                               \
+      unsigned int vpx_static_assert : (boolexp) ? 1 : -1; \
+    } vpx_static_assert;                                   \
+    (void)vpx_static_assert;                               \
+  } while (0)
+#endif  // _MSC_VER
+
+#endif  // VPX_VPX_PORTS_STATIC_ASSERT_H_
index ef17f0ad2c57abd68c15612bdbe0ef9811d6d9e1..53fbd1e80086837ecad3e82924e4edd1337644fa 100644 (file)
@@ -14,6 +14,7 @@ PORTS_SRCS-yes += vpx_ports.mk
 PORTS_SRCS-yes += bitops.h
 PORTS_SRCS-yes += mem.h
 PORTS_SRCS-yes += msvc.h
+PORTS_SRCS-yes += static_assert.h
 PORTS_SRCS-yes += system_state.h
 PORTS_SRCS-yes += vpx_timer.h