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

Add <stdatomic.h> check to JAS_TRY_COMPILE_C11_THREADS #370

Merged
merged 1 commit into from
Jan 16, 2024
Merged

Add <stdatomic.h> check to JAS_TRY_COMPILE_C11_THREADS #370

merged 1 commit into from
Jan 16, 2024

Conversation

BillyONeal
Copy link
Contributor

@BillyONeal BillyONeal commented Jan 16, 2024

In

#if defined(JAS_THREADS_C11)
#include <threads.h>
#include <stdatomic.h>
, JAS_THREADS_C11 assumes that both <threads.h> and <stdatomic.h> are available, but here, <stdatomic.h> is not checked. This causes builds with MSVC to fail with spew like:

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(36): error C2061: syntax error: identifier 'atomic_bool'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(36): error C2059: syntax error: ';'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(37): error C2061: syntax error: identifier 'atomic_char'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(37): error C2059: syntax error: ';'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(38): error C2061: syntax error: identifier 'atomic_schar'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(38): error C2059: syntax error: ';'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(39): error C2061: syntax error: identifier 'atomic_uchar'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(39): error C2059: syntax error: ';'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(40): error C2061: syntax error: identifier 'atomic_short'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(40): error C2059: syntax error: ';'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(41): error C2061: syntax error: identifier 'atomic_ushort'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(41): error C2059: syntax error: ';'

(MSVC 17.8 supports C atomics but it's behind a bunch of 'enable experimental things' switches right now, so including <stdatomic.h> without checking STDC_NO_ATOMICS fails like this)

Thanks to Charlie Barto and Casey Carter for helping me debug this.

In https://github.com/jasper-software/jasper/blob/b867d1adb2e6423c260407338bdc8d698330764e/src/libjasper/include/jasper/jas_thread.h#L87-L89 , JAS_THREADS_C11 assumes that both <threads.h> and <stdatomic.h> are available, but here, <stdatomic.h> is not checked. This causes builds with MSVC to fail with spew like:

```console
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(36): error C2061: syntax error: identifier 'atomic_bool'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(36): error C2059: syntax error: ';'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(37): error C2061: syntax error: identifier 'atomic_char'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(37): error C2059: syntax error: ';'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(38): error C2061: syntax error: identifier 'atomic_schar'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(38): error C2059: syntax error: ';'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(39): error C2061: syntax error: identifier 'atomic_uchar'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(39): error C2059: syntax error: ';'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(40): error C2061: syntax error: identifier 'atomic_short'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(40): error C2059: syntax error: ';'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(41): error C2061: syntax error: identifier 'atomic_ushort'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\vcruntime_c11_stdatomic.h(41): error C2059: syntax error: ';'
```

(MSVC 17.4 supports C atomics but it's behind a bunch of 'enable experimental things' switches right now, so including `<stdatomic.h>` without checking `STDC_NO_ATOMICS` fails like this)

Thanks to Charlie Barto and Casey Carter for helping me debug this.
@mdadams mdadams merged commit ec76987 into jasper-software:master Jan 16, 2024
9 checks passed
@BillyONeal BillyONeal deleted the fix-c-atomics-detection branch January 17, 2024 03:55
@BillyONeal
Copy link
Contributor Author

Thanks!

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.

2 participants