Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 71 additions & 32 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Canfigger ChangeLog

2025-01-06

* Fix Windows build

2024-02-29

* release v0.3.0
Expand Down
49 changes: 25 additions & 24 deletions canfigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ SOFTWARE.
#include <stdio.h>
#include <stdlib.h> // free(), malloc()
#include <string.h>
#include <stdarg.h> // 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
Expand All @@ -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);

Expand All @@ -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;
}


Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand Down
17 changes: 7 additions & 10 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
7 changes: 1 addition & 6 deletions tests/meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
incdir = include_directories('..')

main_lib = declare_dependency(link_with : buildtarget)

test_cases = [
'colons',
'file_open_err',
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions tests/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@
#include <limits.h>
#include "canfigger.h"

#ifndef PATH_MAX
#define PATH_MAX 1024
#endif

#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a)[0])