aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-07-15 23:06:28 +0200
committerMattias Andrée <maandree@kth.se>2016-07-15 23:06:28 +0200
commit75bf6ecd2173d7e6b37b9709502997fbf75b2a90 (patch)
tree252379a4c22e12bf6fe4a6de3595ecfa7bd33fe7 /src
parentImplement libcoopgamma_connect (diff)
downloadlibcoopgamma-75bf6ecd2173d7e6b37b9709502997fbf75b2a90.tar.gz
libcoopgamma-75bf6ecd2173d7e6b37b9709502997fbf75b2a90.tar.bz2
libcoopgamma-75bf6ecd2173d7e6b37b9709502997fbf75b2a90.tar.xz
Fix warnings
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src')
-rw-r--r--src/libcoopgamma.c132
-rw-r--r--src/libcoopgamma.h136
2 files changed, 174 insertions, 94 deletions
diff --git a/src/libcoopgamma.c b/src/libcoopgamma.c
index 8e94531..36acdd5 100644
--- a/src/libcoopgamma.c
+++ b/src/libcoopgamma.c
@@ -31,9 +31,18 @@
+#if defined(__clang__)
+# pragma GCC diagnostic ignored "-Wdocumentation"
+# pragma GCC diagnostic ignored "-Wcovered-switch-default"
+# pragma GCC diagnostic ignored "-Wcast-align"
+#endif
+
+
+
#if defined(__GNUC__)
# define NAME_OF_THE_PROCESS (argv0)
-char* argv0 __attribute__((weak)) = "libcoopgamma";
+extern const char* argv0;
+const char* argv0 __attribute__((weak)) = "libcoopgamma";
#else
# define NAME_OF_THE_PROCESS ("libcoopgamma")
#endif
@@ -61,7 +70,7 @@ char* argv0 __attribute__((weak)) = "libcoopgamma";
((buf != NULL ? *(type*)(buf + off) = (datum) : 0), off += sizeof(type))
#define unmarshal_prim(datum, type) \
- ((datum) = *(type*)(buf + off), off += sizeof(type))
+ ((datum) = *(const type*)(buf + off), off += sizeof(type))
#define marshal_version(version) \
marshal_prim(version, int)
@@ -119,32 +128,39 @@ char* argv0 __attribute__((weak)) = "libcoopgamma";
(ctx)->error.description = NULL))
-#define SYNC_CALL(send_call, recv_call, fail_return) \
- libcoopgamma_async_context_t async; \
- size_t _selected; \
- if (send_call < 0) \
- { \
- reflush: \
- if (errno != EINTR) \
- return fail_return; \
- if (libcoopgamma_flush(ctx) < 0) \
- goto reflush; \
- } \
-resync: \
- switch (libcoopgamma_synchronise(ctx, &async, 1, &_selected)) \
- { \
- default: \
- break; \
- case -1: \
- if (errno != EINTR) \
- return fail_return; \
- /* Fall through */ \
- case -2: \
- goto resync; \
- } \
+#define SYNC_CALL(send_call, recv_call, fail_return) \
+ libcoopgamma_async_context_t async; \
+ size_t _selected; \
+ if (send_call < 0) \
+ { \
+ reflush: \
+ if (errno != EINTR) \
+ return fail_return; \
+ if (libcoopgamma_flush(ctx) < 0) \
+ goto reflush; \
+ } \
+resync: \
+ switch (libcoopgamma_synchronise(ctx, &async, (size_t)1, &_selected)) \
+ { \
+ default: \
+ break; \
+ case -1: \
+ if (errno != EINTR) \
+ return fail_return; \
+ /* Fall through */ \
+ case -2: \
+ goto resync; \
+ } \
return recv_call
+#define INTEGRAL_DEPTHS \
+ case LIBCOOPGAMMA_UINT8: \
+ case LIBCOOPGAMMA_UINT16: \
+ case LIBCOOPGAMMA_UINT32: \
+ case LIBCOOPGAMMA_UINT64:
+
+
/**
* Initialise a `libcoopgamma_ramps8_t`, `libcoopgamma_ramps16_t`, `libcoopgamma_ramps32_t`,
@@ -153,7 +169,7 @@ resync: \
* `this->red_size`, `this->green_size`, and `this->blue_size` must already be set
*
* @param this The record to initialise
- * @para width The `sizeof(*(this->red))`
+ * @param width The `sizeof(*(this->red))`
* @return Zero on success, -1 on error
*/
int (libcoopgamma_ramps_initialise)(void* restrict this, size_t width)
@@ -200,7 +216,7 @@ void libcoopgamma_ramps_destroy(void* restrict this)
*/
size_t (libcoopgamma_ramps_marshal)(const void* restrict this, void* restrict vbuf, size_t width)
{
- libcoopgamma_ramps8_t* restrict this8 = (libcoopgamma_ramps8_t* restrict)this;
+ const libcoopgamma_ramps8_t* restrict this8 = (const libcoopgamma_ramps8_t* restrict)this;
MARSHAL_PROLOGUE;
marshal_version(LIBCOOPGAMMA_RAMPS_VERSION);
marshal_prim(this8->red_size, size_t);
@@ -368,6 +384,9 @@ int libcoopgamma_crtc_info_initialise(libcoopgamma_crtc_info_t* restrict this)
*
* @param this The record to destroy
*/
+#if defined(__GNUC__)
+__attribute__((__const__))
+#endif
void libcoopgamma_crtc_info_destroy(libcoopgamma_crtc_info_t* restrict this)
{
(void) this;
@@ -901,6 +920,9 @@ int libcoopgamma_async_context_initialise(libcoopgamma_async_context_t* restrict
*
* @param this The record to destroy
*/
+#if defined(__GNUC__)
+__attribute__((__const__))
+#endif
void libcoopgamma_async_context_destroy(libcoopgamma_async_context_t* restrict this)
{
(void) this;
@@ -964,7 +986,7 @@ char** libcoopgamma_get_methods(void)
char** rc;
char* buffer;
int n = 0, saved_errno;
- size_t size;
+ size_t size = 0;
methods = malloc(4 * sizeof(*methods));
if (methods == NULL)
@@ -975,7 +997,7 @@ char** libcoopgamma_get_methods(void)
char* method;
if ((n >= 4) && ((n & -n) == n))
{
- void* new = realloc(methods, (n << 1) * sizeof(*methods));
+ void* new = realloc(methods, (size_t)(n << 1) * sizeof(*methods));
if (new == NULL)
goto fail;
methods = new;
@@ -992,10 +1014,10 @@ char** libcoopgamma_get_methods(void)
size += strlen(method) + 1;
}
- rc = malloc((n + 1) * sizeof(char*) + size);
+ rc = malloc((size_t)(n + 1) * sizeof(char*) + size);
if (rc == NULL)
goto fail;
- buffer = ((char*)rc) + (n + 1) * sizeof(char*);
+ buffer = ((char*)rc) + (size_t)(n + 1) * sizeof(char*);
rc[n] = NULL;
while (n--)
{
@@ -1059,7 +1081,14 @@ static char* libcoopgamma_query(const char* restrict method, const char* restric
goto fail_child;
close(pipe_rw[1]);
}
+#if defined(__GNUC__)
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wcast-qual"
+#endif
execvp("coopgammad", (char* const*)(args));
+#if defined(__GNUC__)
+# pragma GCC diagnostic pop
+#endif
fail_child:
saved_errno = errno;
perror(NAME_OF_THE_PROCESS);
@@ -1325,7 +1354,7 @@ int libcoopgamma_connect(const char* restrict method, const char* restrict site,
return -1;
retry:
- if (connect(ctx->fd, (struct sockaddr*)(&address), sizeof(address)) < 0)
+ if (connect(ctx->fd, (struct sockaddr*)(&address), (socklen_t)sizeof(address)) < 0)
{
if (((errno == ECONNREFUSED) || (errno == ENOENT) || (errno == ENOTDIR)) && !tries++)
{
@@ -1336,10 +1365,16 @@ int libcoopgamma_connect(const char* restrict method, const char* restrict site,
case 0:
/* Child */
close(ctx->fd);
+#if defined(__GNUC__)
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wcast-qual"
+#endif
execvp("coopgammad", (char* const*)(args));
+#if defined(__GNUC__)
+# pragma GCC diagnostic pop
+#endif
perror(NAME_OF_THE_PROCESS);
exit(1);
- break;
default:
/* Parent */
if (waitpid(pid, &status, 0) < 0)
@@ -1570,7 +1605,7 @@ int libcoopgamma_synchronise(libcoopgamma_context_t* restrict ctx,
{ \
ssize_t n__; \
char* msg__; \
- snprintf(NULL, 0, format "%zn", __VA_ARGS__, &n__); \
+ snprintf(NULL, (size_t)0, format "%zn", __VA_ARGS__, &n__); \
msg__ = malloc((size_t)n__ + (payload_size)); \
if (msg__ == NULL) \
goto fail; \
@@ -1765,6 +1800,13 @@ static int check_error(libcoopgamma_context_t* restrict ctx, libcoopgamma_async_
+#if defined(__GNUC__)
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wnonnull"
+#endif
+
+
+
/**
* List all available CRTC:s, send request part
*
@@ -1779,7 +1821,7 @@ int libcoopgamma_get_crtcs_send(libcoopgamma_context_t* restrict ctx,
libcoopgamma_async_context_t* restrict async)
{
async->message_id = ctx->message_id;
- SEND_MESSAGE(ctx, NULL, 0,
+ SEND_MESSAGE(ctx, NULL, (size_t)0,
"Command: enumerate-crtcs\n"
"Message ID: %" PRIu32 "\n"
"\n",
@@ -1911,7 +1953,7 @@ int libcoopgamma_get_gamma_info_send(const char* restrict crtc, libcoopgamma_con
}
async->message_id = ctx->message_id;
- SEND_MESSAGE(ctx, NULL, 0,
+ SEND_MESSAGE(ctx, NULL, (size_t)0,
"Command: get-gamma-info\n"
"Message ID: %" PRIu32 "\n"
"CRTC: %s\n"
@@ -2074,7 +2116,7 @@ int libcoopgamma_get_gamma_send(libcoopgamma_filter_query_t* restrict query,
async->message_id = ctx->message_id;
async->coalesce = query->coalesce;
- SEND_MESSAGE(ctx, NULL, 0,
+ SEND_MESSAGE(ctx, NULL, (size_t)0,
"Command: get-gamma\n"
"Message ID: %" PRIu32 "\n"
"CRTC: %s\n"
@@ -2174,8 +2216,10 @@ int libcoopgamma_get_gamma_recv(libcoopgamma_filter_table_t* restrict table,
{
case LIBCOOPGAMMA_FLOAT: width = sizeof(float); break;
case LIBCOOPGAMMA_DOUBLE: width = sizeof(double); break;
- default:
- width = table->depth / 8;
+ default: INTEGRAL_DEPTHS
+ if ((table->depth <= 0) || ((table->depth & 7) != 0))
+ goto bad;
+ width = (size_t)(table->depth / 8);
break;
}
@@ -2304,13 +2348,13 @@ int libcoopgamma_set_gamma_send(libcoopgamma_filter_t* restrict filter, libcoopg
{
case LIBCOOPGAMMA_FLOAT: stopwidth = sizeof(float); break;
case LIBCOOPGAMMA_DOUBLE: stopwidth = sizeof(double); break;
- default:
+ default: INTEGRAL_DEPTHS
if ((depth <= 0) || ((depth & 7) != 0))
{
errno = EINVAL;
goto fail;
}
- stopwidth = depth / 8;
+ stopwidth = (size_t)(depth / 8);
break;
}
@@ -2393,3 +2437,9 @@ int libcoopgamma_set_gamma_sync(libcoopgamma_filter_t* restrict filter, libcoopg
libcoopgamma_set_gamma_recv(ctx, &async), -1);
}
+
+
+#if defined(__GNUC__)
+# pragma GCC diagnostic pop
+#endif
+
diff --git a/src/libcoopgamma.h b/src/libcoopgamma.h
index 341bd1a..e4764bd 100644
--- a/src/libcoopgamma.h
+++ b/src/libcoopgamma.h
@@ -20,11 +20,19 @@
+#include <limits.h>
#include <stddef.h>
#include <stdint.h>
+#if defined(__clang__)
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wdocumentation"
+#endif
+
+
+
/**
* Unmarshal was successful
*/
@@ -266,7 +274,7 @@ typedef struct libcoopgamma_ramps##suffix \
*/ \
type* blue; \
\
-} libcoopgamma_ramps##suffix##_t;
+} libcoopgamma_ramps##suffix##_t
/**
* `typedef struct libcoopgamma_ramps8 libcoopgamma_ramps8_t`
@@ -318,11 +326,6 @@ LIBCOOPGAMMA_RAMPS__(d, double);
typedef struct libcoopgamma_filter
{
/**
- * The data type and bit-depth of the ramp stops
- */
- libcoopgamma_depth_t depth;
-
- /**
* The priority of the filter, higher priority
* is applied first. The gamma correction should
* have priority 0.
@@ -350,6 +353,11 @@ typedef struct libcoopgamma_filter
libcoopgamma_lifespan_t lifespan;
/**
+ * The data type and bit-depth of the ramp stops
+ */
+ libcoopgamma_depth_t depth;
+
+ /**
* The gamma ramp adjustments of the filter
*/
union
@@ -405,6 +413,17 @@ typedef struct libcoopgamma_crtc_info
libcoopgamma_depth_t depth;
/**
+ * Is gamma adjustments supported on the CRTC?
+ * If not, `.depth`, `.red_size`, `.green_size`,
+ * and `.blue_size` are undefined
+ */
+ libcoopgamma_support_t supported;
+
+#if INT_MAX != LONG_MAX
+ int padding__;
+#endif
+
+ /**
* The number of stops in the red ramp
*/
size_t red_size;
@@ -419,13 +438,6 @@ typedef struct libcoopgamma_crtc_info
*/
size_t blue_size;
- /**
- * Is gamma adjustments supported on the CRTC?
- * If not, `.depth`, `.red_size`, `.green_size`,
- * and `.blue_size` are undefined
- */
- libcoopgamma_support_t supported;
-
} libcoopgamma_crtc_info_t;
@@ -437,6 +449,18 @@ typedef struct libcoopgamma_crtc_info
typedef struct libcoopgamma_filter_query
{
/**
+ * Do no return filters with higher
+ * priority than this value
+ */
+ int64_t high_priority;
+
+ /**
+ * Do no return filters with lower
+ * priority than this value
+ */
+ int64_t low_priority;
+
+ /**
* The CRTC for which the the current
* filters shall returned
*/
@@ -448,17 +472,9 @@ typedef struct libcoopgamma_filter_query
*/
int coalesce;
- /**
- * Do no return filters with higher
- * priority than this value
- */
- int64_t high_priority;
-
- /**
- * Do no return filters with lower
- * priority than this value
- */
- int64_t low_priority;
+#if INT_MAX != LONG_MAX
+ int padding__;
+#endif
} libcoopgamma_filter_query_t;
@@ -528,11 +544,6 @@ typedef struct libcoopgamma_queried_filter
typedef struct libcoopgamma_filter_table
{
/**
- * The data type and bit-depth of the ramp stops
- */
- libcoopgamma_depth_t depth;
-
- /**
* The number of stops in the red ramp
*/
size_t red_size;
@@ -564,6 +575,15 @@ typedef struct libcoopgamma_filter_table
*/
libcoopgamma_queried_filter_t* filters;
+ /**
+ * The data type and bit-depth of the ramp stops
+ */
+ libcoopgamma_depth_t depth;
+
+#if INT_MAX != LONG_MAX
+ int padding__;
+#endif
+
} libcoopgamma_filter_table_t;
@@ -610,16 +630,32 @@ typedef struct libcoopgamma_error
typedef struct libcoopgamma_context
{
/**
+ * The error of the last failed function call
+ *
+ * This member is undefined after successful function call
+ */
+ libcoopgamma_error_t error;
+
+ /**
* File descriptor for the socket
*/
int fd;
/**
- * The error of the last failed function call
- *
- * This member is undefined after successful function call
+ * Whether `libcoopgamma_synchronise` have
+ * read the empty end-of-headers line
*/
- libcoopgamma_error_t error;
+ int have_all_headers;
+
+ /**
+ * Whether `libcoopgamma_synchronise` is reading
+ * a corrupt but recoverable message
+ */
+ int bad_message;
+
+#if INT_MAX != LONG_MAX
+ int padding__;
+#endif
/**
* Message ID of the next message
@@ -627,6 +663,13 @@ typedef struct libcoopgamma_context
uint32_t message_id;
/**
+ * The ID of outbound message to which the inbound
+ * message being read by `libcoopgamma_synchronise`
+ * is a response
+ */
+ uint32_t in_response_to;
+
+ /**
* Buffer with the outbound message
*/
char* outbound;
@@ -678,25 +721,6 @@ typedef struct libcoopgamma_context
*/
size_t curline;
- /**
- * The ID of outbound message to which the inbound
- * message being read by `libcoopgamma_synchronise`
- * is a response
- */
- uint32_t in_response_to;
-
- /**
- * Whether `libcoopgamma_synchronise` have
- * read the empty end-of-headers line
- */
- int have_all_headers;
-
- /**
- * Whether `libcoopgamma_synchronise` is reading
- * a corrupt but recoverable message
- */
- int bad_message;
-
} libcoopgamma_context_t;
@@ -768,7 +792,7 @@ typedef struct libcoopgamma_async_context
* `this->red_size`, `this->green_size`, and `this->blue_size` must already be set
*
* @param this The record to initialise
- * @para width The `sizeof(*(this->red))`
+ * @param width The `sizeof(*(this->red))`
* @return Zero on success, -1 on error
*/
int (libcoopgamma_ramps_initialise)(void* restrict, size_t);
@@ -1468,5 +1492,11 @@ int libcoopgamma_set_gamma_sync(libcoopgamma_filter_t* restrict, libcoopgamma_de
+#if defined(__clang__)
+# pragma GCC diagnostic pop
+#endif
+
+
+
#endif