diff options
author | Emanuele Giaquinta <exg@irssi.org> | 2008-12-08 16:06:11 +0000 |
---|---|---|
committer | exg <exg@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2008-12-08 16:06:11 +0000 |
commit | 8c64738cdc3f3c18d97f70968a48583ee17512b3 (patch) | |
tree | eb6bf8d3505e1e3d0b3f902d62578ffdc3b13734 /src/perl/common | |
parent | 0cea011470306523c6040a8861cdf2fa1d9244d1 (diff) | |
download | irssi-8c64738cdc3f3c18d97f70968a48583ee17512b3.zip |
Add perl_signal_args_to_c() to convert signal parameters from Perl to C values,
and make Irssi::signal_emit/Irssi::signal_continue use it. Also make
perl_call_signal() turn NULLs into undef, so we can recover them in
perl_signal_args_to_c(), which is its inverse operation.
Patch by Lukas Mai.
git-svn-id: file:///var/www/svn.irssi.org/SVN/irssi/trunk@4953 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/perl/common')
-rw-r--r-- | src/perl/common/Core.xs | 63 |
1 files changed, 31 insertions, 32 deletions
diff --git a/src/perl/common/Core.xs b/src/perl/common/Core.xs index c1e526bb..4032340a 100644 --- a/src/perl/common/Core.xs +++ b/src/perl/common/Core.xs @@ -65,6 +65,15 @@ static void add_tuple(gpointer key_, gpointer value_, gpointer user_data) hv_store(hash, key, strlen(key), new_pv(value), 0); } +static void wrap_signal_emit(void *signal, void **p) { + signal_emit(signal, 6, p[0], p[1], p[2], p[3], p[4], p[5]); +} + +static void wrap_signal_continue(void *dummy, void **p) { + (void)dummy; + signal_continue(6, p[0], p[1], p[2], p[3], p[4], p[5]); +} + MODULE = Irssi::Core PACKAGE = Irssi PROTOTYPES: ENABLE @@ -72,44 +81,34 @@ void signal_emit(signal, ...) char *signal CODE: - void *p[SIGNAL_MAX_ARGUMENTS]; - int n; - - memset(p, 0, sizeof(p)); - for (n = 1; n < items && n < SIGNAL_MAX_ARGUMENTS+1; n++) { - if (SvPOKp(ST(n))) - p[n-1] = SvPV(ST(n), PL_na); - else if (irssi_is_ref_object(ST(n))) - p[n-1] = irssi_ref_object(ST(n)); - else if (SvROK(ST(n))) - p[n-1] = (void *) SvIV((SV*)SvRV(ST(n))); - else if (SvIOK(ST(n))) - p[n-1] = (void *)SvIV(ST(n)); - else - p[n-1] = NULL; + int signal_id; + SV *args[SIGNAL_MAX_ARGUMENTS]; + int n, used; + + signal_id = signal_get_uniq_id(signal); + used = items - 1; + if (used > SIGNAL_MAX_ARGUMENTS) { + used = SIGNAL_MAX_ARGUMENTS; + } + for (n = 0; n < used; ++n) { + args[n] = ST(n + 1); } - signal_emit(signal, items-1, p[0], p[1], p[2], p[3], p[4], p[5]); + perl_signal_args_to_c(wrap_signal_emit, signal, signal_id, args, used); void signal_continue(...) CODE: - void *p[SIGNAL_MAX_ARGUMENTS]; - int n; - - memset(p, 0, sizeof(p)); - for (n = 0; n < items && n < SIGNAL_MAX_ARGUMENTS; n++) { - if (SvPOKp(ST(n))) - p[n] = SvPV(ST(n), PL_na); - else if (irssi_is_ref_object(ST(n))) - p[n] = irssi_ref_object(ST(n)); - else if (SvROK(ST(n))) - p[n] = (void *) SvIV((SV*)SvRV(ST(n))); - else if (SvIOK(ST(n))) - p[n] = (void *) SvIV(ST(n)); - else - p[n] = NULL; + SV *args[SIGNAL_MAX_ARGUMENTS]; + int n, used; + + used = items; + if (used > SIGNAL_MAX_ARGUMENTS) { + used = SIGNAL_MAX_ARGUMENTS; + } + for (n = 0; n < used; ++n) { + args[n] = ST(n); } - signal_continue(items, p[0], p[1], p[2], p[3], p[4], p[5]); + perl_signal_args_to_c(wrap_signal_continue, NULL, signal_get_emitted_id(), args, used); void signal_add(...) |