Updated to libcsptr 2.0
This commit is contained in:
parent
8233695a2b
commit
fb2416b07b
6 changed files with 40 additions and 10 deletions
2
dependencies/csptr
vendored
2
dependencies/csptr
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 3b6b26f8b3464a70cc76628e4b65b776a7760ba4
|
||||
Subproject commit 74a77900cbc67c69b53d7a3fbefb046bfc76b00c
|
|
@ -47,17 +47,17 @@ struct event *read_event(int fd) {
|
|||
if (read(fd, buf, assert_size) < (ssize_t) assert_size)
|
||||
return NULL;
|
||||
|
||||
return unique_ptr(struct event, ({ .kind = kind, .data = buf }), destroy_event);
|
||||
return unique_ptr(struct event, { .kind = kind, .data = buf }, destroy_event);
|
||||
}
|
||||
case POST_TEST: {
|
||||
double *elapsed_time = malloc(sizeof (double));
|
||||
if (read(fd, elapsed_time, sizeof (double)) < (ssize_t) sizeof (double))
|
||||
return NULL;
|
||||
|
||||
return unique_ptr(struct event, ({ .kind = kind, .data = elapsed_time }), destroy_event);
|
||||
return unique_ptr(struct event, { .kind = kind, .data = elapsed_time }, destroy_event);
|
||||
}
|
||||
default:
|
||||
return unique_ptr(struct event, ({ .kind = kind, .data = NULL }));
|
||||
return unique_ptr(struct event, { .kind = kind, .data = NULL });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ struct process *spawn_test_worker(struct criterion_test *test, void (*func)(stru
|
|||
}
|
||||
|
||||
close(fds[1]);
|
||||
return unique_ptr(struct process, ({ .pid = pid, .in = fds[0] }), close_process);
|
||||
return unique_ptr(struct process, { .pid = pid, .in = fds[0] }, close_process);
|
||||
}
|
||||
|
||||
struct process_status wait_proc(struct process *proc) {
|
||||
|
|
|
@ -66,10 +66,10 @@ static struct criterion_test_set *read_all_tests(void) {
|
|||
|
||||
qsort(tests, nb_tests, sizeof (void *), compare_test);
|
||||
|
||||
return unique_ptr(struct criterion_test_set, ({
|
||||
return unique_ptr(struct criterion_test_set, {
|
||||
.tests = tests,
|
||||
.nb_tests = nb_tests
|
||||
}), destroy_test_set);
|
||||
}, destroy_test_set);
|
||||
}
|
||||
|
||||
static void map_tests(struct criterion_test_set *set, struct criterion_global_stats *stats, void (*fun)(struct criterion_global_stats *, struct criterion_test *)) {
|
||||
|
|
30
src/sorted-list.c
Normal file
30
src/sorted-list.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include <criterion/common.h>
|
||||
#include <criterion/sorted-list.h>
|
||||
#include <csptr/smart_ptr.h>
|
||||
|
||||
static void destroy_sorted_list(void *ptr, UNUSED void *meta) {
|
||||
sfree(((struct criterion_sorted_list *) ptr)->first);
|
||||
}
|
||||
|
||||
struct criterion_sorted_list *new_sorted_list(int (*cmp)(void *, void *)) {
|
||||
return unique_ptr(struct criterion_sorted_list,
|
||||
{ .cmp = cmp }, destroy_sorted_list);
|
||||
}
|
||||
|
||||
void insert_sorted_list(struct criterion_sorted_list *l, void *ptr, size_t size) {
|
||||
struct criterion_sorted_list_node *n, *prev = NULL;
|
||||
for (n = l->first; l->cmp(ptr, n->data) > 0; ++n)
|
||||
prev = n;
|
||||
|
||||
struct criterion_sorted_list_node *new =
|
||||
smalloc(sizeof(struct criterion_sorted_list_node) + size, 0, UNIQUE);
|
||||
|
||||
memcpy(new->data, ptr, size);
|
||||
if (prev) {
|
||||
new->next = prev->next;
|
||||
prev->next = new;
|
||||
} else {
|
||||
new->next = NULL;
|
||||
l->first = new;
|
||||
}
|
||||
}
|
|
@ -43,7 +43,7 @@ static void destroy_stats(void *ptr, UNUSED void *meta) {
|
|||
}
|
||||
|
||||
s_glob_stats *stats_init(void) {
|
||||
return unique_ptr(s_glob_stats, ({0}), destroy_stats);
|
||||
return unique_ptr(s_glob_stats, {0}, destroy_stats);
|
||||
}
|
||||
|
||||
static void destroy_test_stats(void *ptr, UNUSED void *meta) {
|
||||
|
@ -53,11 +53,11 @@ static void destroy_test_stats(void *ptr, UNUSED void *meta) {
|
|||
}
|
||||
|
||||
s_test_stats *test_stats_init(struct criterion_test *t) {
|
||||
return shared_ptr(s_test_stats, ({
|
||||
return shared_ptr(s_test_stats, {
|
||||
.test = t,
|
||||
.progress = t->data->line_,
|
||||
.file = t->data->file_
|
||||
}), destroy_test_stats);
|
||||
}, destroy_test_stats);
|
||||
}
|
||||
|
||||
void stat_push_event(s_glob_stats *stats,
|
||||
|
|
Loading…
Add table
Reference in a new issue