[glib: 4/7] giomodules: g_io_module_* must always be exported




commit 90fcbc7dfc989ae03a2f5ef5e6128809d16153ef
Author: Xavier Claessens <xavier claessens collabora com>
Date:   Wed Oct 5 17:40:57 2022 -0400

    giomodules: g_io_module_* must always be exported
    
    Those symbols are not used by GIO itself but by external modules.

 gio/giomodule.h                       | 12 ++++++++----
 gio/tests/modules/symbol-visibility.h |  2 +-
 gio/tests/modules/test-module-a.c     |  2 --
 gio/tests/modules/test-module-b.c     |  2 --
 gio/tests/resourceplugin.c            |  2 --
 gmodule/gmodule.c                     |  5 +++++
 gmodule/gmodule.h                     | 16 +++++++++-------
 7 files changed, 23 insertions(+), 18 deletions(-)
---
diff --git a/gio/giomodule.h b/gio/giomodule.h
index 1c53aa8ee4..2fe7e1d06e 100644
--- a/gio/giomodule.h
+++ b/gio/giomodule.h
@@ -103,7 +103,11 @@ GIO_AVAILABLE_IN_ALL
 GTypeClass*        g_io_extension_ref_class                   (GIOExtension      *extension);
 
 
-/* API for the modules to implement */
+/* API for the modules to implement.
+ * Note that those functions are not implemented by libgio, they are declared
+ * here to be implemented in modules, that's why it uses G_MODULE_EXPORT
+ * instead of GIO_AVAILABLE_IN_ALL.
+ */
 
 /**
  * g_io_module_load: (skip)
@@ -123,7 +127,7 @@ GTypeClass*        g_io_extension_ref_class                   (GIOExtension
  * statically. The old symbol names continue to be supported, but cannot be used
  * for static builds.
  **/
-GIO_AVAILABLE_IN_ALL
+G_MODULE_EXPORT
 void   g_io_module_load   (GIOModule *module);
 
 /**
@@ -143,7 +147,7 @@ void   g_io_module_load   (GIOModule *module);
  * statically. The old symbol names continue to be supported, but cannot be used
  * for static builds.
  **/
-GIO_AVAILABLE_IN_ALL
+G_MODULE_EXPORT
 void   g_io_module_unload (GIOModule *module);
 
 /**
@@ -187,7 +191,7 @@ void   g_io_module_unload (GIOModule *module);
  *
  * Since: 2.24
  **/
-GIO_AVAILABLE_IN_ALL
+G_MODULE_EXPORT
 char **g_io_module_query (void);
 
 G_END_DECLS
diff --git a/gio/tests/modules/symbol-visibility.h b/gio/tests/modules/symbol-visibility.h
index e838944448..2aa1fc6632 100644
--- a/gio/tests/modules/symbol-visibility.h
+++ b/gio/tests/modules/symbol-visibility.h
@@ -3,7 +3,7 @@
 
 /* This is the same check that's done in configure to create config.h */
 #ifdef _WIN32
-#ifdef GLIB_STATIC_COMPILATION
+#ifdef GLIB_TEST_STATIC_COMPILATION
 #define GLIB_TEST_EXPORT_SYMBOL extern
 #else
 #ifdef _MSC_VER
diff --git a/gio/tests/modules/test-module-a.c b/gio/tests/modules/test-module-a.c
index 0a64ea60a6..6ac065d8a0 100644
--- a/gio/tests/modules/test-module-a.c
+++ b/gio/tests/modules/test-module-a.c
@@ -20,8 +20,6 @@
  * if advised of the possibility of such damage.
  */
 
-#include "config.h" /* for _GLIB_EXTERN */
-
 #include <gio/gio.h>
 
 #include "symbol-visibility.h"
diff --git a/gio/tests/modules/test-module-b.c b/gio/tests/modules/test-module-b.c
index 8d3527e435..21932287f4 100644
--- a/gio/tests/modules/test-module-b.c
+++ b/gio/tests/modules/test-module-b.c
@@ -20,8 +20,6 @@
  * if advised of the possibility of such damage.
  */
 
-#include "config.h" /* for _GLIB_EXTERN */
-
 #include <gio/gio.h>
 
 #include "symbol-visibility.h"
diff --git a/gio/tests/resourceplugin.c b/gio/tests/resourceplugin.c
index 1f218f26f7..1f5f7ef87e 100644
--- a/gio/tests/resourceplugin.c
+++ b/gio/tests/resourceplugin.c
@@ -6,8 +6,6 @@
  * g_io_module*() symbols, is defined to be _GLIB_EXTERN,
  * which must be overridden to export the symbols.
  */
-#include "modules/symbol-visibility.h"
-#define _GLIB_EXTERN GLIB_TEST_EXPORT_SYMBOL
 
 #include <gio/gio.h>
 
diff --git a/gmodule/gmodule.c b/gmodule/gmodule.c
index 972d8ad631..49fc396643 100644
--- a/gmodule/gmodule.c
+++ b/gmodule/gmodule.c
@@ -178,6 +178,11 @@
  * non-default
  * [visibility flag](https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fvisibility-1260)
  * such as `hidden`.
+ *
+ * This macro must only be used when compiling a shared module. Modules that
+ * support both shared and static linking should define their own macro that
+ * expands to %G_MODULE_EXPORT when compiling the shared module, but is empty
+ * when compiling the static module on Windows.
  */
 
 /**
diff --git a/gmodule/gmodule.h b/gmodule/gmodule.h
index 03ac91d10f..664d8bbaa7 100644
--- a/gmodule/gmodule.h
+++ b/gmodule/gmodule.h
@@ -35,14 +35,16 @@ G_BEGIN_DECLS
 /* exporting and importing functions, this is special cased
  * to feature Windows dll stubs.
  */
-#define        G_MODULE_IMPORT         extern
-#ifdef G_PLATFORM_WIN32
-#  define      G_MODULE_EXPORT         __declspec(dllexport)
+#if defined(_WIN32) || defined(__CYGWIN__)
+#  define G_MODULE_EXPORT __declspec(dllexport)
+#  define G_MODULE_IMPORT __declspec(dllimport) extern
 #elif __GNUC__ >= 4
-#  define      G_MODULE_EXPORT         __attribute__((visibility("default")))
-#else /* !G_PLATFORM_WIN32 && __GNUC__ < 4 */
-#  define      G_MODULE_EXPORT
-#endif /* !G_PLATFORM_WIN32 */
+#  define G_MODULE_EXPORT __attribute__((visibility("default")))
+#  define G_MODULE_IMPORT extern
+#else /* !defined(_WIN32) && !defined(__CYGWIN__) && __GNUC__ < 4 */
+#  define G_MODULE_EXPORT
+#  define G_MODULE_IMPORT extern
+#endif
 
 /**
  * GModuleFlags:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]