From: Ben Pfaff Date: Fri, 21 Nov 2008 20:35:20 +0000 (-0800) Subject: Dynamically allocate switch status categories. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3a7107e9ef6d4c744c86b239042a20f58f81a9b;p=openvswitch Dynamically allocate switch status categories. I got tired of increasing the statically allocated number of categories whenever we exceeded it, so this will make things simpler. --- diff --git a/secchan/status.c b/secchan/status.c index c1e54943..8b6224c4 100644 --- a/secchan/status.c +++ b/secchan/status.c @@ -57,8 +57,8 @@ struct switch_status_category { struct switch_status { const struct settings *s; time_t booted; - struct switch_status_category categories[8]; - int n_categories; + struct switch_status_category *categories; + int n_categories, allocated_categories; }; struct status_reply { @@ -190,12 +190,16 @@ switch_status_start(struct secchan *secchan, const struct settings *s, void switch_status_register_category(struct switch_status *ss, const char *category, - void (*cb)(struct status_reply *, - void *aux), + void (*cb)(struct status_reply *, void *aux), void *aux) { struct switch_status_category *c; - assert(ss->n_categories < ARRAY_SIZE(ss->categories)); + if (ss->n_categories >= ss->allocated_categories) { + ss->allocated_categories = 1 + ss->allocated_categories * 2; + ss->categories = xrealloc(ss->categories, + (sizeof *ss->categories + * ss->allocated_categories)); + } c = &ss->categories[ss->n_categories++]; c->cb = cb; c->aux = aux;