gtk-rs / gtk3-rs

Rust bindings for GTK 3
https://gtk-rs.org
MIT License
508 stars 90 forks source link

[BUG] Wrong return turn (u32 vs gint) for GtkNotebook append_page #785

Open dvogel opened 1 year ago

dvogel commented 1 year ago

Bug description

Please provide a code sample as small as possible which reproduces the bug.

Upstream gtk_notebook_append_page returns a gint. In gtk3-rs NotebookExtManual.append_page returns a u32. The documentation says the function will return -1 on error, which is impossible in the rust code.

GuillaumeGomez commented 1 year ago

There is an assert in the code to ensure the returned value is >= 0. It'll panic if it isn't the case so it can never return something less than 0.

GuillaumeGomez commented 1 year ago

It might a bit problematic because it can actually return -1 with our code since we accept nullable arguments and the function returns -1 if an argument is nullable. So either we don't allow the arguments to be nullable, or we return Option<u32>.

sdroege commented 1 year ago

If the function doesn't allow NULL then we should not allow passing None.

But I think this can actually fail in other ways, can't it? It calls into a virtual method somewhere and it looks like at least the default implementation of that can also fail in other reasons (if the page already was added to another notebook maybe?).