Skip to content

gtk.cfg: Fix gtk_widget_destroy definition and usage#8546

Draft
Tamaranch wants to merge 1 commit into
cppcheck-opensource:mainfrom
Tamaranch:gtk_widget_destroy
Draft

gtk.cfg: Fix gtk_widget_destroy definition and usage#8546
Tamaranch wants to merge 1 commit into
cppcheck-opensource:mainfrom
Tamaranch:gtk_widget_destroy

Conversation

@Tamaranch
Copy link
Copy Markdown
Contributor

gtk_widget_destroy is only for GtkWidget derived objects.

@chrchr-github
Copy link
Copy Markdown
Collaborator

Please add a (simple) example using gtk_widget_destroy() in gtk.c.

@Tamaranch Tamaranch force-pushed the gtk_widget_destroy branch from 5d43e32 to 435e7b4 Compare May 11, 2026 13:43
@Tamaranch
Copy link
Copy Markdown
Contributor Author

Please add a (simple) example using gtk_widget_destroy() in gtk.c.

Done. I also removed duplicate definition of gtk_widget_destroy and added definition of gtk_window_new for proper test.

@chrchr-github
Copy link
Copy Markdown
Collaborator

The value of GTK_WINDOW_TOPLEVEL seems to be documented, so you could add it to gtk.cfg to fix the CI failure.

@Tamaranch Tamaranch force-pushed the gtk_widget_destroy branch from 435e7b4 to b3bad5f Compare May 11, 2026 14:56
@Tamaranch
Copy link
Copy Markdown
Contributor Author

Tamaranch commented May 11, 2026

The value of GTK_WINDOW_TOPLEVEL seems to be documented, so you could add it to gtk.cfg to fix the CI failure.

I wasn't notified for the CI failure, sorry. (err: now I am :))

@Tamaranch Tamaranch changed the title gtk.cfg: Remove incorrect release function gtk.cfg: Fix gtk_widget_destroy definition and usage May 12, 2026
@Tamaranch Tamaranch force-pushed the gtk_widget_destroy branch from b3bad5f to b4da3c5 Compare May 12, 2026 14:17
Copy link
Copy Markdown
Collaborator

@danmar danmar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am no expert but when I ask chatgpt it says:

GTK 3
Using gtk_widget_destroy() is standard and commonly used.

GTK 4
GTK 4 documentation removed gtk_widget_destroy(). In GTK 4, widgets are generally disposed of by:

  • Removing them from their parent, or
  • Calling g_object_unref() if you own an extra reference

As I interpret it, this change might cause false positives for regular fine GTK 4 code.

gtk_widget_destroy is only for GtkWidget derived objects, and in
practice should only be used for GtkWindow derived widgets (it is
replaced with gtk_window_destroy in gtk4).
@Tamaranch Tamaranch force-pushed the gtk_widget_destroy branch from b4da3c5 to 0605fae Compare May 13, 2026 07:01
@Tamaranch
Copy link
Copy Markdown
Contributor Author

I am no expert but when I ask chatgpt it says:

GTK 3
Using gtk_widget_destroy() is standard and commonly used.
GTK 4
GTK 4 documentation removed gtk_widget_destroy(). In GTK 4, widgets are generally disposed of by:

  • Removing them from their parent, or
  • Calling g_object_unref() if you own an extra reference

As I interpret it, this change might cause false positives for regular fine GTK 4 code.

Yes you're right, I added the definition of gtk_window_destroy too.

@Tamaranch
Copy link
Copy Markdown
Contributor Author

Tamaranch commented May 13, 2026

Oh wait, we'll have another issue: gtk_window_new doesn't take any parameter in gtk4…

Should we really add a test for gtk_widget_destroy here?

@Tamaranch Tamaranch marked this pull request as draft May 13, 2026 07:13
@danmar
Copy link
Copy Markdown
Collaborator

danmar commented May 13, 2026

I fear that if you use gtk_window_new to allocate and then g_object_unref() to destroy the object you get a false positive about mismatching allocation and deallocation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants