Re: [AD] Fwd: [sam@xxxxxxxxxx: allegro crashes when unloading the svgalib module] |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On 2003-04-07, Eric <ebotcazou@xxxxxxxxxx> wrote:
>
> You are the specialist of modules so commit whatever you want on both
> branches.
The attached patch was applied to both.
--
王浩禎
Index: src/linux/svgalib.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/linux/svgalib.c,v
retrieving revision 1.29.2.3
diff -u -r1.29.2.3 svgalib.c
--- src/linux/svgalib.c 7 Feb 2003 13:35:56 -0000 1.29.2.3
+++ src/linux/svgalib.c 9 Apr 2003 07:07:56 -0000
@@ -92,6 +92,15 @@
+#ifdef ALLEGRO_MODULE
+
+/* If this is non-zero, this module won't be unloaded. */
+int _module_dont_unload_me_dirty_hack = 0;
+
+#endif
+
+
+
/* _svgalib_read_line:
* Return linear offset for reading line.
*/
@@ -177,6 +186,13 @@
tcgetattr(__al_linux_console_fd, &termio);
ret = vga_setmode(num);
+
+#ifdef ALLEGRO_MODULE
+ /* A side-effect of vga_setmode() is that it will register an
+ * atexit handler. See umodules.c for this problem.
+ */
+ _module_dont_unload_me_dirty_hack = 1;
+#endif
tcsetattr(__al_linux_console_fd, TCSANOW, &termio);
if (tio)
Index: src/unix/umodules.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/unix/umodules.c,v
retrieving revision 1.5.2.3
diff -u -r1.5.2.3 umodules.c
--- src/unix/umodules.c 14 Mar 2003 13:56:36 -0000 1.5.2.3
+++ src/unix/umodules.c 9 Apr 2003 07:07:56 -0000
@@ -156,13 +156,26 @@
{
MODULE *m, *next;
void (*shutdown)(void);
+ int *dont_unload;
for (m = module_list; m; m = next) {
next = m->next;
+
shutdown = dlsym(m->handle, "_module_shutdown");
if (shutdown)
shutdown();
- dlclose(m->handle);
+
+ /* Dirty hack: If the loaded module registers its own cleanup
+ * function with atexit, we mustn't unload the module, otherwise
+ * the atexit machinery will end up referring to a function that
+ * won't exist by the end of the program. This problem only
+ * affects SVGAlib currently.
+ */
+ dont_unload = dlsym(m->handle, "_module_dont_unload_me_dirty_hack");
+
+ if ((!dont_unload) || !(*dont_unload))
+ dlclose(m->handle);
+
free(m);
}