summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2002-05-07 23:40:21 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2002-05-07 23:40:21 +0000
commitc1384d919b2e0fe7a17553113fea1f3c3867b9aa (patch)
tree178ca8b194188be55512c9a4819db342a5158ef1 /src
parent0d76b6538132e8baa793d5a199cc14cddcaf7593 (diff)
downloadirssi-c1384d919b2e0fe7a17553113fea1f3c3867b9aa.zip
return value wasn't a good idea after all - added Irssi::timeout_add_once()
instead. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2758 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src')
-rw-r--r--src/perl/common/Core.xs17
-rw-r--r--src/perl/perl-sources.c18
2 files changed, 25 insertions, 10 deletions
diff --git a/src/perl/common/Core.xs b/src/perl/common/Core.xs
index 0fb93efb..d6fdfdd8 100644
--- a/src/perl/common/Core.xs
+++ b/src/perl/common/Core.xs
@@ -193,7 +193,22 @@ CODE:
croak("Irssi::timeout() : msecs must be >= 10");
RETVAL = -1;
} else {
- RETVAL = perl_timeout_add(msecs, func, data);
+ RETVAL = perl_timeout_add(msecs, func, data, FALSE);
+ }
+OUTPUT:
+ RETVAL
+
+int
+timeout_add_once(msecs, func, data)
+ int msecs
+ SV *func
+ SV *data
+CODE:
+ if (msecs < 10) {
+ croak("Irssi::timeout_once() : msecs must be >= 10");
+ RETVAL = -1;
+ } else {
+ RETVAL = perl_timeout_add(msecs, func, data, TRUE);
}
OUTPUT:
RETVAL
diff --git a/src/perl/perl-sources.c b/src/perl/perl-sources.c
index 06516474..3e74a659 100644
--- a/src/perl/perl-sources.c
+++ b/src/perl/perl-sources.c
@@ -28,7 +28,8 @@
typedef struct {
PERL_SCRIPT_REC *script;
int tag;
- int refcount;
+ int refcount;
+ int once; /* run only once */
SV *func;
SV *data;
@@ -41,14 +42,15 @@ static void perl_source_ref(PERL_SOURCE_REC *rec)
rec->refcount++;
}
-static void perl_source_unref(PERL_SOURCE_REC *rec)
+static int perl_source_unref(PERL_SOURCE_REC *rec)
{
if (--rec->refcount != 0)
- return;
+ return TRUE;
SvREFCNT_dec(rec->data);
SvREFCNT_dec(rec->func);
g_free(rec);
+ return FALSE;
}
static void perl_source_destroy(PERL_SOURCE_REC *rec)
@@ -81,12 +83,10 @@ static int perl_source_event(PERL_SOURCE_REC *rec)
char *error = g_strdup(SvPV(ERRSV, PL_na));
signal_emit("script error", 2, rec->script, error);
g_free(error);
- } else if (retcount > 0 && POPi != 0) {
- /* stopped */
- perl_source_destroy(rec);
}
- perl_source_unref(rec);
+ if (perl_source_unref(rec) && rec->once)
+ perl_source_destroy(rec);
PUTBACK;
FREETMPS;
@@ -95,7 +95,7 @@ static int perl_source_event(PERL_SOURCE_REC *rec)
return 1;
}
-int perl_timeout_add(int msecs, SV *func, SV *data)
+int perl_timeout_add(int msecs, SV *func, SV *data, int once)
{
PERL_SCRIPT_REC *script;
PERL_SOURCE_REC *rec;
@@ -117,7 +117,7 @@ int perl_timeout_add(int msecs, SV *func, SV *data)
return rec->tag;
}
-int perl_input_add(int source, int condition, SV *func, SV *data)
+int perl_input_add(int source, int condition, SV *func, SV *data, int once)
{
PERL_SCRIPT_REC *script;
PERL_SOURCE_REC *rec;