Cleanup: return gasmix by value

Currently, get_gasmix_from_event() and get_gasmix() return pointers
to either static or to (possibly changing) dive data. This seems like
a dangerous practice and the returned data should be used immediately.

Instead, return the gasmix by value. This is in preparation of
const-ifying input parameters of a number of core functions, which
will ultimately let the merge() function take const-arguments in
preparation of undo of dive-merging.

On common 64-bit systems gasmix (two "int"s) is the size of a pointer
and can be returned in a register.

On 32-bit systems a pointer to the struct to be filled out will be
passed.

Since get_gasmix() now returns a value, the first invocation is
tested by a NULL-initialized "struct event *". Document this in
a comment.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-08-16 13:35:14 +02:00 committed by Dirk Hohndel
parent b6187f73aa
commit f5b11daffd
10 changed files with 65 additions and 55 deletions

View file

@ -307,10 +307,10 @@ static void save_one_event(struct membuffer *b, struct dive *dive, struct event
show_index(b, ev->value, "value='", "'");
show_utf8(b, ev->name, " name='", "'", 1);
if (event_is_gaschange(ev)) {
struct gasmix *mix = get_gasmix_from_event(dive, ev);
struct gasmix mix = get_gasmix_from_event(dive, ev);
if (ev->gas.index >= 0)
show_integer(b, ev->gas.index, "cylinder='", "'");
put_gasmix(b, mix);
put_gasmix(b, &mix);
}
put_format(b, " />\n");
}