Skip to contentSkip to conversation

include/types: move stdlib.h-kind types to common header

PATCH In review Jan Beulich 3 participants 4 messages Jan 12, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 include/types: move stdlib.h-kind types to common header

size_t, ssize_t, and ptrdiff_t are all expected to be uniformly defined on any ports Xen might gain. In particular I hope new ports can rely on __SIZE_TYPE__ and __PTRDIFF_TYPE__ being made available by the compiler.

---
This is just to start with some hopefully uncontroversial low hanging fruit.

xen/arch/arm/include/asm/types.h +0 -13
@@ -54,19 +54,6 @@ typedef u64 register_t;
 #define PRIregister "016lx"
 #endif
 
-#if defined(__SIZE_TYPE__)
-typedef __SIZE_TYPE__ size_t;
-#else
-typedef unsigned long size_t;
-#endif
-typedef signed long ssize_t;
-
-#if defined(__PTRDIFF_TYPE__)
-typedef __PTRDIFF_TYPE__ ptrdiff_t;
-#else
-typedef signed long ptrdiff_t;
-#endif
-
 #endif /* __ASSEMBLY__ */
 
 #endif /* __ARM_TYPES_H__ */
xen/arch/x86/include/asm/types.h +0 -13
@@ -32,19 +32,6 @@ typedef unsigned long paddr_t;
 #define INVALID_PADDR (~0UL)
 #define PRIpaddr "016lx"
 
-#if defined(__SIZE_TYPE__)
-typedef __SIZE_TYPE__ size_t;
-#else
-typedef unsigned long size_t;
-#endif
-typedef signed long ssize_t;
-
-#if defined(__PTRDIFF_TYPE__)
-typedef __PTRDIFF_TYPE__ ptrdiff_t;
-#else
-typedef signed long ptrdiff_t;
-#endif
-
 #endif /* __ASSEMBLY__ */
 
 #endif /* __X86_TYPES_H__ */
xen/include/xen/types.h +13 -0
@@ -5,6 +5,19 @@
 
 #include <asm/types.h>
 
+#if defined(__SIZE_TYPE__)
+typedef __SIZE_TYPE__ size_t;
+#else
+typedef unsigned long size_t;
+#endif
+typedef signed long ssize_t;
+
+#if defined(__PTRDIFF_TYPE__)
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+#else
+typedef signed long ptrdiff_t;
+#endif
+
 #define BITS_TO_LONGS(bits) \
     (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)
 #define DECLARE_BITMAP(name,bits) \
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Jan Beulich

size_t, ssize_t, and ptrdiff_t are all expected to be uniformly defined on any ports Xen might gain. In particular I hope new ports can rely on __SIZE_TYPE__ and __PTRDIFF_TYPE__ being made available by the compiler.

Thankyou for starting this.

Quoted 2 lines

---
This is just to start with some hopefully uncontroversial low hanging fruit.

However, I'd advocate going one step further and making real a xen/stddef.h header to match our existing stdboot and stdarg, now that we have fully divorced ourselves from the compiler-provided freestanding headers.

This way, the type are declared in the usual place in a C environment.

I was then also going to use this approach to start breaking up xen/lib.h which is a dumping ground of far too much stuff.  In particular, when we have a stddef.h, I think it is entirely reasonable to move things like ARRAY_SIZE/count_args()/etc into it, because they are entirely standard in the Xen codebase.

~Andrew

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

size_t, ssize_t, and ptrdiff_t are all expected to be uniformly defined on any ports Xen might gain. In particular I hope new ports can rely on __SIZE_TYPE__ and __PTRDIFF_TYPE__ being made available by the compiler.

Thanks.

Quoted 7 lines
Quoted 2 lines

---
This is just to start with some hopefully uncontroversial low hanging fruit.

However, I'd advocate going one step further and making real a xen/stddef.h header to match our existing stdboot and stdarg, now that we have fully divorced ourselves from the compiler-provided freestanding headers.

Hmm, to be honest I'm not convinced. It'll be interesting to see what other maintainers think about such further moving away from Linux'es basic model.

Quoted 7 lines

This way, the type are declared in the usual place in a C environment.

I was then also going to use this approach to start breaking up xen/lib.h which is a dumping ground of far too much stuff.  In particular, when we have a stddef.h, I think it is entirely reasonable to move things like ARRAY_SIZE/count_args()/etc into it, because they are entirely standard in the Xen codebase.

Yet these aren't what people would expect to live there. If we introduce further std*.h, then I think these would better strictly conform to what the C standard expects to be put there.

Jan

Acked-by on v1 1/1
#3 lore raw
In reply to Jan Beulich

Hi Jan,

Quoted 5 lines · Jan Beulich

size_t, ssize_t, and ptrdiff_t are all expected to be uniformly defined on any ports Xen might gain. In particular I hope new ports can rely on __SIZE_TYPE__ and __PTRDIFF_TYPE__ being made available by the compiler.

I also don't have any strong opinion either way about continuing to use types.h or introduce stddef.h.

Cheers,

Signature · 1 line
Julien Grall