[perl-Glib-Object-Introspection] Avoid passing two copies of the user data to Perl callbacks



commit ee646f92dc04bf2774515524e0a76f62b88744d3
Author: Torsten SchÃnfeld <kaffeetisch gmx de>
Date:   Sun Jan 27 22:07:42 2013 +0100

    Avoid passing two copies of the user data to Perl callbacks

 gperl-i11n-invoke-info.c |    7 -------
 gperl-i11n-invoke-perl.c |   30 ++++++++++++++++--------------
 t/callbacks.t            |    4 ++--
 3 files changed, 18 insertions(+), 23 deletions(-)
---
diff --git a/gperl-i11n-invoke-info.c b/gperl-i11n-invoke-info.c
index e565da4..8248132 100644
--- a/gperl-i11n-invoke-info.c
+++ b/gperl-i11n-invoke-info.c
@@ -227,13 +227,6 @@ prepare_perl_invocation_info (GPerlI11nInvocationInfo *iinfo,
 	iinfo->is_callback = (g_base_info_get_type (info) == GI_INFO_TYPE_CALLBACK);
 	dwarn ("  is_function = %d, is_vfunc = %d, is_callback = %d, is_signal = %d\n",
 	       iinfo->is_function, iinfo->is_vfunc, iinfo->is_callback, iinfo->is_signal);
-	if (iinfo->is_signal) {
-		 /* FIXME: Need separate iinfo struct for calls into perl, with
-		  * a field "has_implicit_invocant". */
-		iinfo->is_method = TRUE;
-	} else {
-		iinfo->is_method = FALSE;
-	}
 
 	iinfo->n_args = g_callable_info_get_n_args (info);
 
diff --git a/gperl-i11n-invoke-perl.c b/gperl-i11n-invoke-perl.c
index 602b3a3..4326847 100644
--- a/gperl-i11n-invoke-perl.c
+++ b/gperl-i11n-invoke-perl.c
@@ -10,7 +10,7 @@ invoke_perl_code (ffi_cif* cif, gpointer resp, gpointer* args, gpointer userdata
 	guint in_inout;
 	guint n_return_values, n_returned;
 	I32 context;
-	SV *instance_sv = NULL, *data_sv = NULL, *first_sv = NULL, *last_sv = NULL;
+	SV *first_sv = NULL, *last_sv = NULL;
 	dGPERL_CALLBACK_MARSHAL_SP;
 
 	PERL_UNUSED_VAR (cif);
@@ -44,22 +44,23 @@ invoke_perl_code (ffi_cif* cif, gpointer resp, gpointer* args, gpointer userdata
 
 	/* convert the implicit instance argument and push the first SV onto
 	 * the stack; depending on the "swap" setting, this might be the
-	 * instance or the user data */
-	if (iinfo.is_method) {
+	 * instance or the user data.  this is only relevant for signals. */
+	if (iinfo.is_signal) {
+		SV *instance_sv, *data_sv;
+		args_offset = 1;
 		instance_sv = SAVED_STACK_SV (instance_pointer_to_sv (
 		                                cb_interface,
 		                                CAST_RAW (args[0], gpointer)));
-		args_offset = 1;
+		data_sv = info->data ? SvREFCNT_inc (info->data) : NULL;
+		first_sv = info->swap_data ? data_sv     : instance_sv;
+		last_sv  = info->swap_data ? instance_sv : data_sv;
+		dwarn ("  info->data = %p, info->swap_data = %d\n",
+		       info->data, info->swap_data);
+		dwarn ("  instance = %p, data = %p, first = %p, last = %p\n",
+		       instance_sv, data_sv, first_sv, last_sv);
+		if (first_sv)
+			XPUSHs (sv_2mortal (first_sv));
 	}
-	data_sv = info->data ? SvREFCNT_inc (info->data) : NULL;
-	first_sv = info->swap_data ? data_sv     : instance_sv;
-	last_sv  = info->swap_data ? instance_sv : data_sv;
-	dwarn ("  info->data = %p, info->swap_data = %d\n",
-	       info->data, info->swap_data);
-	dwarn ("  instance = %p, data = %p, first = %p, last = %p\n",
-	       instance_sv, data_sv, first_sv, last_sv);
-	if (first_sv)
-		XPUSHs (sv_2mortal (first_sv));
 
 	/* find arguments; use type information from interface to find in and
 	 * in-out args and their types, count in-out and out args, and find
@@ -125,7 +126,8 @@ invoke_perl_code (ffi_cif* cif, gpointer resp, gpointer* args, gpointer userdata
 		g_base_info_unref ((GIBaseInfo *) arg_type);
 	}
 
-	/* push the last SV onto the stack; this might be the user data or the instance */
+	/* push the last SV onto the stack; this might be the user data or the
+	 * instance.  this is only relevant for signals. */
 	if (last_sv)
 		XPUSHs (sv_2mortal (last_sv));
 
diff --git a/t/callbacks.t b/t/callbacks.t
index c66106d..af035fd 100644
--- a/t/callbacks.t
+++ b/t/callbacks.t
@@ -5,11 +5,11 @@ BEGIN { require './t/inc/setup.pl' };
 use strict;
 use warnings;
 
-plan tests => 16;
+plan tests => 25;
 
 my $data = 42;
 my $result = 23;
-my $callback  = sub { is shift, $data; return $result; };
+my $callback  = sub { is @_, 1; is $_[0], $data; return $result; };
 
 is (Regress::test_callback_user_data ($callback, $data), $result);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]