--- rxvt-unicode/src/rxvtutil.h 2006/01/29 22:27:04 1.22 +++ rxvt-unicode/src/rxvtutil.h 2007/11/20 17:44:44 1.30 @@ -4,14 +4,33 @@ #include #include +using namespace std; + #define PP_CONCAT_(a, b) a ## b #define PP_CONCAT(a, b) PP_CONCAT_(a, b) #define PP_STRINGIFY_(a) #a #define PP_STRINGIFY(a) PP_STRINGIFY_(a) -// actually, some gcc-3.x versions work, too -#define HAVE_GCC_BUILTINS (__GNUC__ >= 4) -#define HAVE_GCC_BUILTINS 0 +#define HAVE_GCC_BUILTINS (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ == 4)) + +#if __GNUC__ >= 3 +# define rxvt_attribute(x) __attribute__(x) +#else +# define rxvt_attribute(x) +#endif + +#define NORETURN rxvt_attribute ((noreturn)) +#define UNUSED rxvt_attribute ((unused)) +#define CONST rxvt_attribute ((const)) + +// increases code size unless -fno-enforce-eh-specs +#if __GNUC__ +# define NOTHROW +# define THROW(x) +#else +# define NOTHROW throw() +# define THROW(x) throw x +#endif extern class byteorder { static unsigned int e; // at least 32 bits @@ -35,12 +54,14 @@ template static inline void swap (T& a, U& b) { T t=a; a=(T)b; b=(U)t; } +template static inline T squared_diff (T a, T b) { return (a-b)*(a-b); } + // linear interpolation template static inline T lerp (T a, U b, P p) { - return (int(a) * int(p) + int(b) * int(100 - p)) / 100; + return (long(a) * long(100 - p) + long(b) * long(p) + 50) / 100; } // some bit functions, xft fuck me plenty @@ -49,8 +70,8 @@ static inline int popcount (unsigned int x) { return __builtin_popcount (x); } #else // count trailing zero bits and count # of one bits -int ctz (unsigned int x); -int popcount (unsigned int x); +int ctz (unsigned int x) CONST; +int popcount (unsigned int x) CONST; #endif // in range including end @@ -68,7 +89,7 @@ }; /* simplevec taken (and heavily modified), from: - * + * * MICO --- a free CORBA implementation * Copyright (C) 1997-98 Kay Roemer & Arno Puder */ @@ -424,7 +445,7 @@ void *rxvt_temp_buf (int len); template -inline T * +static inline T * rxvt_temp_buf (int len) { return (T *)rxvt_temp_buf (len * sizeof (T));