From e58cbf8addcfca0494dc33cd47b44f097da106e5 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Wed, 19 Dec 2018 20:50:02 +0000 Subject: [PATCH] Convert non-mandatory attributes to macros They're shorter and more portable. Signed-off-by: Yuxuan Shui --- src/c2.c | 2 +- src/common.h | 2 +- src/compton.c | 20 ++++++++++---------- src/compton.h | 2 +- src/kernel.c | 12 ++++++------ src/kernel.h | 9 +++++---- src/opengl.h | 2 +- src/render.c | 2 +- src/utils.h | 14 +++++++------- src/win.h | 4 ++-- src/x.h | 6 +++--- 11 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/c2.c b/src/c2.c index 5e8115b3..dd3a1d83 100644 --- a/src/c2.c +++ b/src/c2.c @@ -344,7 +344,7 @@ c2_dump_raw(c2_ptr_t p); /** * Wrapper of c2_dump_raw(). */ -static inline void __attribute__((unused)) +static inline void attr_unused c2_dump(c2_ptr_t p) { c2_dump_raw(p); printf("\n"); diff --git a/src/common.h b/src/common.h index b9a8b2b0..f9875370 100644 --- a/src/common.h +++ b/src/common.h @@ -1524,7 +1524,7 @@ xr_sync(session_t *ps, Drawable d, XSyncFence *pfence) { if (!*pfence) *pfence = XSyncCreateFence(ps->dpy, d, False); if (*pfence) { - Bool __attribute__((unused)) triggered = False; + Bool attr_unused triggered = False; /* if (XSyncQueryFence(ps->dpy, *pfence, &triggered) && triggered) XSyncResetFence(ps->dpy, *pfence); */ // The fence may fail to be created (e.g. because of died drawable) diff --git a/src/compton.c b/src/compton.c index d8a55c5c..bb833f66 100644 --- a/src/compton.c +++ b/src/compton.c @@ -1271,7 +1271,7 @@ root_damaged(session_t *ps) { * Xlib error handler function. */ static int -xerror(Display __attribute__((unused)) *dpy, XErrorEvent *ev) { +xerror(Display attr_unused *dpy, XErrorEvent *ev) { if (!should_ignore(ps_g, ev->serial)) x_print_error(ev->serial, ev->request_code, ev->minor_code, ev->error_code); return 0; @@ -1281,7 +1281,7 @@ xerror(Display __attribute__((unused)) *dpy, XErrorEvent *ev) { * XCB error handler function. */ void -ev_xcb_error(session_t __attribute__((unused)) *ps, xcb_generic_error_t *err) { +ev_xcb_error(session_t attr_unused *ps, xcb_generic_error_t *err) { if (!should_ignore(ps, err->sequence)) x_print_error(err->sequence, err->major_code, err->minor_code, err->error_code); } @@ -1395,12 +1395,12 @@ opts_set_no_fading_openclose(session_t *ps, bool newval) { //!@} #endif -static inline int __attribute__((unused)) +static inline int attr_unused ev_serial(xcb_generic_event_t *ev) { return ev->full_sequence; } -static inline const char * __attribute__((unused)) +static inline const char * attr_unused ev_name(session_t *ps, xcb_generic_event_t *ev) { static char buf[128]; switch (ev->response_type & 0x7f) { @@ -1437,7 +1437,7 @@ ev_name(session_t *ps, xcb_generic_event_t *ev) { return buf; } -static inline Window __attribute__((unused)) +static inline Window attr_unused ev_window(session_t *ps, xcb_generic_event_t *ev) { switch (ev->response_type) { case FocusIn: @@ -1504,7 +1504,7 @@ ev_focus_detail_name(xcb_focus_in_event_t* ev) { return "Unknown"; } -static inline void __attribute__((unused)) +static inline void attr_unused ev_focus_report(xcb_focus_in_event_t *ev) { printf(" { mode: %s, detail: %s }\n", ev_focus_mode_name(ev), ev_focus_detail_name(ev)); @@ -1850,7 +1850,7 @@ ev_shape_notify(session_t *ps, xcb_shape_notify_event_t *ev) { */ static void ev_screen_change_notify(session_t *ps, - xcb_randr_screen_change_notify_event_t __attribute__((unused)) *ev) { + xcb_randr_screen_change_notify_event_t attr_unused *ev) { if (ps->o.xinerama_shadow_crop) cxinerama_upd_scrs(ps); @@ -1865,7 +1865,7 @@ ev_screen_change_notify(session_t *ps, inline static void ev_selection_clear(session_t *ps, - xcb_selection_clear_event_t __attribute__((unused)) *ev) { + xcb_selection_clear_event_t attr_unused *ev) { // The only selection we own is the _NET_WM_CM_Sn selection. // If we lose that one, we should exit. fprintf(stderr, "Another composite manager started and " @@ -1876,7 +1876,7 @@ ev_selection_clear(session_t *ps, /** * Get a window's name from window ID. */ -static inline void __attribute__((unused)) +static inline void attr_unused ev_window_name(session_t *ps, Window wid, char **name) { *name = ""; if (wid) { @@ -4090,7 +4090,7 @@ session_run(session_t *ps) { } static void -sigint_handler(int __attribute__((unused)) signum) { +sigint_handler(int attr_unused signum) { exit(0); } diff --git a/src/compton.h b/src/compton.h index 1f7ace77..161497e9 100644 --- a/src/compton.h +++ b/src/compton.h @@ -59,7 +59,7 @@ void map_win(session_t *ps, Window id); * * Truncate to 0 if the result is negative. */ -static inline unsigned long __attribute__((const)) +static inline unsigned long attr_const sub_unslong(unsigned long a, unsigned long b) { return (a > b) ? a - b : 0; } diff --git a/src/kernel.c b/src/kernel.c index 5c955eca..f8163101 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -3,8 +3,8 @@ #include -#include "utils.h" #include "kernel.h" +#include "utils.h" /* * A picture will help @@ -23,11 +23,11 @@ * center +-----+-------------------+-----+ */ -double -sum_kernel(conv *map, int x, int y, int width, int height) { +double attr_const attr_pure sum_kernel(const conv *map, int x, int y, int width, + int height) { int fx, fy; - double *g_data; - double *g_line = map->data; + const double *g_data; + const double *g_line = map->data; int g_size = map->size; int center = g_size / 2; int fx_start, fx_end; @@ -77,7 +77,7 @@ sum_kernel(conv *map, int x, int y, int width, int height) { return v; } -static double __attribute__((const)) gaussian(double r, double x, double y) { +static double attr_const attr_pure gaussian(double r, double x, double y) { // Formula can be found here: // https://en.wikipedia.org/wiki/Gaussian_blur#Mathematics // Except a special case for r == 0 to produce sharp shadows diff --git a/src/kernel.h b/src/kernel.h index 7881a1e4..fcc5ddf7 100644 --- a/src/kernel.h +++ b/src/kernel.h @@ -2,18 +2,19 @@ // Copyright (c) Yuxuan Shui #pragma once +#include "compiler.h" /// Code for generating convolution kernels typedef struct conv { - int size; - double data[]; + int size; + double data[]; } conv; /// Calculate the sum of a rectangle part of the convolution kernel /// the rectangle is defined by top left (x, y), and a size (width x height) -double -sum_kernel(conv *map, int x, int y, int width, int height); +double attr_const attr_pure sum_kernel(const conv *map, int x, int y, int width, + int height); /// Create a kernel with gaussian distribution of radius r conv *gaussian_kernel(double r); diff --git a/src/opengl.h b/src/opengl.h index e6ad57da..ad934840 100644 --- a/src/opengl.h +++ b/src/opengl.h @@ -166,7 +166,7 @@ void glx_release_pixmap(session_t *ps, glx_texture_t *ptex); void glx_paint_pre(session_t *ps, region_t *preg) -__attribute__((nonnull(1, 2))); +attr_nonnull(1, 2); /** * Check if a texture is binded, or is binded to the given pixmap. diff --git a/src/render.c b/src/render.c index 8e89486f..53b9e307 100644 --- a/src/render.c +++ b/src/render.c @@ -51,7 +51,7 @@ static inline void xrfilter_reset(session_t *ps, xcb_render_picture_t p) { #undef FILTER } -static inline void __attribute__((nonnull(1, 2))) +static inline void attr_nonnull(1, 2) set_tgt_clip(session_t *ps, region_t *reg) { switch (ps->o.backend) { case BKEND_XRENDER: diff --git a/src/utils.h b/src/utils.h index 5aadda96..acd97178 100644 --- a/src/utils.h +++ b/src/utils.h @@ -36,7 +36,7 @@ static inline bool safe_isnan(double a) { * @param max maximum value * @return normalized value */ -static inline int __attribute__((const)) +static inline int attr_const normalize_i_range(int i, int min, int max) { if (i > max) return max; if (i < min) return min; @@ -46,7 +46,7 @@ normalize_i_range(int i, int min, int max) { /** * Select the larger integer of two. */ -static inline int __attribute__((const)) +static inline int attr_const max_i(int a, int b) { return (a > b ? a : b); } @@ -54,7 +54,7 @@ max_i(int a, int b) { /** * Select the smaller integer of two. */ -static inline int __attribute__((const)) +static inline int attr_const min_i(int a, int b) { return (a > b ? b : a); } @@ -62,7 +62,7 @@ min_i(int a, int b) { /** * Select the larger long integer of two. */ -static inline long __attribute__((const)) +static inline long attr_const max_l(long a, long b) { return (a > b ? a : b); } @@ -70,7 +70,7 @@ max_l(long a, long b) { /** * Select the smaller long integer of two. */ -static inline long __attribute__((const)) +static inline long attr_const min_l(long a, long b) { return (a > b ? b : a); } @@ -83,7 +83,7 @@ min_l(long a, long b) { * @param max maximum value * @return normalized value */ -static inline double __attribute__((const)) +static inline double attr_const normalize_d_range(double d, double min, double max) { if (d > max) return max; if (d < min) return min; @@ -96,7 +96,7 @@ normalize_d_range(double d, double min, double max) { * @param d double value to normalize * @return normalized value */ -static inline double __attribute__((const)) +static inline double attr_const normalize_d(double d) { return normalize_d_range(d, 0.0, 1.0); } diff --git a/src/win.h b/src/win.h index 787e5fc5..07e2d190 100644 --- a/src/win.h +++ b/src/win.h @@ -379,7 +379,7 @@ win_get_bounding_shape_global_by_val(win *w) { * Calculate the extents of the frame of the given window based on EWMH * _NET_FRAME_EXTENTS and the X window border width. */ -static inline margin_t __attribute__((pure)) +static inline margin_t attr_pure win_calc_frame_extents(const win *w) { margin_t result = w->frame_extents; result.top = max_i(result.top, w->g.border_width); @@ -392,7 +392,7 @@ win_calc_frame_extents(const win *w) { /** * Check whether a window has WM frames. */ -static inline bool __attribute__((pure)) +static inline bool attr_pure win_has_frame(const win *w) { return w->g.border_width || w->frame_extents.top || w->frame_extents.left diff --git a/src/x.h b/src/x.h index 9e22bab9..40d02ab7 100644 --- a/src/x.h +++ b/src/x.h @@ -98,19 +98,19 @@ xcb_render_picture_t x_create_picture_with_pictfmt_and_pixmap( session_t *ps, xcb_render_pictforminfo_t *pictfmt, xcb_pixmap_t pixmap, unsigned long valuemask, const xcb_render_create_picture_value_list_t *attr) -__attribute__((nonnull(1, 2))); +attr_nonnull(1, 2); xcb_render_picture_t x_create_picture_with_visual_and_pixmap( session_t *ps, xcb_visualid_t visual, xcb_pixmap_t pixmap, unsigned long valuemask, const xcb_render_create_picture_value_list_t *attr) -__attribute__((nonnull(1))); +attr_nonnull(1); xcb_render_picture_t x_create_picture_with_standard_and_pixmap( session_t *ps, xcb_pict_standard_t standard, xcb_pixmap_t pixmap, unsigned long valuemask, const xcb_render_create_picture_value_list_t *attr) -__attribute__((nonnull(1))); +attr_nonnull(1); /** * Create an picture.