[perl-Gtk2] Gtk2::Gdk::Region::spans_intersect_foreach(): allow empty spans list
- From: Torsten Schönfeld <tsch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-Gtk2] Gtk2::Gdk::Region::spans_intersect_foreach(): allow empty spans list
- Date: Sun, 12 Dec 2010 13:37:33 +0000 (UTC)
commit 931dd526e025bd3e3970959179606aefe8543a5d
Author: Kevin Ryde <user42 zip com au>
Date: Sun Nov 28 08:12:26 2010 +1100
Gtk2::Gdk::Region::spans_intersect_foreach(): allow empty spans list
Don't pass spans==NULL for an empty input array, but instead explicitly do
nothing in that case. Avoids a g_log if the Perl level spans array is empty.
https://bugzilla.gnome.org/show_bug.cgi?id=635950
t/GdkRegion.t | 8 +++++++-
xs/GdkRegion.xs | 49 ++++++++++++++++++++++++++++---------------------
2 files changed, 35 insertions(+), 22 deletions(-)
---
diff --git a/t/GdkRegion.t b/t/GdkRegion.t
index a142fd1..dae8c15 100644
--- a/t/GdkRegion.t
+++ b/t/GdkRegion.t
@@ -1,6 +1,6 @@
#!/usr/bin/perl -w
use strict;
-use Gtk2::TestHelper tests => 29, noinit => 1;
+use Gtk2::TestHelper tests => 30, noinit => 1;
# $Id$
@@ -51,6 +51,12 @@ $region -> spans_intersect_foreach([24, 43, 5,
is($data, "bla");
}, "bla");
+{
+ my $callback = 0;
+ $region -> spans_intersect_foreach([], 1, sub { $callback = 1; });
+ is($callback, 0, 'spans_intersect_foreach() 0 coords - no callback');
+}
+
ok (! eval { $region->spans_intersect_foreach([1], 1, sub {}); 1 },
'spans_intersect_foreach() 1 coord - expect error');
ok (! eval { $region->spans_intersect_foreach([1,2], 1, sub {}); 1 },
diff --git a/xs/GdkRegion.xs b/xs/GdkRegion.xs
index 54ec46c..1b5aaeb 100644
--- a/xs/GdkRegion.xs
+++ b/xs/GdkRegion.xs
@@ -260,28 +260,35 @@ gdk_region_spans_intersect_foreach (region, spans_ref, sorted, func, data=NULL)
if ((n_spans % 3) != 0)
croak ("span list not a multiple of 3");
n_spans /= 3;
- spans = g_new0 (GdkSpan, n_spans);
-
- for (i = 0; i < n_spans; i++) {
- if ((value = av_fetch (array, 3*i, 0)) && gperl_sv_is_defined (*value))
- spans[i].x = SvIV (*value);
- if ((value = av_fetch (array, 3*i + 1, 0)) && gperl_sv_is_defined (*value))
- spans[i].y = SvIV (*value);
- if ((value = av_fetch (array, 3*i + 2, 0)) && gperl_sv_is_defined (*value))
- spans[i].width = SvIV (*value);
- }
-
- callback = gperl_callback_new (func, data, 0, NULL, 0);
- gdk_region_spans_intersect_foreach (region,
- spans,
- n_spans,
- sorted,
- (GdkSpanFunc) gtk2perl_gdk_span_func,
- callback);
-
- gperl_callback_destroy (callback);
- g_free (spans);
+ /* gdk_region_spans_intersect_foreach() is happy to take n_spans==0
+ and do nothing, but it doesn't like spans==NULL (as of Gtk 2.20),
+ and NULL is what g_new0() gives for a count of 0. So explicit
+ skip if n_spans==0. */
+ if (n_spans != 0) {
+ spans = g_new0 (GdkSpan, n_spans);
+
+ for (i = 0; i < n_spans; i++) {
+ if ((value = av_fetch (array, 3*i, 0)) && gperl_sv_is_defined (*value))
+ spans[i].x = SvIV (*value);
+ if ((value = av_fetch (array, 3*i + 1, 0)) && gperl_sv_is_defined (*value))
+ spans[i].y = SvIV (*value);
+ if ((value = av_fetch (array, 3*i + 2, 0)) && gperl_sv_is_defined (*value))
+ spans[i].width = SvIV (*value);
+ }
+
+ callback = gperl_callback_new (func, data, 0, NULL, 0);
+
+ gdk_region_spans_intersect_foreach (region,
+ spans,
+ n_spans,
+ sorted,
+ (GdkSpanFunc) gtk2perl_gdk_span_func,
+ callback);
+
+ gperl_callback_destroy (callback);
+ g_free (spans);
+ }
#if GTK_CHECK_VERSION (2, 18, 0)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]