Skip to content

macOS: plugin loading, hidapi, and stdlib.h fixes#363

Merged
bl4ckb0ne merged 1 commit into
collabora:masterfrom
rocketmark:upstream-pr/mac-support
May 22, 2026
Merged

macOS: plugin loading, hidapi, and stdlib.h fixes#363
bl4ckb0ne merged 1 commit into
collabora:masterfrom
rocketmark:upstream-pr/mac-support

Conversation

@rocketmark

@rocketmark rocketmark commented May 14, 2026

Copy link
Copy Markdown
Contributor

Picks up the macOS support work from #345 (thanks @kylemcdonald) with the reviewer feedback addressed:

  • survive_plugins.unix.h: use .dylib extension and _NSGetExecutablePath() on Apple. Also fixes a latent Linux bug where readlink() return value was used as an array index without checking for error (-1).
  • CMakeLists.txt: find hidapi on Apple via pkg_check_modules rather than hardcoded Homebrew paths, which differ between Apple Silicon (/opt/homebrew) and Intel (/usr/local).
  • cn_matrix.h: replace <malloc.h> with <stdlib.h> on non-Windows — <malloc.h> does not exist on macOS; <stdlib.h> provides malloc everywhere. On MSVC, <malloc.h> is kept via #ifdef _WIN32 because that is where alloca is declared (Windows CI failed LNK2019 on alloca without it).
  • api_example.c and survive_kalman_lighthouses.c: left unchanged (reverted the printf uncomment and null guard from MacOS compatibility #345 per reviewer feedback).

🤖 Co-authored with Claude Code

@rocketmark rocketmark mentioned this pull request May 14, 2026
Comment on lines +49 to +57
if (_NSGetExecutablePath(exe_path, &size) != 0)
exe_path[0] = 0;
#else
ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1);
if (len > 0)
exe_path[len] = 0;
else
exe_path[0] = 0;
#endif

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Braces around if statements are required

#else
ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1);
if (len > 0)
exe_path[len] = 0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if that's needed, PATH_MAX should be big enough and it is already zero'd

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Both issues cleaned up. Good catches.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Squash this commit with fca5e6f and its good to go

survive_plugins.unix.h: use .dylib extension and _NSGetExecutablePath()
on Apple. Also fixes a latent Linux bug where readlink() return value
was used as an array index without checking for error (-1).

CMakeLists.txt: find hidapi on Apple via pkg-config rather than
hardcoded Homebrew paths, which differ between Apple Silicon
(/opt/homebrew) and Intel (/usr/local).

cn_matrix.h: replace <malloc.h> with <stdlib.h> unconditionally, but
guard the re-inclusion of <malloc.h> with _WIN32. <malloc.h> does not
exist on macOS; <stdlib.h> provides malloc on all platforms. MSVC does
not declare alloca in <stdlib.h> — it lives in <malloc.h>.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@rocketmark rocketmark force-pushed the upstream-pr/mac-support branch from 3723170 to 0950df3 Compare May 22, 2026 14:54
@rocketmark

Copy link
Copy Markdown
Contributor Author

Squashed

@bl4ckb0ne

Copy link
Copy Markdown
Collaborator

The alloca fix should've stayed as its own commit since its unrelated to the macos stuff, but since its so small i'll accept the MR as one. Thanks.

@bl4ckb0ne bl4ckb0ne merged commit 5588cad into collabora:master May 22, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants