From 51345a3ded6ecd073921b7e83ec06bbd8988c345 Mon Sep 17 00:00:00 2001 From: David Wragg Date: Thu, 21 Oct 2010 17:49:04 +0100 Subject: Eliminate the AMQP_EMPTY_* macros from amqp.h Hooray, amqp.h is now ISO C90 clean. --- examples/amqp_bind.c | 2 +- examples/amqp_consumer.c | 8 ++++---- examples/amqp_exchange_declare.c | 2 +- examples/amqp_listen.c | 8 ++++---- examples/amqp_listenq.c | 2 +- examples/amqp_unbind.c | 2 +- librabbitmq/amqp.h | 11 +++++------ librabbitmq/amqp_api.c | 4 +++- tools/common.c | 2 +- tools/consume.c | 8 ++++---- tools/declare_queue.c | 2 +- 11 files changed, 26 insertions(+), 25 deletions(-) diff --git a/examples/amqp_bind.c b/examples/amqp_bind.c index 1f183a5..8ffda3f 100644 --- a/examples/amqp_bind.c +++ b/examples/amqp_bind.c @@ -94,7 +94,7 @@ int main(int argc, char const * const *argv) { amqp_cstring_bytes(queue), amqp_cstring_bytes(exchange), amqp_cstring_bytes(bindingkey), - AMQP_EMPTY_TABLE); + amqp_empty_table); die_on_amqp_error(amqp_get_rpc_reply(conn), "Unbinding"); die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); diff --git a/examples/amqp_consumer.c b/examples/amqp_consumer.c index 9341823..2a0d9b9 100644 --- a/examples/amqp_consumer.c +++ b/examples/amqp_consumer.c @@ -163,8 +163,8 @@ int main(int argc, char const * const *argv) { die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); { - amqp_queue_declare_ok_t *r = amqp_queue_declare(conn, 1, AMQP_EMPTY_BYTES, 0, 0, 0, 1, - AMQP_EMPTY_TABLE); + amqp_queue_declare_ok_t *r = amqp_queue_declare(conn, 1, amqp_empty_bytes, 0, 0, 0, 1, + amqp_empty_table); die_on_amqp_error(amqp_get_rpc_reply(conn), "Declaring queue"); queuename = amqp_bytes_malloc_dup(r->queue); if (queuename.bytes == NULL) { @@ -174,10 +174,10 @@ int main(int argc, char const * const *argv) { } amqp_queue_bind(conn, 1, queuename, amqp_cstring_bytes(exchange), amqp_cstring_bytes(bindingkey), - AMQP_EMPTY_TABLE); + amqp_empty_table); die_on_amqp_error(amqp_get_rpc_reply(conn), "Binding queue"); - amqp_basic_consume(conn, 1, queuename, AMQP_EMPTY_BYTES, 0, 1, 0, AMQP_EMPTY_TABLE); + amqp_basic_consume(conn, 1, queuename, amqp_empty_bytes, 0, 1, 0, amqp_empty_table); die_on_amqp_error(amqp_get_rpc_reply(conn), "Consuming"); run(conn); diff --git a/examples/amqp_exchange_declare.c b/examples/amqp_exchange_declare.c index e77ac52..b4b28ad 100644 --- a/examples/amqp_exchange_declare.c +++ b/examples/amqp_exchange_declare.c @@ -89,7 +89,7 @@ int main(int argc, char const * const *argv) { die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); amqp_exchange_declare(conn, 1, amqp_cstring_bytes(exchange), amqp_cstring_bytes(exchangetype), - 0, 0, AMQP_EMPTY_TABLE); + 0, 0, amqp_empty_table); die_on_amqp_error(amqp_get_rpc_reply(conn), "Declaring exchange"); die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); diff --git a/examples/amqp_listen.c b/examples/amqp_listen.c index f208652..7fd5af2 100644 --- a/examples/amqp_listen.c +++ b/examples/amqp_listen.c @@ -95,8 +95,8 @@ int main(int argc, char const * const *argv) { die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); { - amqp_queue_declare_ok_t *r = amqp_queue_declare(conn, 1, AMQP_EMPTY_BYTES, 0, 0, 0, 1, - AMQP_EMPTY_TABLE); + amqp_queue_declare_ok_t *r = amqp_queue_declare(conn, 1, amqp_empty_bytes, 0, 0, 0, 1, + amqp_empty_table); die_on_amqp_error(amqp_get_rpc_reply(conn), "Declaring queue"); queuename = amqp_bytes_malloc_dup(r->queue); if (queuename.bytes == NULL) { @@ -106,10 +106,10 @@ int main(int argc, char const * const *argv) { } amqp_queue_bind(conn, 1, queuename, amqp_cstring_bytes(exchange), amqp_cstring_bytes(bindingkey), - AMQP_EMPTY_TABLE); + amqp_empty_table); die_on_amqp_error(amqp_get_rpc_reply(conn), "Binding queue"); - amqp_basic_consume(conn, 1, queuename, AMQP_EMPTY_BYTES, 0, 1, 0, AMQP_EMPTY_TABLE); + amqp_basic_consume(conn, 1, queuename, amqp_empty_bytes, 0, 1, 0, amqp_empty_table); die_on_amqp_error(amqp_get_rpc_reply(conn), "Consuming"); { diff --git a/examples/amqp_listenq.c b/examples/amqp_listenq.c index 98c389f..18489da 100644 --- a/examples/amqp_listenq.c +++ b/examples/amqp_listenq.c @@ -90,7 +90,7 @@ int main(int argc, char const * const *argv) { amqp_channel_open(conn, 1); die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); - amqp_basic_consume(conn, 1, amqp_cstring_bytes(queuename), AMQP_EMPTY_BYTES, 0, 0, 0, AMQP_EMPTY_TABLE); + amqp_basic_consume(conn, 1, amqp_cstring_bytes(queuename), amqp_empty_bytes, 0, 0, 0, amqp_empty_table); die_on_amqp_error(amqp_get_rpc_reply(conn), "Consuming"); { diff --git a/examples/amqp_unbind.c b/examples/amqp_unbind.c index 4b92e12..b014067 100644 --- a/examples/amqp_unbind.c +++ b/examples/amqp_unbind.c @@ -94,7 +94,7 @@ int main(int argc, char const * const *argv) { amqp_cstring_bytes(queue), amqp_cstring_bytes(exchange), amqp_cstring_bytes(bindingkey), - AMQP_EMPTY_TABLE); + amqp_empty_table); die_on_amqp_error(amqp_get_rpc_reply(conn), "Unbinding"); die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); diff --git a/librabbitmq/amqp.h b/librabbitmq/amqp.h index 308119d..a0f8331 100644 --- a/librabbitmq/amqp.h +++ b/librabbitmq/amqp.h @@ -75,8 +75,6 @@ typedef struct amqp_bytes_t_ { void *bytes; } amqp_bytes_t; -#define AMQP_EMPTY_BYTES ((amqp_bytes_t) { .len = 0, .bytes = NULL }) - typedef struct amqp_decimal_t_ { uint8_t decimals; uint32_t value; @@ -87,15 +85,11 @@ typedef struct amqp_table_t_ { struct amqp_table_entry_t_ *entries; } amqp_table_t; -#define AMQP_EMPTY_TABLE ((amqp_table_t) { .num_entries = 0, .entries = NULL }) - typedef struct amqp_array_t_ { int num_entries; struct amqp_field_value_t_ *entries; } amqp_array_t; -#define AMQP_EMPTY_ARRAY ((amqp_array_t) { .num_entries = 0, .entries = NULL }) - /* 0-9 0-9-1 Qpid/Rabbit Type Remarks --------------------------------------------------------------------------- @@ -246,6 +240,11 @@ typedef struct amqp_connection_state_t_ *amqp_connection_state_t; RABBITMQ_EXPORT char const *amqp_version(void); +/* Exported empty data structures */ +RABBITMQ_EXPORT const amqp_bytes_t amqp_empty_bytes; +RABBITMQ_EXPORT const amqp_table_t amqp_empty_table; +RABBITMQ_EXPORT const amqp_array_t amqp_empty_array; + RABBITMQ_EXPORT void init_amqp_pool(amqp_pool_t *pool, size_t pagesize); RABBITMQ_EXPORT void recycle_amqp_pool(amqp_pool_t *pool); RABBITMQ_EXPORT void empty_amqp_pool(amqp_pool_t *pool); diff --git a/librabbitmq/amqp_api.c b/librabbitmq/amqp_api.c index d74f877..bf19761 100644 --- a/librabbitmq/amqp_api.c +++ b/librabbitmq/amqp_api.c @@ -110,7 +110,9 @@ void amqp_abort(const char *fmt, ...) abort(); } - +const amqp_bytes_t amqp_empty_bytes = { 0, NULL }; +const amqp_table_t amqp_empty_table = { 0, NULL }; +const amqp_array_t amqp_empty_array = { 0, NULL }; #define RPC_REPLY(replytype) \ (state->most_recent_api_result.reply_type == AMQP_RESPONSE_NORMAL \ diff --git a/tools/common.c b/tools/common.c index f8b6985..7b0a969 100644 --- a/tools/common.c +++ b/tools/common.c @@ -354,5 +354,5 @@ void process_all_options(int argc, const char **argv, amqp_bytes_t cstring_bytes(const char *str) { - return str ? amqp_cstring_bytes(str) : AMQP_EMPTY_BYTES; + return str ? amqp_cstring_bytes(str) : amqp_empty_bytes; } diff --git a/tools/consume.c b/tools/consume.c index 34037d9..434a6f5 100644 --- a/tools/consume.c +++ b/tools/consume.c @@ -100,7 +100,7 @@ static amqp_bytes_t setup_queue(amqp_connection_state_t conn, /* Declare the queue as auto-delete. */ amqp_queue_declare_ok_t *res = amqp_queue_declare(conn, 1, queue_bytes, 0, 0, 1, 1, - AMQP_EMPTY_TABLE); + amqp_empty_table); if (!res) die_rpc(amqp_get_rpc_reply(conn), "queue.declare"); @@ -119,7 +119,7 @@ static amqp_bytes_t setup_queue(amqp_connection_state_t conn, amqp_bytes_t eb = amqp_cstring_bytes(exchange); if (!amqp_queue_bind(conn, 1, queue_bytes, eb, cstring_bytes(routing_key), - AMQP_EMPTY_TABLE)) + amqp_empty_table)) die_rpc(amqp_get_rpc_reply(conn), "queue.bind"); } @@ -131,8 +131,8 @@ static amqp_bytes_t setup_queue(amqp_connection_state_t conn, static void do_consume(amqp_connection_state_t conn, amqp_bytes_t queue, int no_ack, const char * const *argv) { - if (!amqp_basic_consume(conn, 1, queue, AMQP_EMPTY_BYTES, 0, no_ack, - 0, AMQP_EMPTY_TABLE)) + if (!amqp_basic_consume(conn, 1, queue, amqp_empty_bytes, 0, no_ack, + 0, amqp_empty_table)) die_rpc(amqp_get_rpc_reply(conn), "basic.consume"); for (;;) { diff --git a/tools/declare_queue.c b/tools/declare_queue.c index 3536455..7ef7eb6 100644 --- a/tools/declare_queue.c +++ b/tools/declare_queue.c @@ -88,7 +88,7 @@ int main(int argc, const char **argv) durable, 0, 0, - AMQP_EMPTY_TABLE); + amqp_empty_table); if (reply == NULL) { die_rpc(amqp_get_rpc_reply(conn), "queue.declare"); } -- cgit v1.2.1