From 3395fdcd6ab08d881ee3bfbb50413eb1c445595d Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Mon, 12 Jan 2015 19:04:33 +0100 Subject: [PATCH] gcc4 build fix. * offsetof is not allowed on non-POD types so we need to use offset_of_member (gcc2 accepts offsetof, and C++11 relaxed the constraints on where it is allowed so it should work there too) * we have offset_of_member as a workaround until we switch to C++11, move it from khash (which is soon to be removed) to list.h which is the other place where it is used (for this one single call in our whole codebase) Also fix a typo in vfs.cpp. --- headers/private/kernel/util/khash.h | 7 ------- headers/private/kernel/util/list.h | 9 +++++++++ src/system/kernel/fs/vfs.cpp | 5 +++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/headers/private/kernel/util/khash.h b/headers/private/kernel/util/khash.h index ae1b71fd5a..609b08a58d 100644 --- a/headers/private/kernel/util/khash.h +++ b/headers/private/kernel/util/khash.h @@ -12,13 +12,6 @@ #include -// The use of offsetof() on non-PODs is invalid. Since many structs use -// templated members (i.e. DoublyLinkedList) which makes them non-PODs we -// can't use offsetof() anymore. This macro does the same, but requires an -// instance of the object in question. -#define offset_of_member(OBJECT, MEMBER) \ - ((size_t)((char*)&OBJECT.MEMBER - (char*)&OBJECT)) - // can be allocated on the stack typedef struct hash_iterator { void *current; diff --git a/headers/private/kernel/util/list.h b/headers/private/kernel/util/list.h index 94102e0291..5424c10fb6 100644 --- a/headers/private/kernel/util/list.h +++ b/headers/private/kernel/util/list.h @@ -20,6 +20,15 @@ * you don't have to care about the difference between a link and an item. */ + +// The use of offsetof() on non-PODs is invalid. Since many structs use +// templated members (i.e. DoublyLinkedList) which makes them non-PODs we +// can't use offsetof() anymore. This macro does the same, but requires an +// instance of the object in question. +#define offset_of_member(OBJECT, MEMBER) \ + ((size_t)((char*)&OBJECT.MEMBER - (char*)&OBJECT)) + + typedef struct list_link list_link; /* The object that is put into the list must begin with these diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp index 5acca18d24..6e98ac4f5e 100644 --- a/src/system/kernel/fs/vfs.cpp +++ b/src/system/kernel/fs/vfs.cpp @@ -5145,10 +5145,11 @@ vfs_init(kernel_args* args) vnode::StaticInit(); sVnodeTable = new(std::nothrow) VnodeTable(); - if (sVnodeTable == NULL | sVnodeTable->Init(VNODE_HASH_TABLE_SIZE) != B_OK) + if (sVnodeTable == NULL || sVnodeTable->Init(VNODE_HASH_TABLE_SIZE) != B_OK) panic("vfs_init: error creating vnode hash table\n"); - list_init_etc(&sUnusedVnodeList, offsetof(struct vnode, unused_link)); + struct vnode dummy_vnode; + list_init_etc(&sUnusedVnodeList, offset_of_member(dummy_vnode, unused_link)); struct fs_mount dummyMount; sMountsTable = new(std::nothrow) MountTable();