Skip to content

Commit

Permalink
lib/replace: Do not typedef int bool
Browse files Browse the repository at this point in the history
We need a genuine boolean type, as otherwise expressions like

	bool foo = (4 & 4);
	if (foo == true) {
		exit(1);
	} else {
		exit(2);
	}

could evaluate differently on non-modern platforms, and
that would be a real pain to debug.

_Bool and bool are in C99

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15028

Signed-off-by: Andrew Bartlett <[email protected]>
Reviewed-by: Andreas Schneider <[email protected]>
Reviewed-by: Stefan Metzmacher <[email protected]>

Autobuild-User(master): Andreas Schneider <[email protected]>
Autobuild-Date(master): Wed Mar 23 12:31:47 UTC 2022 on sn-devel-184
  • Loading branch information
abartlet authored and cryptomilk committed Mar 23, 2022
1 parent 1bde388 commit c0f5af2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/perfcounter/perf.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#ifdef HAVE__Bool
#define bool _Bool
#else
typedef int bool;
#error Need a real boolean type
#endif
#endif

Expand Down
2 changes: 1 addition & 1 deletion lib/replace/replace.h
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ int rep_strerror_r(int errnum, char *buf, size_t buflen);
#ifdef HAVE__Bool
#define bool _Bool
#else
typedef int bool;
#error Need a real boolean type
#endif
#endif

Expand Down
5 changes: 3 additions & 2 deletions lib/replace/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ def configure(conf):
msg='Checking for O_DIRECT flag to open(2)')

conf.CHECK_TYPES('"long long" intptr_t uintptr_t ptrdiff_t comparison_fn_t')
conf.CHECK_TYPE('_Bool', define='HAVE__Bool')
conf.CHECK_TYPE('bool', define='HAVE_BOOL')
if not conf.CHECK_TYPE('bool', define='HAVE_BOOL'):
if not conf.CHECK_TYPE('_Bool', define='HAVE__Bool'):
raise Errors.WafError('Samba requires a genuine boolean type')

conf.CHECK_TYPE('int8_t', 'char')
conf.CHECK_TYPE('uint8_t', 'unsigned char')
Expand Down

0 comments on commit c0f5af2

Please sign in to comment.