Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • G GLib
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 852
    • Issues 852
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 43
    • Merge requests 43
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GNOMEGNOME
  • GLib
  • Merge requests
  • !2576

Add a NONE or DEFAULT member to most flags-sets

  • Review changes

  • Download
  • Patches
  • Plain diff
Merged Simon McVittie requested to merge wip/smcv/none-flags into main Mar 31, 2022
  • Overview 26
  • Commits 8
  • Pipelines 4
  • Changes 64

While writing code that wanted to pass G_CONNECT_DEFAULT or G_CONNECT_FLAGS_NONE to make g_signal_connect_object() a bit more self-documenting, I though that rather than adding NONE members to flags-sets one at a time, it seemed cleaner to go through the g*/*.h consistently adding them everywhere.

Some API design choice is involved in choosing whether to call them DEFAULT or NONE. In general, what I've done is:

  • if all existing members are FOO_FLAGS_BAR, use FOO_FLAGS_NONE
  • else if all existing members are FOO_FLAG_BAR, use FOO_FLAG_NONE
  • else if the flag is a way for the caller to alter behaviour, use FOO_DEFAULT
  • else if FOO_NONE seems like it make sense, use it
  • else use FOO_FLAGS_NONE

Requires !2572 (merged), but I haven't rebased it on that MR in order to avoid being behind HEAD.

This would also be useful to "backport" in libglnx, via #define G_CONNECT_DEFAULT ((GConnectFlags) 0) and so on, but I'd prefer to have the names officially approved upstream before doing that.


  • gtype: Add G_TYPE_FLAG_NONE

    This makes code that sets no flags a bit more self-documenting: using G_TYPE_FLAG_NONE makes it clearer that no special behaviour is required than literal 0, and clearer that there is no weird casting between types than (GTypeFlags) 0.

    GTypeFlags and GTypeFundamentalFlags occupy the same namespace and the same bitfield, so I intentionally haven't added G_TYPE_FUNDAMENTAL_FLAGS_NONE.

  • gsignal: Add G_CONNECT_DEFAULT

    This makes calls to g_signal_connect_data() and g_signal_connect_object() with default flags more self-documenting.

  • gioenums: Add G_TLS_CERTIFICATE_FLAGS_NONE

    This makes the absence of flags (in other words, a valid certificate) more self-documenting.

  • gtestutils: Add G_TEST_SUBPROCESS_DEFAULT, G_TEST_TRAP_DEFAULT

    This makes calls to test subprocesses with default behaviour more self-documenting.

  • giomodule test: Don't pass a magic number to g_test_trap_subprocess()

    This worked, but seems like bad style.

  • giochannel: Add G_IO_FLAG_NONE

    This makes the state where no flags are set a bit more self-documenting.

  • gmarkup: Add G_MARKUP_PARSE_FLAGS_NONE

  • gregex: Add G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT

Edited Jun 23, 2022 by Simon McVittie
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: wip/smcv/none-flags