[perl-Glib-Object-Introspection] Do not assume SvREFCNT_inc/_dec are NULL-safe



commit 435871618097219c48ce07bba5fcd9e191a0a367
Author: Torsten SchÃnfeld <kaffeetisch gmx de>
Date:   Fri Jan 11 14:05:29 2013 +0100

    Do not assume SvREFCNT_inc/_dec are NULL-safe

 GObjectIntrospection.xs  |    6 ++++--
 gperl-i11n-callback.c    |    3 +++
 gperl-i11n-invoke-perl.c |   11 +++++------
 3 files changed, 12 insertions(+), 8 deletions(-)
---
diff --git a/GObjectIntrospection.xs b/GObjectIntrospection.xs
index f558669..d4c9fc2 100644
--- a/GObjectIntrospection.xs
+++ b/GObjectIntrospection.xs
@@ -818,7 +818,8 @@ _use_generic_signal_marshaller_for (class, const gchar *package, const gchar *si
 
 	signal_info = g_new0 (GPerlI11nPerlSignalInfo, 1); // FIXME: ctor?
 	signal_info->interface = get_signal_info (container_info, signal);
-	signal_info->args_converter = SvREFCNT_inc (args_converter);
+	if (args_converter)
+		signal_info->args_converter = SvREFCNT_inc (args_converter);
 	if (!signal_info)
 		croak ("Could not find signal %s for package %s",
 		       signal, package);
@@ -846,7 +847,8 @@ _use_generic_signal_marshaller_for (class, const gchar *package, const gchar *si
 	 * g_callable_info_free_closure (signal_info, closure);
 	 * g_free (cif);
 	 * g_base_info_unref (signal_info->interface);
-	 * SvREFCNT_dec (signal_info->args_converter);
+	 * if (signal_info->args_converter)
+	 * 	SvREFCNT_dec (signal_info->args_converter);
 	 * g_free (signal_info);
 	 */
 
diff --git a/gperl-i11n-callback.c b/gperl-i11n-callback.c
index 92e537e..0087f84 100644
--- a/gperl-i11n-callback.c
+++ b/gperl-i11n-callback.c
@@ -85,6 +85,9 @@ release_perl_callback (gpointer data)
 	if (info->sub_name)
 		g_free (info->sub_name);
 
+	if (info->args_converter)
+		SvREFCNT_dec (info->args_converter);
+
 	g_free (info);
 }
 
diff --git a/gperl-i11n-invoke-perl.c b/gperl-i11n-invoke-perl.c
index 97422ff..2c45d14 100644
--- a/gperl-i11n-invoke-perl.c
+++ b/gperl-i11n-invoke-perl.c
@@ -11,7 +11,6 @@ invoke_callback (ffi_cif* cif, gpointer resp, gpointer* args, gpointer userdata)
 	guint n_return_values, n_returned;
 	I32 context;
 	SV *instance_sv = NULL, *data_sv = NULL, *first_sv = NULL, *last_sv = NULL;
-	SV *args_converter;
 	dGPERL_CALLBACK_MARSHAL_SP;
 
 	PERL_UNUSED_VAR (cif);
@@ -30,8 +29,7 @@ invoke_callback (ffi_cif* cif, gpointer resp, gpointer* args, gpointer userdata)
 
 	PUSHMARK (SP);
 
-	args_converter = info->args_converter;
-	if (args_converter) {
+	if (info->args_converter) {
 		/* if we are given an args converter, we will call it directly
 		 * after we pushed the original args onto the stack.  we then
 		 * want to invoke the Perl code with whatever the args
@@ -141,8 +139,8 @@ invoke_callback (ffi_cif* cif, gpointer resp, gpointer* args, gpointer userdata)
 	 * since we created two identical entries on the markstack, the
 	 * call_method or call_sv below will invoke the Perl code with whatever
 	 * the args converter returned. */
-	if (args_converter) {
-		call_sv (args_converter, G_ARRAY);
+	if (info->args_converter) {
+		call_sv (info->args_converter, G_ARRAY);
 		SPAGAIN;
 	}
 
@@ -305,7 +303,8 @@ invoke_perl_signal_handler (ffi_cif* cif, gpointer resp, gpointer* args, gpointe
 	                                        perl_closure->callback);
 	attach_perl_callback_data (cb_info, perl_closure->data);
 	cb_info->swap_data = GPERL_CLOSURE_SWAP_DATA (perl_closure);
-	cb_info->args_converter = SvREFCNT_inc (signal_info->args_converter);
+	if (signal_info->args_converter)
+		cb_info->args_converter = SvREFCNT_inc (signal_info->args_converter);
 
 	c_closure.closure = *closure;
 	c_closure.callback = cb_info->closure;



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