summaryrefslogtreecommitdiff
path: root/src/perl
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2001-10-14 09:07:26 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2001-10-14 09:07:26 +0000
commit80dd9a15ca66ac340426bc256d8d778baefd19bd (patch)
tree096695d819a0ff11515e489c2672811c89e496bc /src/perl
parentb0ac3b83e7cf63e9d9b2864e8990239b5801d527 (diff)
downloadirssi-80dd9a15ca66ac340426bc256d8d778baefd19bd.zip
Irssi::timeout_add() and Irssi::input_add() now accepts any type of variable
as data instead of just string. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1825 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/perl')
-rw-r--r--src/perl/common/Core.xs8
-rw-r--r--src/perl/perl-sources.c20
-rw-r--r--src/perl/perl-sources.h5
3 files changed, 17 insertions, 16 deletions
diff --git a/src/perl/common/Core.xs b/src/perl/common/Core.xs
index 6c04cc9d..4378c5c6 100644
--- a/src/perl/common/Core.xs
+++ b/src/perl/common/Core.xs
@@ -59,9 +59,9 @@ int
timeout_add(msecs, func, data)
int msecs
char *func
- char *data
+ void *data
CODE:
- RETVAL = perl_timeout_add(msecs, func, data);
+ RETVAL = perl_timeout_add(msecs, func, ST(2));
OUTPUT:
RETVAL
@@ -91,9 +91,9 @@ input_add(source, condition, func, data)
int source
int condition
char *func
- char *data
+ void *data
CODE:
- RETVAL = perl_input_add(source, condition, func, data);
+ RETVAL = perl_input_add(source, condition, func, ST(2));
OUTPUT:
RETVAL
diff --git a/src/perl/perl-sources.c b/src/perl/perl-sources.c
index 7b263bcb..3239a20f 100644
--- a/src/perl/perl-sources.c
+++ b/src/perl/perl-sources.c
@@ -29,7 +29,7 @@ typedef struct {
int tag;
int refcount;
char *func;
- char *data;
+ SV *data;
} PERL_SOURCE_REC;
static GSList *perl_sources;
@@ -44,8 +44,8 @@ static void perl_source_unref(PERL_SOURCE_REC *rec)
if (--rec->refcount != 0)
return;
+ SvREFCNT_dec(rec->data);
g_free(rec->func);
- g_free(rec->data);
g_free(rec);
}
@@ -68,7 +68,7 @@ static int perl_source_event(PERL_SOURCE_REC *rec)
SAVETMPS;
PUSHMARK(SP);
- XPUSHs(sv_2mortal(new_pv(rec->data)));
+ XPUSHs(sv_mortalcopy(rec->data));
PUTBACK;
perl_source_ref(rec);
@@ -94,23 +94,24 @@ static int perl_source_event(PERL_SOURCE_REC *rec)
return 1;
}
-int perl_timeout_add(int msecs, const char *func, const char *data)
+int perl_timeout_add(int msecs, const char *func, SV *data)
{
PERL_SOURCE_REC *rec;
rec = g_new(PERL_SOURCE_REC, 1);
perl_source_ref(rec);
+ SvREFCNT_inc(data);
+ rec->data = data;
+
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);
perl_sources = g_slist_append(perl_sources, rec);
return rec->tag;
}
-int perl_input_add(int source, int condition,
- const char *func, const char *data)
+int perl_input_add(int source, int condition, const char *func, SV *data)
{
PERL_SOURCE_REC *rec;
GIOChannel *channel;
@@ -118,9 +119,10 @@ int perl_input_add(int source, int condition,
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);
+ SvREFCNT_inc(data);
+ rec->data = data;
+ rec->func = g_strdup_printf("%s::%s", perl_get_package(), func);
channel = g_io_channel_unix_new(source);
rec->tag = g_input_add(channel, condition,
(GInputFunction) perl_source_event, rec);
diff --git a/src/perl/perl-sources.h b/src/perl/perl-sources.h
index a04c4d80..e61004db 100644
--- a/src/perl/perl-sources.h
+++ b/src/perl/perl-sources.h
@@ -1,9 +1,8 @@
#ifndef __PERL_SOURCES_H
#define __PERL_SOURCES_H
-int perl_timeout_add(int msecs, const char *func, const char *data);
-int perl_input_add(int source, int condition,
- const char *func, const char *data);
+int perl_timeout_add(int msecs, const char *func, SV *data);
+int perl_input_add(int source, int condition, const char *func, SV *data);
void perl_source_remove(int tag);
/* remove all sources used by package */