[PATCH 1/3] Remove 'tripflag' from dive trips

Linus Torvalds torvalds at linux-foundation.org
Mon Nov 26 15:20:20 PST 2012


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Mon, 26 Nov 2012 10:04:14 -0800
Subject: [PATCH 1/3] Remove 'tripflag' from dive trips

Both dives and dive trips have the same 'tripflag' thing, but they are
used very differently.  In particular, for dive trips, the only case
that has any meaning is the TF_AUTOGEN case, so instead of having that
trip flag, replace it with a bitfield that says whether the trip was
auto-generated or not.

And make the one-bit bitfields explicitly unsigned.  Signed bitfields
are almost always a mistake, and can be confusing.

Also remove a few now stale macros that are no longer needed now that we
don't do the GList thing for dive list handling, and our autogen logic
has been simplified.

Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---

This is patch 1 o fa series of three trivial patches. None of them are all 
that exciting, although the third one fixes some crazy memory corruption 
in test15 due to that test having an insane XML file. The two first 
patches just remove some trivial tripflag stuff that we don't really need.

 dive.h     | 7 ++-----
 divelist.c | 8 ++++----
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/dive.h b/dive.h
index b8614bcb314b..abe852508b69 100644
--- a/dive.h
+++ b/dive.h
@@ -269,17 +269,16 @@ struct divecomputer {
 #define W_IDX_PRIMARY 0
 #define W_IDX_SECONDARY 1
 
-typedef enum { TF_NONE, NO_TRIP, IN_TRIP, AUTOGEN_TRIP, ASSIGNED_TRIP, NUM_TRIPFLAGS } tripflag_t;
+typedef enum { TF_NONE, NO_TRIP, IN_TRIP, ASSIGNED_TRIP, NUM_TRIPFLAGS } tripflag_t;
 extern const char *tripflag_names[NUM_TRIPFLAGS];
 
 typedef struct dive_trip {
-	tripflag_t tripflag;
 	timestamp_t when;
 	char *location;
 	char *notes;
 	struct dive *dives;
 	int nrdives;
-	int expanded:1, selected:1;
+	unsigned expanded:1, selected:1, autogen:1;
 	struct dive_trip *next;
 } dive_trip_t;
 
@@ -359,8 +358,6 @@ extern gboolean autogroup;
 #define UNGROUPED_DIVE(_dive) ((_dive)->tripflag == NO_TRIP)
 #define DIVE_IN_TRIP(_dive) ((_dive)->tripflag == IN_TRIP || (_dive)->tripflag == ASSIGNED_TRIP)
 #define DIVE_NEEDS_TRIP(_dive) ((_dive)->tripflag == TF_NONE)
-#define DIVE_TRIP(_trip) ((dive_trip_t *)(_trip)->data)
-#define DIVE_FITS_TRIP(_dive, _dive_trip) ((_dive_trip)->when - TRIP_THRESHOLD <= (_dive)->when)
 
 extern void add_dive_to_trip(struct dive *, dive_trip_t *);
 extern void remove_dive_from_trip(struct dive *);
diff --git a/divelist.c b/divelist.c
index af58b480671f..2d759a606ab2 100644
--- a/divelist.c
+++ b/divelist.c
@@ -46,7 +46,7 @@ gboolean autogroup = FALSE;
 /* this duplicate assignment of "INTRIP" causes the save_xml code
  * to convert an ASSIGNED_TRIP (which is temporary in memory) to
  * a statically assigned trip (INTRIP) in file */
-const char *tripflag_names[NUM_TRIPFLAGS] = { "TF_NONE", "NOTRIP", "INTRIP", "INTRIP", "AUTOGEN_TRIP" };
+const char *tripflag_names[NUM_TRIPFLAGS] = { "TF_NONE", "NOTRIP", "INTRIP", "INTRIP" };
 
 /*
  * The dive list has the dive data in both string format (for showing)
@@ -945,7 +945,7 @@ static void dump_trip_list(void)
 		if (trip->when < last_time)
 			printf("\n\ndive_trip_list OUT OF ORDER!!!\n\n\n");
 		printf("%s trip %d to \"%s\" on %04u-%02u-%02u %02u:%02u:%02u (%d dives - %p)\n",
-			trip->tripflag == AUTOGEN_TRIP ? "autogen " : "",
+			trip->autogen ? "autogen " : "",
 			++i, trip->location,
 			tm.tm_year + 1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
 			trip->nrdives, trip);
@@ -1156,7 +1156,7 @@ static void autogroup_dives(void)
 
 		lastdive = dive;
 		trip = create_and_hookup_trip_from_dive(dive);
-		trip->tripflag = AUTOGEN_TRIP;
+		trip->autogen = 1;
 	}
 
 #ifdef DEBUG_TRIP
@@ -2427,7 +2427,7 @@ void remove_autogen_trips()
 	for_each_dive(i, dive) {
 		dive_trip_t *trip = dive->divetrip;
 
-		if (trip && trip->tripflag == AUTOGEN_TRIP)
+		if (trip && trip->autogen)
 			remove_dive_from_trip(dive);
 	}
 }
-- 
1.8.0.dirty



More information about the subsurface mailing list