Skip to content

Commit

Permalink
adding build of C part of metac
Browse files Browse the repository at this point in the history
  • Loading branch information
aodinokov committed Aug 16, 2024
1 parent d2124d1 commit 9d9a341
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/buildAndTest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ jobs:
run: |
set -x
uname -a
apt update && apt-get install -y ca-certificates
apt update && apt-get install -y ca-certificates pkg-config make gcc check
tar -C /usr/local -xzf go.tar.gz && rm go.tar.gz
ls -la /usr/local/go/bin
export PATH=$PATH:/usr/local/go/bin
go version
export GO111MODULE=on
go test -cover ./...
go build
make test all || true #cat src/value_base_type_test.reflect.c
# this doesn't work (line 4: GITHUB_OUTPUT: unbound variable) echo uname::test >> $GITHUB_OUTPUT
echo ::set-output name=uname::$(uname -a)
Expand Down
9 changes: 6 additions & 3 deletions src/value_base_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ dsprintf_render_with_buf(64)
#endif

metac_flag_t metac_entry_is_char(metac_entry_t * p_entry) {
return metac_entry_check_base_type(p_entry, "char", METAC_ENC_signed_char, sizeof(char)) == 0;
return metac_entry_check_base_type(p_entry, "char", METAC_ENC_signed_char, sizeof(char)) == 0 ||
metac_entry_check_base_type(p_entry, "char", METAC_ENC_unsigned_char, sizeof(char)) == 0; // some platforms are doing this
}
metac_flag_t metac_entry_is_uchar(metac_entry_t * p_entry) {
return metac_entry_check_base_type(p_entry, "unsigned char", METAC_ENC_unsigned_char, sizeof(unsigned char)) == 0;
Expand Down Expand Up @@ -115,7 +116,8 @@ metac_flag_t metac_value_is_ldouble_complex(metac_value_t * p_val) {
}
/**/
int metac_value_char(metac_value_t * p_val, char *p_var) {
return metac_value_base_type(p_val, "char", METAC_ENC_signed_char, (void*)p_var, sizeof(*p_var));
return (metac_value_base_type(p_val, "char", METAC_ENC_signed_char, (void*)p_var, sizeof(*p_var)) == 0 ||
metac_value_base_type(p_val, "char", METAC_ENC_unsigned_char, (void*)p_var, sizeof(*p_var)) == 0)?0:-(EFAULT);
}
int metac_value_uchar(metac_value_t * p_val, unsigned char *p_var) {
return metac_value_base_type(p_val, "unsigned char", METAC_ENC_unsigned_char, (void*)p_var, sizeof(*p_var));
Expand Down Expand Up @@ -167,7 +169,8 @@ int metac_value_ldouble_complex(metac_value_t * p_val, long double complex *p_va
}
/* */
int metac_value_set_char(metac_value_t * p_val, char var) {
return metac_value_set_base_type(p_val, "char", METAC_ENC_signed_char, &var, sizeof(var));
return (metac_value_set_base_type(p_val, "char", METAC_ENC_signed_char, &var, sizeof(var)) == 0 ||
metac_value_set_base_type(p_val, "char", METAC_ENC_unsigned_char, &var, sizeof(var)) == 0)?0:-(EFAULT);
}
int metac_value_set_uchar(metac_value_t * p_val, unsigned char var) {
return metac_value_set_base_type(p_val, "unsigned char", METAC_ENC_unsigned_char, &var, sizeof(var));
Expand Down
13 changes: 13 additions & 0 deletions src/value_base_type_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@
static void test_char(metac_value_t * p_val, char * p_actual_data, metac_flag_t expected_write_err) {
fail_unless(p_val != NULL, "couldn't create p_val");

metac_entry_t *p_entry = metac_entry_final_entry(metac_value_entry(p_val), NULL);
fail_unless(metac_entry_is_base_type(p_entry)!=0);
fail_unless(metac_entry_name(p_entry) != 0, "name is null");
fail_unless(strcmp("char", metac_entry_name(p_entry)) == 0, "expected char, got %s", metac_entry_name(p_entry));
metac_size_t sz;
fail_unless(metac_entry_byte_size(p_entry, &sz) == 0);
fail_unless(sz == sizeof(char), "sz got %d, expected %d", (int)sz, (int)sizeof(char));
metac_encoding_t enc;
fail_unless(metac_entry_base_type_encoding(p_entry, &enc)==0);
fail_unless(enc == METAC_ENC_signed_char || enc == METAC_ENC_unsigned_char, "sz got %d, expected %d or %d",
(int)enc, (int)METAC_ENC_signed_char, (int)METAC_ENC_unsigned_char);


char target;
fail_unless(metac_value_is_char(p_val) != 0, "0 metac_value_is_char returned error");
fail_unless(metac_value_char(p_val, &target) == 0, "0 metac_value_char returned error");
Expand Down

0 comments on commit 9d9a341

Please sign in to comment.