From 0ba5923568ef1bf13eee30012fbf2977fe8b5a7c Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 29 Jan 2015 21:32:56 -0800 Subject: Use macro to initialize cobj_ops. * lib.h (cobj_ops_init): New macro. * hash.c (hash_ops, hash_iter_ops): Initialize with cobj_ops_init. * rand.c (random_state_ops): Likewise. * regex.c (char_set_obj_ops, regex_obj_ops): Likewise. --- ChangeLog | 12 ++++++++++++ hash.c | 24 ++++++++++-------------- lib.h | 3 +++ rand.c | 12 +++++------- regex.c | 24 ++++++++++-------------- 5 files changed, 40 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 869e82ec..450ed480 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2015-01-29 Kaz Kylheku + + Use macro to initialize cobj_ops. + + * lib.h (cobj_ops_init): New macro. + + * hash.c (hash_ops, hash_iter_ops): Initialize with cobj_ops_init. + + * rand.c (random_state_ops): Likewise. + + * regex.c (char_set_obj_ops, regex_obj_ops): Likewise. + 2015-01-29 Kaz Kylheku * arith.c (make_ubignum): New static function. diff --git a/hash.c b/hash.c index 8a4c554b..2a4beda8 100644 --- a/hash.c +++ b/hash.c @@ -426,13 +426,11 @@ static void hash_mark(val hash) } } -static struct cobj_ops hash_ops = { - hash_equal_op, - hash_print_op, - cobj_destroy_free_op, - hash_mark, - hash_hash_op, -}; +static struct cobj_ops hash_ops = cobj_ops_init(hash_equal_op, + hash_print_op, + cobj_destroy_free_op, + hash_mark, + hash_hash_op); static void hash_grow(struct hash *h, val hash) { @@ -655,13 +653,11 @@ static void hash_iter_mark(val hash_iter) reachable_iters = hi; } -static struct cobj_ops hash_iter_ops = { - eq, - cobj_print_op, - cobj_destroy_free_op, - hash_iter_mark, - cobj_hash_op -}; +static struct cobj_ops hash_iter_ops = cobj_ops_init(eq, + cobj_print_op, + cobj_destroy_free_op, + hash_iter_mark, + cobj_hash_op); val hash_begin(val hash) { diff --git a/lib.h b/lib.h index 511f6838..39ffbdbf 100644 --- a/lib.h +++ b/lib.h @@ -204,6 +204,9 @@ struct cobj_ops { cnum (*hash)(val self); }; +#define cobj_ops_init(equal, print, destroy, mark, hash) \ + { equal, print, destroy, mark, hash } + /* Default operations for above structure. * Default equal is eq */ diff --git a/rand.c b/rand.c index 5bbad186..7eff059b 100644 --- a/rand.c +++ b/rand.c @@ -64,13 +64,11 @@ struct rand_state { val random_state_s; -static struct cobj_ops random_state_ops = { - eq, - cobj_print_op, - cobj_destroy_free_op, - cobj_mark_op, - cobj_hash_op -}; +static struct cobj_ops random_state_ops = cobj_ops_init(eq, + cobj_print_op, + cobj_destroy_free_op, + cobj_mark_op, + cobj_hash_op); static val make_state(void) { diff --git a/regex.c b/regex.c index 5c664532..6ee25b9d 100644 --- a/regex.c +++ b/regex.c @@ -797,13 +797,11 @@ static void char_set_cobj_destroy(val chset) chset->co.handle = 0; } -static struct cobj_ops char_set_obj_ops = { - eq, - cobj_print_op, - char_set_cobj_destroy, - cobj_mark_op, - cobj_hash_op -}; +static struct cobj_ops char_set_obj_ops = cobj_ops_init(eq, + cobj_print_op, + char_set_cobj_destroy, + cobj_mark_op, + cobj_hash_op); static nfa_state_t *nfa_state_accept(void) { @@ -1311,13 +1309,11 @@ static void regex_mark(val obj) static void regex_print(val obj, val stream); -static struct cobj_ops regex_obj_ops = { - eq, - regex_print, - regex_destroy, - regex_mark, - cobj_hash_op -}; +static struct cobj_ops regex_obj_ops = cobj_ops_init(eq, + regex_print, + regex_destroy, + regex_mark, + cobj_hash_op); static val reg_nullable(val); -- cgit v1.2.3