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

Re: more Perl ... fun



On 07 Nov 2002 18:33:53 -0600
"Austin T." <purpleflux@system78.com> wrote:

> Ok, I found the info on xchat.org about gdb backtrace and not being
> able to resolve hostnames when running in gdb.  That understood, I
> would like to add more to the segfault in xchat-1.9.4 regarding the
> perl plugin. Again this is on RH8 (perl-5.8.0-55).  Here is my
> backtrace from gdb (if I'm not supposed to send backtraces to this
> list, please let me know):
> 
> [...]

PL_perl_destruct_level shouldn't be set before the interpreter is
created. Setting it straight after calling perl_construct from
perl_init seems to fix it.

The second segfault (the one in perl_auto_load) is really strange.
Disassembling perl_auto_load shows a chunk of code towards the end
that isn't accounted for in the definition of perl_auto_load in
perl.c, somehow added by the perl #includes. A temporary kludge fix
for this would be to move the definition of perl_auto_load to a
separate source file, one which doesn't include anything from perl.
The attached patch does this. (You'll have to run `automake --foreign'
from the top-level directory before recompiling)

diff -rNu xchat-1.9.4-orig/plugins/perl/Makefile.am xchat-1.9.4-perl5.8fix/plugins/perl/Makefile.am
--- xchat-1.9.4-orig/plugins/perl/Makefile.am	2002-06-25 06:32:46.000000000 +0100
+++ xchat-1.9.4-perl5.8fix/plugins/perl/Makefile.am	2002-11-08 04:37:53.000000000 +0000
@@ -1,9 +1,10 @@
 noinst_LIBRARIES = libperl.a
-libperl_a_SOURCES = perl.c
+libperl_a_SOURCES = perl.c perl-5.8-kludge.c
 bin_SCRIPTS = perl.so
 bindir = $(xchatdir)/plugins
 CLEANFILES = perl.so
 
 perl.o: perl.c ../xchat-plugin.h
 	$(COMPILE) -Wno-unused $(PERL_CFLAGS) $(COMMON_CFLAGS) -I.. -c perl.c -o perl.o
-	$(COMPILE) -shared perl.o -o perl.so $(PERL_LDFLAGS)
+	$(COMPILE) -Wno-unused $(PERL_CFLAGS) $(COMMON_CFLAGS) -I.. -c perl-5.8-kludge.c -o perl-5.8-kludge.o
+	$(COMPILE) -shared perl.o perl-5.8-kludge.o -o perl.so $(PERL_LDFLAGS)
diff -rNu xchat-1.9.4-orig/plugins/perl/perl-5.8-kludge.c xchat-1.9.4-perl5.8fix/plugins/perl/perl-5.8-kludge.c
--- xchat-1.9.4-orig/plugins/perl/perl-5.8-kludge.c	1970-01-01 01:00:00.000000000 +0100
+++ xchat-1.9.4-perl5.8fix/plugins/perl/perl-5.8-kludge.c	2002-11-08 04:37:59.000000000 +0000
@@ -0,0 +1,37 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <dirent.h>
+
+#undef PACKAGE
+#include "../../config.h"
+#include "xchat-plugin.h"
+
+int perl_load_file(char *);
+
+void
+perl_auto_load (xchat_plugin *ph)
+{
+	DIR *dir;
+	struct dirent *ent;
+	const char *xdir;
+
+	xdir = xchat_get_info (ph, "xchatdir");
+	dir = opendir (xdir);
+	if (dir)
+	{
+		while ((ent = readdir (dir)))
+		{
+			int len = strlen (ent->d_name);
+			if (len > 3 && strcasecmp (".pl", ent->d_name + len - 3) == 0)
+			{
+				char *file = malloc (len + strlen (xdir) + 2);
+				sprintf (file, "%s/%s", xdir, ent->d_name);
+				perl_load_file (file);
+				free (file);
+			}
+		}
+		closedir (dir);
+	}
+}
+
diff -rNu xchat-1.9.4-orig/plugins/perl/perl.c xchat-1.9.4-perl5.8fix/plugins/perl/perl.c
--- xchat-1.9.4-orig/plugins/perl/perl.c	2002-07-23 08:58:57.000000000 +0100
+++ xchat-1.9.4-perl5.8fix/plugins/perl/perl.c	2002-11-08 04:37:56.000000000 +0000
@@ -920,6 +920,7 @@
 
 	my_perl = perl_alloc ();
 	perl_construct (my_perl);
+	PL_perl_destruct_level = 1;
 
 	warn = 0;
 	xchat_get_prefs (ph, "perl_warnings", NULL, &warn);
@@ -944,7 +945,7 @@
 
   TheHobbit <thehobbit@altern.org>
 */
-static int
+int
 perl_load_file (char *script_name)
 {
 	if (my_perl == NULL)
@@ -953,6 +954,8 @@
 	return execute_perl ("load_n_eval", script_name);
 }
 
+void perl_auto_load (xchat_plugin *);	/* perl-5.8-kludge.c */
+/*
 static void
 perl_auto_load (void)
 {
@@ -978,6 +981,7 @@
 		closedir (dir);
 	}
 }
+*/
 
 /* checks for "~" in a file and expands */
 
@@ -1095,13 +1099,11 @@
 	*plugin_version = VERSION;
 	*plugin_desc = "Perl scripting interface";
 
-	PL_perl_destruct_level = 1;
-
 	xchat_hook_command (ph, "load", PRI_NORM, perl_command_load, 0, 0);
 	xchat_hook_command (ph, "unload", PRI_NORM, perl_command_unload, 0, 0);
 	xchat_hook_command (ph, "unloadall", PRI_NORM, perl_command_unloadall, 0, 0);
 
-	perl_auto_load ();
+	perl_auto_load (ph);
 
 	return 1;
 }