Module: wine Branch: master Commit: 51b75e9a534d8c6021bbcc71889e3c154f0f84ea URL: https://source.winehq.org/git/wine.git/?a=commit;h=51b75e9a534d8c6021bbcc718...
Author: Jacek Caban jacek@codeweavers.com Date: Wed Feb 5 17:12:22 2020 +0100
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: Jacek Caban jacek@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
include/guiddef.h | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-)
diff --git a/include/guiddef.h b/include/guiddef.h index cc26e8b3a5..9fc40c73eb 100644 --- a/include/guiddef.h +++ b/include/guiddef.h @@ -42,30 +42,45 @@ typedef struct _GUID #endif
/* 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++" { - 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) \ extern "C++" { \ - template<> inline const GUID &__wine_uuidof<type>() { \ - static const IID __uuid_inst = {l,w1,w2, {b1,b2,b3,b4,b5,b6,b7,b8}}; \ - return __uuid_inst; \ - } \ - template<> inline const GUID &__wine_uuidof<type*>() { \ - return __wine_uuidof<type>(); \ - } \ + template<> struct __wine_uuidof<type> { \ + static const GUID uuid; \ + }; \ + __WINE_UUID_ATTR const GUID __wine_uuidof<type>::uuid = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}; \ }
-#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)
-#endif +#endif /* __WINE_UUID_ATTR */
#endif