moving more to decl

This commit is contained in:
Gregory Burd 2024-03-18 21:19:26 -04:00
parent a1c08f6fd8
commit e8d3645ed4
12 changed files with 3071 additions and 3018 deletions

View file

@ -99,9 +99,9 @@ IndentPPDirectives: None
Language: Cpp
NamespaceIndentation: None
PointerAlignment: Right
ContinuationIndentWidth: 4
IndentWidth: 4
TabWidth: 4
ContinuationIndentWidth: 2
IndentWidth: 2
TabWidth: 2
ColumnLimit: 80
UseTab: Never
SpaceAfterCStyleCast: false

View file

@ -1,5 +1,6 @@
# Generated from CLion Inspection settings
#bugprone-reserved-identifier,
#misc-no-recursion,
---
Checks: '-*,
-deprecated-non-prototype
@ -74,7 +75,6 @@ hicpp-exception-baseclass,
hicpp-multiway-paths-covered,
misc-misplaced-const,
misc-new-delete-overloads,
misc-no-recursion,
misc-non-copyable-objects,
misc-throw-by-value-catch-by-reference,
misc-unconventional-assign-operator,

View file

@ -44,7 +44,7 @@ clean:
rm -f $(EXAMPLES)
format:
clang-format -i include/*.h src/*.c tests/*.c tests/*.h
clang-format -i include/*.h src/*.c tests/*.c tests/*.h examples/*.c
%.o: src/%.c
$(CC) $(CFLAGS) -c -o $@ $^
@ -60,3 +60,7 @@ examples/mls.c: examples/slm.c
examples/mls: examples/mls.o $(STATIC_LIB)
$(CC) $^ -o $@ $(CFLAGS) $(TEST_FLAGS) -pthread
#dot:
# ./examples/mls
# dot -Tpdf /tmp/slm.dot -o /tmp/slm.pdf >/dev/null 2>&1

View file

@ -79,8 +79,7 @@ main()
struct my_node *found = sl_get_entry(cursor, struct my_node, snode);
printf("[point lookup] key: %d, value: %d\n", found->key, found->value);
if (found->key != found->value / 10) {
printf("FAILURE: key: %d * 10 != value: %d\n", found->key,
found->value);
printf("FAILURE: key: %d * 10 != value: %d\n", found->key, found->value);
exit(-1);
}
// Release `cursor` (== &found->snode).
@ -119,8 +118,7 @@ main()
// Get `entry` from `cursor`.
// Note: entry->snode == *cursor
struct my_node *entry = sl_get_entry(cursor, struct my_node, snode);
printf("[iteration] key: %d, value: %d\n", entry->key,
entry->value);
printf("[iteration] key: %d, value: %d\n", entry->key, entry->value);
// Get next `cursor`.
cursor = sl_next(&slist, cursor);
// Release `entry`.

View file

@ -1,9 +1,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "../include/sl.h"
/*
@ -49,39 +49,54 @@ struct slex_node {
* list or when `a == b`. In those cases the comparison function
* returns before using the code in your block, don't panic. :)
*/
SKIPLIST_DECL(slex, api_, entries, {
SKIPLIST_DECL(slex, api_, entries)
int
__slm_key_compare(slex_t *list, slex_node_t *a, slex_node_t *b, void *aux)
{
(void)list;
(void)aux;
if (a->key < b->key)
return -1;
if (a->key > b->key)
return 1;
return 0;
})
void sprintf_slex_node(slex_node_t *node, char *buf) {
sprintf(buf, "%d", node->key);
}
int main() {
/* Allocate and initialize a Skiplist. */
slex_t _list = SKIP_HEAD_DEFAULT_INITIALIZER(__skip_key_compare_slex);
_list.slh_tail = (struct slex_node *)&_list.slh_head; // TODO...
/* Dynamic allocation, init. */
slex_t *list = (slex_t *)malloc(sizeof(slex_t));
SKIP_DEFAULT_INIT(list, __skip_key_compare_slex, slex_node, entries);
#ifdef STATIC_INIT
free(list);
slex_t *list = &_list;
#else
#define DOT
#ifdef DOT
/* Also declare the functions used to visualize a Sliplist (DOT/Graphviz) */
SKIPLIST_DECL_DOT(slex, api_, entries)
void
sprintf_slex_node(slex_node_t *node, char *buf)
{
sprintf(buf, "%d:%d", node->key, node->value);
}
#endif
struct slex_node *n;
SKIP_ALLOC_NODE(list, n, slex_node, entries);
n->key = -1;
n->value = -1;
api_skip_insert_slex(list, n);
int
main()
{
int rc = 0;
/* Allocate and initialize a Skiplist. */
slex_t *list = (slex_t *)malloc(sizeof(slex_t));
if (list == NULL) {
rc = ENOMEM;
goto fail;
}
rc = api_skip_init_slex(list, 12, 4, __slm_key_compare);
FILE* of = fopen("/tmp/slm.dot", "w");
struct slex_node *n;
/* Insert 7 key/value pairs into the list. */
for (int i = -2; i <= 2; i++) {
SKIP_ALLOC_NODE(list, n, slex_node, entries);
n->key = i;
n->value = i;
api_skip_insert_slex(list, n);
}
FILE *of = fopen("/tmp/slm.dot", "w");
if (!of) {
perror("Failed to open file /tmp/slm.dot");
return EXIT_FAILURE;
@ -89,14 +104,6 @@ int main() {
api_skip_dot_slex(of, list, sprintf_slex_node);
fclose(of);
/* Insert 10 key/value pairs into the list. */
for (int i = 0; i < 10; i++) {
SKIP_ALLOC_NODE(list, n, slex_node, entries);
n->key = i;
n->value = i;
api_skip_insert_slex(list, n);
}
#if 0
/* Delete a specific element in the list. */
struct slex_node query;
@ -124,5 +131,6 @@ int main() {
}
SKIP_INIT(&head);
#endif
return 0;
fail:;
return rc;
}

View file

@ -72,28 +72,33 @@
#if SKIPLIST_MACRO_DEBUG
/* Store the last 2 places the element or head was altered */
struct sl_trace {
char * lastfile;
char *lastfile;
int lastline;
char * prevfile;
char *prevfile;
int prevline;
};
#define TRACEBUF struct sl_trace trace;
#define TRASHIT(x) do {(x) = (void *)-1;} while (0)
#define TRASHIT(x) \
do { \
(x) = (void *)-1; \
} while (0)
#define SLD_TRACE_HEAD(head) do { \
#define SLD_TRACE_HEAD(head) \
do { \
(head)->trace.prevline = (head)->trace.lastline; \
(head)->trace.prevfile = (head)->trace.lastfile; \
(head)->trace.lastline = __LINE__; \
(head)->trace.lastfile = __FILE__; \
} while (0)
} while (0)
#define SLD_TRACE_ELEM(elem) do { \
#define SLD_TRACE_ELEM(elem) \
do { \
(elem)->trace.prevline = (elem)->trace.lastline; \
(elem)->trace.prevfile = (elem)->trace.lastfile; \
(elem)->trace.lastline = __LINE__; \
(elem)->trace.lastfile = __FILE__; \
} while (0)
} while (0)
#else
#define SLD_TRACE_ELEM(elem)
@ -102,7 +107,6 @@ struct sl_trace {
#define TRASHIT(x)
#endif /* QUEUE_MACRO_DEBUG */
/*
* Private, internal API.
*/
@ -113,14 +117,15 @@ struct sl_trace {
* can grow to (`array[-2]`) and the length, or number of elements used in the
* array so far (`array[-1]`).
*/
#define ARRAY_ALLOC(var, type, size) do { \
#define ARRAY_ALLOC(var, type, size) \
do { \
(size) = (size == 0 ? 254 : size); \
(var) = (type**)calloc(sizeof(type*), size + 2); \
(var) = (type **)calloc(sizeof(type *), size + 2); \
if ((var) != NULL) { \
*(var)++ = (type *)size; \
*(var)++ = 0; \
} \
} while(0)
} while (0)
#define ARRAY_FREE(var) free((var)-2)
#define ARRAY_SIZE(list) (unsigned int)(uintptr_t)(list)[-2]
#define ARRAY_SET_SIZE(list, size) (list)[-2] = (void *)(uintptr_t)(size)
@ -141,10 +146,14 @@ struct sl_trace {
}
#define SKIP_HEAD_DEFAULT_INITIALIZER(cmp) \
{ 0, 0, 12, 4, cmp, NULL, NULL, NULL }
{ \
0, 0, 12, 4, cmp, NULL, NULL, NULL \
}
#define SKIP_HEAD_INITIALIZER(cmp, max, fanout) \
{ 0, 0, max, fanout, cmp, NULL, NULL, NULL }
{ \
0, 0, max, fanout, cmp, NULL, NULL, NULL \
}
#define SKIP_ENTRY(type) \
struct { \
@ -164,23 +173,19 @@ struct sl_trace {
#if 0
#define SKIP_FOREACH(var, head, field) \
for((var) = SKIP_FIRST(head); \
(var)!= SKIP_END(head); \
for ((var) = SKIP_FIRST(head); (var) != SKIP_END(head); \
(var) = SKIP_NEXT(var, field))
#define SKIP_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = SKIP_FIRST(head); \
(var) && ((tvar) = SKIP_NEXT(var, field), 1); \
for ((var) = SKIP_FIRST(head); (var) && ((tvar) = SKIP_NEXT(var, field), 1); \
(var) = (tvar))
#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
for((var) = TAILQ_LAST(head, headname); \
(var) != TAILQ_END(head); \
for ((var) = TAILQ_LAST(head, headname); (var) != TAILQ_END(head); \
(var) = TAILQ_PREV(var, headname, field))
#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \
for ((var) = TAILQ_LAST(head, headname); \
(var) != TAILQ_END(head) && \
for ((var) = TAILQ_LAST(head, headname); (var) != TAILQ_END(head) && \
((tvar) = TAILQ_PREV(var, headname, field), 1); \
(var) = (tvar))
#endif
@ -190,16 +195,20 @@ struct sl_trace {
*/
#define SKIP_COMPARATOR(list, type, fn) \
int __skip_cmp_##type(struct list *head, struct type *a, struct type *b, void *aux) { \
int __skip_cmp_##type(struct list *head, struct type *a, struct type *b, \
void *aux) \
{ \
if (a == b) \
return 0; \
if (a == (head)->slh_head || b == (head)->slh_tail) \
return -1; \
if (a == (head)->slh_tail || b == (head)->slh_head) \
return 1; \
fn }
fn \
}
#define SKIP_INIT(head, max, fanout, type, field, fn) do { \
#define SKIP_INIT(head, max, fanout, type, field, fn) \
do { \
(head)->level = 0; \
(head)->length = 0; \
(head)->max = max; \
@ -208,19 +217,22 @@ struct sl_trace {
SKIP_ALLOC_NODE(head, (head)->slh_head, type, field); \
SKIP_ALLOC_NODE(head, (head)->slh_tail, type, field); \
ARRAY_SET_LENGTH((head)->slh_head->field.sle_next, max); \
for(size_t __i = 0; __i < ARRAY_SIZE((head)->slh_head->field.sle_next); __i++) { \
for (size_t __i = 0; __i < ARRAY_SIZE((head)->slh_head->field.sle_next); \
__i++) { \
(head)->slh_head->field.sle_next[__i] = (head)->slh_tail; \
} \
(head)->slh_head->field.sle_prev = NULL; \
ARRAY_SET_LENGTH((head)->slh_tail->field.sle_next, max); \
for(size_t __i = 0; __i < ARRAY_SIZE((head)->slh_tail->field.sle_next); __i++) { \
for (size_t __i = 0; __i < ARRAY_SIZE((head)->slh_tail->field.sle_next); \
__i++) { \
(head)->slh_tail->field.sle_next[__i] = NULL; \
} \
(head)->slh_head->field.sle_prev = (head)->slh_tail; \
SLD_TRACE_HEAD(head); \
} while (0)
#define SKIP_DEFAULT_INIT(head, fn, type, field) do { \
#define SKIP_DEFAULT_INIT(head, fn, type, field) \
do { \
(head)->level = 0; \
(head)->length = 0; \
(head)->max = 12; \
@ -229,20 +241,22 @@ struct sl_trace {
SKIP_ALLOC_NODE(head, (head)->slh_head, type, field); \
SKIP_ALLOC_NODE(head, (head)->slh_tail, type, field); \
ARRAY_SET_LENGTH((head)->slh_head->field.sle_next, (head)->max); \
for(size_t __i = 0; __i < ARRAY_SIZE((head)->slh_head->field.sle_next); __i++) { \
for (size_t __i = 0; __i < ARRAY_SIZE((head)->slh_head->field.sle_next); \
__i++) { \
(head)->slh_head->field.sle_next[__i] = (head)->slh_tail; \
} \
(head)->slh_head->field.sle_prev = NULL; \
ARRAY_SET_LENGTH((head)->slh_tail->field.sle_next, (head)->max); \
for(size_t __i = 0; __i < ARRAY_SIZE((head)->slh_tail->field.sle_next); __i++) { \
for (size_t __i = 0; __i < ARRAY_SIZE((head)->slh_tail->field.sle_next); \
__i++) { \
(head)->slh_tail->field.sle_next[__i] = NULL; \
} \
(head)->slh_head->field.sle_prev = (head)->slh_tail; \
SLD_TRACE_HEAD(head); \
} while (0)
#define SKIP_ALLOC_NODE(head, var, type, field) do { \
#define SKIP_ALLOC_NODE(head, var, type, field) \
do { \
(var) = (struct type *)calloc(1, sizeof(struct type)); \
ARRAY_ALLOC((var)->field.sle_next, struct type, (head)->max); \
if ((var) && (var)->field.sle_next) { \
@ -251,12 +265,7 @@ struct sl_trace {
} \
} while (0)
#define SKIP_FREE_NODE(node, field) do { \
free((node)->field.sle_next); \
free((node)); \
} while (0)
#define SKIPLIST_DECL(decl, prefix, field, key_cmp_logic) \
#define SKIPLIST_DECL(decl, prefix, field) \
\
/* Skiplist node type */ \
typedef struct decl##_node decl##_node_t; \
@ -269,7 +278,7 @@ struct sl_trace {
decl##_node_t *slh_head; \
decl##_node_t *slh_tail; \
TRACEBUF \
}decl##_t; \
} decl##_t; \
\
/* -- __skip_key_compare_ \
* \
@ -282,18 +291,21 @@ struct sl_trace {
* a == b : return 0 \
* a > b : return 1 \
*/ \
static int __skip_key_compare_##decl(decl##_t *slist, decl##_node_t *a, decl##_node_t *b, void *aux) { \
static int __skip_key_compare_##decl(decl##_t *slist, decl##_node_t *a, \
decl##_node_t *b, void *aux) \
{ \
if (a == b) \
return 0; \
if (a == slist->slh_head || b == slist->slh_tail) \
return -1; \
if (a == slist->slh_tail || b == slist->slh_head) \
return 1; \
do { key_cmp_logic } while(0); \
return slist->cmp(slist, a, b, aux); \
} \
\
/* -- __skip_toss_ */ \
static int __skip_toss_##decl(size_t max, size_t fanout) { \
static int __skip_toss_##decl(size_t max, size_t fanout) \
{ \
size_t level = 0; \
while (level + 1 < max) { \
if (rand() % fanout == 0) /* NOLINT(*-msc50-cpp) */ \
@ -304,8 +316,61 @@ struct sl_trace {
return level; \
} \
\
/* -- skip_alloc_node_ */ \
int prefix##skip_alloc_node_##decl(decl##_t *slist, decl##_node_t **node) \
{ \
decl##_node_t *n; \
n = (decl##_node_t *)calloc(1, sizeof(decl##_node_t)); \
ARRAY_ALLOC(n->field.sle_next, struct decl##_node, slist->max); \
if (n && n->field.sle_next) { \
ARRAY_SET_SIZE(n->field.sle_next, slist->max); \
ARRAY_SET_LENGTH(n->field.sle_next, 0); \
*node = n; \
return 0; \
} \
return ENOMEM; \
} \
\
/* -- skip_init_ \
* max: 12, fanout: 4 are good defaults. \
*/ \
int prefix##skip_init_##decl(decl##_t *slist, size_t max, size_t fanout, \
int (*cmp)(struct decl *, decl##_node_t *, decl##_node_t *, void *)) \
{ \
int rc = 0; \
slist->level = 0; \
slist->length = 0; \
slist->max = max; \
slist->fanout = fanout; \
slist->cmp = cmp; \
rc = prefix##skip_alloc_node_##decl(slist, &slist->slh_head); \
if (rc) \
goto fail; \
rc = prefix##skip_alloc_node_##decl(slist, &slist->slh_tail); \
if (rc) \
goto fail; \
ARRAY_SET_LENGTH(slist->slh_head->field.sle_next, max); \
for (size_t __i = 0; __i < max; __i++) \
slist->slh_head->field.sle_next[__i] = slist->slh_tail; \
slist->slh_head->field.sle_prev = NULL; \
ARRAY_SET_LENGTH(slist->slh_tail->field.sle_next, max); \
for (size_t __i = 0; __i < max; __i++) \
slist->slh_tail->field.sle_next[__i] = NULL; \
slist->slh_head->field.sle_prev = slist->slh_tail; \
fail:; \
return rc; \
} \
\
/* -- skip_free_node_ */ \
void prefix##skip_free_node_##decl(decl##_node_t *node) \
{ \
free(node->field.sle_next); \
free(node); \
} \
\
/* -- skip_insert_ */ \
int prefix##skip_insert_##decl(decl##_t *slist, decl##_node_t *n) { \
int prefix##skip_insert_##decl(decl##_t *slist, decl##_node_t *n) \
{ \
if (n == NULL) \
return ENOMEM; \
decl##_node_t *prev, *elm = slist->slh_head; \
@ -317,17 +382,19 @@ struct sl_trace {
return ENOMEM; \
/* Find the position in the list where this element belongs. */ \
do { \
while(elm && slist->cmp(slist, elm->field.sle_next[i], n, slist->aux) < 0) \
while (elm && \
__skip_key_compare_##decl(slist, elm->field.sle_next[i], n, \
slist->aux) < 0) \
elm = elm->field.sle_next[i]; \
path[i] = elm; \
ARRAY_SET_LENGTH(path, ARRAY_LENGTH(path)+1); \
} while(i--); \
ARRAY_SET_LENGTH(path, ARRAY_LENGTH(path) + 1); \
} while (i--); \
i = 0; \
prev = elm; \
elm = elm->field.sle_next[0]; \
if (slist->cmp(slist, elm, n, slist->aux) == 0) { \
ARRAY_FREE(path); \
if (__skip_key_compare_##decl(slist, elm, n, slist->aux) == 0) { \
/* Don't overwrite, to do that use _REPLACE not _INSERT */ \
ARRAY_FREE(path); \
return -1; \
} \
size_t level = __skip_toss_##decl(slist->max, slist->fanout); \
@ -352,9 +419,13 @@ struct sl_trace {
} \
\
/* -- __skip_integrity_check_ */ \
static int __skip_integrity_check_##decl() { \
static int __skip_integrity_check_##decl(decl##_t *slist) \
{ \
((void)slist); /* TODO */ \
return 0; \
} \
}
#define SKIPLIST_DECL_DOT(decl, prefix, field) \
\
/* A type for a function that writes into a char[2048] buffer \
* a description of the value within the node. */ \
@ -363,16 +434,21 @@ struct sl_trace {
/* -- __skip_dot_node_ \
* Writes out a fragment of a DOT file representing a node. \
*/ \
static void __skip_dot_node_##decl(FILE *os, decl##_t *slist, decl##_node_t *node, size_t nsg, skip_sprintf_node_##decl##_t fn) { \
fprintf(os, "\"node%zu%p\"", nsg, (void*)node); \
fprintf(os, " [label = \""); \
size_t level = ARRAY_LENGTH(node->field.sle_next); \
do { \
fprintf(os, " { <w%zu> | <f%zu> %p }", level, level, (void*)node->field.sle_next[level]); \
if (level != 0) fprintf(os, " | "); \
} while(level--); \
if (fn) { \
static void __skip_dot_node_##decl(FILE *os, decl##_t *slist, \
decl##_node_t *node, size_t nsg, skip_sprintf_node_##decl##_t fn) \
{ \
char buf[2048]; \
size_t level, height = ARRAY_LENGTH(node->field.sle_next); \
fprintf(os, "\"node%zu%p\"", nsg, (void *)node); \
fprintf(os, " [label = \""); \
level = height; \
do { \
fprintf(os, " { <w%zu> | <f%zu> %p }", level + 1, level + 1, \
(void *)node->field.sle_next[level]); \
if (level != 0) \
fprintf(os, " | "); \
} while (level--); \
if (fn) { \
fn(node, buf); \
fprintf(os, " <f0> %s\"\n", buf); \
} else { \
@ -383,30 +459,30 @@ struct sl_trace {
\
/* Now edges */ \
level = 0; \
size_t size = ARRAY_LENGTH(node->field.sle_next); \
for (size_t level = 0; level <= size; level++) { \
fprintf(os, "\"node%zu%p\"", nsg, (void*)node); \
fprintf(os, ":f%zu -> ", level); \
fprintf(os, "\"node%zu%p\"", nsg, (void*)node->field.sle_next[level]); \
fprintf(os, ":w%zu [];\n", level); \
for (level = 0; level < height; level++) { \
fprintf(os, "\"node%zu%p\"", nsg, (void *)node); \
fprintf(os, ":f%zu -> ", level + 1); \
fprintf(os, "\"node%zu%p\"", nsg, (void *)node->field.sle_next[level]); \
fprintf(os, ":w%zu [];\n", level + 1); \
} \
\
if (node->field.sle_next[0]) \
if (node->field.sle_next[0] != SKIP_LAST(slist)) \
__skip_dot_node_##decl(os, slist, node->field.sle_next[0], nsg, fn); \
} \
\
/* -- __skip_dot_finish_ \
* Finalise the DOT file of the internal representation. \
*/ \
static void __skip_dot_finish_##decl(FILE *os, size_t nsg) { \
static void __skip_dot_finish_##decl(FILE *os, size_t nsg) \
{ \
size_t i; \
if (nsg > 0) { \
/* Link the nodes together with an invisible node. \
* node0 [shape=record, label = "<f0> | <f1> | <f2> | <f3> | <f4> | <f5> | <f6> | <f7> | <f8> | ", \
* style=invis, \
* width=0.01]; \
* node0 [shape=record, label = "<f0> | <f1> | <f2> | <f3> | \
* <f4> | <f5> | <f6> | <f7> | <f8> | ", style=invis, width=0.01]; \
*/ \
fprintf(os, "node0 [shape=record, label = \""); \
for (size_t i = 0; i < nsg; ++i) { \
for (i = 0; i < nsg; ++i) { \
fprintf(os, "<f%zu> | ", i); \
} \
fprintf(os, "\", style=invis, width=0.01];\n"); \
@ -416,8 +492,8 @@ struct sl_trace {
* node0:f0 -> HeadNode [style=invis]; \
* node0:f1 -> HeadNode1 [style=invis]; \
*/ \
for (size_t i = 0; i < nsg; ++i) { \
fprintf(os, "node0:f%zu -> HeadNode%zu [style=invis];\n", i, i);\
for (i = 0; i < nsg; ++i) { \
fprintf(os, "node0:f%zu -> HeadNode%zu [style=invis];\n", i, i); \
} \
nsg = 0; \
} \
@ -425,7 +501,11 @@ struct sl_trace {
} \
\
/* -- skip_dot_start_ */ \
static int __skip_dot_start_##decl(FILE *os, decl##_t *slist, size_t nsg, skip_sprintf_node_##decl##_t fn) { \
static int __skip_dot_start_##decl(FILE *os, decl##_t *slist, size_t nsg, \
skip_sprintf_node_##decl##_t fn) \
{ \
size_t level; \
decl##_node_t *head; \
if (nsg == 0) { \
fprintf(os, "digraph Skiplist {\n"); \
fprintf(os, "label = \"Skiplist.\"\n"); \
@ -439,16 +519,18 @@ struct sl_trace {
fprintf(os, "\"HeadNode%zu\" [\n", nsg); \
fprintf(os, "label = \""); \
\
/* Write out the head node fields */ \
decl##_node_t *head = slist->slh_head; \
size_t level; \
if (SKIP_EMPTY(slist)) fprintf(os, "Empty HeadNode"); else { \
level = ARRAY_LENGTH(head->field.sle_next) - 1; \
do { \
/* Write out the fields */ \
head = slist->slh_head; \
if (SKIP_EMPTY(slist)) \
fprintf(os, "Empty HeadNode"); \
else { \
level = ARRAY_LENGTH(head->field.sle_next); \
while (level--) { \
decl##_node_t *node = head->field.sle_next[level]; \
fprintf(os, "{ <f%zu> %p }", level, (void *)node); \
if (level != 0) fprintf(os, " | "); \
} while(level--); \
fprintf(os, "{ <f%zu> %p }", level + 1, (void *)node); \
if (level + 1 != 0) \
fprintf(os, " | "); \
} \
} \
fprintf(os, "\"\n"); \
fprintf(os, "shape = \"record\"\n"); \
@ -458,27 +540,27 @@ struct sl_trace {
decl##_node_t *node = slist->slh_head; \
level = 0; \
do { \
fprintf(os, "\"HeadNode%zu\":f%zu -> ", nsg, level); \
fprintf(os, "\"node%zu%p\"", nsg, (void*)node->field.sle_next[level]); \
fprintf(os, ":w%zu [];\n", level); \
} while(level++ < slist->level); \
fprintf(os, "\"HeadNode%zu\":f%zu -> ", nsg, level + 1); \
fprintf(os, "\"node%zu%p\"", nsg, (void *)node->field.sle_next[level]); \
fprintf(os, ":w%zu [];\n", level + 1); \
} while (level++ < slist->level); \
fprintf(os, "}\n\n"); \
\
/* Now all nodes via level 0, if non-empty */ \
node = slist->slh_head; \
if (ARRAY_LENGTH(node->field.sle_next)) \
__skip_dot_node_##decl(os, slist, node, nsg, fn); \
__skip_dot_node_##decl(os, slist, node->field.sle_next[0], nsg, fn); \
fprintf(os, "\n"); \
\
/* The tail, sentinal node */ \
if (!SKIP_EMPTY(slist)) { \
fprintf(os,"\"node%zu0x0\" [label = \"", nsg); \
size_t level = slist->level; \
fprintf(os, "\"node%zu0x0\" [label = \"", nsg); \
level = slist->level; \
do { \
fprintf(os, "<w%zu> NULL", level); \
fprintf(os, "<w%zu> NULL", level + 1); \
if (level != 0) \
fprintf(os, " | "); \
} while(level-- > 0); \
} while (level-- > 0); \
fprintf(os, "\" shape = \"record\"];\n"); \
} \
\
@ -501,43 +583,44 @@ struct sl_trace {
* \
* https://en.wikipedia.org/wiki/DOT_(graph_description_language) \
*/ \
int prefix##skip_dot_##decl(FILE *os, decl##_t *slist, skip_sprintf_node_##decl##_t fn) { \
int prefix##skip_dot_##decl(FILE *os, decl##_t *slist, \
skip_sprintf_node_##decl##_t fn) \
{ \
size_t nsg = 0; \
if (__skip_integrity_check_##decl(slist) != 0) { \
perror("Skiplist failed integrity checks, impossible to diagram.");\
perror("Skiplist failed integrity checks, impossible to diagram."); \
return -1; \
} \
if (os == NULL) \
os = stdout; \
if (!os) { \
perror("Failed to open output file, unable to write DOT file.");\
perror("Failed to open output file, unable to write DOT file."); \
return -1; \
} \
__skip_dot_start_##decl(os, slist, nsg, fn); \
__skip_dot_finish_##decl(os, nsg); \
return 0; \
} \
/* END */
}
#if 0
#define SKIP_REMOVE(head, elm, field) do { \
#define SKIP_REMOVE(head, elm, field) \
do { \
if ((elm)->field.le_next != NULL) \
(elm)->field.le_next->field.le_prev = \
(elm)->field.le_prev; \
(elm)->field.le_next->field.le_prev = (elm)->field.le_prev; \
*(elm)->field.le_prev = (elm)->field.le_next; \
_Q_INVALIDATE((elm)->field.le_prev); \
_Q_INVALIDATE((elm)->field.le_next); \
} while (0)
} while (0)
#define SKIP_REPLACE(elm, elm2, field) do { \
#define SKIP_REPLACE(elm, elm2, field) \
do { \
if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \
(elm2)->field.le_next->field.le_prev = \
&(elm2)->field.le_next; \
(elm2)->field.le_next->field.le_prev = &(elm2)->field.le_next; \
(elm2)->field.le_prev = (elm)->field.le_prev; \
*(elm2)->field.le_prev = (elm2); \
_Q_INVALIDATE((elm)->field.le_prev); \
_Q_INVALIDATE((elm)->field.le_next); \
} while (0)
} while (0)
#endif
#endif /* _SYS_SKIPLIST_H_ */

View file

@ -585,16 +585,14 @@ insert_retry:;
/* check if prev node is duplicated with upper
* layer */
if (cur_layer < top_layer &&
prev[cur_layer] == prev[cur_layer + 1]) {
if (cur_layer < top_layer && prev[cur_layer] == prev[cur_layer + 1]) {
/* duplicate
=> which means that
'being_modified' flag is already true
=> do nothing */
} else {
bool expected = false;
if (ATM_CAS(prev[cur_layer]->being_modified, expected,
bool_true)) {
if (ATM_CAS(prev[cur_layer]->being_modified, expected, bool_true)) {
locked_layer = cur_layer;
} else {
error_code = -1;
@ -645,13 +643,13 @@ insert_retry:;
__sl_write_lock_an(prev[layer]);
exp = next[layer];
if (!ATM_CAS(prev[layer]->next[layer], exp, node)) {
__SLD_P("%02x ASSERT ins %p[%d] -> %p (expected %p)\n",
(int)tid_hash, prev[layer], cur_layer,
ATM_GET(prev[layer]->next[layer]), next[layer]);
__SLD_P("%02x ASSERT ins %p[%d] -> %p (expected %p)\n", (int)tid_hash,
prev[layer], cur_layer, ATM_GET(prev[layer]->next[layer]),
next[layer]);
assert(0);
}
__SLD_P("%02x ins %p[%d] -> %p -> %p\n", (int)tid_hash,
prev[layer], layer, node, ATM_GET(node->next[layer]));
__SLD_P("%02x ins %p[%d] -> %p -> %p\n", (int)tid_hash, prev[layer],
layer, node, ATM_GET(node->next[layer]));
__sl_write_unlock_an(prev[layer]);
}
@ -929,16 +927,14 @@ erase_node_retry:
/* check if prev node duplicates with upper layer */
error_code = 0;
locked_layer = cur_layer + 1;
if (cur_layer < top_layer &&
prev[cur_layer] == prev[cur_layer + 1]) {
if (cur_layer < top_layer && prev[cur_layer] == prev[cur_layer + 1]) {
/* duplicate with upper layer
=> which means that 'being_modified'
flag is already true
=> do nothing. */
} else {
expected = false;
if (ATM_CAS(prev[cur_layer]->being_modified, expected,
bool_true)) {
if (ATM_CAS(prev[cur_layer]->being_modified, expected, bool_true)) {
locked_layer = cur_layer;
} else {
error_code = -1;
@ -958,13 +954,11 @@ erase_node_retry:
goto erase_node_retry;
}
next_node_again = __sl_fnd_next(cur_node, cur_layer, node,
NULL);
next_node_again = __sl_fnd_next(cur_node, cur_layer, node, NULL);
ATM_FETCH_SUB(next_node_again->ref_count, 1);
if (next_node_again != next[cur_layer]) {
/* `next` pointer has been changed, retry */
__SLD_NC_RMV(cur_node, next[cur_layer], top_layer,
cur_layer);
__SLD_NC_RMV(cur_node, next[cur_layer], top_layer, cur_layer);
__sl_clr_flags(prev, cur_layer, top_layer);
ATM_FETCH_SUB(cur_node->ref_count, 1);
YIELD();
@ -994,13 +988,13 @@ erase_node_retry:
assert(next[cur_layer]->is_fully_linked);
if (!ATM_CAS(prev[cur_layer]->next[cur_layer], exp, next[cur_layer])) {
__SLD_P("%02x ASSERT rmv %p[%d] -> %p (node %p)\n", (int)tid_hash,
prev[cur_layer], cur_layer,
ATM_GET(prev[cur_layer]->next[cur_layer]), node);
prev[cur_layer], cur_layer, ATM_GET(prev[cur_layer]->next[cur_layer]),
node);
assert(0);
}
assert(next[cur_layer]->top_layer >= cur_layer);
__SLD_P("%02x rmv %p[%d] -> %p (node %p)\n", (int)tid_hash,
prev[cur_layer], cur_layer, next[cur_layer], node);
__SLD_P("%02x rmv %p[%d] -> %p (node %p)\n", (int)tid_hash, prev[cur_layer],
cur_layer, next[cur_layer], node);
__sl_write_unlock_an(prev[cur_layer]);
}

View file

@ -513,8 +513,7 @@ struct PsnipClockTimespec {
(defined(PSNIP_CLOCK_WALL_METHOD) && \
(PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_GETPROCESSTIMES)) || \
(defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \
(PSNIP_CLOCK_MONOTONIC_METHOD == \
PSNIP_CLOCK_METHOD_GETPROCESSTIMES)) || \
(PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_GETPROCESSTIMES)) || \
(defined(PSNIP_CLOCK_CPU_METHOD) && \
(PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_GETTICKCOUNT64)) || \
(defined(PSNIP_CLOCK_WALL_METHOD) && \
@ -539,8 +538,7 @@ struct PsnipClockTimespec {
(defined(PSNIP_CLOCK_WALL_METHOD) && \
(PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_MACH_ABSOLUTE_TIME)) || \
(defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \
(PSNIP_CLOCK_MONOTONIC_METHOD == \
PSNIP_CLOCK_METHOD_MACH_ABSOLUTE_TIME))
(PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_MACH_ABSOLUTE_TIME))
#include <CoreServices/CoreServices.h>
#include <mach/mach.h>
#include <mach/mach_time.h>
@ -832,8 +830,7 @@ static psnip_uint64_t
munit_clock_get_elapsed(struct PsnipClockTimespec *start,
struct PsnipClockTimespec *end)
{
psnip_uint64_t r = (end->seconds - start->seconds) *
PSNIP_CLOCK_NSEC_PER_SEC;
psnip_uint64_t r = (end->seconds - start->seconds) * PSNIP_CLOCK_NSEC_PER_SEC;
if (end->nanoseconds < start->nanoseconds) {
r -= (start->nanoseconds - end->nanoseconds);
} else {
@ -943,8 +940,8 @@ munit_atomic_cas(ATOMIC_UINT32_T *dest, ATOMIC_UINT32_T *expected,
__c11_atomic_store(dest, value, __ATOMIC_SEQ_CST)
#define munit_atomic_load(src) __c11_atomic_load(src, __ATOMIC_SEQ_CST)
#define munit_atomic_cas(dest, expected, value) \
__c11_atomic_compare_exchange_weak(dest, expected, value, \
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
__c11_atomic_compare_exchange_weak(dest, expected, value, __ATOMIC_SEQ_CST, \
__ATOMIC_SEQ_CST)
#elif defined(__GNUC__) && (__GNUC__ > 4) || \
(__GNUC__ == 4 && __GNUC_MINOR__ >= 7)
#define munit_atomic_store(dest, value) \
@ -1001,8 +998,7 @@ munit_rand_next_state(munit_uint32_t state)
static munit_uint32_t
munit_rand_from_state(munit_uint32_t state)
{
munit_uint32_t res = ((state >> ((state >> 28) + 4)) ^ state) *
(277803737U);
munit_uint32_t res = ((state >> ((state >> 28) + 4)) ^ state) * (277803737U);
res ^= res >> 22;
return res;
}
@ -1147,8 +1143,7 @@ munit_rand_double(void)
/* See http://mumble.net/~campbell/tmp/random_real.c for how to do
* this right. Patches welcome if you feel that this is too
* biased. */
retval = munit_rand_state_uint32(&state) /
((~((munit_uint32_t)0U)) + 1.0);
retval = munit_rand_state_uint32(&state) / ((~((munit_uint32_t)0U)) + 1.0);
} while (!munit_atomic_cas(&munit_rand_state, &old, state));
return retval;
@ -1325,8 +1320,7 @@ munit_test_runner_exec(MunitTestRunner *runner, const MunitTest *test,
munit_rand_seed(runner->seed);
do {
void *data = (test->setup == NULL) ?
runner->user_data :
void *data = (test->setup == NULL) ? runner->user_data :
test->setup(params, runner->user_data);
#if defined(MUNIT_ENABLE_TIMING)
@ -1522,8 +1516,7 @@ munit_test_runner_run_test_with_params(MunitTestRunner *runner,
sizeof(report) - bytes_written);
if (write_res < 0) {
if (stderr_buf != NULL) {
munit_log_errno(MUNIT_LOG_ERROR, stderr,
"unable to write to pipe");
munit_log_errno(MUNIT_LOG_ERROR, stderr, "unable to write to pipe");
}
exit(EXIT_FAILURE);
}
@ -1546,8 +1539,7 @@ munit_test_runner_run_test_with_params(MunitTestRunner *runner,
} else {
close(pipefd[1]);
do {
read_res = read(pipefd[0],
((munit_uint8_t *)(&report)) + bytes_read,
read_res = read(pipefd[0], ((munit_uint8_t *)(&report)) + bytes_read,
sizeof(report) - bytes_read);
if (read_res < 1)
break;
@ -1560,8 +1552,7 @@ munit_test_runner_run_test_with_params(MunitTestRunner *runner,
MUNIT_LIKELY(WIFEXITED(status))) {
if (bytes_read != sizeof(report)) {
munit_logf_internal(MUNIT_LOG_ERROR, stderr_buf,
"child exited unexpectedly with status %d",
WEXITSTATUS(status));
"child exited unexpectedly with status %d", WEXITSTATUS(status));
report.errored++;
} else if (WEXITSTATUS(status) != EXIT_SUCCESS) {
munit_logf_internal(MUNIT_LOG_ERROR, stderr_buf,
@ -1621,12 +1612,10 @@ print_result:
fputs("[ ", MUNIT_OUTPUT_FILE);
if ((test->options & MUNIT_TEST_OPTION_TODO) == MUNIT_TEST_OPTION_TODO) {
if (report.failed != 0 || report.errored != 0 || report.skipped != 0) {
munit_test_runner_print_color(runner, MUNIT_RESULT_STRING_TODO,
'3');
munit_test_runner_print_color(runner, MUNIT_RESULT_STRING_TODO, '3');
result = MUNIT_OK;
} else {
munit_test_runner_print_color(runner, MUNIT_RESULT_STRING_ERROR,
'1');
munit_test_runner_print_color(runner, MUNIT_RESULT_STRING_ERROR, '1');
if (MUNIT_LIKELY(stderr_buf != NULL))
munit_log_internal(MUNIT_LOG_ERROR, stderr_buf,
"Test marked TODO, but was successful.");
@ -1649,14 +1638,11 @@ print_result:
munit_test_runner_print_color(runner, MUNIT_RESULT_STRING_OK, '2');
#if defined(MUNIT_ENABLE_TIMING)
fputs(" ] [ ", MUNIT_OUTPUT_FILE);
munit_print_time(MUNIT_OUTPUT_FILE,
report.wall_clock / report.successful);
munit_print_time(MUNIT_OUTPUT_FILE, report.wall_clock / report.successful);
fputs(" / ", MUNIT_OUTPUT_FILE);
munit_print_time(MUNIT_OUTPUT_FILE,
report.cpu_clock / report.successful);
munit_print_time(MUNIT_OUTPUT_FILE, report.cpu_clock / report.successful);
fprintf(MUNIT_OUTPUT_FILE,
" CPU ]\n %-" MUNIT_XSTRINGIFY(MUNIT_TEST_NAME_LEN) "s Total: [ ",
"");
" CPU ]\n %-" MUNIT_XSTRINGIFY(MUNIT_TEST_NAME_LEN) "s Total: [ ", "");
munit_print_time(MUNIT_OUTPUT_FILE, report.wall_clock);
fputs(" / ", MUNIT_OUTPUT_FILE);
munit_print_time(MUNIT_OUTPUT_FILE, report.cpu_clock);
@ -1679,8 +1665,7 @@ print_result:
fputs(" ]\n", MUNIT_OUTPUT_FILE);
if (stderr_buf != NULL) {
if (result == MUNIT_FAIL || result == MUNIT_ERROR ||
runner->show_stderr) {
if (result == MUNIT_FAIL || result == MUNIT_ERROR || runner->show_stderr) {
fflush(MUNIT_OUTPUT_FILE);
rewind(stderr_buf);
@ -1715,8 +1700,7 @@ munit_test_runner_run_test_wild(MunitTestRunner *runner, const MunitTest *test,
if (next->name == NULL) {
munit_test_runner_run_test_with_params(runner, test, params);
} else {
munit_test_runner_run_test_wild(runner, test, test_name, params,
next);
munit_test_runner_run_test_wild(runner, test, test_name, params, next);
}
if (runner->fatal_failures &&
(runner->report.failed != 0 || runner->report.errored != 0))
@ -1767,11 +1751,11 @@ munit_test_runner_run_test(MunitTestRunner *runner, const MunitTest *test,
for (pe = test->parameters; pe != NULL && pe->name != NULL; pe++) {
/* Did we received a value for this parameter from the CLI? */
filled = 0;
for (cli_p = runner->parameters;
cli_p != NULL && cli_p->name != NULL; cli_p++) {
for (cli_p = runner->parameters; cli_p != NULL && cli_p->name != NULL;
cli_p++) {
if (strcmp(cli_p->name, pe->name) == 0) {
if (MUNIT_UNLIKELY(munit_parameters_add(&params_l, &params,
pe->name, cli_p->value) != MUNIT_OK))
if (MUNIT_UNLIKELY(munit_parameters_add(&params_l, &params, pe->name,
cli_p->value) != MUNIT_OK))
goto cleanup;
filled = 1;
break;
@ -1795,16 +1779,14 @@ munit_test_runner_run_test(MunitTestRunner *runner, const MunitTest *test,
* running a single test, but we don't want every test with
* the same number of parameters to choose the same parameter
* number, so use the test name as a primitive salt. */
pidx = munit_rand_at_most(munit_str_hash(test_name),
possible - 1);
if (MUNIT_UNLIKELY(munit_parameters_add(&params_l, &params,
pe->name, pe->values[pidx]) != MUNIT_OK))
pidx = munit_rand_at_most(munit_str_hash(test_name), possible - 1);
if (MUNIT_UNLIKELY(munit_parameters_add(&params_l, &params, pe->name,
pe->values[pidx]) != MUNIT_OK))
goto cleanup;
} else {
/* We want to try every permutation. Put in a placeholder
* entry, we'll iterate through them later. */
if (MUNIT_UNLIKELY(
munit_parameters_add(&wild_params_l, &wild_params,
if (MUNIT_UNLIKELY(munit_parameters_add(&wild_params_l, &wild_params,
pe->name, NULL) != MUNIT_OK))
goto cleanup;
}
@ -1814,11 +1796,9 @@ munit_test_runner_run_test(MunitTestRunner *runner, const MunitTest *test,
first_wild = params_l;
for (wp = wild_params; wp != NULL && wp->name != NULL; wp++) {
for (pe = test->parameters;
pe != NULL && pe->name != NULL && pe->values != NULL;
pe++) {
pe != NULL && pe->name != NULL && pe->values != NULL; pe++) {
if (strcmp(wp->name, pe->name) == 0) {
if (MUNIT_UNLIKELY(
munit_parameters_add(&params_l, &params,
if (MUNIT_UNLIKELY(munit_parameters_add(&params_l, &params,
pe->name, pe->values[0]) != MUNIT_OK))
goto cleanup;
}
@ -1847,25 +1827,22 @@ munit_test_runner_run_suite(MunitTestRunner *runner, const MunitSuite *suite,
const char *prefix)
{
size_t pre_l;
char *pre = munit_maybe_concat(&pre_l, (char *)prefix,
(char *)suite->prefix);
char *pre = munit_maybe_concat(&pre_l, (char *)prefix, (char *)suite->prefix);
const MunitTest *test;
const char **test_name;
const MunitSuite *child_suite;
/* Run the tests. */
for (test = suite->tests; test != NULL && test->test != NULL; test++) {
if (runner->tests !=
NULL) { /* Specific tests were requested on the CLI */
for (test_name = runner->tests;
test_name != NULL && *test_name != NULL; test_name++) {
if (runner->tests != NULL) { /* Specific tests were requested on the CLI */
for (test_name = runner->tests; test_name != NULL && *test_name != NULL;
test_name++) {
if ((pre_l == 0 || strncmp(pre, *test_name, pre_l) == 0) &&
strncmp(test->name, *test_name + pre_l,
strlen(*test_name + pre_l)) == 0) {
strncmp(test->name, *test_name + pre_l, strlen(*test_name + pre_l)) ==
0) {
munit_test_runner_run_test(runner, test, pre);
if (runner->fatal_failures &&
(runner->report.failed != 0 ||
runner->report.errored != 0))
(runner->report.failed != 0 || runner->report.errored != 0))
goto cleanup;
}
}
@ -1946,8 +1923,7 @@ munit_print_help(int argc, char *const argv[MUNIT_ARRAY_PARAM(argc + 1)],
#endif
printf(" %d.%d.%d\n"
"Full documentation at: https://nemequ.github.io/munit/\n",
(MUNIT_CURRENT_VERSION >> 16) & 0xff,
(MUNIT_CURRENT_VERSION >> 8) & 0xff,
(MUNIT_CURRENT_VERSION >> 16) & 0xff, (MUNIT_CURRENT_VERSION >> 8) & 0xff,
(MUNIT_CURRENT_VERSION >> 0) & 0xff);
for (arg = arguments; arg != NULL && arg->name != NULL; arg++)
arg->write_help(arg, user_data);
@ -1970,8 +1946,7 @@ munit_suite_list_tests(const MunitSuite *suite, munit_bool show_params,
const char *prefix)
{
size_t pre_l;
char *pre = munit_maybe_concat(&pre_l, (char *)prefix,
(char *)suite->prefix);
char *pre = munit_maybe_concat(&pre_l, (char *)prefix, (char *)suite->prefix);
const MunitTest *test;
const MunitParameterEnum *params;
munit_bool first;
@ -1984,8 +1959,8 @@ munit_suite_list_tests(const MunitSuite *suite, munit_bool show_params,
puts(test->name);
if (show_params) {
for (params = test->parameters;
params != NULL && params->name != NULL; params++) {
for (params = test->parameters; params != NULL && params->name != NULL;
params++) {
fprintf(stdout, " - %s: ", params->name);
if (params->values == NULL) {
puts("Any");
@ -2101,8 +2076,7 @@ munit_suite_main_custom(const MunitSuite *suite, void *user_data, int argc,
ts = strtoul(argv[arg + 1], &envptr, 0);
if (*envptr != '\0' || ts > (~((munit_uint32_t)0U))) {
munit_logf_internal(MUNIT_LOG_ERROR, stderr,
"invalid value ('%s') passed to %s", argv[arg + 1],
argv[arg]);
"invalid value ('%s') passed to %s", argv[arg + 1], argv[arg]);
goto cleanup;
}
runner.seed = (munit_uint32_t)ts;
@ -2119,8 +2093,7 @@ munit_suite_main_custom(const MunitSuite *suite, void *user_data, int argc,
iterations = strtoul(argv[arg + 1], &endptr, 0);
if (*endptr != '\0' || iterations > UINT_MAX) {
munit_logf_internal(MUNIT_LOG_ERROR, stderr,
"invalid value ('%s') passed to %s", argv[arg + 1],
argv[arg]);
"invalid value ('%s') passed to %s", argv[arg + 1], argv[arg]);
goto cleanup;
}
@ -2142,8 +2115,7 @@ munit_suite_main_custom(const MunitSuite *suite, void *user_data, int argc,
goto cleanup;
}
runner.parameters[parameters_size].name = (char *)argv[arg + 1];
runner.parameters[parameters_size].value = (char *)
argv[arg + 2];
runner.parameters[parameters_size].value = (char *)argv[arg + 2];
parameters_size++;
runner.parameters[parameters_size].name = NULL;
runner.parameters[parameters_size].value = NULL;
@ -2160,12 +2132,10 @@ munit_suite_main_custom(const MunitSuite *suite, void *user_data, int argc,
else if (strcmp(argv[arg + 1], "never") == 0)
runner.colorize = 0;
else if (strcmp(argv[arg + 1], "auto") == 0)
runner.colorize = munit_stream_supports_ansi(
MUNIT_OUTPUT_FILE);
runner.colorize = munit_stream_supports_ansi(MUNIT_OUTPUT_FILE);
else {
munit_logf_internal(MUNIT_LOG_ERROR, stderr,
"invalid value ('%s') passed to %s", argv[arg + 1],
argv[arg]);
"invalid value ('%s') passed to %s", argv[arg + 1], argv[arg]);
goto cleanup;
}
@ -2202,8 +2172,7 @@ munit_suite_main_custom(const MunitSuite *suite, void *user_data, int argc,
level = MUNIT_LOG_ERROR;
else {
munit_logf_internal(MUNIT_LOG_ERROR, stderr,
"invalid value ('%s') passed to %s", argv[arg + 1],
argv[arg]);
"invalid value ('%s') passed to %s", argv[arg + 1], argv[arg]);
goto cleanup;
}
@ -2229,8 +2198,7 @@ munit_suite_main_custom(const MunitSuite *suite, void *user_data, int argc,
goto cleanup;
}
if (!argument->parse_argument(suite, user_data, &arg, argc,
argv))
if (!argument->parse_argument(suite, user_data, &arg, argc, argv))
goto cleanup;
}
} else {

View file

@ -309,8 +309,7 @@ void munit_errorf_ex(const char *filename, int line, const char *format, ...);
const char *munit_tmp_a_ = a; \
const char *munit_tmp_b_ = b; \
if (MUNIT_UNLIKELY(strcmp(munit_tmp_a_, munit_tmp_b_) != 0)) { \
munit_errorf( \
"assertion failed: string %s == %s (\"%s\" == \"%s\")", #a, \
munit_errorf("assertion failed: string %s == %s (\"%s\" == \"%s\")", #a, \
#b, munit_tmp_a_, munit_tmp_b_); \
} \
MUNIT_PUSH_DISABLE_MSVC_C4127_ \
@ -321,8 +320,7 @@ void munit_errorf_ex(const char *filename, int line, const char *format, ...);
const char *munit_tmp_a_ = a; \
const char *munit_tmp_b_ = b; \
if (MUNIT_UNLIKELY(strcmp(munit_tmp_a_, munit_tmp_b_) == 0)) { \
munit_errorf( \
"assertion failed: string %s != %s (\"%s\" == \"%s\")", #a, \
munit_errorf("assertion failed: string %s != %s (\"%s\" == \"%s\")", #a, \
#b, munit_tmp_a_, munit_tmp_b_); \
} \
MUNIT_PUSH_DISABLE_MSVC_C4127_ \
@ -333,13 +331,12 @@ void munit_errorf_ex(const char *filename, int line, const char *format, ...);
const unsigned char *munit_tmp_a_ = (const unsigned char *)(a); \
const unsigned char *munit_tmp_b_ = (const unsigned char *)(b); \
const size_t munit_tmp_size_ = (size); \
if (MUNIT_UNLIKELY( \
memcmp(munit_tmp_a_, munit_tmp_b_, munit_tmp_size_)) != 0) { \
if (MUNIT_UNLIKELY(memcmp(munit_tmp_a_, munit_tmp_b_, munit_tmp_size_)) != \
0) { \
size_t munit_tmp_pos_; \
for (munit_tmp_pos_ = 0; munit_tmp_pos_ < munit_tmp_size_; \
munit_tmp_pos_++) { \
if (munit_tmp_a_[munit_tmp_pos_] != \
munit_tmp_b_[munit_tmp_pos_]) { \
if (munit_tmp_a_[munit_tmp_pos_] != munit_tmp_b_[munit_tmp_pos_]) { \
munit_errorf( \
"assertion failed: memory %s == %s, at offset %" MUNIT_SIZE_MODIFIER \
"u", \
@ -356,10 +353,10 @@ void munit_errorf_ex(const char *filename, int line, const char *format, ...);
const unsigned char *munit_tmp_a_ = (const unsigned char *)(a); \
const unsigned char *munit_tmp_b_ = (const unsigned char *)(b); \
const size_t munit_tmp_size_ = (size); \
if (MUNIT_UNLIKELY( \
memcmp(munit_tmp_a_, munit_tmp_b_, munit_tmp_size_)) == 0) { \
munit_errorf("assertion failed: memory %s != %s (%zu bytes)", #a, \
#b, munit_tmp_size_); \
if (MUNIT_UNLIKELY(memcmp(munit_tmp_a_, munit_tmp_b_, munit_tmp_size_)) == \
0) { \
munit_errorf("assertion failed: memory %s != %s (%zu bytes)", #a, #b, \
munit_tmp_size_); \
} \
MUNIT_PUSH_DISABLE_MSVC_C4127_ \
} while (0) MUNIT_POP_DISABLE_MSVC_C4127_

View file

@ -122,7 +122,8 @@ uint32_key_cmp(sl_node *a, sl_node *b, void *aux)
}
static size_t
__populate_slist(ex_sl_t *slist){
__populate_slist(ex_sl_t *slist)
{
size_t inserted = 0;
uint32_t n, key;
ex_node_t *node;
@ -203,7 +204,7 @@ test_api_insert(const MunitParameter params[], void *data)
assert_ptr_not_null(slist);
n = munit_rand_int_range(4096, 8192);
while (n--) {
key = munit_rand_int_range(0, ((uint32_t)0-1) / 10);
key = munit_rand_int_range(0, ((uint32_t)0 - 1) / 10);
node = (ex_node_t *)calloc(sizeof(ex_node_t), 1);
if (node == NULL)
return MUNIT_ERROR;
@ -242,7 +243,7 @@ test_api_remove(const MunitParameter params[], void *data)
(void)params;
assert_ptr_not_null(slist);
key = munit_rand_int_range((((uint32_t)0-1) / 10) + 1, ((uint32_t)0-1));
key = munit_rand_int_range((((uint32_t)0 - 1) / 10) + 1, ((uint32_t)0 - 1));
node = (ex_node_t *)calloc(sizeof(ex_node_t), 1);
if (node == NULL)
return MUNIT_ERROR;