Commit 715fa60b authored by Kirill Smelkov's avatar Kirill Smelkov

libgolang: Use custom list_entry on MSVC

list_entry, as provided by linux/list.h, uses statement expressions(*) which
are not supported by MSVC:

    #define list_entry(ptr, type, member) ({              \
            const typeof( ((type *)0)->member ) *__mptr = (ptr);   \
            (type *)( (char *)__mptr - offsetof(type,member) );})

    golang/runtime/libgolang.cpp(439): error C2059: syntax error: '{'
    golang/runtime/libgolang.cpp(439): error C2143: syntax error: missing ';' before '{'
    golang/runtime/libgolang.cpp(439): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    golang/runtime/libgolang.cpp(439): error C2440: 'initializing': cannot convert from 'list_head' to 'int'
    golang/runtime/libgolang.cpp(439): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    golang/runtime/libgolang.cpp(439): error C2143: syntax error: missing ';' before '*'
    golang/runtime/libgolang.cpp(439): error C2065: '__mptr': undeclared identifier
    golang/runtime/libgolang.cpp(439): error C2059: syntax error: ')'

-> work it around by defining list_entry with C++ lambda.

(*) https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
parent 1845b93d
......@@ -50,6 +50,16 @@
# define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
#endif
#include <linux/list.h>
// MSVC does not support statement expressions and typeof
// -> redo list_entry via C++ lambda.
#ifdef _MSC_VER
# undef list_entry
# define list_entry(ptr, type, member) [&]() { \
const decltype( ((type *)0)->member ) *__mptr = (ptr); \
return (type *)( (char *)__mptr - offsetof(type,member) ); \
}()
#endif
using std::atomic;
using std::bad_alloc;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment