[pango/pango2: 1/18] Add a check for mixed linkage




commit 2ee46c3ef8ece19e6c9a76139f8b7ec2c738be78
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jun 5 08:17:24 2022 -0400

    Add a check for mixed linkage
    
    Having both pango 1.x and pango 2 linked into
    the same process will cause trouble, because the
    type and function names conflict.
    
    Error out if we detect this situation.

 meson.build           |  4 +++-
 pango/pango-context.c | 21 +++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)
---
diff --git a/meson.build b/meson.build
index 133e6f7c..057093ae 100644
--- a/meson.build
+++ b/meson.build
@@ -239,11 +239,13 @@ pango_deps += mathlib_dep
 # gobject
 glib_dep = dependency('glib-2.0', version: glib_req_version,
                       fallback: ['glib', 'libglib_dep'])
+gmodule_dep = dependency('gmodule-2.0', version: glib_req_version,
+                         fallback : ['glib', 'libgmodule_dep'])
 gobject_dep = dependency('gobject-2.0', version: glib_req_version,
                          fallback: ['glib', 'libgobject_dep'])
 gio_dep = dependency('gio-2.0', version: glib_req_version,
                          fallback: ['glib', 'libgio_dep'])
-pango_deps += [glib_dep, gobject_dep, gio_dep]
+pango_deps += [glib_dep, gmodule_dep, gobject_dep, gio_dep]
 
 fribidi_dep = dependency('fribidi', version: fribidi_req_version,
                          fallback: ['fribidi', 'libfribidi_dep'],
diff --git a/pango/pango-context.c b/pango/pango-context.c
index bd1c75aa..6376d1ff 100644
--- a/pango/pango-context.c
+++ b/pango/pango-context.c
@@ -81,11 +81,32 @@ pango_context_init (PangoContext *context)
   pango_font_description_set_size (context->font_desc, 12 * PANGO_SCALE);
 }
 
+static gboolean
+pango_has_mixed_deps (void)
+{
+  GModule *module;
+  gpointer func;
+  gboolean result = FALSE;
+
+  module = g_module_open (NULL, 0);
+
+  if (g_module_symbol (module, "pango_ot_info_find_script", &func))
+    result = TRUE;
+
+  g_module_close (module);
+
+  return result;
+}
+
 static void
 pango_context_class_init (PangoContextClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+  /* Put the check for mixed linkage here, for lack of a better place */
+  if (pango_has_mixed_deps ())
+    g_error ("Pango 1.x symbols detected.\nUsing Pango 1.x and 2 in the same process is not supported."); 
+
   object_class->finalize = pango_context_finalize;
 }
 


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