Skip to content

Add a NONE or DEFAULT member to most flags-sets

Simon McVittie requested to merge wip/smcv/none-flags into main

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 by Simon McVittie

Merge request reports