[glibmm/gmmproc-refactor] Add a workaround for another GIR quirk.
- From: Krzesimir Nowak <krnowak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm/gmmproc-refactor] Add a workaround for another GIR quirk.
- Date: Sun, 22 Jul 2012 18:15:20 +0000 (UTC)
commit 80c6c68beea1c8ab86ffce985300fbb9e5eb2182
Author: Krzesimir Nowak <qdlacz gmail com>
Date: Sat Jul 14 19:20:47 2012 +0200
Add a workaround for another GIR quirk.
It was exposed by g_bytes_{hash,equal,compare}.
glib/src/bytes.hg | 8 ++----
tools/pm/Common/WrapParser.pm | 44 +++++++++++++++++++++++++++++++---------
2 files changed, 37 insertions(+), 15 deletions(-)
---
diff --git a/glib/src/bytes.hg b/glib/src/bytes.hg
index cfd32f5..24aa1e0 100644
--- a/glib/src/bytes.hg
+++ b/glib/src/bytes.hg
@@ -66,11 +66,9 @@ public:
_WRAP_METHOD(gconstpointer get_data(gsize& size) const, g_bytes_get_data)
_WRAP_METHOD(gsize get_size() const, g_bytes_get_size)
- _PUSH_NAMED_CONV(gconstpointer_to_gbytes, gconstpointer, const GBytes*, static_cast< const GBytes* >(##ARG##), NONE, NONE)
- _WRAP_METHOD(static guint hash(gconstpointer bytes), g_bytes_hash)
- _POP_NAMED_CONV(gconstpointer_to_gbytes)
- _WRAP_METHOD(static bool equal(gconstpointer bytes1, gconstpointer bytes2), g_bytes_equal)
- _WRAP_METHOD(static gint compare(gconstpointer bytes1, gconstpointer bytes2), g_bytes_compare)
+ _WRAP_METHOD(static guint hash(gconstpointer bytes), g_bytes_hash, silence_gir_quirk)
+ _WRAP_METHOD(static bool equal(gconstpointer bytes1, gconstpointer bytes2), g_bytes_equal, silence_gir_quirk)
+ _WRAP_METHOD(static gint compare(gconstpointer bytes1, gconstpointer bytes2), g_bytes_compare, silence_gir_quirk)
};
} // namespace Glib
diff --git a/tools/pm/Common/WrapParser.pm b/tools/pm/Common/WrapParser.pm
index 643b812..bae88ea 100644
--- a/tools/pm/Common/WrapParser.pm
+++ b/tools/pm/Common/WrapParser.pm
@@ -765,6 +765,7 @@ sub _on_wrap_method ($)
my $constversion = 0;
my $errthrow = 0;
my $ifdef = undef;
+ my $silence_gir_quirk = 0;
my $setup =
{
'b(deprecated)' => \$deprecated,
@@ -773,7 +774,8 @@ sub _on_wrap_method ($)
'ob(refreturn)' => \$refreturn,
'b(constversion)' => \$constversion,
'ob(errthrow)' => \$errthrow,
- 's(ifdef)' => \$ifdef
+ 's(ifdef)' => \$ifdef,
+ 'b(silence_gir_quirk)' => \$silence_gir_quirk
};
$self->_handle_get_args_results (Common::Shared::get_args \ args, $setup);
@@ -845,18 +847,40 @@ sub _on_wrap_method ($)
shift (@{$c_param_types});
shift (@{$c_param_transfers});
}
- # TODO: Fix it in gobject-introspection. Workaround for wrapping gir
- # <method> which should be <constructor>. This happens where
- # constructor takes an instance of the type it instatiates. That one
- # needs fixing in gir files, not here.
+
if ($cxx_function->get_static () and not $is_a_function)
{
- my $guessed_c_type = join ('', 'const ', $gir_entity->get_a_c_type (), '*');
- my $message = 'This is marked as <method> instead of <constructor>. Please fix it in C library by adding (constructor) annotation after constructor_name (here: "' . $c_function->get_name () . ': (constructor)"). For now working it around by prepending "' $guessed_c_type . '" parameter type.';
+ if (index ($c_function_name, '_new') >= 0)
+ {
+ # Workaround for wrapping gir <method> which should be
+ # <constructor>. This happens where constructor takes an instance
+ # of the type it instatiates. That one needs fixing in gir files,
+ # not here.
+ my $guessed_c_type = join ('', 'const ', $gir_entity->get_a_c_type (), '*');
+ my $message = 'This is marked as <method> instead of <constructor>. Please fix it in C library by adding (constructor) annotation after constructor_name (here: "' . $c_function_name . ': (constructor)"). For now working it around by prepending "' . $guessed_c_type . '" parameter type.';
- $self->fixed_warning ($message);
- unshift (@{$c_param_types}, $guessed_c_type);
- unshift (@{$c_param_transfers}, Common::TypeInfo::Common::TRANSFER_NONE);
+ $self->fixed_warning ($message);
+ unshift (@{$c_param_types}, $guessed_c_type);
+ unshift (@{$c_param_transfers}, Common::TypeInfo::Common::TRANSFER_NONE);
+ }
+ else
+ {
+ # Workaround for rare cases of functions like
+ # g_bytes_hash(gconstpointer bytes) which are treated by
+ # gobject-introspection as methods instead of functions. I do
+ # not know whether this should be fixed in gobject-introspection
+ # and whether we can just assume that prepended C parameter is
+ # going to be the same as first C++ parameter. Probably not.
+ # Wrapping this function manually is the safest bet.
+ unless ($silence_gir_quirk)
+ {
+ my $message = 'This is marked as <method> in GIR, but is wrapped as static method. You probably know what you are doing, so I am assuming that you are not wrapping a constructor and that the first parameter of C function is of the same type as the one of C++ static method. If this is right then add "silence_gir_quirk" option to this macro. Otherwise try either filing a bug to appriopriate product (be it C library or gmmproc) or wrapping this method manually.';
+
+ $self->fixed_warning ($message);
+ }
+ unshift (@{$c_param_types}, $cxx_function->get_param_types ()->[0]);
+ unshift (@{$c_param_transfers}, Common::TypeInfo::Common::TRANSFER_NONE);
+ }
}
my $ret_transfer = $c_function->get_return_transfer;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]