-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[common,Pal/Linux] Compile with Meson
common/ is mesonified and used in Pal/Linux only for now. Signed-off-by: Wojtek Porczyk <woju@invisiblethingslab.com>
- Loading branch information
Showing
14 changed files
with
387 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
common_inc = include_directories( | ||
'.', | ||
join_paths('arch', host_machine.cpu_family()), | ||
) | ||
common_inc = [ | ||
include_directories( | ||
'.', | ||
join_paths('arch', host_machine.cpu_family()), | ||
), | ||
tomlc99_inc, # TODO this is because there's #include "toml.h" in api.h | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
subdir('include') | ||
subdir('src') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
common_src = files( | ||
'avl_tree.c', | ||
'network/hton.c', | ||
'network/inet_pton.c', | ||
'path.c', | ||
'stack_protector.c', | ||
'stdlib/printfmt.c', | ||
'string/atoi.c', | ||
'string/ctype.c', | ||
'string/memcmp.c', | ||
'string/memcpy.c', | ||
'string/memset.c', | ||
'string/strchr.c', | ||
'string/strcmp.c', | ||
'string/strlen.c', | ||
'string/strspn.c', | ||
'string/strstr.c', | ||
'string/toml_utils.c', | ||
'string/utils.c', | ||
) | ||
if asan | ||
common_src += files('asan.c') | ||
endif | ||
if ubsan | ||
common_src += files('ubsan.c') | ||
endif | ||
|
||
common_dep = declare_dependency( | ||
sources: common_src, | ||
|
||
include_directories: common_inc, | ||
|
||
dependencies: [ | ||
uthash_dep, | ||
tomlc99_dep, | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
/cJSON-*/ | ||
/glibc-*/ | ||
/mbedtls-*/ | ||
/tomlc99-*/ | ||
/uthash-*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
project('tomlc99', 'c') | ||
|
||
patch_prog = find_program('patch') | ||
|
||
tomlc99_src = [] | ||
foreach src : ['toml.c', 'toml.h'] | ||
src_patch = '@0@.patch'.format(src) | ||
tomlc99_src += custom_target(src, | ||
command: [ | ||
patch_prog, | ||
'-p1', | ||
'--quiet', | ||
'--directory=@CURRENT_SOURCE_DIR@', | ||
'--input=@0@'.format(src_patch), | ||
'--output=-', | ||
], | ||
input: [src_patch, src], | ||
output: src, | ||
capture: true, | ||
) | ||
endforeach | ||
|
||
tomlc99_inc = include_directories('.') | ||
tomlc99_incpath = meson.current_build_dir() | ||
|
||
tomlc99_dep = declare_dependency( | ||
sources: tomlc99_src, | ||
include_directories: tomlc99_inc, | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
diff --git a/toml.c b/toml.c | ||
index 8ec554e88ec772931aebcff615a6d9624ffacbe6..382fdeda573b6b9aa8402c66e960b4edcb2c7d65 100644 | ||
--- a/toml.c | ||
+++ b/toml.c | ||
@@ -24,15 +24,7 @@ | ||
SOFTWARE. | ||
|
||
*/ | ||
-#define _POSIX_C_SOURCE 200809L | ||
-#include <stdio.h> | ||
-#include <stdlib.h> | ||
-#include <assert.h> | ||
-#include <errno.h> | ||
-#include <stdint.h> | ||
-#include <ctype.h> | ||
-#include <string.h> | ||
-#include <stdbool.h> | ||
+#include "api.h" | ||
#include "toml.h" | ||
|
||
|
||
@@ -1447,61 +1439,6 @@ fail: | ||
} | ||
|
||
|
||
-toml_table_t* toml_parse_file(FILE* fp, | ||
- char* errbuf, | ||
- int errbufsz) | ||
-{ | ||
- int bufsz = 0; | ||
- char* buf = 0; | ||
- int off = 0; | ||
- | ||
- /* read from fp into buf */ | ||
- while (! feof(fp)) { | ||
- | ||
- if (off == bufsz) { | ||
- int xsz = bufsz + 1000; | ||
- char* x = expand(buf, bufsz, xsz); | ||
- if (!x) { | ||
- snprintf(errbuf, errbufsz, "out of memory"); | ||
- xfree(buf); | ||
- return 0; | ||
- } | ||
- buf = x; | ||
- bufsz = xsz; | ||
- } | ||
- | ||
- errno = 0; | ||
- int n = fread(buf + off, 1, bufsz - off, fp); | ||
- if (ferror(fp)) { | ||
- snprintf(errbuf, errbufsz, "%s", | ||
- errno ? strerror(errno) : "Error reading file"); | ||
- xfree(buf); | ||
- return 0; | ||
- } | ||
- off += n; | ||
- } | ||
- | ||
- /* tag on a NUL to cap the string */ | ||
- if (off == bufsz) { | ||
- int xsz = bufsz + 1; | ||
- char* x = expand(buf, bufsz, xsz); | ||
- if (!x) { | ||
- snprintf(errbuf, errbufsz, "out of memory"); | ||
- xfree(buf); | ||
- return 0; | ||
- } | ||
- buf = x; | ||
- bufsz = xsz; | ||
- } | ||
- buf[off] = 0; | ||
- | ||
- /* parse it, cleanup and finish */ | ||
- toml_table_t* ret = toml_parse(buf, errbuf, errbufsz); | ||
- xfree(buf); | ||
- return ret; | ||
-} | ||
- | ||
- | ||
static void xfree_kval(toml_keyval_t* p) | ||
{ | ||
if (!p) return; | ||
@@ -2062,66 +1999,19 @@ int toml_rtoi(toml_raw_t src, int64_t* ret_) | ||
|
||
/* Run strtoll on buf to get the integer */ | ||
char* endp; | ||
- errno = 0; | ||
*ret = strtoll(buf, &endp, base); | ||
- return (errno || *endp) ? -1 : 0; | ||
+ return (*endp) ? -1 : 0; | ||
} | ||
|
||
|
||
int toml_rtod_ex(toml_raw_t src, double* ret_, char* buf, int buflen) | ||
{ | ||
- if (!src) return -1; | ||
- | ||
- char* p = buf; | ||
- char* q = p + buflen; | ||
- const char* s = src; | ||
- double dummy; | ||
- double* ret = ret_ ? ret_ : &dummy; | ||
- | ||
- | ||
- /* allow +/- */ | ||
- if (s[0] == '+' || s[0] == '-') | ||
- *p++ = *s++; | ||
- | ||
- /* disallow +_1.00 */ | ||
- if (s[0] == '_') | ||
- return -1; | ||
- | ||
- /* decimal point, if used, must be surrounded by at least one digit on each side */ | ||
- { | ||
- char* dot = strchr(s, '.'); | ||
- if (dot) { | ||
- if (dot == s || !isdigit(dot[-1]) || !isdigit(dot[1])) | ||
- return -1; | ||
- } | ||
- } | ||
- | ||
- /* zero must be followed by . or 'e', or NUL */ | ||
- if (s[0] == '0' && s[1] && !strchr("eE.", s[1])) | ||
- return -1; | ||
- | ||
- /* just strip underscores and pass to strtod */ | ||
- while (*s && p < q) { | ||
- int ch = *s++; | ||
- if (ch == '_') { | ||
- // disallow '__' | ||
- if (s[0] == '_') return -1; | ||
- // disallow last char '_' | ||
- if (s[0] == 0) return -1; | ||
- continue; /* skip _ */ | ||
- } | ||
- *p++ = ch; | ||
- } | ||
- if (*s || p == q) return -1; /* reached end of string or buffer is full? */ | ||
- | ||
- /* cap with NUL */ | ||
- *p = 0; | ||
- | ||
- /* Run strtod on buf to get the value */ | ||
- char* endp; | ||
- errno = 0; | ||
- *ret = strtod(buf, &endp); | ||
- return (errno || *endp) ? -1 : 0; | ||
+ /* FIXME: strtod() is not supported by Gramine */ | ||
+ (void)src; | ||
+ (void)ret_; | ||
+ (void)buf; | ||
+ (void)buflen; | ||
+ return -1; | ||
} | ||
|
||
int toml_rtod(toml_raw_t src, double* ret_) | ||
@@ -2240,33 +2130,6 @@ toml_datum_t toml_timestamp_at(const toml_array_t* arr, int idx) | ||
return ret; | ||
} | ||
|
||
-toml_datum_t toml_string_in(const toml_table_t* arr, const char* key) | ||
-{ | ||
- toml_datum_t ret; | ||
- memset(&ret, 0, sizeof(ret)); | ||
- toml_raw_t raw = toml_raw_in(arr, key); | ||
- if (raw) { | ||
- ret.ok = (0 == toml_rtos(raw, &ret.u.s)); | ||
- } | ||
- return ret; | ||
-} | ||
- | ||
-toml_datum_t toml_bool_in(const toml_table_t* arr, const char* key) | ||
-{ | ||
- toml_datum_t ret; | ||
- memset(&ret, 0, sizeof(ret)); | ||
- ret.ok = (0 == toml_rtob(toml_raw_in(arr, key), &ret.u.b)); | ||
- return ret; | ||
-} | ||
- | ||
-toml_datum_t toml_int_in(const toml_table_t* arr, const char* key) | ||
-{ | ||
- toml_datum_t ret; | ||
- memset(&ret, 0, sizeof(ret)); | ||
- ret.ok = (0 == toml_rtoi(toml_raw_in(arr, key), &ret.u.i)); | ||
- return ret; | ||
-} | ||
- | ||
toml_datum_t toml_double_in(const toml_table_t* arr, const char* key) | ||
{ | ||
toml_datum_t ret; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
diff --git a/toml.h b/toml.h | ||
index b91ef890303238e734f06bbfc95ab39b7851e031..735518d25d411d78ad417efb333683014c6d4c45 100644 | ||
--- a/toml.h | ||
+++ b/toml.h | ||
@@ -26,7 +26,6 @@ | ||
#define TOML_H | ||
|
||
|
||
-#include <stdio.h> | ||
#include <stdint.h> | ||
|
||
|
||
@@ -41,13 +40,6 @@ typedef struct toml_table_t toml_table_t; | ||
typedef struct toml_array_t toml_array_t; | ||
typedef struct toml_datum_t toml_datum_t; | ||
|
||
-/* Parse a file. Return a table on success, or 0 otherwise. | ||
- * Caller must toml_free(the-return-value) after use. | ||
- */ | ||
-TOML_EXTERN toml_table_t* toml_parse_file(FILE* fp, | ||
- char* errbuf, | ||
- int errbufsz); | ||
- | ||
/* Parse a string containing the full config. | ||
* Return a table on success, or 0 otherwise. | ||
* Caller must toml_free(the-return-value) after use. | ||
@@ -110,9 +102,6 @@ TOML_EXTERN toml_table_t* toml_table_at(const toml_array_t* arr, int idx); | ||
/* ... retrieve the key in table at keyidx. Return 0 if out of range. */ | ||
TOML_EXTERN const char* toml_key_in(const toml_table_t* tab, int keyidx); | ||
/* ... retrieve values using key. */ | ||
-TOML_EXTERN toml_datum_t toml_string_in(const toml_table_t* arr, const char* key); | ||
-TOML_EXTERN toml_datum_t toml_bool_in(const toml_table_t* arr, const char* key); | ||
-TOML_EXTERN toml_datum_t toml_int_in(const toml_table_t* arr, const char* key); | ||
TOML_EXTERN toml_datum_t toml_double_in(const toml_table_t* arr, const char* key); | ||
TOML_EXTERN toml_datum_t toml_timestamp_in(const toml_table_t* arr, const char* key); | ||
/* .. retrieve array or table using key. */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
project('uthash', 'c') | ||
|
||
patch_prog = find_program('patch') | ||
|
||
subdir('src') | ||
|
||
uthash_dep = declare_dependency( | ||
sources: uthash_h, | ||
include_directories: include_directories('src/'), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
uthash_h = custom_target('uthash.h', | ||
command: [ | ||
patch_prog, | ||
'-p1', | ||
'--quiet', | ||
'--directory=@CURRENT_SOURCE_DIR@', | ||
'--input=uthash.h.patch', | ||
'--output=-', | ||
], | ||
input: ['uthash.h.patch', 'uthash.h'], | ||
output: 'uthash.h', | ||
capture: true, | ||
) |
Oops, something went wrong.