Commit ac509d88877c07bb06497206d74a2baa25b6d895
1 parent
2acf5af0
Move offsetof to osdep.h, remove local defintions.
With this container_of can actually be used without causing build errors. Reformat container_of. git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5234 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
5 changed files
with
7 additions
and
18 deletions
block-qcow2.c
@@ -61,10 +61,6 @@ | @@ -61,10 +61,6 @@ | ||
61 | 61 | ||
62 | #define REFCOUNT_SHIFT 1 /* refcount size is 2 bytes */ | 62 | #define REFCOUNT_SHIFT 1 /* refcount size is 2 bytes */ |
63 | 63 | ||
64 | -#ifndef offsetof | ||
65 | -#define offsetof(type, field) ((size_t) &((type *)0)->field) | ||
66 | -#endif | ||
67 | - | ||
68 | typedef struct QCowHeader { | 64 | typedef struct QCowHeader { |
69 | uint32_t magic; | 65 | uint32_t magic; |
70 | uint32_t version; | 66 | uint32_t version; |
exec-all.h
@@ -256,10 +256,6 @@ static inline void tb_add_jump(TranslationBlock *tb, int n, | @@ -256,10 +256,6 @@ static inline void tb_add_jump(TranslationBlock *tb, int n, | ||
256 | 256 | ||
257 | TranslationBlock *tb_find_pc(unsigned long pc_ptr); | 257 | TranslationBlock *tb_find_pc(unsigned long pc_ptr); |
258 | 258 | ||
259 | -#ifndef offsetof | ||
260 | -#define offsetof(type, field) ((size_t) &((type *)0)->field) | ||
261 | -#endif | ||
262 | - | ||
263 | #if defined(_WIN32) | 259 | #if defined(_WIN32) |
264 | #define ASM_DATA_SECTION ".section \".data\"\n" | 260 | #define ASM_DATA_SECTION ".section \".data\"\n" |
265 | #define ASM_PREVIOUS_SECTION ".section .text\n" | 261 | #define ASM_PREVIOUS_SECTION ".section .text\n" |
linux-user/signal.c
@@ -549,10 +549,6 @@ int do_sigaction(int sig, const struct target_sigaction *act, | @@ -549,10 +549,6 @@ int do_sigaction(int sig, const struct target_sigaction *act, | ||
549 | return ret; | 549 | return ret; |
550 | } | 550 | } |
551 | 551 | ||
552 | -#ifndef offsetof | ||
553 | -#define offsetof(type, field) ((size_t) &((type *)0)->field) | ||
554 | -#endif | ||
555 | - | ||
556 | static inline int copy_siginfo_to_user(target_siginfo_t *tinfo, | 552 | static inline int copy_siginfo_to_user(target_siginfo_t *tinfo, |
557 | const target_siginfo_t *info) | 553 | const target_siginfo_t *info) |
558 | { | 554 | { |
monitor.c
@@ -40,10 +40,6 @@ | @@ -40,10 +40,6 @@ | ||
40 | //#define DEBUG | 40 | //#define DEBUG |
41 | //#define DEBUG_COMPLETION | 41 | //#define DEBUG_COMPLETION |
42 | 42 | ||
43 | -#ifndef offsetof | ||
44 | -#define offsetof(type, field) ((size_t) &((type *)0)->field) | ||
45 | -#endif | ||
46 | - | ||
47 | /* | 43 | /* |
48 | * Supported types: | 44 | * Supported types: |
49 | * | 45 | * |
osdep.h
@@ -23,9 +23,14 @@ | @@ -23,9 +23,14 @@ | ||
23 | #define unlikely(x) __builtin_expect(!!(x), 0) | 23 | #define unlikely(x) __builtin_expect(!!(x), 0) |
24 | #endif | 24 | #endif |
25 | 25 | ||
26 | +#ifndef offsetof | ||
27 | +#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER) | ||
28 | +#endif | ||
29 | +#ifndef container_of | ||
26 | #define container_of(ptr, type, member) ({ \ | 30 | #define container_of(ptr, type, member) ({ \ |
27 | - const typeof( ((type *)0)->member ) *__mptr = (ptr); \ | ||
28 | - (type *)( (char *)__mptr - offsetof(type,member) );}) | 31 | + const typeof(((type *) 0)->member) *__mptr = (ptr); \ |
32 | + (type *) ((char *) __mptr - offsetof(type, member));}) | ||
33 | +#endif | ||
29 | 34 | ||
30 | #ifndef MIN | 35 | #ifndef MIN |
31 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) | 36 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) |