diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index cd89f12..09f5a5c 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -24,41 +24,80 @@ on: - '**/windows.yml' jobs: - VisualStudio: - runs-on: windows-latest - strategy: - fail-fast: false - matrix: - platform: ['x64', 'x86'] - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 + MSYS2: + runs-on: windows-latest + strategy: + fail-fast: false + matrix: + platform: ['UCRT64', 'CLANG64'] + steps: + - uses: actions/checkout@v4 - # Install a 32-bit Python so building related stuff work. - - name: Setup x86 Python - if: matrix.platform == 'x86' - uses: actions/setup-python@v5 - with: - architecture: 'x86' - python-version: '3.12' + - uses: msys2/setup-msys2@v2 + with: + msystem: ${{matrix.platform}} + pacboy: >- + cc:p + cmake:p + ninja:p + pkgconf:p + python-certifi:p + python-pip:p + # Make sure Python is updated to >=3.11 (fix https://github.com/msys2/MINGW-packages/issues/17415). + update: true - # https://github.com/actions/runner-images/issues/5459#issuecomment-1532856844 - - name: Remove bad Strawberry Perl patch binary in search path - run: del C:\Strawberry\c\bin\patch.EXE + - name: Install packages + shell: msys2 {0} + run: | + python -m pip install --pre meson - - name: Install packages - run: | - python -m pip install --pre meson + - name: Configure + shell: msys2 {0} + run: meson setup builddir -Ddefault_library=static -Db_sanitize=none - - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: ${{matrix.platform}} - - name: Configure - run: meson setup builddir -Db_sanitize=none + - name: Build + shell: msys2 {0} + run: meson compile -C builddir - - name: Build - run: meson compile -C builddir + - name: Test + shell: msys2 {0} + run: meson test -C builddir || cat builddir\meson-logs\testlog.txt - - name: Test - run: meson test -C builddir + # https://github.com/andy5995/canfigger/issues/31 + #VisualStudio: + #runs-on: windows-latest + #strategy: + #fail-fast: false + #matrix: + #platform: ['x64', 'x86'] + #steps: + #- uses: actions/checkout@v4 + + ## Install a 32-bit Python so building related stuff work. + #- name: Setup x86 Python + #if: matrix.platform == 'x86' + #uses: actions/setup-python@v5 + #with: + #architecture: 'x86' + #python-version: '3.12' + + ## https://github.com/actions/runner-images/issues/5459#issuecomment-1532856844 + #- name: Remove bad Strawberry Perl patch binary in search path + #run: del C:\Strawberry\c\bin\patch.EXE + + #- name: Install packages + #run: | + #python -m pip install --pre meson + + #- uses: ilammy/msvc-dev-cmd@v1 + #with: + #arch: ${{matrix.platform}} + #- name: Configure + #run: meson setup builddir -Ddefault_library=static -Db_sanitize=none + + #- name: Build + #run: meson compile -C builddir + + #- name: Test + #run: | + #meson test -C builddir || cat builddir\meson-logs\testlog.txt diff --git a/ChangeLog.txt b/ChangeLog.txt index 05a374d..841ff6d 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,9 @@ # Canfigger ChangeLog +2025-01-06 + + * Fix Windows build + 2024-02-29 * release v0.3.0 diff --git a/canfigger.c b/canfigger.c index 5170bc1..9994b8c 100644 --- a/canfigger.c +++ b/canfigger.c @@ -30,7 +30,6 @@ SOFTWARE. #include #include // free(), malloc() #include -#include // valist (variable argument function) // This is only required for version info and can be removed // if you're copying the canfigger source files to use as @@ -40,8 +39,6 @@ SOFTWARE. #include "canfigger.h" -#define strdup_wrap(...) strdup_wrap_real(__VA_ARGS__, (size_t)0) - static char *grab_str_segment(char *a, char **dest, const int c); static void free_list(struct Canfigger **node); @@ -56,25 +53,28 @@ struct line static char * -strdup_wrap_real(const char *argv, ...) +strclone(const char *src, size_t n) { - va_list args; - char *src = (char *) argv; - va_start(args, argv); - size_t n = va_arg(args, size_t); // Try to get the second argument - - char *retval = NULL; - if (n == 0) // If n is 0, it means there was no second argument - retval = strdup(src); + char *dest = NULL; + if (n == 0) + { + dest = malloc(strlen(src) + 1); + if (dest) + strcpy(dest, src); + } else - retval = strndup(src, n); - - va_end(args); - if (retval) - return retval; + { + dest = malloc(n + 1); + if (dest) + { + memcpy(dest, src, n); + dest[n] = '\0'; + } + } - perror("Failed to duplicate string:"); - return NULL; + if (!dest) + perror("malloc (canfigger)"); + return dest; } @@ -233,12 +233,12 @@ grab_str_segment(char *a, char **dest, const int c) char *b = strchr(a, c); if (!b) { - *dest = strdup_wrap(a); - return b; // NULL + *dest = strclone(a, 0); + return b; } size_t len = b - a; - *dest = strdup_wrap(a, len); + *dest = strclone(a, len); if (!*dest) return NULL; @@ -279,7 +279,7 @@ add_key_node(struct Canfigger **root, struct Canfigger **cur_node) static char * read_entire_file(const char *filename) { - FILE *fp = fopen(filename, "r"); + FILE *fp = fopen(filename, "rb"); if (!fp) { fprintf(stderr, "Failed to open %s: %s\n", filename, strerror(errno)); @@ -376,6 +376,7 @@ canfigger_parse_file(const char *file, const int delimiter) { line.len = line.end - line.start; char tmp_line[line.len + 1]; + memcpy(tmp_line, line.start, line.len); tmp_line[line.len] = '\0'; @@ -435,7 +436,7 @@ canfigger_parse_file(const char *file, const int delimiter) struct attributes *attr_ptr = cur_node->attributes; attr_ptr->current = NULL; - attr_ptr->str = strdup_wrap(line_ptr); + attr_ptr->str = strclone(line_ptr, 0); if (!attr_ptr->str) { free_incomplete_node(&cur_node); diff --git a/meson.build b/meson.build index 20bced6..ff74507 100644 --- a/meson.build +++ b/meson.build @@ -36,21 +36,18 @@ conf.set('CANFIGGER_VERSION_MINOR', minor_version) conf.set('CANFIGGER_VERSION_PATCH', patch_version) config_h = configure_file(output : 'config.h', configuration : conf) -inc = include_directories('.') - src = ('canfigger.c') -buildtarget = library( - meson.project_name(), - src, - include_directories : inc, - version : meson.project_version(), - install: not meson.is_subproject() - ) + buildtarget = library( + meson.project_name(), + src, + version : meson.project_version(), + install: not meson.is_subproject(), + ) # How to use in a superproject and other info # https://mesonbuild.com/Subprojects.html canfigger_dep = declare_dependency( - include_directories : inc, + include_directories : include_directories('.'), link_with : buildtarget ) diff --git a/tests/meson.build b/tests/meson.build index 079886b..65fbd3b 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,7 +1,3 @@ -incdir = include_directories('..') - -main_lib = declare_dependency(link_with : buildtarget) - test_cases = [ 'colons', 'file_open_err', @@ -16,8 +12,7 @@ foreach case : test_cases exe = executable( 'test_' + case, case + '.c', - include_directories : incdir, - dependencies : [main_lib], + dependencies : [canfigger_dep], c_args: '-DSOURCE_DIR="@0@"'.format(meson.current_source_dir()) ) test(case, exe) diff --git a/tests/test.h b/tests/test.h index 35f4fa3..dc368b9 100644 --- a/tests/test.h +++ b/tests/test.h @@ -9,4 +9,8 @@ #include #include "canfigger.h" +#ifndef PATH_MAX +#define PATH_MAX 1024 +#endif + #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a)[0])