[perl-Glib-Object-Introspection] Allow undef for boxed types if permissible



commit 5ab75ac6e5fff6b2aae9652b7bd4a46ae8d34d10
Author: Torsten SchÃnfeld <kaffeetisch gmx de>
Date:   Fri Oct 14 18:59:17 2011 +0200

    Allow undef for boxed types if permissible

 GObjectIntrospection.xs        |    1 +
 gperl-i11n-marshal-arg.c       |   15 ++++++++++-----
 gperl-i11n-marshal-interface.c |    9 +++++++--
 3 files changed, 18 insertions(+), 7 deletions(-)
---
diff --git a/GObjectIntrospection.xs b/GObjectIntrospection.xs
index e918282..e085ccc 100644
--- a/GObjectIntrospection.xs
+++ b/GObjectIntrospection.xs
@@ -161,6 +161,7 @@ static SV * interface_to_sv (GITypeInfo* info,
 static void sv_to_interface (GIArgInfo * arg_info,
                              GITypeInfo * type_info,
                              GITransfer transfer,
+                             gboolean may_be_null,
                              SV * sv,
                              GIArgument * arg,
                              GPerlI11nInvocationInfo * invocation_info);
diff --git a/gperl-i11n-marshal-arg.c b/gperl-i11n-marshal-arg.c
index 46719a2..90c57a5 100644
--- a/gperl-i11n-marshal-arg.c
+++ b/gperl-i11n-marshal-arg.c
@@ -17,9 +17,14 @@ sv_to_arg (SV * sv,
 		/* Interfaces and void types need to be able to handle undef
 		 * separately. */
 		if (!may_be_null && tag != GI_TYPE_TAG_INTERFACE
-		                 && tag != GI_TYPE_TAG_VOID)
-			ccroak ("undefined value for mandatory argument '%s' encountered",
-			       g_base_info_get_name ((GIBaseInfo *) arg_info));
+		                 && tag != GI_TYPE_TAG_VOID) {
+			if (arg_info) {
+				ccroak ("undefined value for mandatory argument '%s' encountered",
+				        g_base_info_get_name ((GIBaseInfo *) arg_info));
+			} else {
+				ccroak ("undefined value encountered");
+			}
+		}
 
 	switch (tag) {
 	    case GI_TYPE_TAG_VOID:
@@ -88,8 +93,8 @@ sv_to_arg (SV * sv,
 
 	    case GI_TYPE_TAG_INTERFACE:
 		dwarn ("    type %p -> interface\n", type_info);
-		sv_to_interface (arg_info, type_info, transfer, sv, arg,
-		                 invocation_info);
+		sv_to_interface (arg_info, type_info, transfer, may_be_null,
+		                 sv, arg, invocation_info);
 		break;
 
 	    case GI_TYPE_TAG_GLIST:
diff --git a/gperl-i11n-marshal-interface.c b/gperl-i11n-marshal-interface.c
index cbf8d36..525bb42 100644
--- a/gperl-i11n-marshal-interface.c
+++ b/gperl-i11n-marshal-interface.c
@@ -53,6 +53,7 @@ static void
 sv_to_interface (GIArgInfo * arg_info,
                  GITypeInfo * type_info,
                  GITransfer transfer,
+                 gboolean may_be_null,
                  SV * sv,
                  GIArgument * arg,
                  GPerlI11nInvocationInfo * invocation_info)
@@ -118,8 +119,12 @@ sv_to_interface (GIArgInfo * arg_info,
 				gpointer mem = gperl_get_boxed_check (sv, type);
 				g_memmove (arg->v_pointer, mem, n_bytes);
 			} else {
-				/* FIXME: Check transfer setting. */
-				arg->v_pointer = gperl_get_boxed_check (sv, type);
+				if (may_be_null && sv == &PL_sv_undef) {
+					arg->v_pointer = NULL;
+				} else {
+					/* FIXME: Check transfer setting. */
+					arg->v_pointer = gperl_get_boxed_check (sv, type);
+				}
 			}
 		}
 		break;



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