From 0d27092ef52bb929bc1dde3513671e7f351f55ff Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Wed, 5 Jan 2022 19:41:23 +1100 Subject: [PATCH] [all] move min/max and upcast macros into `common/util.h` --- client/include/util.h | 7 +------ common/include/common/util.h | 32 ++++++++++++++++++++++++++++++++ common/src/rects.c | 4 +--- host/src/app.c | 1 + profile/client/src/main.c | 4 +--- 5 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 common/include/common/util.h diff --git a/client/include/util.h b/client/include/util.h index de9fb3f8..0ab0a445 100644 --- a/client/include/util.h +++ b/client/include/util.h @@ -24,12 +24,7 @@ #include #include #include "common/types.h" - -#define min(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; }) -#define max(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b; }) - -#define UPCAST(type, x) \ - (type *)((uintptr_t)(x) - offsetof(type, base)) +#include "common/util.h" // reads the specified file into a new buffer // the callee must free the buffer diff --git a/common/include/common/util.h b/common/include/common/util.h new file mode 100644 index 00000000..8b533f22 --- /dev/null +++ b/common/include/common/util.h @@ -0,0 +1,32 @@ +/** + * Looking Glass + * Copyright © 2017-2021 The Looking Glass Authors + * https://looking-glass.io + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _H_LG_COMMON_UTIL_ +#define _H_LG_COMMON_UTIL_ + +#define min(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); \ + _a < _b ? _a : _b; }) +#define max(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); \ + _a > _b ? _a : _b; }) + +#define UPCAST(type, x) \ + (type *)((uintptr_t)(x) - offsetof(type, base)) + +#endif diff --git a/common/src/rects.c b/common/src/rects.c index 20a5a141..dba63336 100644 --- a/common/src/rects.c +++ b/common/src/rects.c @@ -19,12 +19,10 @@ */ #include "common/rects.h" +#include "common/util.h" #include -#define min(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; }) -#define max(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b; }) - struct Corner { int x; diff --git a/host/src/app.c b/host/src/app.c index 90737070..03793145 100644 --- a/host/src/app.c +++ b/host/src/app.c @@ -33,6 +33,7 @@ #include "common/time.h" #include "common/stringutils.h" #include "common/cpuinfo.h" +#include "common/util.h" #include diff --git a/profile/client/src/main.c b/profile/client/src/main.c index b82e0a48..02c7e224 100644 --- a/profile/client/src/main.c +++ b/profile/client/src/main.c @@ -25,6 +25,7 @@ #include "common/locking.h" #include "common/stringutils.h" #include "common/ivshmem.h" +#include "common/util.h" #include #include @@ -37,9 +38,6 @@ #include -#define min(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; }) -#define max(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b; }) - struct state { bool running;