[x265] [PATCH 1 of 2] cmake: add CHECKED_BUILD option so we can add optional runtime checking

Steve Borho steve at borho.org
Tue May 6 07:14:40 CEST 2014


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1399350389 18000
#      Mon May 05 23:26:29 2014 -0500
# Node ID 5c590a31734b50d357651cd0536d21c56985d764
# Parent  075705aa41a9144bb1a4d7f12d837169767630e1
cmake: add CHECKED_BUILD option so we can add optional runtime checking

diff -r 075705aa41a9 -r 5c590a31734b source/CMakeLists.txt
--- a/source/CMakeLists.txt	Mon May 05 23:26:59 2014 -0500
+++ b/source/CMakeLists.txt	Mon May 05 23:26:29 2014 -0500
@@ -27,6 +27,11 @@
 
 SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" "${CMAKE_MODULE_PATH}")
 
+option(CHECKED_BUILD "Enable run-time sanity checks (debugging)" OFF)
+if(CHECKED_BUILD)
+    add_definitions(-DCHECKED_BUILD=1)
+endif()
+
 # System architecture detection
 string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" SYSPROC)
 set(X86_ALIASES x86 i386 i686 x86_64 amd64)
diff -r 075705aa41a9 -r 5c590a31734b source/common/common.h
--- a/source/common/common.h	Mon May 05 23:26:59 2014 -0500
+++ b/source/common/common.h	Mon May 05 23:26:29 2014 -0500
@@ -64,6 +64,18 @@
 
 #endif // if defined(__GNUC__)
 
+/* If compiled with CHECKED_BUILD perform run-time checks and log any that
+ * fail, both to stderr and to a file */
+#if CHECKED_BUILD
+#define X265_CHECK(expr, ...) if (!(expr)) { \
+    x265_log(NULL, X265_LOG_ERROR, __VA_ARGS__); \
+    FILE *fp = fopen("x265_check_failures.txt", "a"); \
+    if (fp) { fprintf(fp, "%s:%d\n", __FILE__, __LINE__); fprintf(fp, __VA_ARGS__); fclose(fp); } \
+}
+#else
+#define X265_CHECK(expr, ...)
+#endif
+
 #if HIGH_BIT_DEPTH
 typedef uint16_t pixel;
 typedef uint32_t sum_t;
diff -r 075705aa41a9 -r 5c590a31734b source/common/version.cpp
--- a/source/common/version.cpp	Mon May 05 23:26:59 2014 -0500
+++ b/source/common/version.cpp	Mon May 05 23:26:29 2014 -0500
@@ -68,9 +68,15 @@
 #endif
 
 #if X86_64
-#define NVM_BITS          "[64 bit] "
+#define NVM_BITS        "[64 bit]"
 #else
-#define NVM_BITS          "[32 bit] "
+#define NVM_BITS        "[32 bit]"
+#endif
+
+#if CHECKED_BUILD
+#define CHECKED         "[CHECKED] "
+#else
+#define CHECKED         " "
 #endif
 
 #if HIGH_BIT_DEPTH
@@ -82,4 +88,4 @@
 #endif
 
 const char *x265_version_str = XSTR(X265_VERSION);
-const char *x265_build_info_str = NVM_ONOS NVM_COMPILEDBY NVM_BITS BITDEPTH;
+const char *x265_build_info_str = NVM_ONOS NVM_COMPILEDBY NVM_BITS CHECKED BITDEPTH;


More information about the x265-devel mailing list