From 50876d6330f6625f302e575131f48acf9d9e2490 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 29 May 2023 13:21:07 -0700 Subject: [PATCH] deque: Replace deque_init_null() by DEQUE_EMPTY_INITIALIZER. --- src/data/casewindow.c | 2 +- src/libpspp/deque.c | 12 +--------- src/libpspp/deque.h | 21 +++++++---------- src/libpspp/model-checker.c | 47 ++++++++++++++++--------------------- src/libpspp/model-checker.h | 1 + 5 files changed, 31 insertions(+), 52 deletions(-) diff --git a/src/data/casewindow.c b/src/data/casewindow.c index 6277c4402d..763ceb2c41 100644 --- a/src/data/casewindow.c +++ b/src/data/casewindow.c @@ -226,7 +226,7 @@ casewindow_memory_create (struct taint *taint UNUSED, const struct caseproto *proto UNUSED) { struct casewindow_memory *cwm = xmalloc (sizeof *cwm); - cwm->cases = deque_init (&cwm->deque, 4, sizeof *cwm->cases); + *cwm = (struct casewindow_memory) { .deque = DEQUE_EMPTY_INITIALIZER }; return cwm; } diff --git a/src/libpspp/deque.c b/src/libpspp/deque.c index a511cf3ad0..6c8e519379 100644 --- a/src/libpspp/deque.c +++ b/src/libpspp/deque.c @@ -23,16 +23,6 @@ #include "gl/minmax.h" #include "gl/xalloc.h" -/* Initializes DEQUE as an empty deque with an initial capacity - of zero. */ -void -deque_init_null (struct deque *deque) -{ - deque->capacity = 0; - deque->front = 0; - deque->back = 0; -} - /* Initializes DEQUE as an empty deque of elements ELEM_SIZE bytes in size, with an initial capacity of at least CAPACITY. Returns the initial deque data array. */ @@ -40,7 +30,7 @@ void * deque_init (struct deque *deque, size_t capacity, size_t elem_size) { void *data = NULL; - deque_init_null (deque); + *deque = (struct deque) DEQUE_EMPTY_INITIALIZER; if (capacity > 0) { deque->capacity = 1; diff --git a/src/libpspp/deque.h b/src/libpspp/deque.h index 151308013c..d5c26e8914 100644 --- a/src/libpspp/deque.h +++ b/src/libpspp/deque.h @@ -16,23 +16,18 @@ /* Deque data structure. - This code slightly simplifies the implementation of a deque as - a circular queue. To use it, declare a "struct deque" and a - pointer to the element type. For example, for a deque of - "int"s: + This code slightly simplifies the implementation of a deque as a circular + queue. To use it, declare a "struct deque" and a pointer to the element + type. For example, for deque of "int"s with an initial capacity of 0: - struct deque deque; - int *data; - - To initialize the deque with a initial capacity of 0: - - deque_init_null (&deque); - data = NULL; + struct deque deque = DEQUE_EMPTY_INITIALIZER; + int *data = NULL; Alternatively, to initialize the deque with an initial minimum capacity of, e.g., 4: - data = deque_init (&deque, 4, sizeof *data); + struct deque deque; + int *data = deque_init (&deque, 4, sizeof *data); Functions that access elements in the deque return array indexes. This is fairly convenient: @@ -75,8 +70,8 @@ struct deque size_t front; /* One past the front of the queue. */ size_t back; /* The back of the queue. */ }; +#define DEQUE_EMPTY_INITIALIZER { .capacity = 0 } -void deque_init_null (struct deque *); void *deque_init (struct deque *, size_t capacity, size_t elem_size); void *deque_expand (struct deque *, void *, size_t elem_size); diff --git a/src/libpspp/model-checker.c b/src/libpspp/model-checker.c index ee13422a04..801bfda769 100644 --- a/src/libpspp/model-checker.c +++ b/src/libpspp/model-checker.c @@ -1683,36 +1683,29 @@ init_mc (struct mc *mc, const struct mc_class *class, } /* Initialize MC. */ - mc->class = class; - mc->options = options; - mc->results = mc_results_create (); - - mc->hash = (mc->options->hash_bits > 0 - ? bitvector_allocate (1 << mc->options->hash_bits) - : NULL); - - mc->queue = NULL; - deque_init_null (&mc->queue_deque); - - mc_path_init (&mc->path); - mc_path_push (&mc->path, 0); - ds_init_empty (&mc->path_string); - mc->state_named = false; - mc->state_error = false; - - mc->progress = 0; - mc->next_progress = mc->options->progress_usec != 0 ? 100 : UINT_MAX; - mc->prev_progress = 0; - mc->prev_progress_time = mc->results->start; + struct mc_results *results = mc_results_create (); + *mc = (struct mc) { + .class = class, + .options = options, + .results = results, + .hash = (options->hash_bits > 0 + ? bitvector_allocate (1 << options->hash_bits) + : NULL), + .queue_deque = DEQUE_EMPTY_INITIALIZER, + .path = MC_PATH_EMPTY_INITIALIZER, + .path_string = DS_EMPTY_INITIALIZER, + .next_progress = options->progress_usec != 0 ? 100 : UINT_MAX, + .prev_progress_time = results->start, + .saved_interrupted_ptr = interrupted_ptr, + .saved_sigint = signal (SIGINT, sigint_handler), + }; - if (mc->options->strategy == MC_RANDOM + interrupted_ptr = &mc->interrupted; + if (options->strategy == MC_RANDOM || options->queue_limit_strategy == MC_DROP_RANDOM) - srand (mc->options->seed); + srand (options->seed); - mc->interrupted = false; - mc->saved_interrupted_ptr = interrupted_ptr; - interrupted_ptr = &mc->interrupted; - mc->saved_sigint = signal (SIGINT, sigint_handler); + mc_path_push (&mc->path, 0); class->init (mc); } diff --git a/src/libpspp/model-checker.h b/src/libpspp/model-checker.h index be97d389bc..b0edd147aa 100644 --- a/src/libpspp/model-checker.h +++ b/src/libpspp/model-checker.h @@ -344,6 +344,7 @@ struct mc_path size_t length; /* Number of operations. */ size_t capacity; /* Number of operations for which room is allocated. */ }; +#define MC_PATH_EMPTY_INITIALIZER { .ops = NULL } void mc_path_init (struct mc_path *); void mc_path_copy (struct mc_path *, const struct mc_path *); -- 2.30.2