[perl-Glib] Handle the boxed type for GError
- From: Torsten SchÃnfeld <tsch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-Glib] Handle the boxed type for GError
- Date: Sat, 7 Jul 2012 12:59:35 +0000 (UTC)
commit 84d19e6fc3347cf41f61143956ca29da4269436a
Author: Torsten SchÃnfeld <kaffeetisch gmx de>
Date: Sat Jul 7 14:57:10 2012 +0200
Handle the boxed type for GError
This allows Glib to correctly handle signals with GError arguments.
Patch originally by Sven-Haegar Koch.
https://bugzilla.gnome.org/show_bug.cgi?id=679015
GBoxed.xs | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
NEWS | 5 ++++
t/boxed_errors.t | 38 +++++++++++++++++++++++++++++++++++++
3 files changed, 97 insertions(+), 1 deletions(-)
---
diff --git a/GBoxed.xs b/GBoxed.xs
index bae734c..2a53c36 100644
--- a/GBoxed.xs
+++ b/GBoxed.xs
@@ -697,6 +697,57 @@ static GPerlBoxedWrapperClass gstring_wrapper_class = {
NULL
};
+
+#if GLIB_CHECK_VERSION (2, 26, 0)
+
+static SV*
+gerror_wrap (GType gtype,
+ const char * package,
+ gpointer boxed,
+ gboolean own)
+{
+ SV *sv;
+ GError *error;
+ PERL_UNUSED_VAR (gtype);
+ PERL_UNUSED_VAR (package);
+
+ if (!boxed)
+ return &PL_sv_undef;
+
+ error = (GError*) boxed;
+
+ sv = gperl_sv_from_gerror (error);
+
+ if (own)
+ g_error_free (error);
+
+ return sv;
+}
+
+static gpointer
+gerror_unwrap (GType gtype,
+ const char * package,
+ SV * sv)
+{
+ GError *error = NULL;
+ PERL_UNUSED_VAR (gtype);
+ PERL_UNUSED_VAR (package);
+
+ gperl_gerror_from_sv (sv, &error);
+
+ return error;
+}
+
+static GPerlBoxedWrapperClass gerror_wrapper_class = {
+ gerror_wrap,
+ gerror_unwrap,
+ NULL
+};
+
+#endif
+
+
+
MODULE = Glib::Boxed PACKAGE = Glib::Boxed
BOOT:
@@ -706,7 +757,9 @@ BOOT:
gperl_register_boxed (G_TYPE_GSTRING, "Glib::GString", &gstring_wrapper_class);
#if GLIB_CHECK_VERSION (2, 4, 0)
gperl_register_boxed (G_TYPE_STRV, "Glib::Strv", &strv_wrapper_class);
- /*gperl_set_isa ("Glib::Strv", "Glib::Boxed");*/
+#endif
+#if GLIB_CHECK_VERSION (2, 26, 0)
+ gperl_register_boxed (G_TYPE_ERROR, "Glib::Error", &gerror_wrapper_class);
#endif
diff --git a/NEWS b/NEWS
index 5d08b22..06149b1 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,8 @@
+Overview of changes in Glib <next>
+==================================
+
+* Correctly handle the boxed type for GError.
+
Overview of changes in Glib 1.261 (stable)
==========================================
diff --git a/t/boxed_errors.t b/t/boxed_errors.t
new file mode 100644
index 0000000..4da6b59
--- /dev/null
+++ b/t/boxed_errors.t
@@ -0,0 +1,38 @@
+#!/usr/bin/perl
+
+# Test the GBoxed wrapper for GError.
+
+use strict;
+use warnings;
+use Test::More;
+use Glib ':constants';
+
+if (Glib->CHECK_VERSION (2, 26, 0)) {
+ plan tests => 5;
+} else {
+ plan skip_all => 'new in 2.26';
+}
+
+Glib::Type->register_object (
+ 'Glib::Object',
+ 'Foo',
+ signals => {
+ throw => {
+ param_types => [qw(Glib::Error)],
+ },
+ },
+);
+
+my $foo = Glib::Object::new ('Foo');
+$foo->signal_connect (throw => \&throw_handler, 23);
+$foo->signal_emit ('throw', Glib::File::Error->new ('io', 'End of file reached'));
+
+sub throw_handler {
+ my ($instance, $error, $data) = @_;
+ is ($instance, $foo);
+ is ($data, 23);
+
+ isa_ok ($error, 'Glib::File::Error');
+ is ($error->value, 'io');
+ is ($error->message, 'End of file reached');
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]