Skip to content
Snippets Groups Projects
Commit d1c0ca59 authored by Xavier Claessens's avatar Xavier Claessens
Browse files

glib-networking: Use upstream mechanism to build static modules

https://bugzilla.gnome.org/show_bug.cgi?id=791372
parent d0e43d5a
No related branches found
No related tags found
No related merge requests found
......@@ -59,7 +59,7 @@ endif
include $(GSTREAMER_NDK_BUILD_PATH)/tools.mk
# Path for the static GIO modules
G_IO_MODULES_PATH := $(GSTREAMER_ROOT)/lib/gio/modules/static
G_IO_MODULES_PATH := $(GSTREAMER_ROOT)/lib/gio/modules
# Host tools
ifeq ($(HOST_OS),windows)
......
......@@ -49,10 +49,10 @@ static JavaVM *_java_vm = NULL;
static GstClockTime _priv_gst_info_start_time;
#define GST_G_IO_MODULE_DECLARE(name) \
extern void G_PASTE(g_io_module_, G_PASTE(name, _load_static)) (void)
extern void G_PASTE(g_io_, G_PASTE(name, _load)) (GIOModule *module)
#define GST_G_IO_MODULE_LOAD(name) \
G_PASTE(g_io_module_, G_PASTE(name, _load_static)) ()
G_PASTE(g_io_, G_PASTE(name, _load)) (NULL)
/* Declaration of static plugins */
@PLUGINS_DECLARATION@
......
......@@ -27,6 +27,6 @@ class Package(custom.GStreamer, package.Package):
[DistroVersion.DEBIAN_SQUEEZE,
DistroVersion.UBUNTU_MAVERICK,
DistroVersion.UBUNTU_LUCID]:
self.files += ['glib-networking', 'glib-networking-static']
self.files += ['glib-networking']
elif self.config.target_platform == Platform.LINUX:
self.sys_deps = {self.config.target_distro_version: ['glib-networking']}
# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python
import shutil
import os
from cerbero.errors import FatalError
from cerbero.utils.shell import which
class Recipe(recipe.Recipe):
name = 'glib-networking-static'
version = '2.48.2'
licenses = [License.LGPLv2Plus]
stype = SourceType.TARBALL
url = 'http://ftp.gnome.org/pub/gnome/sources/glib-networking/2.48/glib-networking-%(version)s.tar.xz'
tarball_dirname = 'glib-networking-%(version)s'
autoreconf = True
configure_options = "--without-ca-certificates --enable-static-modules --enable-static --enable-more-warnings"
deps = ['glib', 'gnutls', 'glib-networking']
patches = ['glib-networking/0001-Add-support-for-static-modules.patch',
'glib-networking/0002-Get-the-CA-certificate-path-from-the-environment-var.patch',
'glib-networking/0003-gnutls-Use-db-relative-to-libglib-2.0-if-needed.patch',
'glib-networking/0004-gtlsbackend-gnutls-Get-anchor-file-relative-to-libgi.patch']
files_devel = ['lib/gio/modules/static/libgiognutls.a',
'lib/gio/modules/static/libgiognutls.la']
def prepare(self):
self.tmp_destdir = os.path.join(self.build_dir, 'static-build')
querymodule_path = which('true')
if self.config.target_platform in [Platform.ANDROID, Platform.IOS]:
self.append_env['CFLAGS'] = ' -DGST_CA_CERTIFICATES_FROM_ENV'
self.config_sh = 'GIO_QUERYMODULES=%s %s' % (querymodule_path, self.config_sh)
def install(self):
plugins_dir = os.path.join(self.config.prefix,
os.path.dirname(self.files_devel[0]))
if not os.path.exists(plugins_dir):
os.makedirs(plugins_dir)
shutil.copy(os.path.join(self.build_dir, 'tls', 'gnutls', '.libs',
'libgiognutls.a'), plugins_dir)
shutil.copy(os.path.join(self.build_dir, 'tls', 'gnutls', '.libs',
'libgiognutls.la'), plugins_dir)
......@@ -9,9 +9,9 @@ class Recipe(recipe.Recipe):
stype = SourceType.TARBALL
url = 'http://ftp.gnome.org/pub/gnome/sources/glib-networking/2.54/glib-networking-%(version)s.tar.xz'
autoreconf = True
configure_options = "--without-ca-certificates --enable-more-warnings"
configure_options = "--without-ca-certificates --enable-more-warnings --enable-static"
deps = ['glib', 'gnutls']
patches = ['glib-networking/0001-Add-support-for-static-modules.patch',
patches = ['glib-networking/0001-Allow-static-build-of-modules.patch',
'glib-networking/0002-Get-the-CA-certificate-path-from-the-environment-var.patch',
'glib-networking/0003-gnutls-Use-db-relative-to-libglib-2.0-if-needed.patch',
'glib-networking/0004-gtlsbackend-gnutls-Get-anchor-file-relative-to-libgi.patch']
......
From b09cd11cc3339fe89fbb944e253e6bba70f7b5fd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= <sebastian@centricular.com>
Date: Fri, 7 Mar 2014 12:50:24 +0100
Subject: [PATCH 1/2] Add support for static modules
Other than the previous approach this now doesn't go via
dlopen() and stuff but just registers the module directly.
Also does not require any GLib changes.
---
configure.ac | 20 ++++++++++++++++++++
glib-networking.mk | 5 ++++-
tls/gnutls/gnutls-module.c | 12 +++++++++++-
tls/gnutls/gtlsbackend-gnutls.c | 27 ++++++++++++++++++++++-----
tls/gnutls/gtlsbackend-gnutls.h | 7 ++++++-
5 files changed, 63 insertions(+), 8 deletions(-)
diff --git a/configure.ac b/configure.ac
index 84ceb68..a5521a0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -233,6 +233,26 @@ if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then
-Werror=declaration-after-statement"
fi
+dnl ****************************************************
+dnl *** Check for GIO static modules ***
+dnl ****************************************************
+AC_MSG_CHECKING([whether to build static modules or not])
+AC_ARG_ENABLE(
+ static-modules,
+ AC_HELP_STRING(
+ [--enable-static-modules],
+ [build static modules @<:@default=no@:>@]),
+ [AS_CASE(
+ [$enableval], [no], [], [yes], [],
+ [AC_MSG_ERROR([bad value "$enableval" for --enable-static-modules])])],
+ [enable_static_modules=no])
+AC_MSG_RESULT([$enable_static_modules])
+if test "x$enable_static_modules" = xyes; then
+ AC_DEFINE(G_IO_MODULE_BUILD_STATIC, 1,
+ [Define if static modules should be built])
+fi
+AM_CONDITIONAL(G_IO_MODULE_BUILD_STATIC, [test "x$enable_static_modules" = "xyes"])
+
dnl *****************************
dnl *** done ***
dnl *****************************
diff --git a/glib-networking.mk b/glib-networking.mk
index 29b6a6a..5231766 100644
--- a/glib-networking.mk
+++ b/glib-networking.mk
@@ -1,6 +1,9 @@
### glib-networking declarations
-module_flags = -export_dynamic -avoid-version -module -no-undefined -export-symbols-regex '^g_io_module_(load|unload|query)'
+module_flags = -export_dynamic -avoid-version -module -no-undefined
+if !G_IO_MODULE_BUILD_STATIC
+module_flags += -export-symbols-regex '^g_io_module_(load|unload|query)'
+endif
giomoduledir = $(GIO_MODULE_DIR)
diff --git a/tls/gnutls/gnutls-module.c b/tls/gnutls/gnutls-module.c
index a725f9b..8da3c2b 100644
--- a/tls/gnutls/gnutls-module.c
+++ b/tls/gnutls/gnutls-module.c
@@ -24,7 +24,16 @@
#include "gtlsbackend-gnutls.h"
#include "gtlsbackend-gnutls-pkcs11.h"
-
+#ifdef G_IO_MODULE_BUILD_STATIC
+void
+g_io_module_gnutls_register (void)
+{
+ g_io_module_gnutls_load_static ();
+#ifdef HAVE_PKCS11
+ g_io_module_gnutls_pkcs11_load_static ();
+#endif
+}
+#else
void
g_io_module_load (GIOModule *module)
{
@@ -48,3 +57,4 @@ g_io_module_query (void)
};
return g_strdupv (eps);
}
+#endif
diff --git a/tls/gnutls/gtlsbackend-gnutls.c b/tls/gnutls/gtlsbackend-gnutls.c
index 55ec1a5..277fff2 100644
--- a/tls/gnutls/gtlsbackend-gnutls.c
+++ b/tls/gnutls/gtlsbackend-gnutls.c
@@ -39,10 +39,22 @@ struct _GTlsBackendGnutlsPrivate
static void g_tls_backend_gnutls_interface_init (GTlsBackendInterface *iface);
+#ifdef G_IO_MODULE_BUILD_STATIC
+G_DEFINE_TYPE_EXTENDED (GTlsBackendGnutls, g_tls_backend_gnutls, G_TYPE_OBJECT, 0,
+ G_IMPLEMENT_INTERFACE (G_TYPE_TLS_BACKEND,
+ g_tls_backend_gnutls_interface_init);)
+void _g_io_modules_ensure_extension_points_registered (void);
+#else
G_DEFINE_DYNAMIC_TYPE_EXTENDED (GTlsBackendGnutls, g_tls_backend_gnutls, G_TYPE_OBJECT, 0,
G_IMPLEMENT_INTERFACE_DYNAMIC (G_TYPE_TLS_BACKEND,
g_tls_backend_gnutls_interface_init);)
+static void
+g_tls_backend_gnutls_class_finalize (GTlsBackendGnutlsClass *backend_class)
+{
+}
+#endif
+
#ifdef GTLS_GNUTLS_DEBUG
static void
gtls_log_func (int level, const char *msg)
@@ -61,8 +73,11 @@ gtls_gnutls_init (gpointer data)
gnutls_global_set_log_level (9);
#endif
+#ifndef G_IO_MODULE_BUILD_STATIC
/* Leak the module to keep it from being unloaded. */
g_type_plugin_use (g_type_get_plugin (G_TYPE_TLS_BACKEND_GNUTLS));
+#endif
+
return NULL;
}
@@ -116,11 +131,6 @@ g_tls_backend_gnutls_class_init (GTlsBackendGnutlsClass *backend_class)
g_type_class_add_private (backend_class, sizeof (GTlsBackendGnutlsPrivate));
}
-static void
-g_tls_backend_gnutls_class_finalize (GTlsBackendGnutlsClass *backend_class)
-{
-}
-
static GTlsDatabase*
g_tls_backend_gnutls_get_default_database (GTlsBackend *backend)
{
@@ -303,10 +313,17 @@ g_tls_backend_gnutls_lookup_session (unsigned int type,
return session_data;
}
+#ifdef G_IO_MODULE_BUILD_STATIC
+void
+g_io_module_gnutls_load_static (void)
+{
+ _g_io_modules_ensure_extension_points_registered ();
+#else
void
g_tls_backend_gnutls_register (GIOModule *module)
{
g_tls_backend_gnutls_register_type (G_TYPE_MODULE (module));
+#endif
g_io_extension_point_implement (G_TLS_BACKEND_EXTENSION_POINT_NAME,
g_tls_backend_gnutls_get_type(),
"gnutls",
diff --git a/tls/gnutls/gtlsbackend-gnutls.h b/tls/gnutls/gtlsbackend-gnutls.h
index 22caa00..24e139b 100644
--- a/tls/gnutls/gtlsbackend-gnutls.h
+++ b/tls/gnutls/gtlsbackend-gnutls.h
@@ -44,7 +44,12 @@ struct _GTlsBackendGnutls
};
GType g_tls_backend_gnutls_get_type (void) G_GNUC_CONST;
-void g_tls_backend_gnutls_register (GIOModule *module);
+
+#ifdef G_IO_MODULE_BUILD_STATIC
+void g_io_module_gnutls_load_static (void);
+#else
+void g_tls_backend_gnutls_register (GIOModule *module);
+#endif
void g_tls_backend_gnutls_store_session (unsigned int type,
GBytes *session_id,
--
1.9.0
From 1be558a53fb59e28ee7e67609d4f4e0b34c50144 Mon Sep 17 00:00:00 2001
From: Xavier Claessens <xavier.claessens@collabora.com>
Date: Fri, 1 Dec 2017 16:03:18 -0500
Subject: [PATCH 1/5] Allow static build of modules
To be able to static link all modules into an executable,
g_io_module_load/unload/query() symbols needs to be renamed to the new
naming scheme supported by glib 2.56. Those functions should also
support receiving NULL GIOModule, and register the extension point
manually since they won't be pre-discovered by reading giomodule.cache.
https://bugzilla.gnome.org/show_bug.cgi?id=791100
---
glib-networking.mk | 2 +-
proxy/gnome/gnome-proxy-module.c | 6 +++---
proxy/gnome/gproxyresolvergnome.c | 2 ++
proxy/libproxy/glibproxyresolver.c | 2 ++
proxy/libproxy/libproxy-module.c | 6 +++---
tls/gnutls/gnutls-module.c | 6 +++---
tls/gnutls/gtlsbackend-gnutls.c | 8 +++++++-
7 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/glib-networking.mk b/glib-networking.mk
index f6b8253..1297a59 100644
--- a/glib-networking.mk
+++ b/glib-networking.mk
@@ -1,6 +1,6 @@
### glib-networking declarations
-module_flags = -export_dynamic -avoid-version -module -no-undefined -export-symbols-regex '^g_io_module_(load|unload|query)'
+module_flags = -export_dynamic -avoid-version -module -no-undefined -export-symbols-regex '^g_io_.*_(load|unload|query)'
giomoduledir = $(GIO_MODULE_DIR)
diff --git a/proxy/gnome/gnome-proxy-module.c b/proxy/gnome/gnome-proxy-module.c
index f5f2469..e483b9e 100644
--- a/proxy/gnome/gnome-proxy-module.c
+++ b/proxy/gnome/gnome-proxy-module.c
@@ -25,7 +25,7 @@
void
-g_io_module_load (GIOModule *module)
+g_io_gnomeproxy_load (GIOModule *module)
{
gchar *locale_dir;
#ifdef G_OS_WIN32
@@ -48,12 +48,12 @@ g_io_module_load (GIOModule *module)
}
void
-g_io_module_unload (GIOModule *module)
+g_io_gnomeproxy_unload (GIOModule *module)
{
}
gchar **
-g_io_module_query (void)
+g_io_gnomeproxy_query (void)
{
gchar *eps[] = {
G_PROXY_RESOLVER_EXTENSION_POINT_NAME,
diff --git a/proxy/gnome/gproxyresolvergnome.c b/proxy/gnome/gproxyresolvergnome.c
index 0f5559f..2efc533 100644
--- a/proxy/gnome/gproxyresolvergnome.c
+++ b/proxy/gnome/gproxyresolvergnome.c
@@ -537,6 +537,8 @@ void
g_proxy_resolver_gnome_register (GIOModule *module)
{
g_proxy_resolver_gnome_register_type (G_TYPE_MODULE (module));
+ if (module == NULL)
+ g_io_extension_point_register (G_PROXY_RESOLVER_EXTENSION_POINT_NAME);
g_io_extension_point_implement (G_PROXY_RESOLVER_EXTENSION_POINT_NAME,
g_proxy_resolver_gnome_get_type(),
"gnome",
diff --git a/proxy/libproxy/glibproxyresolver.c b/proxy/libproxy/glibproxyresolver.c
index edbda64..8870a42 100644
--- a/proxy/libproxy/glibproxyresolver.c
+++ b/proxy/libproxy/glibproxyresolver.c
@@ -231,6 +231,8 @@ void
g_libproxy_resolver_register (GIOModule *module)
{
g_libproxy_resolver_register_type (G_TYPE_MODULE (module));
+ if (module == NULL)
+ g_io_extension_point_register (G_PROXY_RESOLVER_EXTENSION_POINT_NAME);
g_io_extension_point_implement (G_PROXY_RESOLVER_EXTENSION_POINT_NAME,
g_libproxy_resolver_get_type(),
"libproxy",
diff --git a/proxy/libproxy/libproxy-module.c b/proxy/libproxy/libproxy-module.c
index 11f36f1..1c39047 100644
--- a/proxy/libproxy/libproxy-module.c
+++ b/proxy/libproxy/libproxy-module.c
@@ -27,7 +27,7 @@
void
-g_io_module_load (GIOModule *module)
+g_io_libproxy_load (GIOModule *module)
{
gchar *locale_dir;
#ifdef G_OS_WIN32
@@ -50,12 +50,12 @@ g_io_module_load (GIOModule *module)
}
void
-g_io_module_unload (GIOModule *module)
+g_io_libproxy_unload (GIOModule *module)
{
}
gchar **
-g_io_module_query (void)
+g_io_libproxy_query (void)
{
gchar *eps[] = {
G_PROXY_RESOLVER_EXTENSION_POINT_NAME,
diff --git a/tls/gnutls/gnutls-module.c b/tls/gnutls/gnutls-module.c
index 6a56a9a..3bf08b8 100644
--- a/tls/gnutls/gnutls-module.c
+++ b/tls/gnutls/gnutls-module.c
@@ -30,7 +30,7 @@
void
-g_io_module_load (GIOModule *module)
+g_io_gnutls_load (GIOModule *module)
{
gchar *locale_dir;
#ifdef G_OS_WIN32
@@ -56,12 +56,12 @@ g_io_module_load (GIOModule *module)
}
void
-g_io_module_unload (GIOModule *module)
+g_io_gnutls_unload (GIOModule *module)
{
}
gchar **
-g_io_module_query (void)
+g_io_gnutls_query (void)
{
gchar *eps[] = {
G_TLS_BACKEND_EXTENSION_POINT_NAME,
diff --git a/tls/gnutls/gtlsbackend-gnutls.c b/tls/gnutls/gtlsbackend-gnutls.c
index 332ca05..4c7da79 100644
--- a/tls/gnutls/gtlsbackend-gnutls.c
+++ b/tls/gnutls/gtlsbackend-gnutls.c
@@ -57,6 +57,8 @@ gtls_log_func (int level, const char *msg)
static gpointer
gtls_gnutls_init (gpointer data)
{
+ GTypePlugin *plugin;
+
gnutls_global_init ();
#ifdef GTLS_GNUTLS_DEBUG
@@ -65,7 +67,9 @@ gtls_gnutls_init (gpointer data)
#endif
/* Leak the module to keep it from being unloaded. */
- g_type_plugin_use (g_type_get_plugin (G_TYPE_TLS_BACKEND_GNUTLS));
+ plugin = g_type_get_plugin (G_TYPE_TLS_BACKEND_GNUTLS);
+ if (plugin != NULL)
+ g_type_plugin_use (plugin);
return NULL;
}
@@ -310,6 +314,8 @@ void
g_tls_backend_gnutls_register (GIOModule *module)
{
g_tls_backend_gnutls_register_type (G_TYPE_MODULE (module));
+ if (module == NULL)
+ g_io_extension_point_register (G_TLS_BACKEND_EXTENSION_POINT_NAME);
g_io_extension_point_implement (G_TLS_BACKEND_EXTENSION_POINT_NAME,
g_tls_backend_gnutls_get_type(),
"gnutls",
--
2.7.4
......@@ -38,7 +38,9 @@ class Recipe(recipe.Recipe):
'glib/0009-Implementation-of-Cocoa-event-loop-integration-in-GM.patch',
'glib/0010-GSocket-Fix-race-conditions-on-Win32-if-multiple-thr.patch',
'glib/0013-gmain-Fix-erroneous-if-condition-when-dtrace-is-disa.patch',
'glib/0001-gmodule-Use-RTLD_DEFAULT-if-defined-__BIONIC__.patch'
'glib/0001-gmodule-Use-RTLD_DEFAULT-if-defined-__BIONIC__.patch',
'glib/0001-GIOModule-Use-unique-names-for-load-unload-symbols.patch',
'glib/0002-GTypeModule-Allow-registering-static-types.patch'
]
files_libs = [
......
From ee181a3549043b6c3c73ed698314280c4c2a7899 Mon Sep 17 00:00:00 2001
From: Xavier Claessens <xavier.claessens@collabora.com>
Date: Thu, 30 Nov 2017 15:36:21 -0500
Subject: [PATCH 1/2] GIOModule: Use unique names for load/unload symbols
GIO modules should include their name into their exported symbols to
make them unique. This avoids symbol clash when building modules
statically.
extract_name() function is copied from GStreamer which recently
switched to the same symbol naming scheme.
https://bugzilla.gnome.org/show_bug.cgi?id=684282
---
gio/Makefile.am | 3 ++-
gio/gio-querymodules.c | 16 +++++++++++-
gio/giomodule-priv.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++
gio/giomodule-priv.h | 3 +++
gio/giomodule.c | 44 +++++++++++++++++++++++++++-----
gio/giomodule.h | 18 +++++++++++++
gio/meson.build | 3 ++-
7 files changed, 147 insertions(+), 9 deletions(-)
create mode 100644 gio/giomodule-priv.c
diff --git a/gio/Makefile.am b/gio/Makefile.am
index 0cfda50..9b3d04e 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -476,6 +476,7 @@ gio_base_sources = \
gioenums.h \
gioerror.c \
giomodule.c \
+ giomodule-priv.c \
giomodule-priv.h \
gioscheduler.c \
giostream.c \
@@ -815,7 +816,7 @@ glib_compile_resources_SOURCES = \
gvdb/gvdb-builder.c \
glib-compile-resources.c
-gio_querymodules_SOURCES = gio-querymodules.c
+gio_querymodules_SOURCES = gio-querymodules.c giomodule-priv.c
gio_querymodules_LDADD = libgio-2.0.la \
$(top_builddir)/gobject/libgobject-2.0.la \
$(top_builddir)/gmodule/libgmodule-2.0.la \
diff --git a/gio/gio-querymodules.c b/gio/gio-querymodules.c
index 7abfe07..74c6594 100644
--- a/gio/gio-querymodules.c
+++ b/gio/gio-querymodules.c
@@ -20,6 +20,7 @@
#include "config.h"
#include "giomodule.h"
+#include "giomodule-priv.h"
#include <gstdio.h>
#include <errno.h>
@@ -83,7 +84,20 @@ query_dir (const char *dirname)
if (module)
{
- g_module_symbol (module, "g_io_module_query", (gpointer) &query);
+ gchar *modulename;
+ gchar *symname;
+
+ modulename = _g_io_module_extract_name (name);
+ symname = g_strconcat ("g_io_", modulename, "_query", NULL);
+ g_module_symbol (module, symname, (gpointer) &query);
+ g_free (symname);
+ g_free (modulename);
+
+ if (!query)
+ {
+ /* Fallback to old name */
+ g_module_symbol (module, "g_io_module_query", (gpointer) &query);
+ }
if (query)
{
diff --git a/gio/giomodule-priv.c b/gio/giomodule-priv.c
new file mode 100644
index 0000000..d359eac
--- /dev/null
+++ b/gio/giomodule-priv.c
@@ -0,0 +1,69 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright (C) 2017 Collabora Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Xavier Claessens <xavier.claessens@collabora.com>
+ */
+
+#include "config.h"
+#include "giomodule.h"
+#include "giomodule-priv.h"
+
+#include <string.h>
+
+/**
+ * _g_io_module_extract_name:
+ * @filename: filename of a GIOModule
+ *
+ * Extract the plugin name from its filename. It removes optional "lib" or
+ * "libgio" prefix, and removes everything after the first dot. For example:
+ * "libgiognutls.so" -> "gnutls".
+ *
+ * Returns: (transfer full): the module's name
+ */
+gchar *
+_g_io_module_extract_name (const char *filename)
+{
+ gchar *bname, *name;
+ const gchar *dot;
+ gsize prefix_len, len;
+ int i;
+
+ bname = g_path_get_basename (filename);
+ for (i = 0; bname[i]; ++i)
+ {
+ if (bname[i] == '-')
+ bname[i] = '_';
+ }
+
+ if (g_str_has_prefix (bname, "libgio"))
+ prefix_len = 6;
+ else if (g_str_has_prefix (bname, "lib"))
+ prefix_len = 3;
+ else
+ prefix_len = 0; /* use whole name (minus suffix) as plugin name */
+
+ dot = g_utf8_strchr (bname, -1, '.');
+ if (dot)
+ len = dot - bname - prefix_len;
+ else
+ len = strlen (bname + prefix_len);
+
+ name = g_strndup (bname + prefix_len, len);
+ g_free (bname);
+
+ return name;
+}
diff --git a/gio/giomodule-priv.h b/gio/giomodule-priv.h
index e480593..68d46f2 100644
--- a/gio/giomodule-priv.h
+++ b/gio/giomodule-priv.h
@@ -41,6 +41,9 @@ GType _g_io_module_get_default_type (const gchar *extension_point,
void *_g_io_win32_get_module (void);
#endif
+gchar *_g_io_module_extract_name (const char *filename);
+
+
G_END_DECLS
#endif /* __G_IO_MODULE_PRIV_H__ */
diff --git a/gio/giomodule.c b/gio/giomodule.c
index 4047695..1adfd93 100644
--- a/gio/giomodule.c
+++ b/gio/giomodule.c
@@ -291,6 +291,43 @@ g_io_module_finalize (GObject *object)
}
static gboolean
+load_symbols (GIOModule *module)
+{
+ gchar *name;
+ gchar *load_symname;
+ gchar *unload_symname;
+ gboolean ret;
+
+ name = _g_io_module_extract_name (module->filename);
+ load_symname = g_strconcat ("g_io_", name, "_load", NULL);
+ unload_symname = g_strconcat ("g_io_", name, "_unload", NULL);
+
+ ret = g_module_symbol (module->library,
+ load_symname,
+ (gpointer) &module->load) &&
+ g_module_symbol (module->library,
+ unload_symname,
+ (gpointer) &module->unload);
+
+ if (!ret)
+ {
+ /* Fallback to old names */
+ ret = g_module_symbol (module->library,
+ "g_io_module_load",
+ (gpointer) &module->load) &&
+ g_module_symbol (module->library,
+ "g_io_module_unload",
+ (gpointer) &module->unload);
+ }
+
+ g_free (name);
+ g_free (load_symname);
+ g_free (unload_symname);
+
+ return ret;
+}
+
+static gboolean
g_io_module_load_module (GTypeModule *gmodule)
{
GIOModule *module = G_IO_MODULE (gmodule);
@@ -310,12 +347,7 @@ g_io_module_load_module (GTypeModule *gmodule)
}
/* Make sure that the loaded library contains the required methods */
- if (! g_module_symbol (module->library,
- "g_io_module_load",
- (gpointer) &module->load) ||
- ! g_module_symbol (module->library,
- "g_io_module_unload",
- (gpointer) &module->unload))
+ if (!load_symbols (module))
{
g_printerr ("%s\n", g_module_error ());
g_module_close (module->library);
diff --git a/gio/giomodule.h b/gio/giomodule.h
index 485f5eb..c4817ad 100644
--- a/gio/giomodule.h
+++ b/gio/giomodule.h
@@ -112,6 +112,12 @@ GTypeClass* g_io_extension_ref_class (GIOExtension
* This function is run after the module has been loaded into GIO,
* to initialize the module. Typically, this function will call
* g_io_extension_point_implement().
+ *
+ * Since 2.56 this function can be renamed to g_io_<modulename>_load where
+ * `modulename` is the plugin's filename with optional "lib" or "libgio" prefix
+ * and everything after first dot stripped off (e.g. libgiognutls.so -> gnutls).
+ * Renaming those symbols avoids symbol name clash when building modules
+ * statically.
**/
GLIB_AVAILABLE_IN_ALL
void g_io_module_load (GIOModule *module);
@@ -124,6 +130,12 @@ void g_io_module_load (GIOModule *module);
*
* This function is run when the module is being unloaded from GIO,
* to finalize the module.
+ *
+ * Since 2.56 this function can be renamed to g_io_<modulename>_unload where
+ * `modulename` is the plugin's filename with optional "lib" or "libgio" prefix
+ * and everything after first dot stripped off (e.g. libgiognutls.so -> gnutls).
+ * Renaming those symbols avoids symbol name clash when building modules
+ * statically.
**/
GLIB_AVAILABLE_IN_ALL
void g_io_module_unload (GIOModule *module);
@@ -155,6 +167,12 @@ void g_io_module_unload (GIOModule *module);
* run gio-querymodules in order to build the cache files required for
* lazy loading.
*
+ * Since 2.56 this function can be renamed to g_io_<modulename>_query where
+ * `modulename` is the plugin's filename with optional "lib" or "libgio" prefix
+ * and everything after first dot stripped off (e.g. libgiognutls.so -> gnutls).
+ * Renaming those symbols avoids symbol name clash when building modules
+ * statically.
+ *
* Returns: (transfer full): A %NULL-terminated array of strings,
* listing the supported extension points of the module. The array
* must be suitable for freeing with g_strfreev().
diff --git a/gio/meson.build b/gio/meson.build
index ddfd18f..17cb1f8 100644
--- a/gio/meson.build
+++ b/gio/meson.build
@@ -442,6 +442,7 @@ gio_sources = files(
'ginputstream.c',
'gioerror.c',
'giomodule.c',
+ 'giomodule-priv.c',
'gioscheduler.c',
'giostream.c',
'gloadableicon.c',
@@ -805,7 +806,7 @@ executable('gresource', 'gresource-tool.c',
link_args : noseh_link_args,
dependencies : [libelf, libintl, libgio_dep, libgobject_dep, libgmodule_dep, libglib_dep])
-executable('gio-querymodules', 'gio-querymodules.c',
+executable('gio-querymodules', 'gio-querymodules.c', 'giomodule-priv.c',
install : true,
c_args : ['-DHAVE_CONFIG_H=1'] + gio_c_args,
# intl.lib is not compatible with SAFESEH
--
2.7.4
From 16a4b321013ee38230c533e9fea05a952f8d2ba5 Mon Sep 17 00:00:00 2001
From: Xavier Claessens <xavier.claessens@collabora.com>
Date: Thu, 30 Nov 2017 19:26:35 -0500
Subject: [PATCH 2/2] GTypeModule: Allow registering static types
This makes easier to write a module that can be both dynamic and static.
It will allow to statically build modules from glib-networking, for
example.
https://bugzilla.gnome.org/show_bug.cgi?id=684282
---
gobject/gtypemodule.c | 47 ++++++++++++++++++++++++++++++++++++++---------
1 file changed, 38 insertions(+), 9 deletions(-)
diff --git a/gobject/gtypemodule.c b/gobject/gtypemodule.c
index 5289ffe..c67f789 100644
--- a/gobject/gtypemodule.c
+++ b/gobject/gtypemodule.c
@@ -344,7 +344,7 @@ g_type_module_complete_interface_info (GTypePlugin *plugin,
/**
* g_type_module_register_type:
- * @module: a #GTypeModule
+ * @module: (nullable): a #GTypeModule
* @parent_type: the type for the parent class
* @type_name: name for the type
* @type_info: type information structure
@@ -362,6 +362,9 @@ g_type_module_complete_interface_info (GTypePlugin *plugin,
* As long as any instances of the type exist, the type plugin will
* not be unloaded.
*
+ * Since 2.56 if @module is %NULL this will call g_type_register_static()
+ * instead. This can be used when making a static build of the module.
+ *
* Returns: the new or existing type ID
*/
GType
@@ -374,10 +377,22 @@ g_type_module_register_type (GTypeModule *module,
ModuleTypeInfo *module_type_info = NULL;
GType type;
- g_return_val_if_fail (module != NULL, 0);
g_return_val_if_fail (type_name != NULL, 0);
g_return_val_if_fail (type_info != NULL, 0);
+ if (module == NULL)
+ {
+ /* Cannot pass type_info directly to g_type_register_static() here because
+ * it has class_finalize != NULL and that's forbidden for static types */
+ return g_type_register_static_simple (parent_type,
+ type_name,
+ type_info->class_size,
+ type_info->class_init,
+ type_info->instance_size,
+ type_info->instance_init,
+ flags);
+ }
+
type = g_type_from_name (type_name);
if (type)
{
@@ -429,7 +444,7 @@ g_type_module_register_type (GTypeModule *module,
/**
* g_type_module_add_interface:
- * @module: a #GTypeModule
+ * @module: (nullable): a #GTypeModule
* @instance_type: type to which to add the interface.
* @interface_type: interface type to add
* @interface_info: type information structure
@@ -440,6 +455,9 @@ g_type_module_register_type (GTypeModule *module,
*
* As long as any instances of the type exist, the type plugin will
* not be unloaded.
+ *
+ * Since 2.56 if @module is %NULL this will call g_type_add_interface_static()
+ * instead. This can be used when making a static build of the module.
*/
void
g_type_module_add_interface (GTypeModule *module,
@@ -448,10 +466,15 @@ g_type_module_add_interface (GTypeModule *module,
const GInterfaceInfo *interface_info)
{
ModuleInterfaceInfo *module_interface_info = NULL;
-
- g_return_if_fail (module != NULL);
+
g_return_if_fail (interface_info != NULL);
+ if (module == NULL)
+ {
+ g_type_add_interface_static (instance_type, interface_type, interface_info);
+ return;
+ }
+
if (g_type_is_a (instance_type, interface_type))
{
GTypePlugin *old_plugin = g_type_interface_get_plugin (instance_type,
@@ -492,7 +515,7 @@ g_type_module_add_interface (GTypeModule *module,
/**
* g_type_module_register_enum:
- * @module: a #GTypeModule
+ * @module: (nullable): a #GTypeModule
* @name: name for the type
* @const_static_values: an array of #GEnumValue structs for the
* possible enumeration values. The array is
@@ -507,6 +530,9 @@ g_type_module_add_interface (GTypeModule *module,
* As long as any instances of the type exist, the type plugin will
* not be unloaded.
*
+ * Since 2.56 if @module is %NULL this will call g_type_register_static()
+ * instead. This can be used when making a static build of the module.
+ *
* Since: 2.6
*
* Returns: the new or existing type ID
@@ -518,7 +544,7 @@ g_type_module_register_enum (GTypeModule *module,
{
GTypeInfo enum_type_info = { 0, };
- g_return_val_if_fail (G_IS_TYPE_MODULE (module), 0);
+ g_return_val_if_fail (module == NULL || G_IS_TYPE_MODULE (module), 0);
g_return_val_if_fail (name != NULL, 0);
g_return_val_if_fail (const_static_values != NULL, 0);
@@ -531,7 +557,7 @@ g_type_module_register_enum (GTypeModule *module,
/**
* g_type_module_register_flags:
- * @module: a #GTypeModule
+ * @module: (nullable): a #GTypeModule
* @name: name for the type
* @const_static_values: an array of #GFlagsValue structs for the
* possible flags values. The array is
@@ -546,6 +572,9 @@ g_type_module_register_enum (GTypeModule *module,
* As long as any instances of the type exist, the type plugin will
* not be unloaded.
*
+ * Since 2.56 if @module is %NULL this will call g_type_register_static()
+ * instead. This can be used when making a static build of the module.
+ *
* Since: 2.6
*
* Returns: the new or existing type ID
@@ -557,7 +586,7 @@ g_type_module_register_flags (GTypeModule *module,
{
GTypeInfo flags_type_info = { 0, };
- g_return_val_if_fail (G_IS_TYPE_MODULE (module), 0);
+ g_return_val_if_fail (module == NULL || G_IS_TYPE_MODULE (module), 0);
g_return_val_if_fail (name != NULL, 0);
g_return_val_if_fail (const_static_values != NULL, 0);
--
2.7.4
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment