Commit 51b75e9a authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

guiddef.h: Improve __uuidof implementation.

This patch ensures that the reference is unique and identical for all uses in module, fixes handling of const types and uses direct reference instead of depending on optimizer to produce sane code. Based on patch by Kevin Puetz. Signed-off-by: 's avatarJacek Caban <jacek@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 544fd950
...@@ -42,30 +42,45 @@ typedef struct _GUID ...@@ -42,30 +42,45 @@ typedef struct _GUID
#endif #endif
/* Macros for __uuidof emulation */ /* Macros for __uuidof emulation */
#if defined(__cplusplus) && !defined(_MSC_VER) #ifdef __cplusplus
# if defined(__MINGW32__)
# define __WINE_UUID_ATTR __attribute__((selectany))
# elif defined(__GNUC__)
# define __WINE_UUID_ATTR __attribute__((visibility("hidden"),weak))
# endif
#endif
#ifdef __WINE_UUID_ATTR
extern "C++" { extern "C++" {
template<typename T> const GUID &__wine_uuidof(); template<typename T> struct __wine_uuidof;
template<typename T> struct __wine_uuidof_type {
typedef __wine_uuidof<T> inst;
};
template<typename T> struct __wine_uuidof_type<T *> {
typedef __wine_uuidof<T> inst;
};
template<typename T> struct __wine_uuidof_type<T * const> {
typedef __wine_uuidof<T> inst;
};
} }
#define __CRT_UUID_DECL(type,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \ #define __CRT_UUID_DECL(type,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \
extern "C++" { \ extern "C++" { \
template<> inline const GUID &__wine_uuidof<type>() { \ template<> struct __wine_uuidof<type> { \
static const IID __uuid_inst = {l,w1,w2, {b1,b2,b3,b4,b5,b6,b7,b8}}; \ static const GUID uuid; \
return __uuid_inst; \ }; \
} \ __WINE_UUID_ATTR const GUID __wine_uuidof<type>::uuid = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}; \
template<> inline const GUID &__wine_uuidof<type*>() { \
return __wine_uuidof<type>(); \
} \
} }
#define __uuidof(type) __wine_uuidof<typeof(type)>() #define __uuidof(type) __wine_uuidof_type<typeof(type)>::inst::uuid
#else #else /* __WINE_UUID_ATTR */
#define __CRT_UUID_DECL(type,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) #define __CRT_UUID_DECL(type,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8)
#endif #endif /* __WINE_UUID_ATTR */
#endif #endif
......
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