[C#] Check int lengths at compile time
authorMatt Corallo <git@bluematt.me>
Tue, 23 Jan 2024 21:17:20 +0000 (21:17 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 29 Jan 2024 16:37:41 +0000 (16:37 +0000)
...cause I was using the wrong headers trying to do debug builds
and it took much too long to debug.

csharp_strings.py

index 17b0bf887e85ea68d4477ef7ee066f24b3e6ec9f..9dd23d1f9f4c0e8b2c8541fa96a88f710b24b066 100644 (file)
@@ -350,6 +350,18 @@ _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKu8slice, datalen),
 
 _Static_assert(sizeof(void*) <= 8, "Pointers must fit into 64 bits");
 
+// Int types across Windows/Linux are different, so make sure we're using the right headers.
+_Static_assert(sizeof(void*) == sizeof(uintptr_t), "stdints must be correct");
+_Static_assert(sizeof(void*) == sizeof(intptr_t), "stdints must be correct");
+_Static_assert(sizeof(uint64_t) == 8, "stdints must be correct");
+_Static_assert(sizeof(int64_t) == 8, "stdints must be correct");
+_Static_assert(sizeof(uint32_t) == 4, "stdints must be correct");
+_Static_assert(sizeof(int32_t) == 4, "stdints must be correct");
+_Static_assert(sizeof(uint16_t) == 2, "stdints must be correct");
+_Static_assert(sizeof(int16_t) == 2, "stdints must be correct");
+_Static_assert(sizeof(uint8_t) == 1, "stdints must be correct");
+_Static_assert(sizeof(int8_t) == 1, "stdints must be correct");
+
 #define DECL_ARR_TYPE(ty, name) \\
        struct name##array { \\
                uint64_t arr_len; /* uint32_t would suffice but we want to align uint64_ts as well */ \\