Skip to content

Conversation

@omcaif
Copy link
Contributor

@omcaif omcaif commented Sep 25, 2025

Description

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. 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):

#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).

Tests

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...

Checklist:

  • I have read the contribution guidelines.
  • I have updated the documentation, if applicable. (Check if there is no
    need to update the documentation, for example if this is a bug fix that
    doesn't change the API.)
  • I have ensured that the change is tested somewhere in the testsuite
    (adding new test cases if necessary).
  • If I added or modified a C++ API call, I have also amended the
    corresponding Python bindings (and if altering ImageBufAlgo functions, also
    exposed the new functionality as oiiotool options).
  • My code follows the prevailing code style of this project. If I haven't
    already run clang-format before submitting, I definitely will look at the CI
    test that runs clang-format and fix anything that it highlights as being
    nonconforming.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Sep 25, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

template<> struct BaseTypeFromC<int64_t> { static constexpr TypeDesc::BASETYPE value = TypeDesc::INT64; };
template<> struct BaseTypeFromC<const int64_t> { static constexpr TypeDesc::BASETYPE value = TypeDesc::INT64; };
#if defined(__GNUC__) && __WORDSIZE == 64 && !(defined(__APPLE__) && defined(__MACH__)) || defined(__NetBSD__)
#if defined(__GNUC__) && IS_64_BIT && !(defined(__APPLE__) && defined(__MACH__)) || defined(__NetBSD__)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is the only place it's used, how about just changing to

Suggested change
#if defined(__GNUC__) && IS_64_BIT && !(defined(__APPLE__) && defined(__MACH__)) || defined(__NetBSD__)
#if defined(__GNUC__) && (ULONG_MAX == 0xffffffffffffffff) && !(defined(__APPLE__) && defined(__MACH__)) || defined(__NetBSD__)

and then you don't actually need to define IS_64_BIT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with this change.

I was worried that the word size might be something like 128 bits in the future (hence the explicit check for both 64 bit and 32 bit, then erroring out otherwise), but now that I think about it, the compile will fail anyway in that case.

@lgritz
Copy link
Collaborator

lgritz commented Sep 26, 2025

Is this intended as a DevDays project?

@omcaif
Copy link
Contributor Author

omcaif commented Sep 26, 2025

Is this intended as a DevDays project?

No.

By the way, I am not sure how to respond on suggested changes. I just looked through the contributing guidelines and did not see anything about it.

Should I just use the GitHub UI to "sign off and commit suggestion"? Rebase? Add another commit manually to incorporate the change? Do I need to add a "Co-Author" tag?

Anyway, I have allowed maintainers to edit this PR, so feel free to make any edits you see fit.

@lgritz
Copy link
Collaborator

lgritz commented Sep 26, 2025

Is this intended as a DevDays project?

No.

No problem either way, I just was trying to figure out whether or not to tag it as such.

Should I just use the GitHub UI to "sign off and commit suggestion"? Rebase? Add another commit manually to incorporate the change? Do I need to add a "Co-Author" tag?

Anyway, I have allowed maintainers to edit this PR, so feel free to make any edits you see fit.

Any of the above. You can click and sign off on the change. Or you can do it yourself and push the additional commit. (Just make sure EVERY commit is done with -s or otherwise contains the DCO signoff in the commit comments.) You do not need to rebase again, for such a small change, when we expect that nothing has changed in main since you posted the PR that could make it a nontrivial merge or would interfere with the correctness of your patch.

You do not need a co-author tag for something this trivial.

Use standard defines to determine if the system is 64 bits.

Despite __WORDSIZE not being standard, musl libc also has it defined in
another header (either bits/reg.h or bits/user.h), but it is probably a
good idea to avoid using it anyway for standard compliance.

Signed-off-by: omcaif <[email protected]>
feenableexcept is a GNU extention and is not part of the standard. For
example, musl libc does not implement it.

Signed-off-by: omcaif <[email protected]>
@omcaif
Copy link
Contributor Author

omcaif commented Sep 26, 2025

Okay, thanks. I think I updated the commit now to address your comment.

Copy link
Collaborator

@lgritz lgritz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the fixes

@lgritz lgritz merged commit 168d797 into AcademySoftwareFoundation:main Sep 27, 2025
31 checks passed
lgritz pushed a commit to lgritz/OpenImageIO that referenced this pull request Sep 27, 2025
…mySoftwareFoundation#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]>
@lgritz lgritz added the build / testing / port / CI Affecting the build system, tests, platform support, porting, or continuous integration. label Oct 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build / testing / port / CI Affecting the build system, tests, platform support, porting, or continuous integration.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants