Skip to contentSkip to conversation

xen: Give compile.h header guards

PATCH In review Andrew Cooper 5 participants 7 messages May 19, 2025 – May 20, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: Give compile.h header guards

---
CC: Anthony PERARD <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>

---
 xen/include/xen/compile.h.in | 3 +++
 xen/tools/process-banner.sed | 5 +++++
 2 files changed, 8 insertions(+)
xen/include/xen/compile.h.in +3 -0
index 3151d1e7d1bf..9206341ba692 100644
@@ -1,3 +1,6 @@
+#ifndef XEN_COMPILE_H
+#define XEN_COMPILE_H
+
 #define XEN_COMPILE_DATE	"@@date@@"
 #define XEN_COMPILE_TIME	"@@time@@"
 #define XEN_COMPILE_BY		"@@whoami@@"
xen/tools/process-banner.sed +5 -0
index 56c76558bcd9..4cf3f9a1163a 100755
@@ -12,3 +12,8 @@ s_(.*)_"\1\\n"_
 
 # Trailing \ on all but the final line.
 $!s_$_ \\_
+
+# Append closing header guard
+$a\
+\
+#endif /* XEN_COMPILE_H */

base-commit: 6fc02ebdd053856221f37ba5306232ac1575332d
prerequisite-patch-id: 7bc1c498ba2c9c4a4939a56a0006f820f47f2a66

Signature · 1 line
2.39.5
#1 lore raw
Quoted 1 line · Andrew Cooper

Is this to please Misra in some way?

Quoted 12 lines
xen/include/xen/compile.h.in +3 -0
@@ -1,3 +1,6 @@
+#ifndef XEN_COMPILE_H
+#define XEN_COMPILE_H
+
 #define XEN_COMPILE_DATE	"@@date@@"
 #define XEN_COMPILE_TIME	"@@time@@"
 #define XEN_COMPILE_BY		"@@whoami@@"

xen/tools/process-banner.sed s_(.*)_"\1\\n"_ · line 19

Quoted 8 lines
xen/tools/process-banner.sed +5 -0
@@ -12,3 +12,8 @@ s_(.*)_"\1\\n"_
 
 # Trailing \ on all but the final line.
 $!s_$_ \\_
+
+# Append closing header guard
+$a\
+\
+#endif /* XEN_COMPILE_H */

This split of #ifndef and #endif is ugly. Can't we switch to something more conventional, like

#define XEN_BANNER "@@banner@@"

with the first sed invocation then replacing this by the result of a nested sed invocation using process-banner.sed (which of course would need adjusting some)? (Maybe the double quotes would need omitting here, for process-banner.sed to uniformly apply them.)

Jan

#2 lore raw
Quoted 5 lines · Jan Beulich
Quoted 1 line · Andrew Cooper

Is this to please Misra in some way?

Directive 4.10: "Precautions shall be taken in order to prevent the contents of a header file being included more than once". One approach is to special-case this file, but Andrew suggested this approach which addresses the issue directly.

Quoted 32 lines
Quoted 12 lines
xen/include/xen/compile.h.in +3 -0
@@ -1,3 +1,6 @@
+#ifndef XEN_COMPILE_H
+#define XEN_COMPILE_H
+
 #define XEN_COMPILE_DATE	"@@date@@"
 #define XEN_COMPILE_TIME	"@@time@@"
 #define XEN_COMPILE_BY		"@@whoami@@"

xen/tools/process-banner.sed s_(.*)_"\1\\n"_ · line 19

Quoted 8 lines
xen/tools/process-banner.sed +5 -0
@@ -12,3 +12,8 @@ s_(.*)_"\1\\n"_
 
 # Trailing \ on all but the final line.
 $!s_$_ \\_
+
+# Append closing header guard
+$a\
+\
+#endif /* XEN_COMPILE_H */

This split of #ifndef and #endif is ugly. Can't we switch to something more conventional, like

#define XEN_BANNER "@@banner@@"

with the first sed invocation then replacing this by the result of a nested sed invocation using process-banner.sed (which of course would need adjusting some)? (Maybe the double quotes would need omitting here, for process-banner.sed to uniformly apply them.)

Jan

Signature · 4 lines
Nicola Vetrini, B.Sc.
Software Engineer
BUGSENG (https://bugseng.com)
LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
#3 lore raw
In reply to Jan Beulich
Quoted 29 lines · Jan Beulich
Quoted 1 line · Andrew Cooper

Is this to please Misra in some way?

Quoted 12 lines
xen/include/xen/compile.h.in +3 -0
@@ -1,3 +1,6 @@
+#ifndef XEN_COMPILE_H
+#define XEN_COMPILE_H
+
 #define XEN_COMPILE_DATE	"@@date@@"
 #define XEN_COMPILE_TIME	"@@time@@"
 #define XEN_COMPILE_BY		"@@whoami@@"

xen/tools/process-banner.sed s_(.*)_"\1\\n"_ · line 19

Quoted 8 lines
xen/tools/process-banner.sed +5 -0
@@ -12,3 +12,8 @@ s_(.*)_"\1\\n"_
 
 # Trailing \ on all but the final line.
 $!s_$_ \\_
+
+# Append closing header guard
+$a\
+\
+#endif /* XEN_COMPILE_H */

This split of #ifndef and #endif is ugly. Can't we switch to something more conventional, like

Quoted 6 lines

#define XEN_BANNER "@@banner@@"

with the first sed invocation then replacing this by the result of a nested sed invocation using process-banner.sed (which of course would need adjusting some)? (Maybe the double quotes would need omitting here, for process-banner.sed to uniformly apply them.)

While I agree with Jan that this is kind of ugly, it is a unique case and I would prefer an ugly but simple solution than a more complex solution. This would be different if we were talking about a widespread pattern, in which case the price for complexity would be worth it.

My 2 cents in this case are in favor of the simplest approach. I would ack this patch.

#4 lore raw
Quoted 37 lines · Stefano Stabellini
Quoted 29 lines · Jan Beulich
Quoted 1 line · Andrew Cooper

Is this to please Misra in some way?

Quoted 12 lines
xen/include/xen/compile.h.in +3 -0
@@ -1,3 +1,6 @@
+#ifndef XEN_COMPILE_H
+#define XEN_COMPILE_H
+
 #define XEN_COMPILE_DATE	"@@date@@"
 #define XEN_COMPILE_TIME	"@@time@@"
 #define XEN_COMPILE_BY		"@@whoami@@"

xen/tools/process-banner.sed s_(.*)_"\1\\n"_ · line 19

Quoted 8 lines
xen/tools/process-banner.sed +5 -0
@@ -12,3 +12,8 @@ s_(.*)_"\1\\n"_
 
 # Trailing \ on all but the final line.
 $!s_$_ \\_
+
+# Append closing header guard
+$a\
+\
+#endif /* XEN_COMPILE_H */

This split of #ifndef and #endif is ugly. Can't we switch to something more conventional, like

Quoted 6 lines

#define XEN_BANNER "@@banner@@"

with the first sed invocation then replacing this by the result of a nested sed invocation using process-banner.sed (which of course would need adjusting some)? (Maybe the double quotes would need omitting here, for process-banner.sed to uniformly apply them.)

Quoted 7 lines

While I agree with Jan that this is kind of ugly, it is a unique case and I would prefer an ugly but simple solution than a more complex solution. This would be different if we were talking about a widespread pattern, in which case the price for complexity would be worth it.

My 2 cents in this case are in favor of the simplest approach. I would ack this patch.

Feel free to do so; my comment was not meant as a plain objection, but more as a suggestion. The one thing I would ask for is a non-empty description, though.

Jan

Reviewed-by
#5 lore raw
Quoted 43 lines · Jan Beulich
Quoted 42 lines · Stefano Stabellini
Quoted 29 lines · Jan Beulich
Quoted 1 line · Andrew Cooper

Is this to please Misra in some way?

Quoted 12 lines
xen/include/xen/compile.h.in +3 -0
@@ -1,3 +1,6 @@
+#ifndef XEN_COMPILE_H
+#define XEN_COMPILE_H
+
 #define XEN_COMPILE_DATE	"@@date@@"
 #define XEN_COMPILE_TIME	"@@time@@"
 #define XEN_COMPILE_BY		"@@whoami@@"

xen/tools/process-banner.sed s_(.*)_"\1\\n"_ · line 19

Quoted 8 lines
xen/tools/process-banner.sed +5 -0
@@ -12,3 +12,8 @@ s_(.*)_"\1\\n"_
 
 # Trailing \ on all but the final line.
 $!s_$_ \\_
+
+# Append closing header guard
+$a\
+\
+#endif /* XEN_COMPILE_H */

This split of #ifndef and #endif is ugly. Can't we switch to something more conventional, like

Quoted 6 lines

#define XEN_BANNER "@@banner@@"

with the first sed invocation then replacing this by the result of a nested sed invocation using process-banner.sed (which of course would need adjusting some)? (Maybe the double quotes would need omitting here, for process-banner.sed to uniformly apply them.)

While I agree with Jan that this is kind of ugly, it is a unique case and I would prefer an ugly but simple solution than a more complex solution. This would be different if we were talking about a widespread pattern, in which case the price for complexity would be worth it.

Quoted 6 lines
Quoted 2 lines

My 2 cents in this case are in favor of the simplest approach. I would ack this patch.

Feel free to do so; my comment was not meant as a plain objection, but more as a suggestion. The one thing I would ask for is a non-empty description, though.

Fair enough. Andrew, please add a better commit message. With that:

#6 lore raw
In reply to Andrew Cooper
Quoted 19 lines · Andrew Cooper

---
CC: Anthony PERARD <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>

---
 xen/include/xen/compile.h.in | 3 +++
 xen/tools/process-banner.sed | 5 +++++
 2 files changed, 8 insertions(+)
xen/include/xen/compile.h.in +0 -0
index 3151d1e7d1bf..9206341ba692 100644

xen/include/xen/compile.h.in line 3

Quoted 3 lines
xen/include/xen/compile.h.in +3 -0
@@ -1,3 +1,6 @@
+#ifndef XEN_COMPILE_H
+#define XEN_COMPILE_H
+

Why not follow CODING_STYLE ?

OT: Maybe while on it, why not add SPDX comments too ?

Quoted 17 lines
xen/include/xen/compile.h.in +0 -0
 #define XEN_COMPILE_DATE       "@@date@@"
 #define XEN_COMPILE_TIME       "@@time@@"
 #define XEN_COMPILE_BY         "@@whoami@@"
xen/tools/process-banner.sed +5 -0
index 56c76558bcd9..4cf3f9a1163a 100755
@@ -12,3 +12,8 @@ s_(.*)_"\1\\n"_
 
 # Trailing \ on all but the final line.
 $!s_$_ \\_
+
+# Append closing header guard
+$a\
+\
+#endif /* XEN_COMPILE_H */
Quoted 6 lines

base-commit: 6fc02ebdd053856221f37ba5306232ac1575332d
prerequisite-patch-id: 7bc1c498ba2c9c4a4939a56a0006f820f47f2a66 --
2.39.5

Frediano