|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Problems with GHashTable in signal handlerHi, I try to use the "create-plugin-widget" signal of Gtk2::WebKit::WebView, which passes a GHashTable to the callback. Here it's signature from the docs: GtkWidget* user_function (WebKitWebView *web_view, gchar *mime_type, gchar *uri, GHashTable *param, gpointer user_data) : Run Last / Action (from http://webkitgtk.org/reference/webkitgtk-WebKitWebView.html#WebKitWebView-create-plugin-widget ) Perl dies with this error message when my signal handler is called: GType GHashTable (146176672) is not registered with gperl Since signal handling is completely covered on Glib level I don't think this problem is related to Gtk2::WebKit. The Glib perldoc says GHashTable is bound to the native Perl hash datatype. I grep'ed the sources of Glib and Gtk2 to find any examples of passing GHashTables to Perl - with no luck. Any help on this is appreciated ;) I am using Perl 5.10.1 and these module versions on Debian sid: Glib::VERSION = 1.222 Gtk2::VERSION = 1.221 Gtk2::WebKit::VERSION = 0.06 Thanks, Jörn -- LINUX - Linux Is Not gnU linuX _______________________________________________ gtk-perl-list mailing list gtk-perl-list@... http://mail.gnome.org/mailman/listinfo/gtk-perl-list |
|
|
Re: Problems with GHashTable in signal handlerOn Oct 25, 2009, at 8:55 AM, Jörn Reder wrote: > Hi, > > I try to use the "create-plugin-widget" signal of > Gtk2::WebKit::WebView, > which passes a GHashTable to the callback. Here it's signature from > the > docs: > > GtkWidget* user_function (WebKitWebView *web_view, > gchar *mime_type, > gchar *uri, > GHashTable *param, > gpointer user_data) : Run Last / > Action > > (from http://webkitgtk.org/reference/webkitgtk-WebKitWebView.html#WebKitWebView-create-plugin-widget > ) > > Perl dies with this error message when my signal handler is called: > > GType GHashTable (146176672) is not registered with gperl > > Since signal handling is completely covered on Glib level I don't > think > this problem is related to Gtk2::WebKit. The Glib perldoc says > GHashTable is bound to the native Perl hash datatype. I grep'ed the > sources of Glib and Gtk2 to find any examples of passing GHashTables > to > Perl - with no luck. > > Any help on this is appreciated ;) Actually, the docs say "The GLib types GList (a doubly-linked list), GSList (singly-linked list), GHashTable, GArray, etc have all been replaced by native Perl datatypes." That is, "replace by", not "bound to." GHashTable is not really bindable, because it is a generic mapping of arbitrary pointer to arbitrary pointer; you must know something about what is in it in order to use it, and we can't create a generic wrapper for that. Therefore, for each function that passes a hash table, we map that by hand to a perl hash. However, it's not actually very common for the gnome APIs to pass GHashTables around -- they're normally used for implementation. In fact, i can't really think of where we've had to do this... libgobject started registering a GType for GHashTable in 2.10, to make it possible to say "this signal argument is a hash table" instead of "this signal argument is a pointer". However, as the gobject- introspection guys pointed out, this isn't terribly useful; you need to know more information, like "this object is a hash table whose keys are strings and whose values are gobjects". We don't have that at a generic level. So the only real option that you have is to create a custom marshaller for this signal, implemented in Gtk2::WebKit::WebView. This marshaller would be used only for this signal, where we know that the hash table is supposed to be a map of strings to strings. You'd do something like call g_hash_table_foreach() to push all the keys and values in the hash table into a new hash, and pass a reference to that new hash to perl in place of the hash table. (The closer you stick to the C api, the fewer problems people will have here.) If you're supposed to allow the callback to modify the hash, then you'll have to push those changes back the other way when the callback returns. Read gperl_marshal.h for a template and helpers. There are a few examples of custom marshallers in Gtk2, nearly all used for arguments that are unfriendly to non-C languages (e.g. write-through integer parameters, C arrays, and G_TYPE_POINTER args that you're supposed to cast to something else). Search Gtk2 for gperl_signal_set_marshaller_for and follow where that takes you. From Glib::xsapi: void gperl_signal_set_marshaller_for (GType instance_type, char * detailed_signal, GClosureMarshal marshaller) You need this function only in rare cases, usually as workarounds for bad signal parameter types or to implement writable arguments. Use the given marshaller to marshal all handlers for detailed_sig- nal on instance_type. "gperl_signal_connect" will look for mar- shallers registered here, and apply them to the GPerlClosure it creates for the given callback being connected. Use the helper macros in gperl_marshal.h to help write your mar- shaller function. That header, which is installed with the Glib module but not #included through gperl.h, includes commentary and examples which you should follow closely to avoid nasty bugs. Use the Source, Luke. WARNING: Bend over backwards and turn your head around 720 degrees before attempting to write a GPerlClosure marshaller without using the macros in gperl_marshal.h. If you absolutely cannot use those macros, be certain to understand what those macros do so you can get the semantics correct, and keep your code synchronized with them, or you may miss very important bugfixes. -- Me: What's that in your mouth? Zella: *swallows laboriously* Nothing. Me: What did you just swallow? Zella: A booger. Me: Baby girl, don't eat boogers. That's gross. Zella: But it was in my nose. _______________________________________________ gtk-perl-list mailing list gtk-perl-list@... http://mail.gnome.org/mailman/listinfo/gtk-perl-list |
|
|
Re: Problems with GHashTable in signal handlerHi muppet, thanks for your excellent (as always) explanation. Meantime Florian (the author of Gtk2::WebKit) sent me an updated version for testing which covers the create-plugin-widget signal correctly. Perl community rocks ;) Regards, Jörn -- sub i($){print$_[0]}*j=*ENV;sub w($){sleep$_[0]}sub _($){i"$p:$c> ",w+01 ,$_=$_[0],tr;i-za-h,;a-hi-z ;,i$_,w+01,i"\n"}$|=1;$f='HO';($c=$j{PWD})=~ s+$j{$f."ME"}+~+;$p.="$j{USER}\@".`hostname`;chop$p;_"kl",$c='~',_"zu,". "-zn,*",_"#,epg,lw,gwc,mfmkcbm,cvsvwev,uiqt,kwvbmvb?",i"$p:$c> ";w+1<<07 _______________________________________________ gtk-perl-list mailing list gtk-perl-list@... http://mail.gnome.org/mailman/listinfo/gtk-perl-list |
|
|
Re: Problems with GHashTable in signal handlerOn Sun, Oct 25, 2009 at 10:40 PM, muppet <scott@...> wrote: Emmanuel Rodriguez
Thanks for the explanation! This has come very handy as I was wondering how this could be done. I always wanted to change a parameter in Gtk2::Unique and didn't knew that it was even possible until you wrote this :) I've now implemented this for Gtk2::Unique which now looks more Perl-ish than ever! _______________________________________________ gtk-perl-list mailing list gtk-perl-list@... http://mail.gnome.org/mailman/listinfo/gtk-perl-list |
| Free embeddable forum powered by Nabble | Forum Help |