1 /* testgmodule.c - test program for GMODULE
2 * Copyright (C) 1998 Tim Janik
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GLib Team and others 1997-1999. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
34 g_print ("GModule: Hello global clash\n");
37 typedef void (*SimpleFunc) (void);
38 typedef void (*GModuleFunc) (GModule *);
40 SimpleFunc gplugin_clash_func;
46 GModule *module_self, *module_a, *module_b;
48 gchar *plugin_a, *plugin_b;
49 SimpleFunc f_a, f_b, f_self;
52 string = g_get_current_dir ();
53 g_print ("testgmodule (%s):\n", string);
56 plugin_a = g_strconcat (string, "\\libgplugin_a.dll", NULL);
57 plugin_b = g_strconcat (string, "\\libgplugin_b.dll", NULL);
58 #else /* !NATIVE_WIN32 */
59 plugin_a = g_strconcat (string, "/.libs/", "libgplugin_a.so", NULL);
60 plugin_b = g_strconcat (string, "/.libs/", "libgplugin_b.so", NULL);
61 #endif /* NATIVE_WIN32 */
66 g_print ("get main module handle\n");
67 module_self = g_module_open (NULL, G_MODULE_BIND_LAZY);
70 g_print ("error: %s\n", g_module_error ());
73 g_print ("load plugin from \"%s\"\n", plugin_a);
74 module_a = g_module_open (plugin_a, G_MODULE_BIND_LAZY);
77 g_print ("error: %s\n", g_module_error ());
80 g_print ("load plugin from \"%s\"\n", plugin_b);
81 module_b = g_module_open (plugin_b, G_MODULE_BIND_LAZY);
84 g_print ("error: %s\n", g_module_error ());
88 /* get plugin specific symbols and call them
90 string = "gplugin_a_func";
91 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
92 if (!g_module_symbol (module_a, string, (gpointer) &f_a))
94 g_print ("error: %s\n", g_module_error ());
97 string = "gplugin_b_func";
98 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
99 if (!g_module_symbol (module_b, string, (gpointer) &f_b))
101 g_print ("error: %s\n", g_module_error ());
104 g_print ("call plugin function(%p) A: ", f_a);
106 g_print ("call plugin function(%p) B: ", f_b);
109 /* get and call globally clashing functions
111 string = "g_clash_func";
112 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_self)));
113 if (!g_module_symbol (module_self, string, (gpointer) &f_self))
115 g_print ("error: %s\n", g_module_error ());
118 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
119 if (!g_module_symbol (module_a, string, (gpointer) &f_a))
121 g_print ("error: %s\n", g_module_error ());
124 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
125 if (!g_module_symbol (module_b, string, (gpointer) &f_b))
127 g_print ("error: %s\n", g_module_error ());
130 g_print ("call plugin function(%p) self: ", f_self);
132 g_print ("call plugin function(%p) A: ", f_a);
134 g_print ("call plugin function(%p) B: ", f_b);
137 /* get and call clashing plugin functions
139 string = "gplugin_clash_func";
140 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
141 if (!g_module_symbol (module_a, string, (gpointer) &f_a))
143 g_print ("error: %s\n", g_module_error ());
146 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
147 if (!g_module_symbol (module_b, string, (gpointer) &f_b))
149 g_print ("error: %s\n", g_module_error ());
152 g_print ("call plugin function(%p) A: ", f_a);
153 gplugin_clash_func = f_a;
154 gplugin_clash_func ();
155 g_print ("call plugin function(%p) B: ", f_b);
156 gplugin_clash_func = f_b;
157 gplugin_clash_func ();
159 /* call gmodule function form A
161 string = "gplugin_a_module_func";
162 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
163 if (!g_module_symbol (module_a, string, (gpointer) &gmod_f))
165 g_print ("error: %s\n", g_module_error ());
168 g_print ("call plugin A's module function(%p):\n{\n", gmod_f);
175 g_print ("unload plugin A:\n");
176 if (!g_module_close (module_a))
177 g_print ("error: %s\n", g_module_error ());
178 g_print ("unload plugin B:\n");
179 if (!g_module_close (module_b))
180 g_print ("error: %s\n", g_module_error ());
183 g_log_set_fatal_mask ("GModule", G_LOG_FATAL_MASK|G_LOG_LEVEL_WARNING);
184 g_module_symbol (0, 0, 0);
186 g_on_error_query (".libs/testgmodule");