Skip to contentSkip to conversation

cpu: Clean up includes

PATCH In review Peter Maydell 3 participants 4 messages Jan 18, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpu: Clean up includes

Clean up includes so that osdep.h is included first and headers which it implies are not included manually.

This commit was created with scripts/clean-includes.

---
 qom/cpu.c         | 1 +
 target-i386/cpu.c | 5 +----
 2 files changed, 2 insertions(+), 4 deletions(-)
qom/cpu.c +1 -0
index 8f537a4..edd6b6a 100644
@@ -18,6 +18,7 @@
  * <http://www.gnu.org/licenses/gpl-2.0.html>
  */
 
+#include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "qom/cpu.h"
 #include "sysemu/kvm.h"
target-i386/cpu.c +1 -4
index 0d447b5..1e3b98a 100644
@@ -16,10 +16,7 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <inttypes.h>
+#include "qemu/osdep.h"
 
 #include "cpu.h"
 #include "sysemu/kvm.h"
Signature · 1 line
1.9.1
#1 lore raw

Am 18.01.2016 um 18:35 schrieb Peter Maydell:

Quoted 16 lines

Clean up includes so that osdep.h is included first and headers which it implies are not included manually.

This commit was created with scripts/clean-includes.

---
 qom/cpu.c         | 1 +
 target-i386/cpu.c | 5 +----
 2 files changed, 2 insertions(+), 4 deletions(-)
qom/cpu.c +0 -0
index 8f537a4..edd6b6a 100644

qom/cpu.c line 22

Quoted 5 lines
qom/cpu.c +1 -0
@@ -18,6 +18,7 @@
  * <http://www.gnu.org/licenses/gpl-2.0.html>
  */
 
+#include "qemu/osdep.h"
 #include "qemu-common.h"

Shouldn't qemu-common.h include osdep.h?

Otherwise looks okay.

Regards,
Andreas

Quoted 18 lines
qom/cpu.c +0 -0
 #include "qom/cpu.h"
 #include "sysemu/kvm.h"
target-i386/cpu.c +1 -4
index 0d447b5..1e3b98a 100644
@@ -16,10 +16,7 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <inttypes.h>
+#include "qemu/osdep.h"
 
 #include "cpu.h"
 #include "sysemu/kvm.h"
Signature · 2 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Graham Norton; HRB 21284 (AG Nürnberg)
#2 lore raw
Quoted 20 lines · Andreas Färber

Am 18.01.2016 um 18:35 schrieb Peter Maydell:

Quoted 19 lines

Clean up includes so that osdep.h is included first and headers which it implies are not included manually.

This commit was created with scripts/clean-includes.

---
 qom/cpu.c         | 1 +
 target-i386/cpu.c | 5 +----
 2 files changed, 2 insertions(+), 4 deletions(-)
qom/cpu.c +0 -0
index 8f537a4..edd6b6a 100644
@@ -18,6 +18,7 @@
  * <http://www.gnu.org/licenses/gpl-2.0.html>
  */
 
Quoted 4 lines

qom/cpu.c line 22

Quoted 2 lines
qom/cpu.c +1 -0
+#include "qemu/osdep.h"
 #include "qemu-common.h"

Shouldn't qemu-common.h include osdep.h?

It does, but the intention is that every .c file should include qemu/osdep.h as its first include (even if some other include it has also results in osdep.h being pulled in). This is a simple rule that's easy to check in code review and hopefully also in an automated way. It should also help us in future disentangling of some of the things that qemu-common.h pulls in into their own header files.

thanks
-- PMM

#3 lore raw
Quoted 5 lines · Peter Maydell
Quoted 5 lines
Quoted 5 lines

+++ b/qom/cpu.c

qom/cpu.c +0 -0
@@ -18,6 +18,7 @@
  * <http://www.gnu.org/licenses/gpl-2.0.html>
  */
 
Quoted 8 lines
Quoted 4 lines

qom/cpu.c line 22

Quoted 2 lines
qom/cpu.c +1 -0
+#include "qemu/osdep.h"
 #include "qemu-common.h"

Shouldn't qemu-common.h include osdep.h?

It does, but the intention is that every .c file should include qemu/osdep.h as its first include (even if some other include it has also results in osdep.h being pulled in).

Eventually, we want to force that NO .h file includes qemu/osdep.h. If every .c file includes it first, then all other .h files can count on it already being included and therefore don't need to include it themselves. (This is comparable to the rule used in other projects, like libvirt's handling of config.h which must be first in all .c files and must not be included in .h files).

Quoted 3 lines

This is a simple
rule that's easy to check in code review and hopefully also in an automated way.

Indeed - we MUST turn on automation after all these individual patches are in, to make sure we don't regress (again, something that libvirt has already managed to do, so it shouldn't be too hard to automate, except that libvirt's automation is courtesy of gnulib which we don't use here).

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org