Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenBSD: Use our own implementation of wcsnlen()if not available #11083

Merged
merged 5 commits into from
Jan 10, 2023

Conversation

daschuer
Copy link
Member

This seems to be required to make our code compile with OpenBSD. See: https://mixxx.zulipchat.com/#narrow/stream/247620-development-help/topic/compiling.20mixxx.20on.20openbsd.20-current

It get also around the macro hell with MSVC/MingWG/wxWigets headers and avoids a redundant null check if actually the C++11 implementation is used.

Our implementation matches:
https://github.com/wxWidgets/wxWidgets/blob/fec8c06a53f5f2eb65e3328eadddd22334e7971f/include/wx/wxcrt.h#L183

@JoergAtGithub
Copy link
Member

I don't think this is the right approach, because this for-loop replaces the much more efficient SIMD implementations of these standard functions, which would be used otherwise.

I think the real problem is, that strnlen and wcsnlen used in these wrappers are not standard functions. Instead wcsnlen_s and strnlen_s should be used. These are official C11 standard functions.

@daschuer
Copy link
Member Author

daschuer commented Nov 22, 2022

I have no added a special case for OpenBSD only. Hopefully this solves the issue.
I have not used the proposed c++ function, because they are not available on all targets.
Using our own wrapper seems to more robust than fielding with
__STDC_LIB_EXT1__ __STDC_WANT_LIB_EXT1__ in a header that may cause unwanted side effects and test it on all our targets.

@daschuer daschuer changed the title Use our own implementation of wcsnlen() and strnlen() OpenBSD: Use our own implementation of wcsnlen()if not available Nov 22, 2022
@JoergAtGithub
Copy link
Member

I wonder if we've selected the C language version properly. Could you try set(CMAKE_C_STANDARD 11) or set(CMAKE_C_STANDARD 17) in CMakelists.txt

@@ -35,27 +35,40 @@ class StringCollator {
/// A nullptr-safe variant of the corresponding standard C function.
///
/// Treats nullptr like an empty string and returns 0.
inline std::size_t strnlen(
/// The c++11 strnlen_s() is not available on all targets
Copy link
Member

Choose a reason for hiding this comment

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

It's C11, not C++11

@daschuer
Copy link
Member Author

I wonder if we've selected the C language version properly. Could you try set(CMAKE_C_STANDARD 11) or set(CMAKE_C_STANDARD 17) in CMakelists.txt

This does not make any difference, because the C Standard is only set for c files, but we have only c++ files.
My gcc 9.4.0 is anyway reporting:

              GNU dialect of ISO C17.  This is the default for C code.
               GNU dialect of -std=c++14.  This is the default for C++ code.

So that should be fine. I have no OpenBSD, so I cannot test.

@Swiftb0y
Copy link
Member

If we compile with -pedantic, gcc ensures we're using only ISO C/C++ instead of their GNU dialects. That should make it easier to ensure compatibility with *BSD...

@JoergAtGithub
Copy link
Member

These bound checking _s functions of the C11 standard seems to be rather controversial: https://stackoverflow.com/questions/50724726/why-didnt-gcc-or-glibc-implement-s-functions/50724865#50724865

They are official part of the standard (Annex K), but it's optional to implement them.

The function wcsnlen (without _s) was never standardized.

@oneofvalts
Copy link

With this, I'm able to compile without getting an error on wcsnlen on OpenBSD.

@daschuer
Copy link
Member Author

OK, Than this is ready for merge. @Swiftb0y can you have a final look?

Copy link
Member

@Swiftb0y Swiftb0y left a comment

Choose a reason for hiding this comment

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

LGTM

@Swiftb0y
Copy link
Member

Feel free to squash or rebase or just merge yourself.

@daschuer daschuer merged commit a33647d into mixxxdj:main Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants