summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2016-08-17 16:39:26 -0800
committerKent Overstreet <kent.overstreet@gmail.com>2016-08-27 05:27:01 -0800
commitcf5d9245a12234f156a3534fc50db07705223eb4 (patch)
tree350774df7d1b4f37469b3dd9d9e3ba8b7f1df931
parent09e9374b5eef9da7466f7f19bb65c5d1b6a0c0aa (diff)
bcache: move type_is() to util.h
-rw-r--r--drivers/md/bcache/bkey.h4
-rw-r--r--drivers/md/bcache/util.h45
2 files changed, 19 insertions, 30 deletions
diff --git a/drivers/md/bcache/bkey.h b/drivers/md/bcache/bkey.h
index 881c5ebea4f3..1e68822e13bd 100644
--- a/drivers/md/bcache/bkey.h
+++ b/drivers/md/bcache/bkey.h
@@ -25,10 +25,6 @@ struct bkey_s {
};
};
-#define type_is(_val, _type) \
- (__builtin_types_compatible_p(typeof(_val), _type) || \
- __builtin_types_compatible_p(typeof(_val), const _type))
-
#define bkey_next(_k) \
({ \
BUILD_BUG_ON(!type_is(_k, struct bkey *) && \
diff --git a/drivers/md/bcache/util.h b/drivers/md/bcache/util.h
index f451e4a08e39..9f52ba08b943 100644
--- a/drivers/md/bcache/util.h
+++ b/drivers/md/bcache/util.h
@@ -61,6 +61,10 @@ struct closure;
#define CPU_BIG_ENDIAN 1
#endif
+#define type_is(_val, _type) \
+ (__builtin_types_compatible_p(typeof(_val), _type) || \
+ __builtin_types_compatible_p(typeof(_val), const _type))
+
#define DECLARE_HEAP(type, name) \
struct { \
size_t size, used; \
@@ -243,18 +247,13 @@ static inline int bch_strtoul_h(const char *cp, long *res)
}
#define strtoi_h(cp, res) \
- (__builtin_types_compatible_p(typeof(*res), int) \
- ? bch_strtoint_h(cp, (void *) res) \
- : __builtin_types_compatible_p(typeof(*res), long) \
- ? bch_strtol_h(cp, (void *) res) \
- : __builtin_types_compatible_p(typeof(*res), long long) \
- ? bch_strtoll_h(cp, (void *) res) \
- : __builtin_types_compatible_p(typeof(*res), unsigned int) \
- ? bch_strtouint_h(cp, (void *) res) \
- : __builtin_types_compatible_p(typeof(*res), unsigned long) \
- ? bch_strtoul_h(cp, (void *) res) \
- : __builtin_types_compatible_p(typeof(*res), unsigned long long)\
- ? bch_strtoull_h(cp, (void *) res) : -EINVAL)
+ ( type_is(*res, int) ? bch_strtoint_h(cp, (void *) res)\
+ : type_is(*res, long) ? bch_strtol_h(cp, (void *) res)\
+ : type_is(*res, long long) ? bch_strtoll_h(cp, (void *) res)\
+ : type_is(*res, unsigned) ? bch_strtouint_h(cp, (void *) res)\
+ : type_is(*res, unsigned long) ? bch_strtoul_h(cp, (void *) res)\
+ : type_is(*res, unsigned long long) ? bch_strtoull_h(cp, (void *) res)\
+ : -EINVAL)
#define strtoul_safe(cp, var) \
({ \
@@ -287,20 +286,14 @@ static inline int bch_strtoul_h(const char *cp, long *res)
#define snprint(buf, size, var) \
snprintf(buf, size, \
- __builtin_types_compatible_p(typeof(var), int) \
- ? "%i\n" : \
- __builtin_types_compatible_p(typeof(var), unsigned) \
- ? "%u\n" : \
- __builtin_types_compatible_p(typeof(var), long) \
- ? "%li\n" : \
- __builtin_types_compatible_p(typeof(var), unsigned long)\
- ? "%lu\n" : \
- __builtin_types_compatible_p(typeof(var), int64_t) \
- ? "%lli\n" : \
- __builtin_types_compatible_p(typeof(var), uint64_t) \
- ? "%llu\n" : \
- __builtin_types_compatible_p(typeof(var), const char *) \
- ? "%s\n" : "%i\n", var)
+ type_is(var, int) ? "%i\n" \
+ : type_is(var, unsigned) ? "%u\n" \
+ : type_is(var, long) ? "%li\n" \
+ : type_is(var, unsigned long) ? "%lu\n" \
+ : type_is(var, s64) ? "%lli\n" \
+ : type_is(var, u64) ? "%llu\n" \
+ : type_is(var, char *) ? "%s\n" \
+ : "%i\n", var)
ssize_t bch_hprint(char *buf, int64_t v);