diff options
author | David Wragg <david@rabbitmq.com> | 2010-10-21 17:49:04 +0100 |
---|---|---|
committer | David Wragg <david@rabbitmq.com> | 2010-10-21 17:49:04 +0100 |
commit | ceda8246d3fe0ceb51f680848c8cbe45c332f71a (patch) | |
tree | 230ced98a3e83f94c37303f0f03d3f1177eb180f | |
parent | 0d25d02e769dca4ced51580a7d47061717da2bec (diff) | |
download | rabbitmq-c-github-ask-ceda8246d3fe0ceb51f680848c8cbe45c332f71a.tar.gz |
Eliminate the amqp_assert macro
It relied on gccisms. Replace it with a amqp_abort function.
-rw-r--r-- | librabbitmq/amqp_api.c | 13 | ||||
-rw-r--r-- | librabbitmq/amqp_connection.c | 27 | ||||
-rw-r--r-- | librabbitmq/amqp_private.h | 9 | ||||
-rw-r--r-- | librabbitmq/amqp_socket.c | 36 |
4 files changed, 46 insertions, 39 deletions
diff --git a/librabbitmq/amqp_api.c b/librabbitmq/amqp_api.c index b2793ff..25b855f 100644 --- a/librabbitmq/amqp_api.c +++ b/librabbitmq/amqp_api.c @@ -52,6 +52,7 @@ #include <stdio.h> #include <string.h> #include <stdint.h> +#include <stdarg.h> #include "amqp.h" #include "amqp_framing.h" @@ -93,6 +94,18 @@ char *amqp_error_string(int err) return strdup(str); } +void amqp_abort(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fputc('\n', stderr); + abort(); +} + + + #define RPC_REPLY(replytype) \ (state->most_recent_api_result.reply_type == AMQP_RESPONSE_NORMAL \ ? (replytype *) state->most_recent_api_result.reply.decoded \ diff --git a/librabbitmq/amqp_connection.c b/librabbitmq/amqp_connection.c index 0bac627..ee467c3 100644 --- a/librabbitmq/amqp_connection.c +++ b/librabbitmq/amqp_connection.c @@ -62,14 +62,14 @@ #define INITIAL_DECODING_POOL_PAGE_SIZE 131072 #define INITIAL_INBOUND_SOCK_BUFFER_SIZE 131072 -#define ENFORCE_STATE(statevec, statenum) \ - { \ - amqp_connection_state_t _check_state = (statevec); \ - int _wanted_state = (statenum); \ - amqp_assert(_check_state->state == _wanted_state, \ - "Programming error: invalid AMQP connection state: expected %d, got %d", \ - _wanted_state, \ - _check_state->state); \ +#define ENFORCE_STATE(statevec, statenum) \ + { \ + amqp_connection_state_t _check_state = (statevec); \ + int _wanted_state = (statenum); \ + if (_check_state->state != _wanted_state) \ + amqp_abort("Programming error: invalid AMQP connection state: expected %d, got %d", \ + _wanted_state, \ + _check_state->state); \ } amqp_connection_state_t amqp_new_connection(void) { @@ -313,8 +313,9 @@ int amqp_handle_input(amqp_connection_state_t state, case CONNECTION_STATE_WAITING_FOR_PROTOCOL_HEADER: decoded_frame->frame_type = AMQP_PSEUDOFRAME_PROTOCOL_HEADER; decoded_frame->channel = AMQP_PSEUDOFRAME_PROTOCOL_CHANNEL; - amqp_assert(D_8(state->inbound_buffer, 3) == (uint8_t) 'P', - "Invalid protocol header received"); + if (D_8(state->inbound_buffer, 3) != (uint8_t) 'P') + amqp_abort("Invalid protocol header received"); + decoded_frame->payload.protocol_header.transport_high = D_8(state->inbound_buffer, 4); decoded_frame->payload.protocol_header.transport_low = D_8(state->inbound_buffer, 5); decoded_frame->payload.protocol_header.protocol_version_major = D_8(state->inbound_buffer, 6); @@ -324,7 +325,7 @@ int amqp_handle_input(amqp_connection_state_t state, return total_bytes_consumed; default: - amqp_assert(0, "Internal error: invalid amqp_connection_state_t->state %d", state->state); + amqp_abort("Internal error: invalid amqp_connection_state_t->state %d", state->state); } } @@ -335,8 +336,8 @@ amqp_boolean_t amqp_release_buffers_ok(amqp_connection_state_t state) { void amqp_release_buffers(amqp_connection_state_t state) { ENFORCE_STATE(state, CONNECTION_STATE_IDLE); - amqp_assert(state->first_queued_frame == NULL, - "Programming error: attempt to amqp_release_buffers while waiting events enqueued"); + if (state->first_queued_frame) + amqp_abort("Programming error: attempt to amqp_release_buffers while waiting events enqueued"); recycle_amqp_pool(&state->frame_pool); recycle_amqp_pool(&state->decoding_pool); diff --git a/librabbitmq/amqp_private.h b/librabbitmq/amqp_private.h index 905c638..0ff71c7 100644 --- a/librabbitmq/amqp_private.h +++ b/librabbitmq/amqp_private.h @@ -279,14 +279,7 @@ extern int amqp_encode_table(amqp_bytes_t encoded, amqp_table_t *input, size_t *offset); -#define amqp_assert(condition, ...) \ - ({ \ - if (!(condition)) { \ - fprintf(stderr, __VA_ARGS__); \ - fputc('\n', stderr); \ - abort(); \ - } \ - }) +extern void amqp_abort(const char *fmt, ...); #define AMQP_CHECK_RESULT_CLEANUP(expr, stmts) \ ({ \ diff --git a/librabbitmq/amqp_socket.c b/librabbitmq/amqp_socket.c index 42fe446..6f93d0c 100644 --- a/librabbitmq/amqp_socket.c +++ b/librabbitmq/amqp_socket.c @@ -124,7 +124,7 @@ static amqp_bytes_t sasl_method_name(amqp_sasl_method_enum method) { switch (method) { case AMQP_SASL_METHOD_PLAIN: return (amqp_bytes_t) {.len = 5, .bytes = "PLAIN"}; default: - amqp_assert(0, "Invalid SASL method: %d", (int) method); + amqp_abort("Invalid SASL method: %d", (int) method); } abort(); /* unreachable */ } @@ -154,7 +154,7 @@ static amqp_bytes_t sasl_response(amqp_pool_t *pool, break; } default: - amqp_assert(0, "Invalid SASL method: %d", (int) method); + amqp_abort("Invalid SASL method: %d", (int) method); } return response; @@ -232,22 +232,22 @@ int amqp_simple_wait_method(amqp_connection_state_t state, int res = amqp_simple_wait_frame(state, &frame); if (res < 0) return res; - - amqp_assert(frame.channel == expected_channel, - "Expected 0x%08X method frame on channel %d, got frame on channel %d", - expected_method, - expected_channel, - frame.channel); - amqp_assert(frame.frame_type == AMQP_FRAME_METHOD, - "Expected 0x%08X method frame on channel %d, got frame type %d", - expected_method, - expected_channel, - frame.frame_type); - amqp_assert(frame.payload.method.id == expected_method, - "Expected method ID 0x%08X on channel %d, got ID 0x%08X", - expected_method, - expected_channel, - frame.payload.method.id); + + if (frame.channel != expected_channel) + amqp_abort("Expected 0x%08X method frame on channel %d, got frame on channel %d", + expected_method, + expected_channel, + frame.channel); + if (frame.frame_type != AMQP_FRAME_METHOD) + amqp_abort("Expected 0x%08X method frame on channel %d, got frame type %d", + expected_method, + expected_channel, + frame.frame_type); + if (frame.payload.method.id != expected_method) + amqp_abort("Expected method ID 0x%08X on channel %d, got ID 0x%08X", + expected_method, + expected_channel, + frame.payload.method.id); *output = frame.payload.method; return 0; } |