diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-12-09 13:01:10 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-12-14 00:29:31 +0800 |
commit | c64c9c923b1f2a4758f3ff639c28790f99c9ce84 (patch) | |
tree | 496b41c40c90cef05eb392bd595977846840d8d5 | |
parent | dfd7f98129c2b9cb862ac414a84c5d82ffa407d0 (diff) | |
download | subsurface-c64c9c923b1f2a4758f3ff639c28790f99c9ce84.tar.gz |
Cleanup: detangle unregister_dive() and delete_single_dive()
These two functions were called in different contexts:
- unregister_dive(): from the undo-commands to remove the dive
from the global dive table, but not delete it. The dive was
already removed from its trip.
- delete_single_dive(): from non-undo code. Most of it not in
use and removed in a sibling-commit. Here, the dive is supposed
to be removed from its trip and a new selection is calculated.
delete_single_dive() calls unregister_dive(), which removes the
dive from its trip. Move remove_dive_from_trip() from the former
to the latter and make both functions independent. Instead
of deleting the dive explicitly in delete_single_dive(), call
the delete_dive_from_table() function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | core/divelist.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/core/divelist.c b/core/divelist.c index 1cf4f5e00..4b809da37 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -1075,16 +1075,15 @@ void delete_dive_from_table(struct dive_table *table, int idx) unregister_dive_from_table(table, idx); } -/* this removes a dive from the dive table and trip-list but doesn't - * free the resources associated with the dive. It returns a pointer - * to the unregistered dive. The returned dive has the selection- - * and hidden-flags cleared. */ +/* This removes a dive from the global dive table but doesn't free the + * resources associated with the dive. The caller must removed the dive + * from the trip-list. Returns a pointer to the unregistered dive. + * The unregistered dive has the selection- and hidden-flags cleared. */ struct dive *unregister_dive(int idx) { struct dive *dive = get_dive(idx); if (!dive) return NULL; /* this should never happen */ - remove_dive_from_trip(dive, false); unregister_dive_from_table(&dive_table, idx); if (dive->selected) amount_selected--; @@ -1092,8 +1091,8 @@ struct dive *unregister_dive(int idx) return dive; } -/* this implements the mechanics of removing the dive from the table, - * but doesn't deal with updating dive trips, etc */ +/* this implements the mechanics of removing the dive from the global + * dive table and the trip, but doesn't deal with updating dive trips, etc */ void delete_single_dive(int idx) { struct dive *dive = get_dive(idx); @@ -1101,8 +1100,8 @@ void delete_single_dive(int idx) return; /* this should never happen */ if (dive->selected) deselect_dive(dive); - dive = unregister_dive(idx); - free_dive(dive); + remove_dive_from_trip(dive, false); + delete_dive_from_table(&dive_table, idx); } struct dive **grow_dive_table(struct dive_table *table) |