Skip to content

Commit e7d2203

Browse files
committed
[Update] Support of x86 architecture
1 parent 5979701 commit e7d2203

File tree

10 files changed

+88
-42
lines changed

10 files changed

+88
-42
lines changed

.github/workflows/build-ubuntu.yml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ on:
1010
jobs:
1111
build:
1212
runs-on: ubuntu-latest
13-
name: ${{ matrix.compiler }} ${{ matrix.regex && '| regex' || ''}}
13+
name: ${{ matrix.compiler }} ${{ matrix.arch }} ${{ matrix.regex && '| regex' || ''}}
1414
strategy:
1515
fail-fast: false
1616
matrix:
1717
build-type: [release]
1818
compiler: [gcc, clang]
1919
regex: [true, false]
20+
arch: [x64, x86]
21+
exclude:
22+
- compiler: clang
23+
arch: x86
2024

2125
steps:
2226
- uses: actions/checkout@v3
@@ -25,9 +29,17 @@ jobs:
2529
run: |
2630
sudo apt-get update
2731
sudo apt-get install -y meson ninja-build pkg-config ${{ matrix.compiler }}
32+
if [ "${{ matrix.arch }}" = "x86" ]; then
33+
sudo apt-get install -y gcc-multilib g++-multilib libc6-dev-i386
34+
fi
2835
2936
- name: Configure project
30-
run: meson setup .build -Dregex=${{ matrix.regex }} -Dexamples=false
37+
run: |
38+
if [ "${{ matrix.arch }}" = "x86" ]; then
39+
meson setup .build --cross-file=cross-files/i686-linux-gnu.txt -Dregex=${{ matrix.regex }} -Dexamples=false
40+
else
41+
meson setup .build -Dregex=${{ matrix.regex }} -Dexamples=false
42+
fi
3143
env:
3244
CC: ${{ matrix.compiler }}
3345

@@ -38,8 +50,12 @@ jobs:
3850

3951
- name: Configure examples
4052
run: |
41-
rm -rf .build/meson-info
42-
meson setup --wipe .build -Dregex=${{ matrix.regex }} -Dexamples=true
53+
if [ "${{ matrix.arch }}" = "x86" ]; then
54+
meson configure -Dexamples=true .build
55+
else
56+
rm -rf .build/meson-info
57+
meson setup --wipe .build -Dregex=${{ matrix.regex }} -Dexamples=true
58+
fi
4359
env:
4460
CC: ${{ matrix.compiler }}
4561

@@ -64,6 +80,6 @@ jobs:
6480
- name: Upload Ubuntu build artifacts
6581
uses: actions/upload-artifact@v4
6682
with:
67-
name: argus-ubuntu-${{ matrix.compiler }}-${{ matrix.regex && 'regex' || 'noregex' }}
83+
name: argus-ubuntu-${{ matrix.compiler }}-${{ matrix.arch }}-${{ matrix.regex && 'regex' || 'noregex' }}
6884
path: artifacts/
6985
if-no-files-found: warn

cross-files/i686-linux-gnu.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[binaries]
2+
c = 'gcc'
3+
cpp = 'g++'
4+
ar = 'ar'
5+
strip = 'strip'
6+
pkg-config = 'pkg-config'
7+
8+
[built-in options]
9+
c_args = ['-m32']
10+
c_link_args = ['-m32']
11+
cpp_args = ['-m32']
12+
cpp_link_args = ['-m32']
13+
14+
[properties]
15+
needs_exe_wrapper = false
16+
pkg_config_libdir = '/usr/lib/i386-linux-gnu/pkgconfig:/usr/share/pkgconfig'
17+
18+
[host_machine]
19+
system = 'linux'
20+
cpu_family = 'x86'
21+
cpu = 'i686'
22+
endian = 'little'

includes/argus/options.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ ARGUS_API char *format_choices_validator(validator_data_t data);
114114
#define V_CHOICE_INT(...) \
115115
MAKE_VALIDATOR(choices_int_validator, format_choices_validator, \
116116
((validator_data_t){ .choices = { \
117-
.as_ints = (long long[]){ __VA_ARGS__ }, \
118-
.count = sizeof((long long[]){ __VA_ARGS__ }) / sizeof(long long), \
117+
.as_ints = (int64_t[]){ __VA_ARGS__ }, \
118+
.count = sizeof((int64_t[]){ __VA_ARGS__ }) / sizeof(int64_t), \
119119
.type = VALUE_TYPE_INT \
120120
}}), ORDER_POST)
121121

includes/argus/types.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,17 @@ union argus_value_u {
120120
char as_char;
121121
char *as_string;
122122

123-
int as_int;
124-
int8_t as_int8;
125-
int16_t as_int16;
126-
int32_t as_int32;
127-
long long as_int64;
123+
int as_int;
124+
int8_t as_int8;
125+
int16_t as_int16;
126+
int32_t as_int32;
127+
int64_t as_int64;
128128

129129
double as_float;
130130
bool as_bool;
131131

132132
char **as_array_string;
133-
long long *as_array_int;
133+
int64_t *as_array_int;
134134
double *as_array_float;
135135
argus_value_t *as_array; /* Generic array */
136136
argus_pair_t *as_map;
@@ -170,8 +170,8 @@ typedef struct argus_map_iterator_s
170170
*/
171171
typedef struct argus_range_s
172172
{
173-
long long min;
174-
long long max;
173+
int64_t min;
174+
int64_t max;
175175
} argus_range_t;
176176

177177
/**
@@ -192,9 +192,9 @@ typedef struct regex_data_s
192192
typedef struct choices_data_s
193193
{
194194
union {
195-
char **as_strings;
196-
long long *as_ints;
197-
double *as_floats;
195+
char **as_strings;
196+
int64_t *as_ints;
197+
double *as_floats;
198198
};
199199
size_t count;
200200
argus_valtype_t type;

source/callbacks/handlers/map_int_handler.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ static int set_kv_pair(argus_t *argus, argus_option_t *option, char *pair)
3434
char *value = separator + 1;
3535

3636
// Convert the string value to integer
37-
char *endptr;
38-
long long int_value = strtoll(value, &endptr, 10);
37+
char *endptr;
38+
int64_t int_value = strtoll(value, &endptr, 10);
3939

4040
// Check if conversion was successful
4141
if (*value == '\0' || *endptr != '\0') {

source/callbacks/validators/choices_validator.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <inttypes.h>
12
#include <stdio.h>
23
#include <stdlib.h>
34
#include <string.h>
@@ -43,12 +44,12 @@ int choices_int_validator(argus_t *argus, void *option_ptr, validator_data_t dat
4344

4445
char *choices_formatted = format_choices_validator(data);
4546
if (choices_formatted) {
46-
ARGUS_PARSING_ERROR(argus, ARGUS_ERROR_INVALID_CHOICE, "Value '%lld' is not one of [%s]",
47+
ARGUS_PARSING_ERROR(argus, ARGUS_ERROR_INVALID_CHOICE, "Value '%d' is not one of [%s]",
4748
option->value.as_int, choices_formatted);
4849
free(choices_formatted);
4950
} else {
5051
ARGUS_PARSING_ERROR(argus, ARGUS_ERROR_INVALID_CHOICE,
51-
"Value '%lld' is not one of the choices", option->value.as_int);
52+
"Value '%d' is not one of the choices", option->value.as_int);
5253
}
5354
return ARGUS_ERROR_INVALID_CHOICE;
5455
}
@@ -87,7 +88,7 @@ char *format_choices_validator(validator_data_t data)
8788
total_length += strlen(choices->as_strings[i]);
8889
break;
8990
case VALUE_TYPE_INT:
90-
total_length += 20; // Max digits for long long
91+
total_length += 20; // Max digits for int64_t
9192
break;
9293
case VALUE_TYPE_FLOAT:
9394
total_length += 20; // Max digits for double
@@ -114,7 +115,7 @@ char *format_choices_validator(validator_data_t data)
114115
safe_strcat(result, total_length + 1, choices->as_strings[i]);
115116
break;
116117
case VALUE_TYPE_INT:
117-
snprintf(item, sizeof(item), "%lld", choices->as_ints[i]);
118+
snprintf(item, sizeof(item), "%" PRId64, choices->as_ints[i]);
118119
safe_strcat(result, total_length + 1, item);
119120
break;
120121
case VALUE_TYPE_FLOAT:

source/callbacks/validators/count_validator.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <inttypes.h>
12
#include <stdio.h>
23
#include <stdlib.h>
34

@@ -13,17 +14,18 @@ int count_validator(argus_t *argus, void *option_ptr, validator_data_t data)
1314
return ARGUS_ERROR_INVALID_RANGE;
1415
}
1516
if (data.range.min > data.range.max) {
16-
ARGUS_PARSING_ERROR(argus, ARGUS_ERROR_INVALID_RANGE, "Range is invalid %lld-%lld",
17-
data.range.min, data.range.max);
17+
ARGUS_PARSING_ERROR(argus, ARGUS_ERROR_INVALID_RANGE,
18+
"Range is invalid %" PRId64 "-%" PRId64, data.range.min,
19+
data.range.max);
1820
return ARGUS_ERROR_INVALID_RANGE;
1921
}
2022

21-
long long count = option->value_count;
23+
int64_t count = option->value_count;
2224

2325
if (count < data.range.min || count > data.range.max) {
2426
ARGUS_PARSING_ERROR(argus, ARGUS_ERROR_INVALID_RANGE,
25-
"Values count %lld is out of range %lld-%lld", count, data.range.min,
26-
data.range.max);
27+
"Values count %" PRId64 " is out of range %" PRId64 "-%" PRId64, count,
28+
data.range.min, data.range.max);
2729
return ARGUS_ERROR_INVALID_RANGE;
2830
}
2931
return (ARGUS_SUCCESS);
@@ -35,6 +37,6 @@ char *format_count_validator(validator_data_t data)
3537
if (!result)
3638
return NULL;
3739

38-
snprintf(result, 32, "%lld-%lld", data.range.min, data.range.max);
40+
snprintf(result, 32, "%" PRId64 "-%" PRId64, data.range.min, data.range.max);
3941
return result;
4042
}

source/callbacks/validators/length_validator.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <inttypes.h>
12
#include <stdio.h>
23
#include <stdlib.h>
34
#include <string.h>
@@ -18,17 +19,18 @@ int length_validator(argus_t *argus, void *option_ptr, validator_data_t data)
1819
return ARGUS_ERROR_INVALID_RANGE;
1920
}
2021
if (data.range.min > data.range.max) {
21-
ARGUS_PARSING_ERROR(argus, ARGUS_ERROR_INVALID_RANGE, "Range is invalid %lld-%lld",
22-
data.range.min, data.range.max);
22+
ARGUS_PARSING_ERROR(argus, ARGUS_ERROR_INVALID_RANGE,
23+
"Range is invalid %" PRId64 "-%" PRId64, data.range.min,
24+
data.range.max);
2325
return ARGUS_ERROR_INVALID_RANGE;
2426
}
2527

26-
long long len = strlen(option->value.as_string);
28+
int64_t len = strlen(option->value.as_string);
2729

2830
if (len < data.range.min || len > data.range.max) {
2931
ARGUS_PARSING_ERROR(argus, ARGUS_ERROR_INVALID_RANGE,
30-
"Value length %lld is out of range %lld-%lld", len, data.range.min,
31-
data.range.max);
32+
"Value length %" PRId64 " is out of range %" PRId64 "-%" PRId64, len,
33+
data.range.min, data.range.max);
3234
return ARGUS_ERROR_INVALID_RANGE;
3335
}
3436
return (ARGUS_SUCCESS);
@@ -40,6 +42,6 @@ char *format_length_validator(validator_data_t data)
4042
if (!result)
4143
return NULL;
4244

43-
snprintf(result, 32, "%lld-%lld chars", data.range.min, data.range.max);
45+
snprintf(result, 32, "%" PRId64 "-%" PRId64 " chars", data.range.min, data.range.max);
4446
return result;
4547
}

source/callbacks/validators/range_validator.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <inttypes.h>
12
#include <stdio.h>
23
#include <stdlib.h>
34

@@ -9,14 +10,16 @@ int range_validator(argus_t *argus, void *option_ptr, validator_data_t data)
910
argus_option_t *option = (argus_option_t *)option_ptr;
1011

1112
if (data.range.min > data.range.max) {
12-
ARGUS_PARSING_ERROR(argus, ARGUS_ERROR_INVALID_RANGE, "Range is invalid %lld-%lld",
13-
data.range.min, data.range.max);
13+
ARGUS_PARSING_ERROR(argus, ARGUS_ERROR_INVALID_RANGE,
14+
"Range is invalid %" PRId64 "-%" PRId64, data.range.min,
15+
data.range.max);
1416
return ARGUS_ERROR_INVALID_RANGE;
1517
}
1618

1719
if (option->value.as_int < data.range.min || option->value.as_int > data.range.max) {
18-
ARGUS_PARSING_ERROR(argus, ARGUS_ERROR_INVALID_RANGE, "Value %d is out of range %lld-%lld",
19-
option->value.as_int, data.range.min, data.range.max);
20+
ARGUS_PARSING_ERROR(argus, ARGUS_ERROR_INVALID_RANGE,
21+
"Value %d is out of range %" PRId64 "-%" PRId64, option->value.as_int,
22+
data.range.min, data.range.max);
2023
return ARGUS_ERROR_INVALID_RANGE;
2124
}
2225
return (ARGUS_SUCCESS);
@@ -28,6 +31,6 @@ char *format_range_validator(validator_data_t data)
2831
if (!result)
2932
return NULL;
3033

31-
snprintf(result, 32, "%lld-%lld", data.range.min, data.range.max);
34+
snprintf(result, 32, "%" PRId64 "-%" PRId64, data.range.min, data.range.max);
3235
return result;
3336
}

tests/unit/test_utils/test_value_utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Test(value_utils, compare_values)
5353
Test(value_utils, choices_to_value)
5454
{
5555
// Test integer choices
56-
argus_value_t int_choices = {.as_array_int = (long long[]){10, 20, 30, 40, 50}};
56+
argus_value_t int_choices = {.as_array_int = (int64_t[]){10, 20, 30, 40, 50}};
5757

5858
argus_value_t result1 = choices_to_value(VALUE_TYPE_INT, int_choices, 5, 2);
5959
cr_assert_eq(result1.as_int, 30, "Third element should be 30");

0 commit comments

Comments
 (0)