summaryrefslogtreecommitdiff
path: root/src/perl/perl-sources.c
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2001-07-30 12:56:57 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2001-07-30 12:56:57 +0000
commit82034efb110ce7055741d1238db46effc2f57bc1 (patch)
treeb137abddfbfd965a26f5caab4a61752808606da2 /src/perl/perl-sources.c
parent279f149295f7ee830c95a9bf0d861a057674b545 (diff)
downloadirssi-82034efb110ce7055741d1238db46effc2f57bc1.zip
Script name is printed now correctly if there's an error in
timeouts/signals. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1688 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/perl/perl-sources.c')
-rw-r--r--src/perl/perl-sources.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/perl/perl-sources.c b/src/perl/perl-sources.c
index a16e87f9..7b263bcb 100644
--- a/src/perl/perl-sources.c
+++ b/src/perl/perl-sources.c
@@ -27,22 +27,38 @@
typedef struct {
int tag;
+ int refcount;
char *func;
char *data;
} PERL_SOURCE_REC;
static GSList *perl_sources;
-static void perl_source_destroy(PERL_SOURCE_REC *rec)
+static void perl_source_ref(PERL_SOURCE_REC *rec)
{
- perl_sources = g_slist_remove(perl_sources, rec);
+ rec->refcount++;
+}
+
+static void perl_source_unref(PERL_SOURCE_REC *rec)
+{
+ if (--rec->refcount != 0)
+ return;
- g_source_remove(rec->tag);
g_free(rec->func);
g_free(rec->data);
g_free(rec);
}
+static void perl_source_destroy(PERL_SOURCE_REC *rec)
+{
+ perl_sources = g_slist_remove(perl_sources, rec);
+
+ g_source_remove(rec->tag);
+ rec->tag = -1;
+
+ perl_source_unref(rec);
+}
+
static int perl_source_event(PERL_SOURCE_REC *rec)
{
dSP;
@@ -55,16 +71,21 @@ static int perl_source_event(PERL_SOURCE_REC *rec)
XPUSHs(sv_2mortal(new_pv(rec->data)));
PUTBACK;
+ perl_source_ref(rec);
retcount = perl_call_pv(rec->func, G_EVAL|G_DISCARD);
SPAGAIN;
if (SvTRUE(ERRSV)) {
STRLEN n_a;
+ char *package;
+ package = perl_function_get_package(rec->func);
signal_emit("script error", 2,
- perl_script_find_package(perl_get_package()),
+ perl_script_find_package(package),
SvPV(ERRSV, n_a));
+ g_free(package);
}
+ perl_source_unref(rec);
PUTBACK;
FREETMPS;
@@ -78,6 +99,8 @@ int perl_timeout_add(int msecs, const char *func, const char *data)
PERL_SOURCE_REC *rec;
rec = g_new(PERL_SOURCE_REC, 1);
+ perl_source_ref(rec);
+
rec->func = g_strdup_printf("%s::%s", perl_get_package(), func);
rec->data = g_strdup(data);
rec->tag = g_timeout_add(msecs, (GSourceFunc) perl_source_event, rec);
@@ -93,6 +116,8 @@ int perl_input_add(int source, int condition,
GIOChannel *channel;
rec = g_new(PERL_SOURCE_REC, 1);
+ perl_source_ref(rec);
+
rec->func = g_strdup_printf("%s::%s", perl_get_package(), func);
rec->data = g_strdup(data);