Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Widget::destroy() should be marked unsafe #957

@sdroege

Description

@sdroege

Based on discussion on IRC

<slomo> i wonder if we should expose g_object_run_dispose() in the Rust bindings
<slomo> ebassi: the docs say "This function should only be called from object system implementations.", but that's not really true, is it? if it's directly called from gtk_widget_destroy() and that can be directly called
* osa1 has quit (Read error)
<ebassi> slomo: In general, yes: you should never call g_object_run_dispose() yourself
<ebassi> But gtk_widget_destroy() is really gtk_object_destroy(), which is really the previous object system
<ebassi> And had to maintain some "backward/historical" compatibility
<imperio> slomo: ?
<slomo> ebassi: ok, not going to expose it then and better teach people about using strong/weak references correctly :)
<ebassi> i.e. after gtk_widget_destroy() the widget is in an inert state, and only the pointer may be still valid
<ebassi> slomo: Yeah, definitely
<slomo> so arguably we should also mark gtk_widget_destroy() as unsafe in the Rust bindings because bad things might happen if using the widget afterwards?
<ebassi> If you're hiding the ref/unref mechanism, and you're using weak refs and correct transfer of ownership, at the end widgets should just not be lying around
<ebassi> slomo: Yes
<slomo> oh no :) ok
<ebassi> If something else is holding a strong reference to a widget, and something else calls gtk_widget_destroy(), the instance is still valid memory because otherwise you wouldn't be able to call g_object_unref() on it
<slomo> but calling any API on that widget might cause everything to explode?
<ebassi> But the widget is unparented and unrealized, and calling methods on it won't likely lead to any nice result—though I consider crashing a bug
<ebassi> Personally, I don't like stuff exploding because people forgot to NULLify stuff inside dispose()
<ebassi> And I consider that a bug
<ebassi> But other people may be more lenient because they haven't had to debug random crashes at 11pm
<slomo> there's also things potentially exploding because there's other code that does not expect any of the fields to be NULL while the object is still alive :)

Someone wants to create a PR and also update our examples to call Window::close() instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions