From c1a3e82213e3de7820ab0949d814b78109a6bf28 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Fri, 20 Oct 2023 10:46:42 +0800 Subject: [PATCH] as-macros-private.h: Define macros for visibility for clang-cl On clang-cl (i.e. Visual Studio-like meaning _MSC_VER is defined) builds, symbols in shared builds have visibility to be hidden by default, and decorating symbols with GCC's default visibility is not enough to export the symbol. Consequently, use the macros in as-desktop-entry.h so that we don't fall into the situation where clang-cl complains as we are attempting to do a __declspec(dllexport) in a hidden visibility section. --- src/as-desktop-entry.h | 6 ++---- src/as-macros-private.h | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/as-desktop-entry.h b/src/as-desktop-entry.h index 7b957317..bdfd76f7 100644 --- a/src/as-desktop-entry.h +++ b/src/as-desktop-entry.h @@ -27,8 +27,7 @@ #include "as-metadata.h" #include "as-utils-private.h" -G_BEGIN_DECLS -#pragma GCC visibility push(hidden) +AS_BEGIN_PRIVATE_DECLS typedef GPtrArray *(*AsTranslateDesktopTextFn) (const GKeyFile *de, const gchar *text, @@ -54,7 +53,6 @@ gboolean as_desktop_entry_parse_file (AsComponent *cpt, gpointer user_data, GError **error); -#pragma GCC visibility pop -G_END_DECLS +AS_END_PRIVATE_DECLS #endif /* __AS_DESKTOP_ENTRY_H */ diff --git a/src/as-macros-private.h b/src/as-macros-private.h index 3f00aee9..9c4d8ba3 100644 --- a/src/as-macros-private.h +++ b/src/as-macros-private.h @@ -26,6 +26,20 @@ #include "as-macros.h" G_BEGIN_DECLS + +#ifdef _MSC_VER + +#define AS_BEGIN_PRIVATE_DECLS G_BEGIN_DECLS +#define AS_END_PRIVATE_DECLS G_END_DECLS + +#ifdef AS_STATIC +# define AS_INTERNAL_VISIBLE +#else +# define AS_INTERNAL_VISIBLE __declspec(dllexport) +#endif + +#else + #pragma GCC visibility push(hidden) #define AS_BEGIN_PRIVATE_DECLS \ @@ -36,6 +50,8 @@ G_BEGIN_DECLS #define AS_INTERNAL_VISIBLE __attribute__((visibility("default"))) +#endif + /** * as_str_equal0: * Returns TRUE if strings are equal, ignoring NULL strings. @@ -107,7 +123,10 @@ G_BEGIN_DECLS } \ G_STMT_END +#ifndef _MSC_VER #pragma GCC visibility pop +#endif + G_END_DECLS #endif /* __AS_MACROS_PRIVATE_H */