diff options
author | Michael Steinert <mike.steinert@gmail.com> | 2012-05-16 12:13:31 -0600 |
---|---|---|
committer | Michael Steinert <mike.steinert@gmail.com> | 2012-05-17 11:44:46 -0600 |
commit | c921feb829e79a33938300350e61e3c3fb217968 (patch) | |
tree | b2054ac86a99fc4a52ded75826aad86e2561781b | |
parent | 162fc19f4d896c3db862f1da303823dcbe9780ec (diff) | |
download | rabbitmq-c-github-ask-c921feb829e79a33938300350e61e3c3fb217968.tar.gz |
Set default visibility to hidden & enable a couple more warnings
Enable the following GCC options:
1. -Wstrict-prototypes
2. -Wcast-align
3. -fno-common
4. -fvisibility=hidden
This commit also includes some general cleanup of header files (mostly
for readability).
Signed-off-by: Michael Steinert <mike.steinert@gmail.com>
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | librabbitmq/CMakeLists.txt | 5 | ||||
-rw-r--r-- | librabbitmq/amqp.h | 371 | ||||
-rw-r--r-- | librabbitmq/amqp_api.c | 14 | ||||
-rw-r--r-- | librabbitmq/amqp_connection.c | 11 | ||||
-rw-r--r-- | librabbitmq/amqp_mem.c | 9 | ||||
-rw-r--r-- | librabbitmq/amqp_private.h | 24 | ||||
-rw-r--r-- | librabbitmq/amqp_socket.c | 6 | ||||
-rw-r--r-- | librabbitmq/amqp_table.c | 11 | ||||
-rw-r--r-- | librabbitmq/amqp_url.c | 9 | ||||
-rw-r--r-- | librabbitmq/codegen.py | 88 | ||||
-rw-r--r-- | librabbitmq/unix/socket.c | 24 | ||||
-rw-r--r-- | librabbitmq/unix/socket.h | 25 | ||||
-rw-r--r-- | librabbitmq/windows/socket.c | 33 | ||||
-rw-r--r-- | librabbitmq/windows/socket.h | 39 | ||||
-rw-r--r-- | tests/test_tables.c | 7 |
17 files changed, 401 insertions, 282 deletions
diff --git a/Makefile.am b/Makefile.am index c44bfc2..09cb5e4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,8 +13,7 @@ librabbitmq_librabbitmq_la_SOURCES = \ librabbitmq/amqp_url.c librabbitmq_librabbitmq_la_CFLAGS = \ - -I$(top_srcdir)/librabbitmq \ - -DBUILDING_LIBRABBITMQ + -I$(top_srcdir)/librabbitmq librabbitmq_librabbitmq_la_LDFLAGS = \ -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \ diff --git a/configure.ac b/configure.ac index ae667fa..3f5801c 100644 --- a/configure.ac +++ b/configure.ac @@ -36,6 +36,10 @@ AC_C_INLINE AX_TRY_CFLAGS([-Wall], [AX_CFLAGS([-Wall])]) AX_TRY_CFLAGS([-Wextra], [AX_CFLAGS([-Wextra])]) AX_TRY_CFLAGS([-pedantic], [AX_CFLAGS([-pedantic])]) +AX_TRY_CFLAGS([-Wstrict-prototypes], [AX_CFLAGS([-Wstrict-prototypes])]) +AX_TRY_CFLAGS([-Wcast-align], [AX_CFLAGS([-Wcast-align])]) +AX_TRY_CFLAGS([-fno-common], [AX_CFLAGS([-fno-common])]) +AX_TRY_CFLAGS([-fvisibility=hidden], [AX_CFLAGS([-fvisibility=hidden])]) AX_TRY_LDFLAGS([-no-undefined], [NO_UNDEFINED=-no-undefined]) AC_SUBST([NO_UNDEFINED]) diff --git a/librabbitmq/CMakeLists.txt b/librabbitmq/CMakeLists.txt index 4364cfb..bced62e 100644 --- a/librabbitmq/CMakeLists.txt +++ b/librabbitmq/CMakeLists.txt @@ -68,10 +68,7 @@ set(LIBRABBITMQ_INCLUDE_DIRS ${LIBRABBITMQ_INCLUDE_DIRS} PARENT_SCOPE) -add_definitions( - -DBUILDING_LIBRABBITMQ - -DHAVE_CONFIG_H - ) +add_definitions(-DHAVE_CONFIG_H) set(RABBITMQ_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/amqp_framing.h diff --git a/librabbitmq/amqp.h b/librabbitmq/amqp.h index 8b91cdc..2e39bd1 100644 --- a/librabbitmq/amqp.h +++ b/librabbitmq/amqp.h @@ -1,6 +1,3 @@ -#ifndef librabbitmq_amqp_h -#define librabbitmq_amqp_h - /* * ***** BEGIN LICENSE BLOCK ***** * Version: MIT @@ -33,23 +30,41 @@ * ***** END LICENSE BLOCK ***** */ -#include <stdint.h> -#include <stddef.h> +#ifndef AMQP_H +#define AMQP_H #ifdef __cplusplus -extern "C" { +#define AMQP_BEGIN_DECLS extern "C" { +#define AMQP_END_DECLS } +#else +#define AMQP_BEGIN_DECLS +#define AMQP_END_DECLS #endif -#ifdef _WIN32 -#ifdef BUILDING_LIBRABBITMQ -#define RABBITMQ_EXPORT extern __declspec(dllexport) +#if defined (_WIN32) || defined (__CYGWIN__) +#ifndef AMQP_WIN32_BUILD +#define AMQP_PUBLIC __declspec(dllimport) #else -#define RABBITMQ_EXPORT extern __declspec(dllimport) +#define AMQP_PUBLIC __declspec(dllexport) #endif +#define AMQP_PRIVATE #else -#define RABBITMQ_EXPORT extern +#if __GNUC__ >= 4 +#define AMQP_PUBLIC \ + __attribute__ ((visibility ("default"))) +#define AMQP_PRIVATE \ + __attribute__ ((visibility ("hidden"))) +#else +#define AMQP_PUBLIC +#define AMQP_PRIVATE +#endif #endif +#include <stddef.h> +#include <stdint.h> + +AMQP_BEGIN_DECLS + typedef int amqp_boolean_t; typedef uint32_t amqp_method_number_t; typedef uint32_t amqp_flags_t; @@ -223,12 +238,14 @@ typedef enum amqp_sasl_method_enum_ { /* Opaque struct. */ typedef struct amqp_connection_state_t_ *amqp_connection_state_t; -RABBITMQ_EXPORT char const *amqp_version(void); +AMQP_PUBLIC +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; +AMQP_PUBLIC extern const amqp_bytes_t amqp_empty_bytes; +AMQP_PUBLIC extern const amqp_table_t amqp_empty_table; +AMQP_PUBLIC extern const amqp_array_t amqp_empty_array; /* Compatibility macros for the above, to avoid the need to update code written against earlier versions of librabbitmq. */ @@ -236,79 +253,141 @@ RABBITMQ_EXPORT const amqp_array_t amqp_empty_array; #define AMQP_EMPTY_TABLE amqp_empty_table #define AMQP_EMPTY_ARRAY 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); - -RABBITMQ_EXPORT void *amqp_pool_alloc(amqp_pool_t *pool, size_t amount); -RABBITMQ_EXPORT void amqp_pool_alloc_bytes(amqp_pool_t *pool, - size_t amount, amqp_bytes_t *output); - -RABBITMQ_EXPORT amqp_bytes_t amqp_cstring_bytes(char const *cstr); -RABBITMQ_EXPORT amqp_bytes_t amqp_bytes_malloc_dup(amqp_bytes_t src); -RABBITMQ_EXPORT amqp_bytes_t amqp_bytes_malloc(size_t amount); -RABBITMQ_EXPORT void amqp_bytes_free(amqp_bytes_t bytes); - -RABBITMQ_EXPORT amqp_connection_state_t amqp_new_connection(void); -RABBITMQ_EXPORT int amqp_get_sockfd(amqp_connection_state_t state); -RABBITMQ_EXPORT void amqp_set_sockfd(amqp_connection_state_t state, - int sockfd); -RABBITMQ_EXPORT int amqp_tune_connection(amqp_connection_state_t state, - int channel_max, - int frame_max, - int heartbeat); -RABBITMQ_EXPORT int amqp_get_channel_max(amqp_connection_state_t state); -RABBITMQ_EXPORT int amqp_destroy_connection(amqp_connection_state_t state); - -RABBITMQ_EXPORT int amqp_handle_input(amqp_connection_state_t state, - amqp_bytes_t received_data, - amqp_frame_t *decoded_frame); - -RABBITMQ_EXPORT amqp_boolean_t amqp_release_buffers_ok( - amqp_connection_state_t state); - -RABBITMQ_EXPORT void amqp_release_buffers(amqp_connection_state_t state); - -RABBITMQ_EXPORT void amqp_maybe_release_buffers(amqp_connection_state_t state); - -RABBITMQ_EXPORT int amqp_send_frame(amqp_connection_state_t state, - amqp_frame_t const *frame); - -RABBITMQ_EXPORT int amqp_table_entry_cmp(void const *entry1, - void const *entry2); - -RABBITMQ_EXPORT int amqp_open_socket(char const *hostname, - int portnumber); - -RABBITMQ_EXPORT int amqp_send_header(amqp_connection_state_t state); - -RABBITMQ_EXPORT amqp_boolean_t amqp_frames_enqueued( - amqp_connection_state_t state); - -RABBITMQ_EXPORT int amqp_simple_wait_frame(amqp_connection_state_t state, - amqp_frame_t *decoded_frame); - -RABBITMQ_EXPORT int amqp_simple_wait_method(amqp_connection_state_t state, - amqp_channel_t expected_channel, - amqp_method_number_t expected_method, - amqp_method_t *output); - -RABBITMQ_EXPORT int amqp_send_method(amqp_connection_state_t state, - amqp_channel_t channel, - amqp_method_number_t id, - void *decoded); - -RABBITMQ_EXPORT amqp_rpc_reply_t amqp_simple_rpc(amqp_connection_state_t state, - amqp_channel_t channel, - amqp_method_number_t request_id, - amqp_method_number_t *expected_reply_ids, - void *decoded_request_method); - -RABBITMQ_EXPORT void *amqp_simple_rpc_decoded(amqp_connection_state_t state, - amqp_channel_t channel, - amqp_method_number_t request_id, - amqp_method_number_t reply_id, - void *decoded_request_method); +AMQP_PUBLIC +void +init_amqp_pool(amqp_pool_t *pool, size_t pagesize); + +AMQP_PUBLIC +void +recycle_amqp_pool(amqp_pool_t *pool); + +AMQP_PUBLIC +void +empty_amqp_pool(amqp_pool_t *pool); + +AMQP_PUBLIC +void * +amqp_pool_alloc(amqp_pool_t *pool, size_t amount); + +AMQP_PUBLIC +void +amqp_pool_alloc_bytes(amqp_pool_t *pool, size_t amount, amqp_bytes_t *output); + +AMQP_PUBLIC +amqp_bytes_t +amqp_cstring_bytes(char const *cstr); + +AMQP_PUBLIC +amqp_bytes_t +amqp_bytes_malloc_dup(amqp_bytes_t src); + +AMQP_PUBLIC +amqp_bytes_t +amqp_bytes_malloc(size_t amount); + +AMQP_PUBLIC +void +amqp_bytes_free(amqp_bytes_t bytes); + +AMQP_PUBLIC +amqp_connection_state_t +amqp_new_connection(void); + +AMQP_PUBLIC +int +amqp_get_sockfd(amqp_connection_state_t state); + +AMQP_PUBLIC +void +amqp_set_sockfd(amqp_connection_state_t state, int sockfd); + +AMQP_PUBLIC +int +amqp_tune_connection(amqp_connection_state_t state, + int channel_max, + int frame_max, + int heartbeat); + +AMQP_PUBLIC +int +amqp_get_channel_max(amqp_connection_state_t state); + +AMQP_PUBLIC +int +amqp_destroy_connection(amqp_connection_state_t state); + +AMQP_PUBLIC +int +amqp_handle_input(amqp_connection_state_t state, + amqp_bytes_t received_data, + amqp_frame_t *decoded_frame); + +AMQP_PUBLIC +amqp_boolean_t +amqp_release_buffers_ok(amqp_connection_state_t state); + +AMQP_PUBLIC +void +amqp_release_buffers(amqp_connection_state_t state); + +AMQP_PUBLIC +void +amqp_maybe_release_buffers(amqp_connection_state_t state); + +AMQP_PUBLIC +int +amqp_send_frame(amqp_connection_state_t state, amqp_frame_t const *frame); + +AMQP_PUBLIC +int +amqp_table_entry_cmp(void const *entry1, void const *entry2); + +AMQP_PUBLIC +int +amqp_open_socket(char const *hostname, int portnumber); + +AMQP_PUBLIC +int +amqp_send_header(amqp_connection_state_t state); + +AMQP_PUBLIC +amqp_boolean_t +amqp_frames_enqueued(amqp_connection_state_t state); + +AMQP_PUBLIC +int +amqp_simple_wait_frame(amqp_connection_state_t state, + amqp_frame_t *decoded_frame); + +AMQP_PUBLIC +int +amqp_simple_wait_method(amqp_connection_state_t state, + amqp_channel_t expected_channel, + amqp_method_number_t expected_method, + amqp_method_t *output); + +AMQP_PUBLIC +int +amqp_send_method(amqp_connection_state_t state, + amqp_channel_t channel, + amqp_method_number_t id, + void *decoded); + +AMQP_PUBLIC +amqp_rpc_reply_t +amqp_simple_rpc(amqp_connection_state_t state, + amqp_channel_t channel, + amqp_method_number_t request_id, + amqp_method_number_t *expected_reply_ids, + void *decoded_request_method); + +AMQP_PUBLIC +void * +amqp_simple_rpc_decoded(amqp_connection_state_t state, + amqp_channel_t channel, + amqp_method_number_t request_id, + amqp_method_number_t reply_id, + void *decoded_request_method); /* * The API methods corresponding to most synchronous AMQP methods @@ -323,48 +402,49 @@ RABBITMQ_EXPORT void *amqp_simple_rpc_decoded(amqp_connection_state_t state, * generally do NOT update this per-connection-global amqp_rpc_reply_t * instance. */ -RABBITMQ_EXPORT amqp_rpc_reply_t amqp_get_rpc_reply( - amqp_connection_state_t state); +AMQP_PUBLIC +amqp_rpc_reply_t +amqp_get_rpc_reply(amqp_connection_state_t state); -RABBITMQ_EXPORT amqp_rpc_reply_t amqp_login(amqp_connection_state_t state, - char const *vhost, - int channel_max, - int frame_max, - int heartbeat, - amqp_sasl_method_enum sasl_method, ...); +AMQP_PUBLIC +amqp_rpc_reply_t +amqp_login(amqp_connection_state_t state, char const *vhost, + int channel_max, int frame_max, int heartbeat, + amqp_sasl_method_enum sasl_method, ...); struct amqp_basic_properties_t_; -RABBITMQ_EXPORT int amqp_basic_publish(amqp_connection_state_t state, - amqp_channel_t channel, - amqp_bytes_t exchange, - amqp_bytes_t routing_key, - amqp_boolean_t mandatory, - amqp_boolean_t immediate, - struct amqp_basic_properties_t_ const *properties, - amqp_bytes_t body); - -RABBITMQ_EXPORT amqp_rpc_reply_t amqp_channel_close( - amqp_connection_state_t state, - amqp_channel_t channel, - int code); -RABBITMQ_EXPORT amqp_rpc_reply_t amqp_connection_close( - amqp_connection_state_t state, - int code); - -RABBITMQ_EXPORT int amqp_basic_ack(amqp_connection_state_t state, - amqp_channel_t channel, - uint64_t delivery_tag, - amqp_boolean_t multiple); - -RABBITMQ_EXPORT amqp_rpc_reply_t amqp_basic_get(amqp_connection_state_t state, - amqp_channel_t channel, - amqp_bytes_t queue, - amqp_boolean_t no_ack); - -RABBITMQ_EXPORT int amqp_basic_reject(amqp_connection_state_t state, - amqp_channel_t channel, - uint64_t delivery_tag, - amqp_boolean_t requeue); + +AMQP_PUBLIC +int +amqp_basic_publish(amqp_connection_state_t state, amqp_channel_t channel, + amqp_bytes_t exchange, amqp_bytes_t routing_key, + amqp_boolean_t mandatory, amqp_boolean_t immediate, + struct amqp_basic_properties_t_ const *properties, + amqp_bytes_t body); + +AMQP_PUBLIC +amqp_rpc_reply_t +amqp_channel_close(amqp_connection_state_t state, amqp_channel_t channel, + int code); + +AMQP_PUBLIC +amqp_rpc_reply_t +amqp_connection_close(amqp_connection_state_t state, int code); + +AMQP_PUBLIC +int +amqp_basic_ack(amqp_connection_state_t state, amqp_channel_t channel, + uint64_t delivery_tag, amqp_boolean_t multiple); + +AMQP_PUBLIC +amqp_rpc_reply_t +amqp_basic_get(amqp_connection_state_t state, amqp_channel_t channel, + amqp_bytes_t queue, amqp_boolean_t no_ack); + +AMQP_PUBLIC +int +amqp_basic_reject(amqp_connection_state_t state, amqp_channel_t channel, + uint64_t delivery_tag, amqp_boolean_t requeue); /* * Can be used to see if there is data still in the buffer, if so @@ -373,8 +453,9 @@ RABBITMQ_EXPORT int amqp_basic_reject(amqp_connection_state_t state, * * Possibly amqp_frames_enqueued should be used for this? */ -RABBITMQ_EXPORT amqp_boolean_t amqp_data_in_buffer( - amqp_connection_state_t state); +AMQP_PUBLIC +amqp_boolean_t +amqp_data_in_buffer(amqp_connection_state_t state); /* * Get the error string for the given error code. @@ -382,16 +463,17 @@ RABBITMQ_EXPORT amqp_boolean_t amqp_data_in_buffer( * The returned string resides on the heap; the caller is responsible * for freeing it. */ -RABBITMQ_EXPORT char *amqp_error_string(int err); +AMQP_PUBLIC +char *amqp_error_string(int err); -RABBITMQ_EXPORT int amqp_decode_table(amqp_bytes_t encoded, - amqp_pool_t *pool, - amqp_table_t *output, - size_t *offset); +AMQP_PUBLIC +int +amqp_decode_table(amqp_bytes_t encoded, amqp_pool_t *pool, + amqp_table_t *output, size_t *offset); -RABBITMQ_EXPORT int amqp_encode_table(amqp_bytes_t encoded, - amqp_table_t *input, - size_t *offset); +AMQP_PUBLIC +int +amqp_encode_table(amqp_bytes_t encoded, amqp_table_t *input, size_t *offset); struct amqp_connection_info { char *user; @@ -401,15 +483,14 @@ struct amqp_connection_info { int port; }; -RABBITMQ_EXPORT void amqp_default_connection_info( - struct amqp_connection_info *parsed); -RABBITMQ_EXPORT int amqp_parse_url(char *url, - struct amqp_connection_info *parsed); +AMQP_PUBLIC +void amqp_default_connection_info(struct amqp_connection_info *parsed); -#ifdef __cplusplus -} -#endif +AMQP_PUBLIC +int amqp_parse_url(char *url, struct amqp_connection_info *parsed); + +AMQP_END_DECLS #include <amqp_framing.h> -#endif +#endif /* AMQP_H */ diff --git a/librabbitmq/amqp_api.c b/librabbitmq/amqp_api.c index b4effec..f011354 100644 --- a/librabbitmq/amqp_api.c +++ b/librabbitmq/amqp_api.c @@ -34,17 +34,13 @@ #include "config.h" #endif -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <stdint.h> -#include <stdarg.h> - -#include "amqp.h" -#include "amqp_framing.h" #include "amqp_private.h" - #include <assert.h> +#include <stdarg.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> static const char *client_error_strings[ERROR_MAX] = { "could not allocate memory", /* ERROR_NO_MEMORY */ diff --git a/librabbitmq/amqp_connection.c b/librabbitmq/amqp_connection.c index 9289316..561d496 100644 --- a/librabbitmq/amqp_connection.c +++ b/librabbitmq/amqp_connection.c @@ -34,15 +34,12 @@ #include "config.h" #endif -#include <stdlib.h> +#include "amqp_private.h" +#include <assert.h> +#include <stdint.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> -#include <stdint.h> -#include <assert.h> - -#include "amqp.h" -#include "amqp_framing.h" -#include "amqp_private.h" #define INITIAL_FRAME_POOL_PAGE_SIZE 65536 #define INITIAL_DECODING_POOL_PAGE_SIZE 131072 diff --git a/librabbitmq/amqp_mem.c b/librabbitmq/amqp_mem.c index ac87bb5..d1cf2ad 100644 --- a/librabbitmq/amqp_mem.c +++ b/librabbitmq/amqp_mem.c @@ -34,14 +34,13 @@ #include "config.h" #endif -#include <stdlib.h> +#include "amqp_private.h" +#include <assert.h> +#include <stdint.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> -#include <stdint.h> #include <sys/types.h> -#include <assert.h> - -#include "amqp.h" char const *amqp_version(void) { return VERSION; /* defined in config.h */ diff --git a/librabbitmq/amqp_private.h b/librabbitmq/amqp_private.h index 27ba3dd..a743c0a 100644 --- a/librabbitmq/amqp_private.h +++ b/librabbitmq/amqp_private.h @@ -33,7 +33,13 @@ * ***** END LICENSE BLOCK ***** */ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif + +#include "amqp.h" +#include "amqp_framing.h" +#include <string.h> /* Error numbering: Because of differences in error numbering on * different platforms, we want to keep error numbers opaque for @@ -60,12 +66,23 @@ /* GCC attributes */ #if __GNUC__ > 2 | (__GNUC__ == 2 && __GNUC_MINOR__ > 4) #define AMQP_NORETURN \ - __attribute__ ((__noreturn__)) + __attribute__ ((__noreturn__)) #else #define AMQP_NORETURN #endif -extern char *amqp_os_error_string(int err); +#if __GNUC__ >= 4 +#define AMQP_PUBLIC \ + __attribute__ ((visibility ("default"))) +#define AMQP_PRIVATE \ + __attribute__ ((visibility ("hidden"))) +#else +#define AMQP_PUBLIC +#define AMQP_PRIVATE +#endif + +char * +amqp_os_error_string(int err); #include "socket.h" @@ -262,6 +279,7 @@ static inline int amqp_decode_bytes(amqp_bytes_t encoded, size_t *offset, } AMQP_NORETURN -extern void amqp_abort(const char *fmt, ...); +void +amqp_abort(const char *fmt, ...); #endif diff --git a/librabbitmq/amqp_socket.c b/librabbitmq/amqp_socket.c index 60bb545..6b9486c 100644 --- a/librabbitmq/amqp_socket.c +++ b/librabbitmq/amqp_socket.c @@ -34,6 +34,7 @@ #include "config.h" #endif +#include "amqp_private.h" #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -41,11 +42,6 @@ #include <stdarg.h> #include <assert.h> -#include "amqp.h" -#include "amqp_framing.h" -#include "amqp_private.h" - - int amqp_open_socket(char const *hostname, int portnumber) { diff --git a/librabbitmq/amqp_table.c b/librabbitmq/amqp_table.c index ec098ba..4e0de12 100644 --- a/librabbitmq/amqp_table.c +++ b/librabbitmq/amqp_table.c @@ -34,15 +34,12 @@ #include "config.h" #endif -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <stdint.h> - -#include "amqp.h" #include "amqp_private.h" - #include <assert.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> #define INITIAL_ARRAY_SIZE 16 #define INITIAL_TABLE_SIZE 16 diff --git a/librabbitmq/amqp_url.c b/librabbitmq/amqp_url.c index 28264d8..eb29ca8 100644 --- a/librabbitmq/amqp_url.c +++ b/librabbitmq/amqp_url.c @@ -34,14 +34,11 @@ #include "config.h" #endif -#include <string.h> +#include "amqp_private.h" +#include <stdint.h> #include <stdio.h> #include <stdlib.h> -#include <stdint.h> - -#include "amqp.h" -#include "amqp_framing.h" -#include "amqp_private.h" +#include <string.h> void amqp_default_connection_info(struct amqp_connection_info *ci) { diff --git a/librabbitmq/codegen.py b/librabbitmq/codegen.py index 67255a6..f805751 100644 --- a/librabbitmq/codegen.py +++ b/librabbitmq/codegen.py @@ -366,15 +366,16 @@ def genErl(spec): * ***** END LICENSE BLOCK ***** */ -#include <stdlib.h> -#include <stdint.h> -#include <string.h> -#include <stdio.h> +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include "amqp.h" -#include "amqp_framing.h" #include "amqp_private.h" #include "socket.h" +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> """ print """ @@ -551,14 +552,12 @@ def genHrl(spec): methods = spec.allMethods() print """/* Autogenerated code. Do not edit. */ -#ifndef librabbitmq_amqp_framing_h -#define librabbitmq_amqp_framing_h +#ifndef AMQP_FRAMING_H +#define AMQP_FRAMING_H #include <amqp.h> -#ifdef __cplusplus -extern "C" { -#endif +AMQP_BEGIN_DECLS """ print "#define AMQP_PROTOCOL_VERSION_MAJOR %d" % (spec.major) print "#define AMQP_PROTOCOL_VERSION_MINOR %d" % (spec.minor) @@ -571,24 +570,47 @@ extern "C" { print """/* Function prototypes. */ -extern char const *amqp_constant_name(int constantNumber); -extern amqp_boolean_t amqp_constant_is_hard_error(int constantNumber); -RABBITMQ_EXPORT char const *amqp_method_name(amqp_method_number_t methodNumber); -extern amqp_boolean_t amqp_method_has_content(amqp_method_number_t methodNumber); -extern int amqp_decode_method(amqp_method_number_t methodNumber, - amqp_pool_t *pool, - amqp_bytes_t encoded, - void **decoded); -extern int amqp_decode_properties(uint16_t class_id, - amqp_pool_t *pool, - amqp_bytes_t encoded, - void **decoded); -extern int amqp_encode_method(amqp_method_number_t methodNumber, - void *decoded, - amqp_bytes_t encoded); -extern int amqp_encode_properties(uint16_t class_id, - void *decoded, - amqp_bytes_t encoded); +AMQP_PUBLIC +char const * +amqp_constant_name(int constantNumber); + +AMQP_PUBLIC +amqp_boolean_t +amqp_constant_is_hard_error(int constantNumber); + +AMQP_PUBLIC +char const * +amqp_method_name(amqp_method_number_t methodNumber); + +AMQP_PUBLIC +amqp_boolean_t +amqp_method_has_content(amqp_method_number_t methodNumber); + +AMQP_PUBLIC +int +amqp_decode_method(amqp_method_number_t methodNumber, + amqp_pool_t *pool, + amqp_bytes_t encoded, + void **decoded); + +AMQP_PUBLIC +int +amqp_decode_properties(uint16_t class_id, + amqp_pool_t *pool, + amqp_bytes_t encoded, + void **decoded); + +AMQP_PUBLIC +int +amqp_encode_method(amqp_method_number_t methodNumber, + void *decoded, + amqp_bytes_t encoded); + +AMQP_PUBLIC +int +amqp_encode_properties(uint16_t class_id, + void *decoded, + amqp_bytes_t encoded); """ print "/* Method field records. */\n" @@ -625,14 +647,12 @@ extern int amqp_encode_properties(uint16_t class_id, for m in methods: if m.isSynchronous and apiMethodInfo.get(m.fullName()) is not False: - print "RABBITMQ_EXPORT %s;" % (m.apiPrototype(),) + print "AMQP_PUBLIC\n%s;" % (m.apiPrototype(),) print """ -#ifdef __cplusplus -} -#endif +AMQP_END_DECLS -#endif""" +#endif /* AMQP_FRAMING_H */""" def generateErl(specPath): genErl(AmqpSpec(specPath)) diff --git a/librabbitmq/unix/socket.c b/librabbitmq/unix/socket.c index d0e2400..cb8a2b9 100644 --- a/librabbitmq/unix/socket.c +++ b/librabbitmq/unix/socket.c @@ -34,17 +34,27 @@ #include "config.h" #endif -#include <sys/types.h> -#include <sys/socket.h> -#include <unistd.h> +#include "amqp_private.h" +#include "socket.h" #include <fcntl.h> #include <stdint.h> -#include <string.h> #include <stdlib.h> +#include <string.h> +#include <sys/socket.h> +#include <sys/types.h> +#include <unistd.h> -#include "amqp.h" -#include "amqp_private.h" -#include "socket.h" +int +amqp_socket_init(void) +{ + return 0; +} + +int +amqp_socket_error(void) +{ + return errno | ERROR_CATEGORY_OS; +} int amqp_socket_socket(int domain, int type, int proto) { diff --git a/librabbitmq/unix/socket.h b/librabbitmq/unix/socket.h index af86ffb..ff6fa73 100644 --- a/librabbitmq/unix/socket.h +++ b/librabbitmq/unix/socket.h @@ -34,28 +34,25 @@ */ #include <errno.h> -#include <sys/types.h> -#include <unistd.h> -#include <sys/uio.h> -#include <sys/socket.h> #include <netdb.h> #include <netinet/in.h> #include <netinet/tcp.h> +#include <sys/socket.h> +#include <sys/types.h> +#include <sys/uio.h> +#include <unistd.h> -static inline int amqp_socket_init(void) -{ - return 0; -} +int +amqp_socket_init(void); -extern int amqp_socket_socket(int domain, int type, int proto); +int +amqp_socket_socket(int domain, int type, int proto); + +int +amqp_socket_error(void); #define amqp_socket_setsockopt setsockopt #define amqp_socket_close close #define amqp_socket_writev writev -static inline int amqp_socket_error() -{ - return errno | ERROR_CATEGORY_OS; -} - #endif diff --git a/librabbitmq/windows/socket.c b/librabbitmq/windows/socket.c index 72ad200..43b919b 100644 --- a/librabbitmq/windows/socket.c +++ b/librabbitmq/windows/socket.c @@ -37,13 +37,11 @@ #include "config.h" #endif -#include <windows.h> -#include <stdint.h> -#include <stdlib.h> - -#include "amqp.h" #include "amqp_private.h" #include "socket.h" +#include <stdint.h> +#include <stdlib.h> +#include <windows.h> static int called_wsastartup; @@ -76,3 +74,28 @@ char *amqp_os_error_string(int err) LocalFree(msg); return copy; } + +int +amqp_socket_setsockopt(int sock, int level, int optname, + const void *optval, size_t optlen) +{ + /* the winsock setsockopt function has its 4th argument as a + const char * */ + return setsockopt(sock, level, optname, (const char *)optval, optlen); +} + +int +amqp_socket_writev(int sock, struct iovec *iov, int nvecs) +{ + DWORD ret; + if (WSASend(sock, (LPWSABUF)iov, nvecs, &ret, 0, NULL, NULL) == 0) + return ret; + else + return -1; +} + +int +amqp_socket_error(void) +{ + return WSAGetLastError() | ERROR_CATEGORY_OS; +} diff --git a/librabbitmq/windows/socket.h b/librabbitmq/windows/socket.h index 0665b3a..4572410 100644 --- a/librabbitmq/windows/socket.h +++ b/librabbitmq/windows/socket.h @@ -35,37 +35,26 @@ #include <winsock2.h> -extern int amqp_socket_init(void); - -#define amqp_socket_socket socket -#define amqp_socket_close closesocket - -static inline int amqp_socket_setsockopt(int sock, int level, int optname, - const void *optval, size_t optlen) -{ - /* the winsock setsockopt function has its 4th argument as a - const char * */ - return setsockopt(sock, level, optname, (const char *)optval, optlen); -} - /* same as WSABUF */ struct iovec { u_long iov_len; void *iov_base; }; -static inline int amqp_socket_writev(int sock, struct iovec *iov, int nvecs) -{ - DWORD ret; - if (WSASend(sock, (LPWSABUF)iov, nvecs, &ret, 0, NULL, NULL) == 0) - return ret; - else - return -1; -} +int +amqp_socket_init(void); + +#define amqp_socket_socket socket +#define amqp_socket_close closesocket + +int +amqp_socket_setsockopt(int sock, int level, int optname, const void *optval, + size_t optlen); + +int +amqp_socket_writev(int sock, struct iovec *iov, int nvecs); -static inline int amqp_socket_error() -{ - return WSAGetLastError() | ERROR_CATEGORY_OS; -} +int +amqp_socket_error(void); #endif diff --git a/tests/test_tables.c b/tests/test_tables.c index be2f7ae..e4b0f43 100644 --- a/tests/test_tables.c +++ b/tests/test_tables.c @@ -40,6 +40,9 @@ #include <amqp.h> +#ifdef _MSC_VER +#define _USE_MATH_DEFINES +#endif #include <math.h> void die(const char *fmt, ...) @@ -52,10 +55,6 @@ void die(const char *fmt, ...) abort(); } -#ifndef M_PI -#define M_PI 3.14159265358979323846264338327 -#endif - static void dump_indent(int indent, FILE *out) { int i; |