Skip to content

Commit 0592e3f

Browse files
omcaiflgritz
authored andcommitted
build: fix some build issues encountered on a musl libc system (#4903)
Two small fixes to compile on musl libc systems. The first commit is about the use of `__WORDSIZE`, which is not a standard define and is defined another header in musl libc. I decided to fix this by following what was done in `libdnf` in [this commit](rpm-software-management/libdnf@82a07db). However, there are other ways, such as including `bits/reg.h` or `bits/user.h`, which define `__WORDSIZE` in musl libc, or using `__LP64__` to check for 64 bit instead (inspired by [Alpine Linux's patch](https://gitlab.alpinelinux.org/alpine/aports/-/blob/0f71e9504b59049e0ec1abb486ba455ab2650c83/community/openimageio/0001-fix-compile-error.patch)): ```c #if defined(__GNUC__) && (__WORDSIZE == 64 || (defined(__LP64__) && __LP64__)) && !(defined(__APPLE__) && defined(__MACH__)) || defined(__NetBSD__) ``` The second commit is about the use of the `feenableexcept` function. This function is only defined by glibc. The original code assumed all Linux systems use glibc (checking `__linux__` define), so I just changed it to check for glibc directly (by checking the `__GLIBC__` define). I have only tested it on my musl libc system. I think just compiling it on different systems is enough of a test in this case... --------- Signed-off-by: omcaif <[email protected]>
1 parent 19e3dee commit 0592e3f

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/include/OpenImageIO/typedesc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ template<> struct BaseTypeFromC<uint64_t> { static constexpr TypeDesc::BASETYPE
409409
template<> struct BaseTypeFromC<const uint64_t> { static constexpr TypeDesc::BASETYPE value = TypeDesc::UINT64; };
410410
template<> struct BaseTypeFromC<int64_t> { static constexpr TypeDesc::BASETYPE value = TypeDesc::INT64; };
411411
template<> struct BaseTypeFromC<const int64_t> { static constexpr TypeDesc::BASETYPE value = TypeDesc::INT64; };
412-
#if defined(__GNUC__) && __WORDSIZE == 64 && !(defined(__APPLE__) && defined(__MACH__)) || defined(__NetBSD__)
412+
#if defined(__GNUC__) && (ULONG_MAX == 0xffffffffffffffff) && !(defined(__APPLE__) && defined(__MACH__)) || defined(__NetBSD__)
413413
// Some platforms consider int64_t and long long to be different types, even
414414
// though they are actually the same size.
415415
static_assert(!std::is_same_v<unsigned long long, uint64_t>);

src/libOpenImageIO/imageinout_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ main(int argc, char* argv[])
537537
getargs(argc, argv);
538538

539539
if (enable_fpe) {
540-
#if defined(__linux__)
540+
#if defined(__GLIBC__)
541541
fprintf(stderr, "Enable floating point exceptions.\n");
542542
feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
543543
#else

0 commit comments

Comments
 (0)