Skip to content

Improve support for CYGWIN#3928

Open
carlo-bramini wants to merge 3 commits into
cisco:masterfrom
carlo-bramini:fix-cygwin-build
Open

Improve support for CYGWIN#3928
carlo-bramini wants to merge 3 commits into
cisco:masterfrom
carlo-bramini:fix-cygwin-build

Conversation

@carlo-bramini
Copy link
Copy Markdown

@carlo-bramini carlo-bramini commented Feb 11, 2026

I tried to build openh264 on CYGWIN but I got few errors that can be fixed quite easily, hopefully.

The platform "cygwin" is not recognized by the script for Meson and this message is printed on the console.

meson.build:143:2: ERROR: Problem encountered: FIXME: Unhandled system cygwin

A full log can be found at meson-logs/meson-log.txt

However, CYGWIN can be handled by adding its name in the same path where MinGW is also handled.

Later, this error appears on the console:

openh264/codec/decoder/plus/src/welsDecoderExt.cpp: In function ‘DWORD WelsDec::pThrProcInit(LPVOID)’:
openh264/codec/decoder/plus/src/welsDecoderExt.cpp:94:3: error: ‘_alloca’ was not declared in this scope; did you mean ‘alloca’?
   94 |   _alloca (WELS_DEC_MAX_THREAD_STACK_SIZE * (sThreadInfo->uiThrNum + 1));
      |   ^~~~~~~
      |   alloca

Similar to other POSIX platforms, CYGWIN supports alloca() rather than _alloca(), so this function needs to be used for reserving stack space.

Finally, this last error happens:

openh264/codec/decoder/core/src/wels_decoder_thread.cpp: In function ‘void SemRelease(SWelsDecSemphore*, long int*)’:
openh264/codec/decoder/core/src/wels_decoder_thread.cpp:118:30: error: cannot convert ‘long int*’ to ‘LPLONG’ {aka ‘int*’}
  118 |   ReleaseSemaphore (s->h, 1, prevcount);
      |                              ^~~~~~~~~
      |                              |
      |                              long int*

On x86_64 and aarch64 ports, long has a size of 8 byte, while LONG is still 4 bytes even when _WIN64 is defined with Windows APIs.
This can be fixed by using a local parameter declared as LONG and, in my opinion, it would be worth to do it also for traditional _WIN32 platforms for a clear type matching.

I hope that you will find these tiny patches useful.

@tyan0
Copy link
Copy Markdown
Contributor

tyan0 commented Feb 11, 2026

The platform "cygwin" is not recognized by the script for Meson and this message is printed on the console.

The patch 244c84e looks good to me.

Later, this error appears on the console:

openh264/codec/decoder/plus/src/welsDecoderExt.cpp: In function ‘DWORD WelsDec::pThrProcInit(LPVOID)’:
openh264/codec/decoder/plus/src/welsDecoderExt.cpp:94:3: error: ‘_alloca’ was not declared in this scope; did you mean ‘alloca’?
   94 |   _alloca (WELS_DEC_MAX_THREAD_STACK_SIZE * (sThreadInfo->uiThrNum + 1));
      |   ^~~~~~~
      |   alloca

Similar to other POSIX platforms, CYGWIN supports alloca() rather than _alloca(), so this function needs to be used for reserving stack space.

_alloca() causes exception (SEH) if stack is not enough. So the intent of the code is check the stack space for multi-thread operation and if not, raise an exception. I'm not sure why the exception here is the right thing for WIN32 platform, however, the behavirour of alloca() when the stack is not enough is undefined unlike _alloca().
So, I think the following patch would be better:

--- b/codec/decoder/plus/src/welsDecoderExt.cpp
+++ a/codec/decoder/plus/src/welsDecoderExt.cpp
@@ -90,7 +90,7 @@ namespace WelsDec {
 ***************************************************************************/
 DECLARE_PROCTHREAD (pThrProcInit, p) {
   SWelsDecThreadInfo* sThreadInfo = (SWelsDecThreadInfo*)p;
-#if defined(WIN32)
+#if defined(WIN32) && !defined(__CYGWIN__)
   _alloca (WELS_DEC_MAX_THREAD_STACK_SIZE * (sThreadInfo->uiThrNum + 1));
 #endif
   return sThreadInfo->pThrProcMain (p);

Finally, this last error happens:

openh264/codec/decoder/core/src/wels_decoder_thread.cpp: In function ‘void SemRelease(SWelsDecSemphore*, long int*)’:
openh264/codec/decoder/core/src/wels_decoder_thread.cpp:118:30: error: cannot convert ‘long int*’ to ‘LPLONG’ {aka ‘int*’}
  118 |   ReleaseSemaphore (s->h, 1, prevcount);
      |                              ^~~~~~~~~
      |                              |
      |                              long int*

On x86_64 and aarch64 ports, long has a size of 8 byte, while LONG is still 4 bytes even when _WIN64 is defined with Windows APIs. This can be fixed by using a local parameter declared as LONG and, in my opinion, it would be worth to do it also for traditional _WIN32 platforms for a clear type matching.

You are right. This (a1ae590) should be the right thing here.

@carlo-bramini
Copy link
Copy Markdown
Author

Thank you very much.
I updated the patch to codec\decoder\plus\src\welsDecoderExt.cpp according to your request.

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