style: Force Python.h to be included before main header
authorAndreas Sandberg <andreas.sandberg@arm.com>
Tue, 7 Feb 2017 15:28:33 +0000 (15:28 +0000)
committerAndreas Sandberg <andreas.sandberg@arm.com>
Tue, 7 Feb 2017 15:28:33 +0000 (15:28 +0000)
Python's header files set various compiler macros (e.g.,
_XOPEN_SOURCE) unconditionally. This triggers preprocessor warnings
that end up being treated as errors. The Python integration manual [1]
strongly recommends that Python.h is included before any system
header. The style guide used to mandate that Python.h is included
first in any file that needs it. This requirement was changed to
always include a source file's main header first, which ended up
triggering these errors.

This change updates the style checker to always include Python.h
before the main header file.

[1] https://docs.python.org/2/extending/extending.html

Change-Id: Id6a4f7fc64a336a8fd26691a0ca682abeb1d1579
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-by: Pierre-Yves PĂ©neau <pierre-yves.peneau@lirmm.fr>
src/python/swig/pyevent.cc
src/sim/init.cc
src/sim/py_interact.cc
util/style/sort_includes.py

index 53f3a3397f2493e5dfd1d2b3072fb890a00a3745..39c57d1164c621ea568d8b437d36ae9a4bcf9ed7 100644 (file)
  * Authors: Nathan Binkert
  */
 
-#include "python/swig/pyevent.hh"
-
 #include <Python.h>
 
+#include "python/swig/pyevent.hh"
+
 #include "base/misc.hh"
 #include "sim/async.hh"
 #include "sim/eventq.hh"
index d46e763241ee2159fcf59877ffd1a0c9995acab7..f2395eec4f82f3c85006a165f30ede31cac48bc6 100644 (file)
  * Authors: Nathan Binkert
  */
 
-#include "sim/init.hh"
-
 #include <Python.h>
 
+#include "sim/init.hh"
+
 #include <marshal.h>
 #include <zlib.h>
 
index 8acff40dd6b1a56d9c98a11848672052ebb02fba..7e6527e814067a131629928a3febae15931b2c71 100644 (file)
  *          Steve Reinhardt
  */
 
-#include "sim/py_interact.hh"
-
 #include <Python.h>
 
+#include "sim/py_interact.hh"
+
 void
 py_interact()
 {
index 334d9e29ea21ff1ca3f65065663a8f48dc32ef75..a35b0846807e394b4defff315170813e69080c54 100644 (file)
@@ -169,8 +169,8 @@ class SortIncludes(object):
         )
 
     block_order = (
-        ('main', ),
         ('python', ),
+        ('main', ),
         ('c', ),
         ('stl', ),
         ('cc', ),