mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
chore(WF_CONTAINER_OF): makes WF_CONTAINER_OF use typeof, if available (#26)
* makes WF_CONTAINER_OF use typeof, if available * convertss WF_CONTAINER_OF to lower case * fixes include guard
This commit is contained in:
parent
f4180224b2
commit
a717248e80
@ -69,7 +69,7 @@ static void wf_impl_session_dispose_filesystems(
|
||||
while (NULL != item)
|
||||
{
|
||||
struct wf_slist_item * next = item->next;
|
||||
struct wf_impl_filesystem * filesystem = WF_CONTAINER_OF(item, struct wf_impl_filesystem, item);
|
||||
struct wf_impl_filesystem * filesystem = wf_container_of(item, struct wf_impl_filesystem, item);
|
||||
wf_impl_filesystem_dispose(filesystem);
|
||||
|
||||
item = next;
|
||||
@ -116,7 +116,7 @@ void wf_impl_session_onwritable(
|
||||
if (!wf_slist_empty(&session->messages))
|
||||
{
|
||||
struct wf_slist_item * item = wf_slist_remove_first(&session->messages);
|
||||
struct wf_message * message = WF_CONTAINER_OF(item, struct wf_message, item);
|
||||
struct wf_message * message = wf_container_of(item, struct wf_message, item);
|
||||
lws_write(session->wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT);
|
||||
wf_message_dispose(message);
|
||||
|
||||
@ -160,7 +160,7 @@ static struct wf_impl_filesystem * wf_impl_session_get_filesystem(
|
||||
while (NULL != item)
|
||||
{
|
||||
struct wf_slist_item * next = item->next;
|
||||
struct wf_impl_filesystem * filesystem = WF_CONTAINER_OF(session->filesystems.first, struct wf_impl_filesystem, item);
|
||||
struct wf_impl_filesystem * filesystem = wf_container_of(session->filesystems.first, struct wf_impl_filesystem, item);
|
||||
if (wsi == filesystem->wsi)
|
||||
{
|
||||
result = filesystem;
|
||||
|
@ -16,7 +16,7 @@ void wf_impl_session_manager_cleanup(
|
||||
while (NULL != item)
|
||||
{
|
||||
struct wf_slist_item * next = item->next;
|
||||
struct wf_impl_session * session = WF_CONTAINER_OF(item, struct wf_impl_session, item);
|
||||
struct wf_impl_session * session = wf_container_of(item, struct wf_impl_session, item);
|
||||
wf_impl_session_dispose(session);
|
||||
|
||||
item = next;
|
||||
@ -51,7 +51,7 @@ struct wf_impl_session * wf_impl_session_manager_get(
|
||||
while (NULL != item)
|
||||
{
|
||||
struct wf_slist_item * next = item->next;
|
||||
struct wf_impl_session * current = WF_CONTAINER_OF(item, struct wf_impl_session, item);
|
||||
struct wf_impl_session * current = wf_container_of(item, struct wf_impl_session, item);
|
||||
|
||||
if (wf_impl_session_contains_wsi(current, wsi)) {
|
||||
session = current;
|
||||
@ -73,7 +73,7 @@ void wf_impl_session_manager_remove(
|
||||
while (NULL != item)
|
||||
{
|
||||
struct wf_slist_item * next = item->next;
|
||||
struct wf_impl_session * session = WF_CONTAINER_OF(item, struct wf_impl_session, item);
|
||||
struct wf_impl_session * session = wf_container_of(item, struct wf_impl_session, item);
|
||||
if (wsi == session->wsi)
|
||||
{
|
||||
wf_slist_remove_after(&manager->sessions, prev);
|
||||
|
@ -7,7 +7,15 @@
|
||||
#include <cstddef>
|
||||
#endif
|
||||
|
||||
#define WF_CONTAINER_OF(pointer, type, member) \
|
||||
#ifdef __GNUC__
|
||||
#define wf_container_of(pointer, type, member) \
|
||||
({ \
|
||||
const typeof( ((type *)0)->member ) * __member = (pointer); \
|
||||
(type *)( (char *)__member - offsetof(type, member) ); \
|
||||
})
|
||||
#else
|
||||
#define wf_container_of(pointer, type, member) \
|
||||
(type *) (((char *) pointer) - offsetof(type, member))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -9,7 +9,7 @@ void wf_message_queue_cleanup(
|
||||
while (NULL != item)
|
||||
{
|
||||
struct wf_slist_item * next = item->next;
|
||||
struct wf_message * message = WF_CONTAINER_OF(item, struct wf_message, item);
|
||||
struct wf_message * message = wf_container_of(item, struct wf_message, item);
|
||||
wf_message_dispose(message);
|
||||
item = next;
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ static int wfp_impl_client_protocol_callback(
|
||||
if ((wsi == protocol->wsi) && (!wf_slist_empty(&protocol->messages)))
|
||||
{
|
||||
struct wf_slist_item * item = wf_slist_remove_first(&protocol->messages);
|
||||
struct wf_message * message = WF_CONTAINER_OF(item, struct wf_message, item);
|
||||
struct wf_message * message = wf_container_of(item, struct wf_message, item);
|
||||
lws_write(wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT);
|
||||
wf_message_dispose(message);
|
||||
|
||||
|
@ -17,7 +17,7 @@ TEST(ContainerOf, FirstMember)
|
||||
MyStruct my_struct = {23, 42};
|
||||
|
||||
int * first = &my_struct.first;
|
||||
ASSERT_EQ(&my_struct, WF_CONTAINER_OF(first, MyStruct, first));
|
||||
ASSERT_EQ(&my_struct, wf_container_of(first, MyStruct, first));
|
||||
}
|
||||
|
||||
TEST(ContainerOf, SecondMember)
|
||||
@ -25,5 +25,5 @@ TEST(ContainerOf, SecondMember)
|
||||
MyStruct my_struct = {23, 42};
|
||||
|
||||
int * second = &my_struct.second;
|
||||
ASSERT_EQ(&my_struct, WF_CONTAINER_OF(second, MyStruct, second));
|
||||
ASSERT_EQ(&my_struct, wf_container_of(second, MyStruct, second));
|
||||
}
|
Loading…
Reference in New Issue
Block a user