Make file.h C++ safe by casting fio_file_flags
authorDaniel Gollub <daniel.gollub@t-online.de>
Wed, 12 Feb 2014 14:51:54 +0000 (15:51 +0100)
committerJens Axboe <axboe@fb.com>
Wed, 12 Feb 2014 15:23:23 +0000 (08:23 -0700)
Fixes for g++ (4.7.2) following compiler errors when fio.h
gets included (e.g. in an external C++ ioengine):

--8<---
[...]
os/../file.h: In function ‘void fio_file_set_open(fio_file*)’:
os/../file.h:142:1: error: invalid conversion from ‘int’ to ‘fio_file_flags’ [-fpermissive]
os/../file.h: In function ‘void fio_file_clear_open(fio_file*)’:
os/../file.h:142:1: error: invalid conversion from ‘int’ to ‘fio_file_flags’ [-fpermissive]
os/../file.h: In function ‘void fio_file_set_closing(fio_file*)’:
[...]
--->8---

Signed-off-by: Daniel Gollub <d.gollub@telekom.de>
Signed-off-by: Jens Axboe <axboe@fb.com>
file.h

diff --git a/file.h b/file.h
index 19413fc8fa777d96b419e62c2c9d0c8433b4c2b2..c1d02a5bea57add8d9049aad117fb91592740459 100644 (file)
--- a/file.h
+++ b/file.h
@@ -128,11 +128,11 @@ struct fio_file {
 #define FILE_FLAG_FNS(name)                                            \
 static inline void fio_file_set_##name(struct fio_file *f)             \
 {                                                                      \
 #define FILE_FLAG_FNS(name)                                            \
 static inline void fio_file_set_##name(struct fio_file *f)             \
 {                                                                      \
-       (f)->flags |= FIO_FILE_##name;                                  \
+       (f)->flags = (enum fio_file_flags) ((f)->flags | FIO_FILE_##name);      \
 }                                                                      \
 static inline void fio_file_clear_##name(struct fio_file *f)           \
 {                                                                      \
 }                                                                      \
 static inline void fio_file_clear_##name(struct fio_file *f)           \
 {                                                                      \
-       (f)->flags &= ~FIO_FILE_##name;                                 \
+       (f)->flags = (enum fio_file_flags) ((f)->flags & ~FIO_FILE_##name);     \
 }                                                                      \
 static inline int fio_file_##name(struct fio_file *f)                  \
 {                                                                      \
 }                                                                      \
 static inline int fio_file_##name(struct fio_file *f)                  \
 {                                                                      \