Fix building under MSVC#160
Conversation
- Add vcpkg integration (CMakePresets.json, vcpkg.json, vcpkg-configuration.json) for dependency management - Update .gitignore for more build/IDE artifacts - Refactor CMakeLists.txt for MSVC/MinGW with conditional warnings - Replace VLA with calloc for MSVC compatibility; ensure proper memory freeing - Add ALIGN and NOINLINE macros; improve safe memory allocation functions - Make for-each/repeat macros portable for compilers without typeof - Replace switch-case ranges with explicit cases for MSVC - Add MSVC-specific workarounds (e.g., disable WASAPI in miniaudio) - General memory safety and portability improvements(?)
| #define forEach(type, item, array, count) \ | ||
| for (typeof(count) item##_i_ = 0; item##_i_ < (count); item##_i_++) \ | ||
| for (type* item = &(array)[item##_i_]; item; item = NULL) | ||
| for (TYPEOF(count) item##_i_ = 0; item##_i_ < (long long)(count); item##_i_++) \ |
There was a problem hiding this comment.
why cast count to long long here?
| void filterAlphabets(char *str) { | ||
| char result[strlen(str) + 1]; | ||
| size_t resultLen = strlen(str) + 1; | ||
| char *result = (char*)malloc(resultLen); |
There was a problem hiding this comment.
you should actually use safeMalloc for this so it handles failed allocations right.
| size_t bufSize = (size_t)sz + 1; | ||
| char *buf = malloc(bufSize); | ||
| snprintf(buf, bufSize, "audiogroup%d.dat", groupIndex); | ||
| free(buf); |
There was a problem hiding this comment.
you free buf here right before it gets used the very next line, you need to free it later
| #include <string.h> | ||
| #include <stdio.h> | ||
| #ifndef _MSC_VER | ||
| #include <sys/time.h> |
There was a problem hiding this comment.
move the sys/time.h header to right below time.h a little further down.
change it from
#else
#include <time.h>
#endifto
#else
#include <time.h>
#ifndef CLOCK_MONOTONIC
#include <sys/time.h>
#endif
#endif|
Superseded by #160 |
|
I have something better for getopt_long, but it's in a branch that requires #210 to get merged first. |
|
Additionally, I have a better solution to the alignment thing in that PR. |
|
This actually seems pretty stale, I might finish this work myself after after the GCC 2.7 and old libc support PRs are in. |
Tested on VS2026 Community (latest as of writing this), not sure what happens when using earlier versions
Also ASAN for some reason seems to detect a null pointer reference in dsound.dll, making it crash when compiled with ASAN enabled
This also adds a new dependency exclusive to Windows: getopt-win32, which has a LGPLv3-only license. Probably not problematic for proprietary forks unless linked statically with it.