[perl-Gtk2] Probe the type of SVs more carefully



commit 75c378d027fa541907696ee34d9571bda911bebf
Author: Torsten SchÃnfeld <kaffeetisch gmx de>
Date:   Sat Aug 6 21:17:02 2011 +0200

    Probe the type of SVs more carefully
    
    Call gperl_sv_is_defined and friends before using SvPOK and friends to
    make sure "get magic" is handled properly.

 xs/GdkPixbuf.xs             |    4 ++--
 xs/GdkRgb.xs                |   20 ++++++++++----------
 xs/GtkBuildable.xs          |    2 +-
 xs/GtkSelection.xs          |    2 +-
 xs/GtkTextBufferRichText.xs |    2 +-
 xs/GtkTreeModel.xs          |    6 +++---
 6 files changed, 18 insertions(+), 18 deletions(-)
---
diff --git a/xs/GdkPixbuf.xs b/xs/GdkPixbuf.xs
index 88ecb5e..abfea7c 100644
--- a/xs/GdkPixbuf.xs
+++ b/xs/GdkPixbuf.xs
@@ -256,7 +256,7 @@ gdk_pixbuf_get_from_drawable (dest_or_class, src, cmap, src_x, src_y, dest_x, de
     PREINIT:
 	GdkPixbuf * pixbuf, * dest;
     CODE:
-	dest = SvROK (dest_or_class)
+	dest = (gperl_sv_is_defined (dest_or_class) && SvROK (dest_or_class))
 	     ? SvGdkPixbuf (dest_or_class)
 	     : NULL;
 	if (ix == 1)
@@ -489,7 +489,7 @@ gdk_pixbuf_new_from_data (class, data, colorspace, has_alpha, bits_per_sample, w
     PREINIT:
 	SV * real_data;
     CODE:
-	if (!data || !SvPOK (data))
+	if (!gperl_sv_is_defined (data) || !SvPOK (data))
 		croak ("expecting a packed string for pixel data");
 	real_data = gperl_sv_copy (data);
 	RETVAL = gdk_pixbuf_new_from_data ((const guchar *)
diff --git a/xs/GdkRgb.xs b/xs/GdkRgb.xs
index 3ea8246..cb8ad14 100644
--- a/xs/GdkRgb.xs
+++ b/xs/GdkRgb.xs
@@ -33,16 +33,16 @@
 static guchar *
 SvImageDataPointer (SV * sv)
 {
-	if (SvIOK (sv))
-		return INT2PTR (guchar*, SvUV (sv));
-	else if (SvPOK (sv))
-		return (guchar *) SvPV_nolen (sv);
-	else
-		croak ("expecting either a string containing pixel data or "
-		       "an integer pointing to the underlying C image data "
-		       "buffer");
-	/* not reached */
-	return NULL;
+	if (gperl_sv_is_defined (sv)) {
+		if (SvIOK (sv))
+			return INT2PTR (guchar*, SvUV (sv));
+		else if (SvPOK (sv))
+			return (guchar *) SvPV_nolen (sv);
+	}
+	croak ("expecting either a string containing pixel data or "
+	       "an integer pointing to the underlying C image data "
+	       "buffer");
+	return NULL; /* not reached */
 }
 
 static GdkRgbCmap *
diff --git a/xs/GtkBuildable.xs b/xs/GtkBuildable.xs
index 26bac10..d192459 100644
--- a/xs/GtkBuildable.xs
+++ b/xs/GtkBuildable.xs
@@ -95,7 +95,7 @@ call_parser_method (GError ** error,
 
 	SPAGAIN;
 
-	if (SvTRUE (ERRSV)) {
+	if (gperl_sv_is_defined (ERRSV) && SvTRUE (ERRSV)) {
 		if (SvROK (ERRSV) && sv_derived_from (ERRSV, "Glib::Error")) {
 			gperl_gerror_from_sv (ERRSV, error);
 		} else {
diff --git a/xs/GtkSelection.xs b/xs/GtkSelection.xs
index 61a7f03..417432d 100644
--- a/xs/GtkSelection.xs
+++ b/xs/GtkSelection.xs
@@ -135,7 +135,7 @@ SvGtkTargetList (SV * sv)
 #if GTK_CHECK_VERSION (2, 9, 0)
 	return gperl_get_boxed_check (sv, GTK_TYPE_TARGET_LIST);
 #else
-	if (!sv || !SvROK (sv) ||
+	if (!gperl_sv_is_defined (sv) || !SvROK (sv) ||
 	    !sv_derived_from (sv, "Gtk2::TargetList"))
 		croak ("variable is not of type Gtk2::TargetList");
 	return INT2PTR (GtkTargetList*, SvUV (SvRV (sv)));
diff --git a/xs/GtkTextBufferRichText.xs b/xs/GtkTextBufferRichText.xs
index 413973f..13f1ea7 100644
--- a/xs/GtkTextBufferRichText.xs
+++ b/xs/GtkTextBufferRichText.xs
@@ -110,7 +110,7 @@ gtk2perl_text_buffer_deserialize_func (GtkTextBuffer     *register_buffer,
         PUTBACK;
 
         call_sv (callback->func, G_DISCARD | G_EVAL);
-        if (SvTRUE (ERRSV)) {
+        if (gperl_sv_is_defined (ERRSV) && SvTRUE (ERRSV)) {
                 if (SvROK (ERRSV) && sv_derived_from (ERRSV, "Glib::Error")) {
                         gperl_gerror_from_sv (ERRSV, error);
                 } else {
diff --git a/xs/GtkTreeModel.xs b/xs/GtkTreeModel.xs
index 91a65c9..7d73213 100644
--- a/xs/GtkTreeModel.xs
+++ b/xs/GtkTreeModel.xs
@@ -210,17 +210,17 @@ iter_from_sv (GtkTreeIter * iter,
 		if ((svp = av_fetch (av, 0, FALSE)))
 			iter->stamp = SvUV (*svp);
 
-		if ((svp = av_fetch (av, 1, FALSE)) && SvIOK (*svp))
+		if ((svp = av_fetch (av, 1, FALSE)) && gperl_sv_is_defined (*svp))
 			iter->user_data = INT2PTR (gpointer, SvIV (*svp));
 		else
 			iter->user_data = NULL;
 
-		if ((svp = av_fetch (av, 2, FALSE)) && SvROK (*svp))
+		if ((svp = av_fetch (av, 2, FALSE)) && gperl_sv_is_ref (*svp))
 			iter->user_data2 =  SvRV (*svp);
 		else
 			iter->user_data2 = NULL;
 
-		if ((svp = av_fetch (av, 3, FALSE)) && SvROK (*svp))
+		if ((svp = av_fetch (av, 3, FALSE)) && gperl_sv_is_ref (*svp))
 			iter->user_data3 =  SvRV (*svp);
 		else
 			iter->user_data3 = NULL;



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