From 46339bf905fc4f7ce4b0cc91f32a9f4ff2af2430 Mon Sep 17 00:00:00 2001 From: Trond Norbye Date: Tue, 6 Oct 2009 00:32:26 +0200 Subject: [PATCH] Create workaround for warnings generated by a broken C99 compiler Some of the flags to turn on extra analysis and warnings in gcc contains various bugs related to struct initializations (see section 6.7.8 in C99) causing bogus warnings to be generated. Due to the fact that we compile with warning == error, this is a showstopper for us. We cannot expect all users to be running the latest compilers, so we have to create the workaround in our code. --- example/Makefile.am | 1 + example/interface_v0.c | 40 ++++++++++++++++++++++++++ example/memcached_light.c | 7 +++++ example/memcached_light.h | 7 +++++ libmemcached/protocol/binary_handler.c | 3 +- 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 example/memcached_light.h diff --git a/example/Makefile.am b/example/Makefile.am index 62bd5911..9c570822 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -1,6 +1,7 @@ noinst_PROGRAMS = memcached_light memcached_light_SOURCES= memcached_light.c \ + memcached_light.h \ storage.h \ interface_v0.c \ interface_v1.c diff --git a/example/interface_v0.c b/example/interface_v0.c index 041fe31e..85dd2c7d 100644 --- a/example/interface_v0.c +++ b/example/interface_v0.c @@ -20,6 +20,7 @@ #include #include #include "storage.h" +#include "memcached_light.h" static protocol_binary_response_status noop_command_handler(const void *cookie, protocol_binary_request_header *header, @@ -521,6 +522,13 @@ static protocol_binary_response_status stat_command_handler(const void *cookie, memcached_binary_protocol_callback_st interface_v0_impl= { .interface_version= 0, +#ifdef FUTURE + /* + ** There is a number of bugs in the extra options for gcc causing + ** warning on these struct initializers. It hurts my heart to remove + ** it so I'll just leave it in here so that we can enable it when + ** we can drop support for the broken compilers + */ .interface.v0.comcode[PROTOCOL_BINARY_CMD_GET]= get_command_handler, .interface.v0.comcode[PROTOCOL_BINARY_CMD_SET]= set_command_handler, .interface.v0.comcode[PROTOCOL_BINARY_CMD_ADD]= add_command_handler, @@ -548,4 +556,36 @@ memcached_binary_protocol_callback_st interface_v0_impl= { .interface.v0.comcode[PROTOCOL_BINARY_CMD_FLUSHQ]= flush_command_handler, .interface.v0.comcode[PROTOCOL_BINARY_CMD_APPENDQ]= concat_command_handler, .interface.v0.comcode[PROTOCOL_BINARY_CMD_PREPENDQ]= concat_command_handler, +#endif }; + +void initialize_iterface_v0_handler(void) +{ + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_GET]= get_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_SET]= set_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_ADD]= add_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_REPLACE]= replace_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_DELETE]= delete_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_INCREMENT]= arithmetic_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_DECREMENT]= arithmetic_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_QUIT]= quit_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_FLUSH]= flush_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_GETQ]= get_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_NOOP]= noop_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_VERSION]= version_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_GETK]= get_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_GETKQ]= get_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_APPEND]= concat_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_PREPEND]= concat_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_STAT]= stat_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_SETQ]= set_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_ADDQ]= add_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_REPLACEQ]= replace_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_DELETEQ]= delete_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_INCREMENTQ]= arithmetic_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_DECREMENTQ]= arithmetic_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_QUITQ]= quit_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_FLUSHQ]= flush_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_APPENDQ]= concat_command_handler; + interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_PREPENDQ]= concat_command_handler; +} diff --git a/example/memcached_light.c b/example/memcached_light.c index 741ef82e..86087c5a 100644 --- a/example/memcached_light.c +++ b/example/memcached_light.c @@ -40,6 +40,7 @@ #include #include #include "storage.h" +#include "memcached_light.h" extern memcached_binary_protocol_callback_st interface_v0_impl; extern memcached_binary_protocol_callback_st interface_v1_impl; @@ -229,6 +230,12 @@ int main(int argc, char **argv) int cmd; memcached_binary_protocol_callback_st *interface= &interface_v0_impl; + /* + * We need to initialize the handlers manually due to a bug in the + * warnings generated by struct initialization in gcc (all the way up to 4.4) + */ + initialize_iterface_v0_handler(); + while ((cmd= getopt(argc, argv, "v1p:?")) != EOF) { switch (cmd) { diff --git a/example/memcached_light.h b/example/memcached_light.h new file mode 100644 index 00000000..e1ca4152 --- /dev/null +++ b/example/memcached_light.h @@ -0,0 +1,7 @@ +/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ +#ifndef MEMCACHED_LIGHT_H +#define MEMCACHED_LIGHT_H + +extern void initialize_iterface_v0_handler(void); + +#endif diff --git a/libmemcached/protocol/binary_handler.c b/libmemcached/protocol/binary_handler.c index 27581ec8..2bafdeb1 100644 --- a/libmemcached/protocol/binary_handler.c +++ b/libmemcached/protocol/binary_handler.c @@ -125,9 +125,10 @@ get_response_handler(const void *cookie, .extlen= 4, .bodylen= htonl(bodylen + keylen + 4), }, - .message.body.flags= htonl(flags), }; + response.message.body.flags= htonl(flags); + protocol_binary_response_status rval; const protocol_binary_response_status success= PROTOCOL_BINARY_RESPONSE_SUCCESS; if ((rval= client->root->spool(client, response.bytes, sizeof(response.bytes))) != success || -- 2.30.2