From: Ben Pfaff Date: Sat, 20 Jun 2009 05:52:40 +0000 (-0700) Subject: output: Make tables reference-counted. X-Git-Tag: v0.7.3~32 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1c8603e9591187542718e43ec7f4202e0da202f;p=pspp-builds.git output: Make tables reference-counted. Adding a reference count to tab_table allows output drivers to retain a copy of a table even after the main output engine is done. This will be useful for the GUI output driver. --- diff --git a/src/output/table.c b/src/output/table.c index 9457923a..1b052888 100644 --- a/src/output/table.c +++ b/src/output/table.c @@ -62,6 +62,7 @@ tab_create (int nc, int nr, int reallocable UNUSED) struct tab_table *t; t = pool_create_container (struct tab_table, container); + t->ref_cnt = 1; t->col_style = TAB_COL_NONE; t->col_group = 0; t->title = NULL; @@ -86,17 +87,28 @@ tab_create (int nc, int nr, int reallocable UNUSED) return t; } -/* Destroys table T. */ +/* Increases T's reference count and, if this causes T's + reference count to reach 0, destroys T. */ void tab_destroy (struct tab_table *t) { - assert (t != NULL); + assert (t->ref_cnt > 0); + if (--t->ref_cnt > 0) + return; if (t->dim_free != NULL) t->dim_free (t->dim_aux); free (t->title); pool_destroy (t->container); } +/* Increases T's reference count. */ +void +tab_ref (struct tab_table *t) +{ + assert (t->ref_cnt > 0); + t->ref_cnt++; +} + /* Sets the width and height of a table, in columns and rows, respectively. Use only to reduce the size of a table, since it does not change the amount of allocated memory. */ diff --git a/src/output/table.h b/src/output/table.h index 516db6a5..03c981a3 100644 --- a/src/output/table.h +++ b/src/output/table.h @@ -76,6 +76,7 @@ typedef void tab_dim_free_func (void *aux); struct tab_table { struct pool *container; + int ref_cnt; /* Reference count. */ /* Contents. */ int col_style; /* Columns: One of TAB_COL_*. */ @@ -129,6 +130,7 @@ struct tab_rendering /* Tables. */ struct tab_table *tab_create (int nc, int nr, int reallocable); void tab_destroy (struct tab_table *); +void tab_ref (struct tab_table *); void tab_resize (struct tab_table *, int nc, int nr); void tab_realloc (struct tab_table *, int nc, int nr); void tab_headers (struct tab_table *, int l, int r, int t, int b);