Page Menu
Home
Search
Configure Global Search
Log In
Files
F23929
ldo-stdbool.patch
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Lawrence D'Oliveiro (ldo)
Nov 13 2013, 5:16 PM
Size
2 KB
Subscribers
None
ldo-stdbool.patch
View Options
commit c4bc00459fa495ce0583bf7ce3eda73d813a4f99
Author: Lawrence D'Oliveiro <ldo@geek-central.gen.nz>
Date: Wed Nov 28 03:19:40 2012 +0000
Beginnings of conversion of all ad-hoc boolean usage to C99-compliant stdbool:
add definitions of "bool" type with values "false" and "true", along with option
to drop old "FALSE" and "TRUE" definitions in future.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 69ddaa1..9f02e50 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -99,6 +99,10 @@ blender_project_hack_post()
enable_testing()
+try_compile(
+ HAVE_STDBOOL_H "${CMAKE_BINARY_DIR}/bin" "${CMAKE_SOURCE_DIR}/build_files/cmake/queries/stdbool.c"
+)
+
#-----------------------------------------------------------------------------
# Redirect output files
@@ -149,6 +153,9 @@ mark_as_advanced(WITH_HEADLESS)
option(WITH_AUDASPACE "Build with blenders audio library (only disable if you know what you're doing!)" ON)
mark_as_advanced(WITH_AUDASPACE)
+option(BOOL_COMPAT "Continue defining \"TRUE\" and \"FALSE\" until these can be replaced with \"true\" and \"false\" from stdbool.h" ON)
+mark_as_advanced(BOOL_COMPAT)
+
# (unix defaults to OpenMP On)
if((UNIX AND NOT APPLE) OR (MINGW))
@@ -269,6 +276,12 @@ mark_as_advanced(WITH_CXX_GUARDEDALLOC)
option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF)
mark_as_advanced(WITH_ASSERT_ABORT)
+if(HAVE_STDBOOL_H)
+ add_definitions(-DHAVE_STDBOOL_H)
+endif()
+if(BOOL_COMPAT)
+ add_definitions(-DBOOL_COMPAT)
+endif()
if(APPLE)
if(NOT CMAKE_OSX_ARCHITECTURES)
@@ -2106,3 +2119,8 @@ if(FIRST_RUN)
message("${_config_msg}")
endif()
+
+# debug
+message(
+ STATUS "HAVE_STDBOOL_H = ${HAVE_STDBOOL_H}"
+)
diff --git a/build_files/cmake/queries/stdbool.c b/build_files/cmake/queries/stdbool.c
new file mode 100644
index 0000000..975a6f1
--- /dev/null
+++ b/build_files/cmake/queries/stdbool.c
@@ -0,0 +1,14 @@
+/*
+ This program will compile correctly if and only if
+ this C compiler supports C99 stdbool.
+
+ Written by Lawrence D'Oliveiro <ldo@geek-central.gen.nz>.
+*/
+
+#include <stdbool.h>
+
+int main(void)
+ {
+ return
+ 0;
+ } /*main*/
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h
index 7c3b705..be1dd97 100644
--- a/source/blender/blenlib/BLI_utildefines.h
+++ b/source/blender/blenlib/BLI_utildefines.h
@@ -32,12 +32,31 @@
* \ingroup bli
*/
-#ifndef FALSE
-# define FALSE 0
+#ifdef HAVE_STDBOOL_H
+# include <stdbool.h>
+#else
+# ifndef HAVE__BOOL
+# ifdef __cplusplus
+typedef bool _Bool;
+# else
+# define _Bool signed char
+# endif
+# endif
+# define bool _Bool
+# define false 0
+# define true 1
+# define __bool_true_false_are_defined 1
#endif
-#ifndef TRUE
-# define TRUE 1
+#ifdef BOOL_COMPAT
+/* interim until all occurrences of these can be updated to stdbool */
+# ifndef FALSE
+# define FALSE 0
+# endif
+
+# ifndef TRUE
+# define TRUE 1
+# endif
#endif
/* useful for finding bad use of min/max */
File Metadata
Details
Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
2c/06/e8885844b372c88c02867bea68c3
Event Timeline
Log In to Comment