Skip to content

Commit

Permalink
Fix CLAMP macro overwritten by glib headers
Browse files Browse the repository at this point in the history
Fixes #188

When I moved the macro definition below all of the includes, I got the
following compiler warning:

/usr/include/glib-2.0/glib/gmacros.h:246:0: note: this is the location
of the previous definition
 #define CLAMP(x, low, high)  (((x) > (high)) ? (high) : (((x) < (low))
? (low) : (x)))

So, that's the macro definition that was being used whenever "CLAMP" was
used. It's pretty obvious what went wrong.
  • Loading branch information
forivall committed May 2, 2015
1 parent 8b0a67a commit ba15832
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/redshift.c
Expand Up @@ -49,11 +49,6 @@
#include "systemtime.h"
#include "hooks.h"


#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define CLAMP(lo,x,up) (MAX((lo), MIN((x), (up))))

/* pause() is not defined on windows platform but is not needed either.
Use a noop macro instead. */
#ifdef __WIN32__
Expand Down Expand Up @@ -97,6 +92,8 @@
# include "location-corelocation.h"
#endif

#undef CLAMP
#define CLAMP(lo,mid,up) (((lo) > (mid)) ? (lo) : (((mid) < (up)) ? (mid) : (up)))

/* Union of state data for gamma adjustment methods */
typedef union {
Expand Down Expand Up @@ -978,8 +975,7 @@ run_continual_mode(const location_t *loc,
}

/* Clamp alpha value */
adjustment_alpha =
MAX(0.0, MIN(adjustment_alpha, 1.0));
adjustment_alpha = CLAMP(0.0, adjustment_alpha, 1.0);
}

/* Interpolate between 6500K and calculated
Expand Down

0 comments on commit ba15832

Please sign in to comment.