macOS: plugin loading, hidapi, and stdlib.h fixes#363
Merged
Conversation
Closed
bl4ckb0ne
requested changes
May 15, 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 |
Collaborator
There was a problem hiding this comment.
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; |
Collaborator
There was a problem hiding this comment.
I'm not sure if that's needed, PATH_MAX should be big enough and it is already zero'd
Contributor
Author
There was a problem hiding this comment.
Both issues cleaned up. Good catches.
bl4ckb0ne
reviewed
May 19, 2026
Collaborator
There was a problem hiding this comment.
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>
3723170 to
0950df3
Compare
Contributor
Author
|
Squashed |
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Picks up the macOS support work from #345 (thanks @kylemcdonald) with the reviewer feedback addressed:
survive_plugins.unix.h: use.dylibextension and_NSGetExecutablePath()on Apple. Also fixes a latent Linux bug wherereadlink()return value was used as an array index without checking for error (-1).CMakeLists.txt: find hidapi on Apple viapkg_check_modulesrather 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 _WIN32because that is whereallocais declared (Windows CI failed LNK2019 onallocawithout it).api_example.candsurvive_kalman_lighthouses.c: left unchanged (reverted the printf uncomment and null guard from MacOS compatibility #345 per reviewer feedback).🤖 Co-authored with Claude Code