repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
zap
github_2023
zigzap
c
fio_timer_test_task
FIO_FUNC void fio_timer_test_task(void *arg) { ++(((size_t *)arg)[0]); }
/* ***************************************************************************** Testing fio_timers ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L9374-L9374
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_socket_test
FIO_FUNC void fio_socket_test(void) { /* initialize unix socket name */ fio_str_s sock_name = FIO_STR_INIT; #ifdef P_tmpdir fio_str_write(&sock_name, P_tmpdir, strlen(P_tmpdir)); if (fio_str_len(&sock_name) && fio_str_data(&sock_name)[fio_str_len(&sock_name) - 1] == '/') fio_str_resize(&sock_name, fio...
/* ***************************************************************************** Testing listening socket ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L9440-L9537
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_cycle_test_task
FIO_FUNC void fio_cycle_test_task(void *arg) { fio_stop(); (void)arg; }
/* ***************************************************************************** Testing listening socket ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L9543-L9546
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_riskyhash_speed_test
FIO_FUNC void fio_riskyhash_speed_test(void) { /* test based on code from BearSSL with credit to Thomas Pornin */ uint8_t buffer[8192]; memset(buffer, 'T', sizeof(buffer)); /* warmup */ uint64_t hash = 0; for (size_t i = 0; i < 4; i++) { hash += fio_risky_hash(buffer, 8192, 1); memcpy(buffer, &hash,...
/* ***************************************************************************** Bad Hash (risky hash) tests ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L9930-L9959
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_siphash_speed_test
FIO_FUNC void fio_siphash_speed_test(void) { /* test based on code from BearSSL with credit to Thomas Pornin */ uint8_t buffer[8192]; memset(buffer, 'T', sizeof(buffer)); /* warmup */ uint64_t hash = 0; for (size_t i = 0; i < 4; i++) { hash += fio_siphash24(buffer, sizeof(buffer), 0, 0); memcpy(buff...
/* ***************************************************************************** SipHash tests ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L9988-L10036
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_sha1_speed_test
FIO_FUNC void fio_sha1_speed_test(void) { /* test based on code from BearSSL with credit to Thomas Pornin */ uint8_t buffer[8192]; uint8_t result[21]; fio_sha1_s sha1; memset(buffer, 'T', sizeof(buffer)); /* warmup */ for (size_t i = 0; i < 4; i++) { sha1 = fio_sha1_init(); fio_sha1_write(&sha1, b...
/* ***************************************************************************** SHA-1 tests ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L10051-L10082
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_base64_speed_test
FIO_FUNC void fio_base64_speed_test(void) { /* test based on code from BearSSL with credit to Thomas Pornin */ char buffer[8192]; char result[8192 * 2]; memset(buffer, 'T', sizeof(buffer)); /* warmup */ for (size_t i = 0; i < 4; i++) { fio_base64_encode(result, buffer, sizeof(buffer)); memcpy(buffer...
/* ***************************************************************************** Base64 tests ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L10406-L10459
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_test_random
FIO_FUNC void fio_test_random(void) { fprintf(stderr, "=== Testing random generator\n"); uint64_t rnd = fio_rand64(); FIO_ASSERT((rnd != fio_rand64() && rnd != fio_rand64()), "fio_rand64 returned the same result three times in a row."); #if NODEBUG uint64_t buffer1[8]; uint8_t buffer2[8192]; cl...
/******************************************************************************* Random Testing ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L10535-L10567
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_uuid_link_test_on_close
FIO_FUNC void fio_uuid_link_test_on_close(void *obj) { fio_atomic_add((uintptr_t *)obj, 1); }
/* ***************************************************************************** Test UUID Linking ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L10617-L10619
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_str2u_test
FIO_FUNC void fio_str2u_test(void) { fprintf(stderr, "=== Testing fio_u2strX and fio_u2strX functions.\n"); char buffer[32]; for (int64_t i = -1024; i < 1024; ++i) { fio_u2str64(buffer, i); __asm__ volatile("" ::: "memory"); FIO_ASSERT((int64_t)fio_str2u64(buffer) == i, "fio_u2str64 / f...
/* ***************************************************************************** Byte Order Testing ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L10644-L10669
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_atof_test
FIO_FUNC void fio_atof_test(void) { fprintf(stderr, "=== Testing fio_ftoa and fio_ftoa (partial)\n"); #define TEST_DOUBLE(s, d, must) \ do { \ char *p = (char *)(s); ...
/* ***************************************************************************** String 2 Float and Float 2 String (partial) testing ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L10910-L11005
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_test
void fio_test(void) { FIO_ASSERT(fio_capa(), "facil.io initialization error!"); fio_malloc_test(); fio_state_callback_test(); fio_str_test(); fio_atol_test(); fio_atof_test(); fio_str2u_test(); fio_llist_test(); fio_ary_test(); fio_set_test(); fio_defer_test(); fio_timer_test(); fio_poll_test(...
/* ***************************************************************************** Run all tests ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L11010-L11037
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
websocket_subscribe_zigcompat
uintptr_t websocket_subscribe_zigcompat(struct websocket_subscribe_s_zigcompat args) { return websocket_subscribe(args.ws, // .ws = args.ws, .channel = args.channel, .on_message = args.on_message, .on_unsubscribe = args.on_unsubscribe, .udata = args.udata, .match = ar...
/** * Subscribes to a channel. See {struct websocket_subscribe_s} for possible * arguments. * * Returns a subscription ID on success and 0 on failure. * * All subscriptions are automatically revoked once the websocket is closed. * * If the connections subscribes to the same channel more than once, messages * w...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio_zig.c#L120-L132
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_cli_map_line2alias
static void fio_cli_map_line2alias(char const *line) { cstr_s n = {.data = line}; while (n.data[0] == '-') { while (n.data[n.len] && n.data[n.len] != ' ' && n.data[n.len] != ',') { ++n.len; } const char *old = NULL; fio_cli_hash_insert(&fio_aliases, FIO_CLI_HASH_VAL(n), n, (void *)line, ...
/* ***************************************************************************** CLI Parsing ***************************************************************************** */ /* ***************************************************************************** CLI Parsing *****************************************************...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/cli/fio_cli.c#L63-L85
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_cli_get_i
int fio_cli_get_i(char const *name) { char const *val = fio_cli_get(name); if (!val) return 0; int i = (int)fio_atol((char **)&val); return i; }
/** Returns the argument's value as an integer. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/cli/fio_cli.c#L400-L406
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_cli_unnamed_count
unsigned int fio_cli_unnamed_count(void) { return (unsigned int)fio_unnamed_count; }
/** Returns the number of unrecognized argument. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/cli/fio_cli.c#L409-L411
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_cli_set
void fio_cli_set(char const *name, char const *value) { cstr_s n = (cstr_s){.data = name, .len = strlen(name)}; fio_cli_hash_insert(&fio_values, FIO_CLI_HASH_VAL(n), n, value, NULL); }
/** * Sets the argument's value as a NUL terminated C String (no copy!). * * Note: this does NOT copy the C strings to memory. Memory should be kept * alive until `fio_cli_end` is called. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/cli/fio_cli.c#L428-L431
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_ary_dealloc
static void fiobj_ary_dealloc(FIOBJ o, void (*task)(FIOBJ, void *), void *arg) { FIO_ARY_FOR((&obj2ary(o)->ary), i) { task(*i, arg); } fio_ary___free(&obj2ary(o)->ary); fio_free(FIOBJ2PTR(o)); }
/* ***************************************************************************** VTable ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_ary.c#L32-L36
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_ary_count
size_t fiobj_ary_count(const FIOBJ ary) { assert(FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY)); return fio_ary___count(&obj2ary(ary)->ary); }
/** Returns the number of elements in the Array. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_ary.c#L52-L55
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_ary_alloc
static inline FIOBJ fiobj_ary_alloc(size_t capa) { fiobj_ary_s *ary = fio_malloc(sizeof(*ary)); if (!ary) { perror("ERROR: fiobj array couldn't allocate memory"); exit(errno); } *ary = (fiobj_ary_s){ .head = { .ref = 1, .type = FIOBJ_T_ARRAY, }, };...
/* ***************************************************************************** Allocation ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_ary.c#L81-L97
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_ary_new
FIOBJ fiobj_ary_new(void) { return fiobj_ary_alloc(0); }
/** Creates a mutable empty Array object. Use `fiobj_free` when done. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_ary.c#L100-L100
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_ary_new2
FIOBJ fiobj_ary_new2(size_t capa) { return fiobj_ary_alloc(capa); }
/** Creates a mutable empty Array object with the requested capacity. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_ary.c#L102-L102
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_ary_capa
size_t fiobj_ary_capa(FIOBJ ary) { assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY)); return fio_ary___capa(&obj2ary(ary)->ary); }
/* ***************************************************************************** Array direct entry access API ***************************************************************************** */ /** Returns the current, temporary, array capacity (it's dynamic). */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_ary.c#L109-L112
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_ary_index
FIOBJ fiobj_ary_index(FIOBJ ary, int64_t pos) { assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY)); return fio_ary___get(&obj2ary(ary)->ary, pos); }
/** * Returns a temporary object owned by the Array. * * Negative values are retrieved from the end of the array. i.e., `-1` * is the last item. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_ary.c#L131-L134
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_ary_set
void fiobj_ary_set(FIOBJ ary, FIOBJ obj, int64_t pos) { assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY)); FIOBJ old = FIOBJ_INVALID; fio_ary___set(&obj2ary(ary)->ary, pos, obj, &old); fiobj_free(old); }
/** * Sets an object at the requested position. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_ary.c#L139-L144
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_ary_push
void fiobj_ary_push(FIOBJ ary, FIOBJ obj) { assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY)); fio_ary___push(&obj2ary(ary)->ary, obj); }
/* ***************************************************************************** Array push / shift API ***************************************************************************** */ /** * Pushes an object to the end of the Array. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_ary.c#L153-L156
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_ary_pop
FIOBJ fiobj_ary_pop(FIOBJ ary) { assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY)); FIOBJ ret = FIOBJ_INVALID; fio_ary___pop(&obj2ary(ary)->ary, &ret); return ret; }
/** Pops an object from the end of the Array. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_ary.c#L159-L164
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_ary_unshift
void fiobj_ary_unshift(FIOBJ ary, FIOBJ obj) { assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY)); fio_ary___unshift(&obj2ary(ary)->ary, obj); }
/** * Unshifts an object to the beginning of the Array. This could be * expensive. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_ary.c#L170-L173
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_ary_shift
FIOBJ fiobj_ary_shift(FIOBJ ary) { assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY)); FIOBJ ret = FIOBJ_INVALID; fio_ary___shift(&obj2ary(ary)->ary, &ret); return ret; }
/** Shifts an object from the beginning of the Array. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_ary.c#L176-L181
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_ary_replace
FIOBJ fiobj_ary_replace(FIOBJ ary, FIOBJ obj, int64_t pos) { assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY)); FIOBJ old = fiobj_ary_index(ary, pos); fiobj_ary_set(ary, obj, pos); return old; }
/* ***************************************************************************** Array Find / Remove / Replace ***************************************************************************** */ /** * Replaces the object at a specific position, returning the old object - * remember to `fiobj_free` the old object. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_ary.c#L191-L196
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_ary_find
int64_t fiobj_ary_find(FIOBJ ary, FIOBJ data) { assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY)); return (int64_t)fio_ary___find(&obj2ary(ary)->ary, data); }
/** * Finds the index of a specifide object (if any). Returns -1 if the object * isn't found. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_ary.c#L202-L205
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_ary_remove
int fiobj_ary_remove(FIOBJ ary, int64_t pos) { assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY)); FIOBJ old = FIOBJ_INVALID; if (fio_ary___remove(&obj2ary(ary)->ary, (intptr_t)pos, &old)) { return -1; } fiobj_free(old); return 0; }
/** * Removes the object at the index (if valid), changing the index of any * following objects. * * Returns 0 on success or -1 (if no object or out of bounds). */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_ary.c#L213-L221
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_ary_remove2
int fiobj_ary_remove2(FIOBJ ary, FIOBJ data) { assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY)); if (-1 == fio_ary___remove2(&obj2ary(ary)->ary, data, &data)) { return -1; } fiobj_free(data); return 0; }
/** * Removes the first instance of an object from the Array (if any), changing the * index of any following objects. * * Returns 0 on success or -1 (if the object wasn't found). */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_ary.c#L229-L236
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_ary_compact
void fiobj_ary_compact(FIOBJ ary) { assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY)); fio_ary___compact(&obj2ary(ary)->ary); }
/* ***************************************************************************** Array compacting (untested) ***************************************************************************** */ /** * Removes any NULL *pointers* from an Array, keeping all Objects (including * explicit NULL objects) in the array. * * Thi...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_ary.c#L249-L252
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
swallow_ch
static inline int swallow_ch(uint8_t **buffer, register uint8_t *const limit, const uint8_t c) { if (**buffer == c) return 1; #if !ALLOW_UNALIGNED_MEMORY_ACCESS || !defined(__x86_64__) /* too short for this mess */ if ((uintptr_t)limit <= 16 + ((uintptr_t)*buffer & (~(uintptr_t)7...
/** * This seems to be faster on some systems, especially for smaller distances. * * On newer systems, `memchr` should be faster. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L253-L302
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_newstr
FIOBJ fiobj_data_newstr(void) { FIOBJ o = fiobj_data_alloc(fio_malloc(4096), -1); REQUIRE_MEM(obj2io(o)->buffer); obj2io(o)->capa = 4096; obj2io(o)->source.dealloc = fio_free; return o; }
/* ***************************************************************************** Creating the IO object ***************************************************************************** */ /** Creates a new local in-memory IO object */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L326-L332
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_newstr2
FIOBJ fiobj_data_newstr2(void *buffer, uintptr_t length, void (*dealloc)(void *)) { FIOBJ o = fiobj_data_alloc(buffer, -1); obj2io(o)->capa = length; obj2io(o)->len = length; obj2io(o)->source.dealloc = dealloc; return o; }
/** * Creates a IO object from an existing buffer. The buffer will be deallocated * using the provided `dealloc` function pointer. Use a NULL `dealloc` function * pointer if the buffer is static and shouldn't be freed. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L339-L346
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_newfd
FIOBJ fiobj_data_newfd(int fd) { FIOBJ o = fiobj_data_alloc(fio_malloc(4096), fd); REQUIRE_MEM(obj2io(o)->buffer); obj2io(o)->source.fpos = 0; return o; }
/** Creates a new local file IO object */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L349-L354
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_newtmpfile
FIOBJ fiobj_data_newtmpfile(void) { // create a temporary file to contain the data. int fd = fio_tmpfile(); if (fd == -1) return 0; return fiobj_data_newfd(fd); }
/** Creates a new local tempfile IO object */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L357-L363
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_slice
FIOBJ fiobj_data_slice(FIOBJ parent, intptr_t offset, uintptr_t length) { /* cut from the end */ if (offset < 0) { size_t parent_len = fiobj_data_len(parent); offset = parent_len + 1 + offset; } if (offset < 0) offset = 0; while (obj2io(parent)->fd == -2) { /* don't slice a slice... climb the ...
/** Creates a slice from an existing Data object. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L366-L392
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_save_str
static int fiobj_data_save_str(FIOBJ o, const char *filename) { int target = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0777); if (target == -1) return -1; errno = 0; size_t total = 0; do { ssize_t act = write(target, obj2io(o)->buffer + total, obj2io(o)->len - total); if (act < 0) g...
/* ***************************************************************************** Saving the IO object ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L398-L417
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_save
int fiobj_data_save(FIOBJ o, const char *filename) { switch (obj2io(o)->fd) { case -1: return fiobj_data_save_str(o, filename); break; case -2: return fiobj_data_save_slice(o, filename); break; default: return fiobj_data_save_file(o, filename); } }
/** Creates a new local file IO object */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L475-L486
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_read_str
static fio_str_info_s fiobj_data_read_str(FIOBJ io, intptr_t length) { if (obj2io(io)->pos == obj2io(io)->len) { /* EOF */ return (fio_str_info_s){.data = NULL, .len = 0}; } if (length <= 0) { /* read to EOF - length */ length = (obj2io(io)->len - obj2io(io)->pos) + length; } if (length <= 0...
/* ***************************************************************************** Reading API ***************************************************************************** */ /** Reads up to `length` bytes */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L493-L518
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_read_slice
static fio_str_info_s fiobj_data_read_slice(FIOBJ io, intptr_t length) { if (obj2io(io)->pos == obj2io(io)->len) { /* EOF */ return (fio_str_info_s){.data = NULL, .len = 0}; } if (length <= 0) { /* read to EOF - length */ length = (obj2io(io)->len - obj2io(io)->pos) + length; } if (length <= ...
/** Reads up to `length` bytes */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L521-L541
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_read_file
static fio_str_info_s fiobj_data_read_file(FIOBJ io, intptr_t length) { uintptr_t fsize = fiobj_data_get_fd_size(io); if (length <= 0) { /* read to EOF - length */ length = (fsize - obj2io(io)->source.fpos) + length; } if (length <= 0) { /* We are at EOF - length or beyond */ errno = 0; re...
/** Reads up to `length` bytes */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L544-L585
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_read
fio_str_info_s fiobj_data_read(FIOBJ io, intptr_t length) { if (!io || !FIOBJ_TYPE_IS(io, FIOBJ_T_DATA)) { errno = EFAULT; return (fio_str_info_s){.data = NULL, .len = 0}; } errno = 0; switch (obj2io(io)->fd) { case -1: return fiobj_data_read_str(io, length); break; case -2: return fiobj...
/** * Reads up to `length` bytes and returns a temporary(!) C string object. * * The C string object will be invalidate the next time a function call to the * IO object is made. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L593-L609
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_read2ch_str
static fio_str_info_s fiobj_data_read2ch_str(FIOBJ io, uint8_t token) { if (obj2io(io)->pos == obj2io(io)->len) /* EOF */ return (fio_str_info_s){.data = NULL, .len = 0}; uint8_t *pos = obj2io(io)->buffer + obj2io(io)->pos; uint8_t *lim = obj2io(io)->buffer + obj2io(io)->len; swallow_ch(&pos, lim, token); ...
/* ***************************************************************************** Tokenize (read2ch) ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L615-L628
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_read2ch
fio_str_info_s fiobj_data_read2ch(FIOBJ io, uint8_t token) { if (!io || !FIOBJ_TYPE_IS(io, FIOBJ_T_DATA)) { errno = EFAULT; return (fio_str_info_s){.data = NULL, .len = 0}; } switch (obj2io(io)->fd) { case -1: return fiobj_data_read2ch_str(io, token); break; case -2: return fiobj_data_read...
/** * Reads until the `token` byte is encountered or until the end of the stream. * * Returns a temporary(!) C string including the end of line marker. * * Careful when using this call on large file streams, as the whole file * stream might be loaded into the memory. * * The C string object will be invalidate t...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L709-L724
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_pos
intptr_t fiobj_data_pos(FIOBJ io) { if (!io || !FIOBJ_TYPE_IS(io, FIOBJ_T_DATA)) return -1; switch (obj2io(io)->fd) { case -1: /* fallthrough */ case -2: return obj2io(io)->pos; break; default: return obj2io(io)->source.fpos; } }
/* ***************************************************************************** Position / Seeking ***************************************************************************** */ /** * Returns the current reading position. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L733-L744
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_len
intptr_t fiobj_data_len(FIOBJ io) { if (!io || !FIOBJ_TYPE_IS(io, FIOBJ_T_DATA)) return -1; return fiobj_data_i(io); }
/** * Returns the length of the stream. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L749-L753
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_seek
void fiobj_data_seek(FIOBJ io, intptr_t position) { if (!io || !FIOBJ_TYPE_IS(io, FIOBJ_T_DATA)) return; switch (obj2io(io)->fd) { case -1: /* fallthrough */ case -2: /* String / Slice code */ if (position == 0) { obj2io(io)->pos = 0; return; } if (position > 0) { if ((uint...
/** * Moves the reading position to the requested position. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L758-L810
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_pread_str
static fio_str_info_s fiobj_data_pread_str(FIOBJ io, intptr_t start_at, uintptr_t length) { if (start_at < 0) start_at = obj2io(io)->len + start_at; if (start_at < 0) start_at = 0; if ((size_t)start_at > obj2io(io)->len) start_at = obj2io(io)->len; if (leng...
/* ***************************************************************************** `fiobj_data_pread` ***************************************************************************** */ // switch(obj2io(o)->fd) { // case -1: // break; // case -2: // break; // default: // }
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L823-L842
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_pread
fio_str_info_s fiobj_data_pread(FIOBJ io, intptr_t start_at, uintptr_t length) { if (!io || !FIOBJ_TYPE_IS(io, FIOBJ_T_DATA)) { errno = EFAULT; return (fio_str_info_s){ .data = NULL, .len = 0, }; } errno = 0; switch (obj2io(io)->fd) { case -1: return fiobj_data_pread_str(io, s...
/** * Reads up to `length` bytes starting at `start_at` position and returns a * temporary(!) C string object. The reading position is ignored and * unchanged. * * The C string object will be invalidate the next time a function call to the * IO object is made. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L904-L924
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_assert_dynamic
void fiobj_data_assert_dynamic(FIOBJ io) { if (!io) { errno = ENFILE; return; } assert(FIOBJ_TYPE(io) == FIOBJ_T_DATA); fiobj_data_pre_write(io, 0); return; }
/* ***************************************************************************** Writing API ***************************************************************************** */ /** * Makes sure the IO object isn't attached to a static or external string. * * If the IO object is attached to a static or external string, ...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L936-L944
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_write
intptr_t fiobj_data_write(FIOBJ io, void *buffer, uintptr_t length) { if (!io || !FIOBJ_TYPE_IS(io, FIOBJ_T_DATA) || (!buffer && length)) { errno = EFAULT; return -1; } errno = 0; /* Unslice slices */ if (obj2io(io)->fd == -2) fiobj_data_assert_dynamic(io); if (obj2io(io)->fd == -1) { /* St...
/** * Writes `length` bytes at the end of the IO stream, ignoring the reading * position. * * Behaves and returns the same value as the system call `write`. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L952-L973
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_puts
intptr_t fiobj_data_puts(FIOBJ io, void *buffer, uintptr_t length) { if (!io || !FIOBJ_TYPE_IS(io, FIOBJ_T_DATA) || (!buffer && length)) { errno = EFAULT; return -1; } /* Unslice slices */ if (obj2io(io)->fd == -2) fiobj_data_assert_dynamic(io); if (obj2io(io)->fd == -1) { /* String Code */ ...
/** * Writes `length` bytes at the end of the IO stream, ignoring the reading * position, adding an EOL marker ("\r\n") to the end of the stream. * * Behaves and returns the same value as the system call `write`. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L981-L1015
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_newstr
FIOBJ fiobj_data_newstr(void) { return FIOBJ_INVALID; }
/** Creates a new local in-memory IO object */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L1163-L1163
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_newstr2
FIOBJ fiobj_data_newstr2(void *buffer, uintptr_t length, void (*dealloc)(void *)) { return FIOBJ_INVALID; }
/** * Creates a IO object from an existing buffer. The buffer will be deallocated * using the provided `dealloc` function pointer. Use a NULL `dealloc` function * pointer if the buffer is static and shouldn't be freed. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L1170-L1173
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_newtmpfile
FIOBJ fiobj_data_newtmpfile(void) { return FIOBJ_INVALID; }
/** Creates a new local tempfile IO object */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L1176-L1176
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_data_newfd
FIOBJ fiobj_data_newfd(int fd) { return FIOBJ_INVALID; }
/** Creates a new local file IO object */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_data.c#L1179-L1179
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_hash_dealloc
static void fiobj_hash_dealloc(FIOBJ o, void (*task)(FIOBJ, void *), void *arg) { FIO_SET_FOR_LOOP(&obj2hash(o)->hash, i) { if (i->obj.key) task((FIOBJ)i->obj.obj, arg); fiobj_free((FIOBJ)i->obj.key); i->obj.key = FIOBJ_INVALID; i->obj.obj = FIOBJ_INVALID; } ob...
/* ***************************************************************************** Hash alloc + VTable ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_hash.c#L58-L70
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_hash_count
size_t fiobj_hash_count(const FIOBJ o) { assert(o && FIOBJ_TYPE_IS(o, FIOBJ_T_HASH)); return fio_hash___count(&obj2hash(o)->hash); }
/** Returns the number of elements in the Array. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_hash.c#L123-L126
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_hash_new
FIOBJ fiobj_hash_new(void) { fiobj_hash_s *h = fio_malloc(sizeof(*h)); FIO_ASSERT_ALLOC(h); *h = (fiobj_hash_s){.head = {.ref = 1, .type = FIOBJ_T_HASH}, .hash = FIO_SET_INIT}; return (FIOBJ)h | FIOBJECT_HASH_FLAG; }
/* ***************************************************************************** Hash API ***************************************************************************** */ /** * Creates a mutable empty Hash object. Use `fiobj_free` when done. * * Notice that these Hash objects are designed for smaller collections and...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_hash.c#L160-L166
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_hash_new2
FIOBJ fiobj_hash_new2(size_t capa) { fiobj_hash_s *h = fio_malloc(sizeof(*h)); FIO_ASSERT_ALLOC(h); *h = (fiobj_hash_s){.head = {.ref = 1, .type = FIOBJ_T_HASH}, .hash = FIO_SET_INIT}; fio_hash___capa_require(&h->hash, capa); return (FIOBJ)h | FIOBJECT_HASH_FLAG; }
/** * Creates a mutable empty Hash object with an initial capacity of `capa`. Use * `fiobj_free` when done. * * Notice that these Hash objects are designed for smaller collections and * retain order of object insertion. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_hash.c#L175-L182
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_hash_capa
size_t fiobj_hash_capa(const FIOBJ hash) { assert(hash && FIOBJ_TYPE_IS(hash, FIOBJ_T_HASH)); return fio_hash___capa(&obj2hash(hash)->hash); }
/** * Returns a temporary theoretical Hash map capacity. * This could be used for testing performance and memory consumption. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_hash.c#L188-L191
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_hash_set
int fiobj_hash_set(FIOBJ hash, FIOBJ key, FIOBJ obj) { assert(hash && FIOBJ_TYPE_IS(hash, FIOBJ_T_HASH)); if (FIOBJ_TYPE_IS(key, FIOBJ_T_STRING)) fiobj_str_freeze(key); fio_hash___insert(&obj2hash(hash)->hash, fiobj_obj2hash(key), key, obj, NULL); fiobj_free(obj); /* take ownership - free the user's referen...
/** * Sets a key-value pair in the Hash, duplicating the Symbol and **moving** * the ownership of the object to the Hash. * * Returns -1 on error. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_hash.c#L199-L206
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_hash_pop
FIOBJ fiobj_hash_pop(FIOBJ hash, FIOBJ *key) { assert(hash && FIOBJ_TYPE_IS(hash, FIOBJ_T_HASH)); FIOBJ old; if (fio_hash___count(&obj2hash(hash)->hash)) return FIOBJ_INVALID; old = fiobj_dup(fio_hash___last(&obj2hash(hash)->hash).obj); if (key) *key = fiobj_dup(fio_hash___last(&obj2hash(hash)->hash)....
/** * Allows the Hash to be used as a stack. * * If a pointer `key` is provided, it will receive ownership of the key * (remember to free). * * Returns FIOBJ_INVALID on error. * * Returns and object if successful (remember to free). */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_hash.c#L218-L228
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_hash_replace
FIOBJ fiobj_hash_replace(FIOBJ hash, FIOBJ key, FIOBJ obj) { assert(hash && FIOBJ_TYPE_IS(hash, FIOBJ_T_HASH)); FIOBJ old = FIOBJ_INVALID; fio_hash___insert(&obj2hash(hash)->hash, fiobj_obj2hash(key), key, obj, &old); fiobj_free(obj); /* take ownership - free the user's reference. */ return old; }
/** * Replaces the value in a key-value pair, returning the old value (and it's * ownership) to the caller. * * A return value of NULL indicates that no previous object existed (but a new * key-value pair was created. * * Errors are silently ignored. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_hash.c#L239-L245
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_hash_remove
FIOBJ fiobj_hash_remove(FIOBJ hash, FIOBJ key) { assert(hash && FIOBJ_TYPE_IS(hash, FIOBJ_T_HASH)); FIOBJ old = FIOBJ_INVALID; fio_hash___remove(&obj2hash(hash)->hash, fiobj_obj2hash(key), key, &old); return old; }
/** * Removes a key-value pair from the Hash, if it exists. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_hash.c#L250-L255
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_hash_remove2
FIOBJ fiobj_hash_remove2(FIOBJ hash, uint64_t hash_value) { assert(hash && FIOBJ_TYPE_IS(hash, FIOBJ_T_HASH)); FIOBJ old = FIOBJ_INVALID; fio_hash___remove(&obj2hash(hash)->hash, hash_value, -1, &old); return old; }
/** * Removes a key-value pair from the Hash, if it exists, returning the old * object (instead of freeing it). */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_hash.c#L261-L266
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_hash_delete
int fiobj_hash_delete(FIOBJ hash, FIOBJ key) { return fio_hash___remove(&obj2hash(hash)->hash, fiobj_obj2hash(key), key, NULL); }
/** * Deletes a key-value pair from the Hash, if it exists, freeing the * associated object. * * Returns -1 on type error or if the object never existed. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_hash.c#L274-L277
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_hash_delete2
int fiobj_hash_delete2(FIOBJ hash, uint64_t key_hash) { return fio_hash___remove(&obj2hash(hash)->hash, key_hash, -1, NULL); }
/** * Deletes a key-value pair from the Hash, if it exists, freeing the * associated object. * * This function takes a `uintptr_t` Hash value (see `fio_siphash`) to * perform a lookup in the HashMap, which is slightly faster than the other * variations. * * Returns -1 on type error or if the object never existe...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_hash.c#L289-L291
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_hash_get
FIOBJ fiobj_hash_get(const FIOBJ hash, FIOBJ key) { assert(hash && FIOBJ_TYPE_IS(hash, FIOBJ_T_HASH)); return fio_hash___find(&obj2hash(hash)->hash, fiobj_obj2hash(key), key); ; }
/** * Returns a temporary handle to the object associated with the Symbol, NULL * if none. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_hash.c#L297-L301
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_hash_get2
FIOBJ fiobj_hash_get2(const FIOBJ hash, uint64_t key_hash) { assert(hash && FIOBJ_TYPE_IS(hash, FIOBJ_T_HASH)); return fio_hash___find(&obj2hash(hash)->hash, key_hash, -1); ; }
/** * Returns a temporary handle to the object associated hashed key value. * * This function takes a `uintptr_t` Hash value (see `fio_siphash`) to * perform a lookup in the HashMap. * * Returns NULL if no object is associated with this hashed key value. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_hash.c#L311-L315
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_hash_haskey
int fiobj_hash_haskey(const FIOBJ hash, FIOBJ key) { assert(hash && FIOBJ_TYPE_IS(hash, FIOBJ_T_HASH)); return fio_hash___find(&obj2hash(hash)->hash, fiobj_obj2hash(key), key) != FIOBJ_INVALID; }
/** * Returns 1 if the key (Symbol) exists in the Hash, even if value is NULL. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_hash.c#L320-L324
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_hash_clear
void fiobj_hash_clear(const FIOBJ hash) { assert(hash && FIOBJ_TYPE_IS(hash, FIOBJ_T_HASH)); fio_hash___free(&obj2hash(hash)->hash); }
/** * Empties the Hash. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_hash.c#L329-L332
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_json_add2parser
static inline void fiobj_json_add2parser(fiobj_json_parser_s *p, FIOBJ o) { if (p->top) { if (p->is_hash) { if (p->key) { fiobj_hash_set(p->top, p->key, o); fiobj_free(p->key); p->key = FIOBJ_INVALID; } else { p->key = o; } } else { fiobj_ary_push(p->top...
/* ***************************************************************************** FIOBJ Callacks ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_json.c#L49-L65
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_json_on_null
static void fio_json_on_null(json_parser_s *p) { fiobj_json_add2parser((fiobj_json_parser_s *)p, fiobj_null()); }
/** a NULL object was detected */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_json.c#L68-L70
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_json_on_true
static void fio_json_on_true(json_parser_s *p) { fiobj_json_add2parser((fiobj_json_parser_s *)p, fiobj_true()); }
/** a TRUE object was detected */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_json.c#L72-L74
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_json_on_false
static void fio_json_on_false(json_parser_s *p) { fiobj_json_add2parser((fiobj_json_parser_s *)p, fiobj_false()); }
/** a FALSE object was detected */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_json.c#L76-L78
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_json_on_number
static void fio_json_on_number(json_parser_s *p, long long i) { fiobj_json_add2parser((fiobj_json_parser_s *)p, fiobj_num_new(i)); }
/** a Numberl was detected (long long). */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_json.c#L80-L82
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_json_on_float
static void fio_json_on_float(json_parser_s *p, double f) { fiobj_json_add2parser((fiobj_json_parser_s *)p, fiobj_float_new(f)); }
/** a Float was detected (double). */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_json.c#L84-L86
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_json_on_string
static void fio_json_on_string(json_parser_s *p, void *start, size_t length) { FIOBJ str = fiobj_str_buf(length); fiobj_str_resize( str, fio_json_unescape_str(fiobj_obj2cstr(str).data, start, length)); fiobj_json_add2parser((fiobj_json_parser_s *)p, str); }
/** a String was detected (int / float). update `pos` to point at ending */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_json.c#L88-L93
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_json_on_start_object
static int fio_json_on_start_object(json_parser_s *p) { fiobj_json_parser_s *pr = (fiobj_json_parser_s *)p; if (pr->target) { /* push NULL, don't free the objects */ fio_json_stack_push(&pr->stack, pr->top); pr->top = pr->target; pr->target = FIOBJ_INVALID; } else { FIOBJ hash = fiobj_hash_new...
/** a dictionary object was detected */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_json.c#L95-L110
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_json_on_end_object
static void fio_json_on_end_object(json_parser_s *p) { fiobj_json_parser_s *pr = (fiobj_json_parser_s *)p; if (pr->key) { FIO_LOG_WARNING("(JSON parsing) malformed JSON, " "ignoring dangling Hash key."); fiobj_free(pr->key); pr->key = FIOBJ_INVALID; } pr->top = FIOBJ_INVALID; f...
/** a dictionary object closure detected */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_json.c#L112-L123
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_json_on_start_array
static int fio_json_on_start_array(json_parser_s *p) { fiobj_json_parser_s *pr = (fiobj_json_parser_s *)p; if (pr->target) return -1; FIOBJ ary = fiobj_ary_new(); fiobj_json_add2parser(pr, ary); fio_json_stack_push(&pr->stack, pr->top); pr->top = ary; pr->is_hash = 0; return 0; }
/** an array object was detected */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_json.c#L125-L135
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_json_on_end_array
static void fio_json_on_end_array(json_parser_s *p) { fiobj_json_parser_s *pr = (fiobj_json_parser_s *)p; pr->top = FIOBJ_INVALID; fio_json_stack_pop(&pr->stack, &pr->top); pr->is_hash = FIOBJ_TYPE_IS(pr->top, FIOBJ_T_HASH); }
/** an array closure was detected */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_json.c#L137-L142
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_json_on_json
static void fio_json_on_json(json_parser_s *p) { // fiobj_json_parser_s *pr = (fiobj_json_parser_s *)p; // FIO_ARY_FOR(&pr->stack, pos) { fiobj_free((FIOBJ)pos.obj); } // fio_json_stack_free(&pr->stack); (void)p; /* nothing special... right? */ }
/** the JSON parsing is complete */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_json.c#L144-L149
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_json_on_error
static void fio_json_on_error(json_parser_s *p) { fiobj_json_parser_s *pr = (fiobj_json_parser_s *)p; #if DEBUG FIO_LOG_DEBUG("JSON on error called."); #endif fiobj_free((FIOBJ)fio_json_stack_get(&pr->stack, 0)); fiobj_free(pr->key); fio_json_stack_free(&pr->stack); *pr = (fiobj_json_parser_s){.top = FIOBJ_...
/** the JSON parsing is complete */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_json.c#L151-L160
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
write_safe_str
static void write_safe_str(FIOBJ dest, const FIOBJ str) { fio_str_info_s s = fiobj_obj2cstr(str); fio_str_info_s t = fiobj_obj2cstr(dest); t.data[t.len] = '"'; t.len++; fiobj_str_resize(dest, t.len); t = fiobj_obj2cstr(dest); const uint8_t *restrict src = (const uint8_t *)s.data; size_t len = s.len; u...
/* ***************************************************************************** JSON formatting ***************************************************************************** */ /** Writes a JSON friendly version of the src String */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_json.c#L167-L259
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_json2obj
size_t fiobj_json2obj(FIOBJ *pobj, const void *data, size_t len) { fiobj_json_parser_s p = {.top = FIOBJ_INVALID}; size_t consumed = fio_json_parse(&p.p, data, len); if (!consumed || p.p.depth) { fiobj_free(fio_json_stack_get(&p.stack, 0)); p.top = FIOBJ_INVALID; } fio_json_stack_free(&p.stack); fio...
/* ***************************************************************************** FIOBJ API ***************************************************************************** */ /** * Parses JSON, setting `pobj` to point to the new Object. * * Returns the number of bytes consumed. On Error, 0 is returned and no data is *...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_json.c#L377-L388
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_hash_update_json
size_t fiobj_hash_update_json(FIOBJ hash, const void *data, size_t len) { if (!hash) return 0; fiobj_json_parser_s p = {.top = FIOBJ_INVALID, .target = hash}; size_t consumed = fio_json_parse(&p.p, data, len); fio_json_stack_free(&p.stack); fiobj_free(p.key); if (p.top != hash) fiobj_free(p.top); ...
/** * Updates a Hash using JSON data. * * Parsing errors and non-dictionar object JSON data are silently ignored, * attempting to update the Hash as much as possible before any errors * encountered. * * Conflicting Hash data is overwritten (prefering the new over the old). * * Returns the number of bytes consu...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_json.c#L402-L412
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_obj2json2
FIOBJ fiobj_obj2json2(FIOBJ dest, FIOBJ o, uint8_t pretty) { assert(dest && FIOBJ_TYPE_IS(dest, FIOBJ_T_STRING)); if (!o) { fiobj_str_write(dest, "null", 4); return 0; } fio_json_stack_s stack = FIO_ARY_INIT; obj2json_data_s data = { .dest = dest, .stack = &stack, .pretty = pretty, ...
/** * Formats an object into a JSON string, appending the JSON string to an * existing String. Remember to `fiobj_free`. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_json.c#L418-L438
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_obj2json
FIOBJ fiobj_obj2json(FIOBJ obj, uint8_t pretty) { return fiobj_obj2json2(fiobj_str_buf(128), obj, pretty); }
/* Formats an object into a JSON string. Remember to `fiobj_free`. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_json.c#L441-L443
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_mustache_free
void fiobj_mustache_free(mustache_s *mustache) { mustache_free(mustache); }
/** Free the mustache template */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_mustache.c#L50-L50
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_mustache_build2
FIOBJ fiobj_mustache_build2(FIOBJ dest, mustache_s *mustache, FIOBJ data) { mustache_build(mustache, .udata1 = (void *)dest, .udata2 = (void *)data); return dest; }
/** * Renders a template into an existing FIOBJ String (`dest`'s end), using the * information in the `data` object. * * Returns FIOBJ_INVALID if an error occured and a FIOBJ String on success. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_mustache.c#L58-L61
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_mustache_build
FIOBJ fiobj_mustache_build(mustache_s *mustache, FIOBJ data) { if (!mustache) return FIOBJ_INVALID; return fiobj_mustache_build2(fiobj_str_buf(mustache->u.read_only.data_length), mustache, data); }
/** * Creates a FIOBJ String containing the rendered template using the information * in the `data` object. * * Returns FIOBJ_INVALID if an error occured and a FIOBJ String on success. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_mustache.c#L69-L74
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_mustache_find_obj_absolute
static inline FIOBJ fiobj_mustache_find_obj_absolute(FIOBJ parent, FIOBJ key) { if (!FIOBJ_TYPE_IS(parent, FIOBJ_T_HASH)) return FIOBJ_INVALID; FIOBJ o = FIOBJ_INVALID; o = fiobj_hash_get(parent, key); return o; }
/* ***************************************************************************** Mustache Callbacks ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_mustache.c#L80-L86
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
mustache_on_arg
static int mustache_on_arg(mustache_section_s *section, const char *name, uint32_t name_len, unsigned char escape) { FIOBJ o = fiobj_mustache_find_obj(section, name, name_len); if (!o) return 0; fio_str_info_s i = fiobj_obj2cstr(o); if (!i.len) return 0; return mustache_writ...
/** * Called when an argument name was detected in the current section. * * A conforming implementation will search for the named argument both in the * existing section and all of it's parents (walking backwards towards the root) * until a value is detected. * * A missing value should be treated the same as an ...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_mustache.c#L154-L163
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
mustache_on_text
static int mustache_on_text(mustache_section_s *section, const char *data, uint32_t data_len) { FIOBJ dest = (FIOBJ)section->udata1; fiobj_str_write(dest, data, data_len); return 0; }
/** * Called when simple template text (string) is detected. * * A conforming implementation will output data as a string (no escaping). */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_mustache.c#L170-L175
675c65b509d48c21a8d1fa4c5ec53fc407643a3b