mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
cleanup: make alloc_taxonomy local to taxonomy.c
The alloc_taxonomy()/free_taxonomy() interface was exceedingly strange. The former gave a "struct taxonomy", the latter took a "struct taxonomy_data". To make things worse, is appears as if the names "taxonomy" and "taxonoma_data" are reversed: the latter contains the former. In any case, the alloc_taxonomy() call is not needed anymore from outside taxonomy.c, as these memory-management details are now hidden in accessor functions. Therefore, make the function local to taxonomy.c. Moreover, rename it to "alloc_taxonomy_table()" and let it take a "taxonomy_data" structure for symmetry with "free_taxonomy()". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
7f1def8602
commit
f93acdace7
2 changed files with 5 additions and 7 deletions
|
@ -26,9 +26,10 @@ char *taxonomy_api_names[TC_NR_CATEGORIES] = {
|
||||||
"adminName3"
|
"adminName3"
|
||||||
};
|
};
|
||||||
|
|
||||||
struct taxonomy *alloc_taxonomy()
|
static void alloc_taxonomy_table(struct taxonomy_data *t)
|
||||||
{
|
{
|
||||||
return calloc(TC_NR_CATEGORIES, sizeof(struct taxonomy));
|
if (!t->category)
|
||||||
|
t->category = calloc(TC_NR_CATEGORIES, sizeof(struct taxonomy));
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_taxonomy(struct taxonomy_data *t)
|
void free_taxonomy(struct taxonomy_data *t)
|
||||||
|
@ -47,8 +48,7 @@ void copy_taxonomy(const struct taxonomy_data *orig, struct taxonomy_data *copy)
|
||||||
if (orig->category == NULL) {
|
if (orig->category == NULL) {
|
||||||
free_taxonomy(copy);
|
free_taxonomy(copy);
|
||||||
} else {
|
} else {
|
||||||
if (copy->category == NULL)
|
alloc_taxonomy_table(copy);
|
||||||
copy->category = alloc_taxonomy();
|
|
||||||
for (int i = 0; i < TC_NR_CATEGORIES; i++) {
|
for (int i = 0; i < TC_NR_CATEGORIES; i++) {
|
||||||
if (i < copy->nr) {
|
if (i < copy->nr) {
|
||||||
free((void *)copy->category[i].value);
|
free((void *)copy->category[i].value);
|
||||||
|
@ -86,8 +86,7 @@ void taxonomy_set_category(struct taxonomy_data *t, enum taxonomy_category categ
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
|
|
||||||
// make sure we have taxonomy data allocated
|
// make sure we have taxonomy data allocated
|
||||||
if (!t->category)
|
alloc_taxonomy_table(t);
|
||||||
t->category = alloc_taxonomy();
|
|
||||||
|
|
||||||
for (int i = 0; i < t->nr; i++) {
|
for (int i = 0; i < t->nr; i++) {
|
||||||
if (t->category[i].category == category) {
|
if (t->category[i].category == category) {
|
||||||
|
|
|
@ -39,7 +39,6 @@ struct taxonomy_data {
|
||||||
struct taxonomy *category;
|
struct taxonomy *category;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct taxonomy *alloc_taxonomy();
|
|
||||||
void free_taxonomy(struct taxonomy_data *t);
|
void free_taxonomy(struct taxonomy_data *t);
|
||||||
void copy_taxonomy(const struct taxonomy_data *orig, struct taxonomy_data *copy);
|
void copy_taxonomy(const struct taxonomy_data *orig, struct taxonomy_data *copy);
|
||||||
int taxonomy_index_for_category(const struct taxonomy_data *t, enum taxonomy_category cat);
|
int taxonomy_index_for_category(const struct taxonomy_data *t, enum taxonomy_category cat);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue