Gtk::Entry::set_icon_from_icon_name(nullptr) segmentation fault

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Gtk::Entry::set_icon_from_icon_name(nullptr) segmentation fault

Gtkmm mailing list
Hello,

I may be very much mistaken, but if I read the documentation for
Gtk::Entry::set_icon_from_icon_name (located at https://developer.gnome
.org/gtkmm/stable/classGtk_1_1Entry.html#a7c61eafbce9c3293566c1b6cc86f8
9e1) it seems that to remove an icon from an Entry, one should provide
an std::nullptr_t as the first parameter.

Doing this results in a segmentation fault, which makes sense because
one cannot construct a Glib::ustring with a nullptr. I have also tried
providing the string "nullptr", since the documentation is not
completely clear and this results in the "broken image" being shown.

This feels like - at the least - a documentation bug. I could not find
the correct way to do this. How can I remove an image from an Entry?

With regards,
Martijn Otto
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Gtk::Entry::set_icon_from_icon_name(nullptr) segmentation fault

Daniel Boles
The documentation is auto generated from the C documentation, which does not always work very well, especially for conversions from char* to Glib::ustring as you saw.

Did you try just passing an empty string? That's usually how you need to mentally translate "nullptr".

I wonder if the documentation converter can possibly do this conversion for us...


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Gtk::Entry::set_icon_from_icon_name(nullptr) segmentation fault

Gtkmm mailing list
I had not thought of trying an empty string, though it's good to know that this is the usual answer to nullptr's that have become objects. I have tried it and it does indeed work as expected when I pass an empty string.

On a side note, I had already got it working the way I wanted by using Gtk::Entry::set_icon_from_pixbuf and passing an empty Glib::RefPtr to it. I noticed that it does have a default constructor that creates an empty object, so the following works:

entry.set_icon_from_pixbuf({});

However, it does not have a constructor taking an std::nullptr_t, which would be a more obvious way to do it, one could then call:

entry.set_icon_from_pixbuf(nullptr);

This models the way that std::shared_ptr works, and IMHO it's more declarative. It should be a simple one-liner to fix this, I'll see about creating a patch for this later.

On di, 2017-07-25 at 14:58 +0100, Daniel Boles wrote:
The documentation is auto generated from the C documentation, which does not always work very well, especially for conversions from char* to Glib::ustring as you saw.

Did you try just passing an empty string? That's usually how you need to mentally translate "nullptr".

I wonder if the documentation converter can possibly do this conversion for us...

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Gtk::Entry::set_icon_from_icon_name(nullptr) segmentation fault

Daniel Boles
On 25 July 2017 at 15:20, Martijn Otto via gtkmm-list <[hidden email]> wrote:
I had not thought of trying an empty string, though it's good to know that this is the usual answer to nullptr's that have become objects.

It's the usual answer for where the C API specifies NULL and the C++ API expects a string. It's not general to all objects.

 
However, it does not have a constructor taking an std::nullptr_t, which would be a more obvious way to do it, one could then call:

entry.set_icon_from_pixbuf(nullptr);

This models the way that std::shared_ptr works, and IMHO it's more declarative. It should be a simple one-liner to fix this, I'll see about creating a patch for this later.

what does not have a constructor from std::nullptr_t is Glib::RefPtr in glibmm 3. Your patch should be directed to that, if anywhere, but then there's probably a reason that it does not exist.

In glibmm next, for gtkmm 4, Glib::RefPtr is a shared_ptr.
 


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Gtk::Entry::set_icon_from_icon_name(nullptr) segmentation fault

Daniel Boles
On 25 July 2017 at 16:02, Daniel Boles <[hidden email]> wrote:
what does not have a constructor from std::nullptr_t is Glib::RefPtr in glibmm 3.

Oops, I meant glibmm 2.4, i.e. the stable ABI, as used by gtkmm 3.

The current development version of the next ABI is 2.54, but it may not always be so. So it's easier to refer to stable/unstable or gtkmm 3/4. If only I could remember to do that. :)



_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Gtk::Entry::set_icon_from_icon_name(nullptr) segmentation fault

Daniel Boles
Besides, to unset the icon, rather than manipulating a set() overload into unsetting, why not just call unset_icon() ?
 

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Gtk::Entry::set_icon_from_icon_name(nullptr) segmentation fault

Gtkmm mailing list
I must admit I had missed that function, after reading the
documentation describing the usage of a "nullptr" to clear the image I
assumed that was the GTK way of doing things.

On di, 2017-07-25 at 19:49 +0100, Daniel Boles wrote:
> Besides, to unset the icon, rather than manipulating a set() overload
> into unsetting, why not just call unset_icon() ?
>  
> _______________________________________________
> gtkmm-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtkmm-list
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Gtk::Entry::set_icon_from_icon_name(nullptr) segmentation fault

Daniel Boles
On 26 July 2017 at 08:20, Martijn Otto via gtkmm-list <[hidden email]> wrote:
I must admit I had missed that function, after reading the
documentation describing the usage of a "nullptr" to clear the image I
assumed that was the GTK way of doing things.


Well, yeah, it's a way, in that usually you can use a set() method with its argument being suitably-typed equivalent of 'empty' or 'null' to achieve unsetting. However, in many or perhaps most cases, there is an unset() to make things simpler, and IMO that is better API and should be offered/used where possible.

If you find any cases where there isn't an unset and the set(empty) is unintuitive or clumsy, then it's probably worth submitting an enhancement to Bugzilla - probably on the GTK+ side, since typically gtkmm just prefers to wrap what GTK+ offers.

That said, as you will have noticed, it's not uncommon for gtkmm to add extra convenience methods that GTK+ probably never will - especially when that "never will" is because the gtkmm methods depend on C++ convenience features. So it's possibly you'll find something that would be better done on the gtkmm side.


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Gtk::Entry::set_icon_from_icon_name(nullptr) segmentation fault

Murray Cumming-5
On Wed, 2017-07-26 at 09:52 +0100, Daniel Boles wrote:
> Well, yeah, it's a way, in that usually you can use a set() method
> with its argument being suitably-typed equivalent of 'empty' or
> 'null' to achieve unsetting.

I don't think we can generally assume that that works as expected.

>  However, in many or perhaps most cases, there is an unset() to make
> things simpler, and IMO that is better API and should be offered/used
> where possible.

Yes, the unset_*() methods are more obvious. We just need to mention
them in the documentation.


--
Murray Cumming
[hidden email]
www.murrayc.com

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Loading...