[gjs/mcatanzaro/#357] Fix 32-bit build
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/mcatanzaro/#357] Fix 32-bit build
- Date: Thu, 22 Oct 2020 19:50:49 +0000 (UTC)
commit f19e67b304df024198f018b3ea0165a37bf5b2fc
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Wed Oct 21 19:26:57 2020 -0500
Fix 32-bit build
Problem is that each separate 'if constexpr' block needs to evaluate to
the same return type. The first block returns GType (long unsigned int).
On x86_64, the second block returns uint64_t (long unsigned int), and
everything is fine. But on i686, the second block instead returns
uint32_t (unsigned int). The types are different, and the build fails.
It doesn't matter that long unsigned int and unsigned int are the same
size on i686: they are different types, so it fails anyway.
I learned a few things about types when working on this. Vanilla int and
unsigned int are always 32 bits on Linux (not surprising), and long long
int and unsigned long long int are always 64 bits (also not surprising).
But I had never previously learned the rule for long int and unsigned
long int. Turns out it matches word size, so long is 64 bits on x86_64
but 32 bits on i686. That's interesting.
I also learned that GType is always long unsigned int in C++. In C, it
is long unsigned int on 64-bit architectures, but it is gsize (size_t)
on 32-bit architectures. That's right, on 32-bit systems, the size of
GType differs based on what programming language you use! I guess if
there are no explosions in practice, and nobody registers more than
four billion types per process, it must be OK?
Thanks to Abderrahim for preparing an earlier version of this fix, and
to both Abderrahim and Jordan for helping me with BuildStream to do an
i686 build.
Fixes #357
gi/js-value-inl.h | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
---
diff --git a/gi/js-value-inl.h b/gi/js-value-inl.h
index 03c0bb19..ac00f172 100644
--- a/gi/js-value-inl.h
+++ b/gi/js-value-inl.h
@@ -52,22 +52,22 @@ constexpr auto get_strict() {
return gboolean{};
else
return;
+ } else {
+ if constexpr (std::is_same_v<T, char32_t>)
+ return char32_t{};
+ else if constexpr (type_fits<T, int32_t>())
+ return int32_t{};
+ else if constexpr (type_fits<T, uint32_t>())
+ return uint32_t{};
+ else if constexpr (type_fits<T, int64_t>())
+ return int64_t{};
+ else if constexpr (type_fits<T, uint64_t>())
+ return uint64_t{};
+ else if constexpr (type_fits<T, double>())
+ return double{};
+ else
+ return T{};
}
-
- if constexpr (std::is_same_v<T, char32_t>)
- return char32_t{};
- else if constexpr (type_fits<T, int32_t>())
- return int32_t{};
- else if constexpr (type_fits<T, uint32_t>())
- return uint32_t{};
- else if constexpr (type_fits<T, int64_t>())
- return int64_t{};
- else if constexpr (type_fits<T, uint64_t>())
- return uint64_t{};
- else if constexpr (type_fits<T, double>())
- return double{};
- else
- return T{};
}
template <typename T>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]