Mercurial > pidgin
changeset 6567:6e25e1e08ffb
[gaim-migrate @ 7089]
Perl signal callbacks just got more spiffy. You can now embed a sub inside
of a callback instead of linking to the function.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Fri, 22 Aug 2003 04:09:06 +0000 |
parents | f6c2a7b5afa7 |
children | 33486b749aa9 |
files | plugins/perl/common/Gaim.xs plugins/perl/perl-handlers.c plugins/perl/perl-handlers.h |
diffstat | 3 files changed, 41 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/perl/common/Gaim.xs Thu Aug 21 23:41:52 2003 +0000 +++ b/plugins/perl/common/Gaim.xs Fri Aug 22 04:09:06 2003 +0000 @@ -14,23 +14,22 @@ gaim_perl_timeout_add(plugin, seconds, func, data); void -signal_connect(instance, signal, plugin, func, data) +signal_connect(instance, signal, plugin, callback, data) void *instance const char *signal Gaim::Plugin plugin - const char *func + SV *callback SV *data CODE: - gaim_perl_signal_connect(plugin, instance, signal, func, data); + gaim_perl_signal_connect(plugin, instance, signal, callback, data); void -signal_disconnect(instance, signal, plugin, func) +signal_disconnect(instance, signal, plugin) void *instance const char *signal Gaim::Plugin plugin - const char *func CODE: - gaim_perl_signal_disconnect(plugin, instance, signal, func); + gaim_perl_signal_disconnect(plugin, instance, signal); void debug(level, category, string)
--- a/plugins/perl/perl-handlers.c Thu Aug 21 23:41:52 2003 +0000 +++ b/plugins/perl/perl-handlers.c Fri Aug 22 04:09:06 2003 +0000 @@ -23,8 +23,16 @@ { signal_handlers = g_list_remove(signal_handlers, handler); + if (handler->instance != NULL) + SvREFCNT_dec(handler->instance); + + if (handler->callback != NULL) + SvREFCNT_dec(handler->callback); + + if (handler->data != NULL) + SvREFCNT_dec(handler->data); + g_free(handler->signal); - g_free(handler->func); g_free(handler); } @@ -82,15 +90,21 @@ XPUSHs((SV *)handler->data); PUTBACK; - gaim_debug(GAIM_DEBUG_INFO, "perl", "Calling handler %s\n", - handler->func); - count = call_pv(handler->func, G_EVAL | G_SCALAR); - SPAGAIN; + + if (ret_value != NULL) + { + count = call_sv(handler->callback, G_SCALAR); + + SPAGAIN; - if (count > 1) - ret_val = POPp; + if (count != 1) + croak("Uh oh! call_sv returned %i != 1", i); + else + ret_val = POPs; + } + else + call_sv(handler->callback, G_SCALAR); - PUTBACK; FREETMPS; LEAVE; @@ -98,8 +112,7 @@ } static GaimPerlSignalHandler * -find_signal_handler(GaimPlugin *plugin, void *instance, - const char *signal, const char *func) +find_signal_handler(GaimPlugin *plugin, void *instance, const char *signal) { GaimPerlSignalHandler *handler; GList *l; @@ -110,8 +123,7 @@ if (handler->plugin == plugin && handler->instance == instance && - !strcmp(handler->signal, signal) && - !strcmp(handler->func, func)) + !strcmp(handler->signal, signal)) { return handler; } @@ -168,7 +180,7 @@ void gaim_perl_signal_connect(GaimPlugin *plugin, void *instance, - const char *signal, const char *func, void *data) + const char *signal, SV *callback, SV *data) { GaimPerlSignalHandler *handler; @@ -176,23 +188,24 @@ handler->plugin = plugin; handler->instance = instance; handler->signal = g_strdup(signal); - handler->func = g_strdup(func); - handler->data = data; + handler->callback = (callback != NULL && callback != &PL_sv_undef + ? newSVsv(callback) : NULL); + handler->data = (data != NULL && data != &PL_sv_undef + ? newSVsv(data) : NULL); signal_handlers = g_list_append(signal_handlers, handler); - gaim_debug(GAIM_DEBUG_MISC, "perl", "plugin = %p\n", plugin); gaim_signal_connect_vargs(instance, signal, plugin, GAIM_CALLBACK(perl_signal_cb), handler); } void gaim_perl_signal_disconnect(GaimPlugin *plugin, void *instance, - const char *signal, const char *func) + const char *signal) { GaimPerlSignalHandler *handler; - handler = find_signal_handler(plugin, instance, signal, func); + handler = find_signal_handler(plugin, instance, signal); if (handler == NULL) {
--- a/plugins/perl/perl-handlers.h Thu Aug 21 23:41:52 2003 +0000 +++ b/plugins/perl/perl-handlers.h Fri Aug 22 04:09:06 2003 +0000 @@ -15,8 +15,8 @@ typedef struct { char *signal; - char *func; - void *data; + SV *callback; + SV *data; void *instance; GaimPlugin *plugin; @@ -29,10 +29,10 @@ void gaim_perl_timeout_clear(void); void gaim_perl_signal_connect(GaimPlugin *plugin, void *instance, - const char *signal, const char *func, - void *data); + const char *signal, SV *callback, + SV *data); void gaim_perl_signal_disconnect(GaimPlugin *plugin, void *instance, - const char *signal, const char *func); + const char *signal); void gaim_perl_signal_clear_for_plugin(GaimPlugin *plugin); void gaim_perl_signal_clear(void);