Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • gtk gtk
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,477
    • Issues 1,477
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 247
    • Merge requests 247
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GNOME
  • gtkgtk
  • Merge requests
  • !1212

Return concrete type from widget constructors instead of GtkWidget*

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Robert Ancell requested to merge robert.ancell/gtk:widget-types into master Nov 26, 2019
  • Overview 6
  • Commits 30
  • Pipelines 21
  • Changes 304

GTK has an odd behaviour in that the widget constructors return the GtkWidget* type. This results in C users of GTK frequently downcasting to access objects. e.g.

GtkWidget *label = gtk_label_new (NULL);
gtk_label_set_label (GTK_LABEL (label), "foo");

instead of:

GtkLabel *label = gtk_label_new (NULL);
gtk_label_set_label (label, "foo");

The downside of all this casting is we lose the ability for the compiler to do any type checking. In the above example if the label was replaced with another widget this would only be detected at run-time. The casting macros also tend to make GTK lines very wide and hard to read, though the alternative requires more casting on functions that take GtkWidget* arguments.

With GTK 4 we have an opportunity to change the constructors in an API (but not ABI) break. This MR shows what changes are required to convert one common widget.

What do others think? Is this a change worth considering?

Edited Sep 10, 2020 by Matthias Clasen
Assignee
Assign to
Reviewer
Request review from
Time tracking
Source branch: widget-types