GNOME Bugzilla – Bug 609280
glib header #include issues (remove #include "glib.h")
Last modified: 2013-02-03 11:45:12 UTC
the header situation in glib is a little bit random at the moment. the main problem is that just about everything does #include <glib.h> which means that a single change to a completely-unrelated header file results in the entirety of glib being rebuilt. i propose that all .c files in glib/ be changed to this: (for file gfoo.c) ----- /* Copyright etc... * */ #include "config.h" /* [1] */ #include "gfoo.h" /* [2] */ #include <glib/gtestutils.h> /* [3] */ #include <glib/gslist.h> #include <stdio.h> /* [4] */ #include <string.h> #include "galias.h" /* [5] */ ... stuff ... ----- [1] config.h needs to be in every file and it needs to come first. See bug 71704. [2] each .c file should include its corresponding .h before any other includes as a way of 'taking responsibility' for ensuring that the .h file can be #included from any context without errors (ie: the .h file does not require other .h files to come before it). note that config.h still needs to be first incase the "gfoo.h" includes some system header files. [3] next, the glib .h files that this module depends on. it seems to me that this list should be kept as small as possible via transitive reduction (eg: we shouldn't include gmessages.h since that's already included via our include of gtestutils.h). this increases the chances of changes to .h files breaking things (which will be promptly noticed and fixed) and reduces the chances of .c files silently depending on unnecessary .h files when such changes occur. <glib.h> should never be included from anything inside of glib/ ever. test cases should use <glib.h>. gobject/ and gio/ can use it too. [4] system headers. boring. [5] aliasing stuff. needs to come after all glib headers, but could maybe be before system headers. feedback?
Sure, sounds ok as a general cleanup goal. I tend to sort system headers early (ie between config.h and other glib headers)
Created attachment 160357 [details] [review] Do not include "glib.h" in gio files
Created attachment 160358 [details] [review] gasyncqueue
Created attachment 160359 [details] [review] gtestutils
Created attachment 160360 [details] [review] gmem
Created attachment 160361 [details] [review] gthread
Comment on attachment 160357 [details] [review] Do not include "glib.h" in gio files looks fine (assuming make check still works)
Comment on attachment 160358 [details] [review] gasyncqueue same comment
Comment on attachment 160360 [details] [review] gmem are you sure we dont need gthreadprivate.h here ?
Comment on attachment 160357 [details] [review] Do not include "glib.h" in gio files commit 434a4e1d250157b13d7036592f097c18fb8376b1
Comment on attachment 160358 [details] [review] gasyncqueue commit d1642386c96b4a2a4479cd7c2b5cd8ddadae99e4
Comment on attachment 160359 [details] [review] gtestutils commit 21302a741cbb3d6373a368df148f6267a0705366
Comment on attachment 160360 [details] [review] gmem committed after double chekc this commit c7940d81802194abe1d4497d3daa2f9c59addb5e
Comment on attachment 160361 [details] [review] gthread comitted the correct patch in commit 81e98c399e11d7621c91ff2911ef4f92c7a382e5
I think we're good here
Not really fixed yet for gio/