Skip to content

Commit

Permalink
Fix __inline vs inline (issue #253)
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhill committed Apr 11, 2016
1 parent 6d127c4 commit fdeac56
Show file tree
Hide file tree
Showing 31 changed files with 138 additions and 135 deletions.
4 changes: 2 additions & 2 deletions src/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,8 @@ struct { \
#ifdef _MSC_VER
#define __launder_type(x) ((const void *)(x))
#else
static __inline const void * __launder_type(const void *);
static __inline const void *
static RD_INLINE const void * __launder_type(const void *);
static RD_INLINE const void *
__launder_type(const void *__x)
{
__asm __volatile("" : "+r" (__x));
Expand Down
28 changes: 14 additions & 14 deletions src/rd.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,29 @@
* allocation fails all hope is lost and the application
* will fail anyway, so no need to handle it handsomely.
*/
static __inline RD_UNUSED void *rd_calloc(size_t num, size_t sz) {
static RD_INLINE RD_UNUSED void *rd_calloc(size_t num, size_t sz) {
void *p = calloc(num, sz);
assert(p);
return p;
}

static __inline RD_UNUSED void *rd_malloc(size_t sz) {
static RD_INLINE RD_UNUSED void *rd_malloc(size_t sz) {
void *p = malloc(sz);
assert(p);
return p;
}

static __inline RD_UNUSED void *rd_realloc(void *ptr, size_t sz) {
static RD_INLINE RD_UNUSED void *rd_realloc(void *ptr, size_t sz) {
void *p = realloc(ptr, sz);
assert(p);
return p;
}

static __inline RD_UNUSED void rd_free(void *ptr) {
static RD_INLINE RD_UNUSED void rd_free(void *ptr) {
free(ptr);
}

static __inline RD_UNUSED char *rd_strdup(const char *s) {
static RD_INLINE RD_UNUSED char *rd_strdup(const char *s) {
#ifndef _MSC_VER
char *n = strdup(s);
#else
Expand All @@ -109,7 +109,7 @@ static __inline RD_UNUSED char *rd_strdup(const char *s) {
return n;
}

static __inline RD_UNUSED char *rd_strndup(const char *s, size_t len) {
static RD_INLINE RD_UNUSED char *rd_strndup(const char *s, size_t len) {
#if HAVE_STRNDUP
char *n = strndup(s, len);
assert(n);
Expand Down Expand Up @@ -190,7 +190,7 @@ static __inline RD_UNUSED char *rd_strndup(const char *s, size_t len) {
*
* Use rd_free() to free the returned pointer.
*/
static __inline RD_UNUSED void *rd_memdup (const void *src, size_t size) {
static RD_INLINE RD_UNUSED void *rd_memdup (const void *src, size_t size) {
void *dst = rd_malloc(size);
memcpy(dst, src, size);
return dst;
Expand All @@ -212,7 +212,7 @@ typedef rd_atomic32_t rd_refcnt_t;
#endif

#ifdef RD_REFCNT_USE_LOCKS
static __inline RD_UNUSED int rd_refcnt_init (rd_refcnt_t *R, int v) {
static RD_INLINE RD_UNUSED int rd_refcnt_init (rd_refcnt_t *R, int v) {
int r;
mtx_init(&R->lock, mtx_plain);
mtx_lock(&R->lock);
Expand All @@ -225,7 +225,7 @@ static __inline RD_UNUSED int rd_refcnt_init (rd_refcnt_t *R, int v) {
#endif

#ifdef RD_REFCNT_USE_LOCKS
static __inline RD_UNUSED void rd_refcnt_destroy (rd_refcnt_t *R) {
static RD_INLINE RD_UNUSED void rd_refcnt_destroy (rd_refcnt_t *R) {
mtx_lock(&R->lock);
assert(R->v == 0);
mtx_unlock(&R->lock);
Expand All @@ -238,7 +238,7 @@ static __inline RD_UNUSED void rd_refcnt_destroy (rd_refcnt_t *R) {


#ifdef RD_REFCNT_USE_LOCKS
static __inline RD_UNUSED int rd_refcnt_set (rd_refcnt_t *R, int v) {
static RD_INLINE RD_UNUSED int rd_refcnt_set (rd_refcnt_t *R, int v) {
int r;
mtx_lock(&R->lock);
r = R->v = v;
Expand All @@ -251,7 +251,7 @@ static __inline RD_UNUSED int rd_refcnt_set (rd_refcnt_t *R, int v) {


#ifdef RD_REFCNT_USE_LOCKS
static __inline RD_UNUSED int rd_refcnt_add0 (rd_refcnt_t *R) {
static RD_INLINE RD_UNUSED int rd_refcnt_add0 (rd_refcnt_t *R) {
int r;
mtx_lock(&R->lock);
r = ++(R->v);
Expand All @@ -262,7 +262,7 @@ static __inline RD_UNUSED int rd_refcnt_add0 (rd_refcnt_t *R) {
#define rd_refcnt_add0(R) rd_atomic32_add(R, 1)
#endif

static __inline RD_UNUSED int rd_refcnt_sub0 (rd_refcnt_t *R) {
static RD_INLINE RD_UNUSED int rd_refcnt_sub0 (rd_refcnt_t *R) {
int r;
#ifdef RD_REFCNT_USE_LOCKS
mtx_lock(&R->lock);
Expand All @@ -277,7 +277,7 @@ static __inline RD_UNUSED int rd_refcnt_sub0 (rd_refcnt_t *R) {
}

#ifdef RD_REFCNT_USE_LOCKS
static __inline RD_UNUSED int rd_refcnt_get (rd_refcnt_t *R) {
static RD_INLINE RD_UNUSED int rd_refcnt_get (rd_refcnt_t *R) {
int r;
mtx_lock(&R->lock);
r = R->v;
Expand Down Expand Up @@ -377,7 +377,7 @@ LIST_HEAD(rd_shptr0_head, rd_shptr0_s);
extern struct rd_shptr0_head rd_shared_ptr_debug_list;
extern mtx_t rd_shared_ptr_debug_mtx;

static __inline RD_UNUSED RD_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
static RD_INLINE RD_UNUSED RD_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
rd_shptr0_t *rd_shared_ptr_get0 (const char *func, int line,
const char *typename,
rd_refcnt_t *ref, void *obj) {
Expand Down
4 changes: 2 additions & 2 deletions src/rdaddr.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ typedef struct rd_sockaddr_list_s {
*
*/

static __inline rd_sockaddr_inx_t *
static RD_INLINE rd_sockaddr_inx_t *
rd_sockaddr_list_next (rd_sockaddr_list_t *rsal) RD_UNUSED;
static __inline rd_sockaddr_inx_t *
static RD_INLINE rd_sockaddr_inx_t *
rd_sockaddr_list_next (rd_sockaddr_list_t *rsal) {
rsal->rsal_curr = (rsal->rsal_curr + 1) % rsal->rsal_cnt;
return &rsal->rsal_addr[rsal->rsal_curr];
Expand Down
16 changes: 8 additions & 8 deletions src/rdatomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ typedef struct {
int64_t val;
} rd_atomic64_t;

static __inline int32_t RD_UNUSED rd_atomic32_add (rd_atomic32_t *ra, int32_t v) {
static RD_INLINE int32_t RD_UNUSED rd_atomic32_add (rd_atomic32_t *ra, int32_t v) {
#ifndef _MSC_VER
return ATOMIC_OP(add, fetch, &ra->val, v);
#else
return InterlockedAdd(&ra->val, v);
#endif
}

static __inline int32_t RD_UNUSED rd_atomic32_sub(rd_atomic32_t *ra, int32_t v) {
static RD_INLINE int32_t RD_UNUSED rd_atomic32_sub(rd_atomic32_t *ra, int32_t v) {
#ifndef _MSC_VER
return ATOMIC_OP(sub, fetch, &ra->val, v);
#else
return InterlockedAdd(&ra->val, -v);
#endif
}

static __inline int32_t RD_UNUSED rd_atomic32_get(rd_atomic32_t *ra) {
static RD_INLINE int32_t RD_UNUSED rd_atomic32_get(rd_atomic32_t *ra) {
#ifndef _MSC_VER
return ATOMIC_OP(fetch, add, &ra->val, 0);
#else
return ra->val;
#endif
}

static __inline int32_t RD_UNUSED rd_atomic32_set(rd_atomic32_t *ra, int32_t v) {
static RD_INLINE int32_t RD_UNUSED rd_atomic32_set(rd_atomic32_t *ra, int32_t v) {
#ifndef _MSC_VER
return ra->val = v; // FIXME
#else
Expand All @@ -42,23 +42,23 @@ static __inline int32_t RD_UNUSED rd_atomic32_set(rd_atomic32_t *ra, int32_t v)
}


static __inline int64_t RD_UNUSED rd_atomic64_add (rd_atomic64_t *ra, int64_t v) {
static RD_INLINE int64_t RD_UNUSED rd_atomic64_add (rd_atomic64_t *ra, int64_t v) {
#ifndef _MSC_VER
return ATOMIC_OP(add, fetch, &ra->val, v);
#else
return InterlockedAdd64(&ra->val, v);
#endif
}

static __inline int64_t RD_UNUSED rd_atomic64_sub(rd_atomic64_t *ra, int64_t v) {
static RD_INLINE int64_t RD_UNUSED rd_atomic64_sub(rd_atomic64_t *ra, int64_t v) {
#ifndef _MSC_VER
return ATOMIC_OP(sub, fetch, &ra->val, v);
#else
return InterlockedAdd64(&ra->val, -v);
#endif
}

static __inline int64_t RD_UNUSED rd_atomic64_get(rd_atomic64_t *ra) {
static RD_INLINE int64_t RD_UNUSED rd_atomic64_get(rd_atomic64_t *ra) {
#ifndef _MSC_VER
return ATOMIC_OP(fetch, add, &ra->val, 0);
#else
Expand All @@ -67,7 +67,7 @@ static __inline int64_t RD_UNUSED rd_atomic64_get(rd_atomic64_t *ra) {
}


static __inline int64_t RD_UNUSED rd_atomic64_set(rd_atomic64_t *ra, int64_t v) {
static RD_INLINE int64_t RD_UNUSED rd_atomic64_set(rd_atomic64_t *ra, int64_t v) {
#ifndef _MSC_VER
return ra->val = v; // FIXME
#else
Expand Down
8 changes: 4 additions & 4 deletions src/rdcrc32.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ rd_crc32_t rd_crc32_reflect(rd_crc32_t data, size_t data_len);
*
* \return The initial crc value.
*****************************************************************************/
static __inline rd_crc32_t rd_crc32_init(void)
static RD_INLINE rd_crc32_t rd_crc32_init(void)
{
#if WITH_ZLIB
return crc32(0, NULL, 0);
Expand All @@ -94,7 +94,7 @@ static __inline rd_crc32_t rd_crc32_init(void)
* \param data_len Number of bytes in the \a data buffer.
* \return The updated crc value.
*****************************************************************************/
static __inline RD_UNUSED
static RD_INLINE RD_UNUSED
rd_crc32_t rd_crc32_update(rd_crc32_t crc, const unsigned char *data, size_t data_len)
{
#if WITH_ZLIB
Expand All @@ -120,7 +120,7 @@ rd_crc32_t rd_crc32_update(rd_crc32_t crc, const unsigned char *data, size_t dat
* \param crc The current crc value.
* \return The final crc value.
*****************************************************************************/
static __inline rd_crc32_t rd_crc32_finalize(rd_crc32_t crc)
static RD_INLINE rd_crc32_t rd_crc32_finalize(rd_crc32_t crc)
{
#if WITH_ZLIB
return crc;
Expand All @@ -133,7 +133,7 @@ static __inline rd_crc32_t rd_crc32_finalize(rd_crc32_t crc)
/**
* Wrapper for performing CRC32 on the provided buffer.
*/
static __inline rd_crc32_t rd_crc32 (const char *data, size_t data_len) {
static RD_INLINE rd_crc32_t rd_crc32 (const char *data, size_t data_len) {
return rd_crc32_finalize(rd_crc32_update(rd_crc32_init(),
(const unsigned char *)data,
data_len));
Expand Down
16 changes: 8 additions & 8 deletions src/rdinterval.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ typedef struct rd_interval_s {
} rd_interval_t;


static __inline RD_UNUSED void rd_interval_init (rd_interval_t *ri) {
static RD_INLINE RD_UNUSED void rd_interval_init (rd_interval_t *ri) {
memset(ri, 0, sizeof(*ri));
}

Expand All @@ -28,7 +28,7 @@ static __inline RD_UNUSED void rd_interval_init (rd_interval_t *ri) {
* If 'interval_us' is set to 0 the fixed interval will be used, see
* 'rd_interval_fixed()'.
*/
static __inline RD_UNUSED rd_ts_t rd_interval (rd_interval_t *ri,
static RD_INLINE RD_UNUSED rd_ts_t rd_interval (rd_interval_t *ri,
rd_ts_t interval_us,
rd_ts_t now) {
rd_ts_t diff;
Expand All @@ -52,15 +52,15 @@ static __inline RD_UNUSED rd_ts_t rd_interval (rd_interval_t *ri,
* Reset the interval to zero, i.e., the next call to rd_interval()
* will be immediate.
*/
static __inline RD_UNUSED void rd_interval_reset (rd_interval_t *ri) {
static RD_INLINE RD_UNUSED void rd_interval_reset (rd_interval_t *ri) {
ri->ri_ts_last = 0;
ri->ri_backoff = 0;
}

/**
* Back off the next interval by `backoff_us` microseconds.
*/
static __inline RD_UNUSED void rd_interval_backoff (rd_interval_t *ri,
static RD_INLINE RD_UNUSED void rd_interval_backoff (rd_interval_t *ri,
int backoff_us) {
ri->ri_backoff = backoff_us;
}
Expand All @@ -70,7 +70,7 @@ static __inline RD_UNUSED void rd_interval_backoff (rd_interval_t *ri,
* If `expedite_us` is 0 the interval will be set to trigger
* immedately on the next rd_interval() call.
*/
static __inline RD_UNUSED void rd_interval_expedite (rd_interval_t *ri,
static RD_INLINE RD_UNUSED void rd_interval_expedite (rd_interval_t *ri,
int expedite_us) {
if (!expedite_us)
ri->ri_ts_last = 0;
Expand All @@ -82,7 +82,7 @@ static __inline RD_UNUSED void rd_interval_expedite (rd_interval_t *ri,
* Specifies a fixed interval to use if rd_interval() is called with
* `interval_us` set to 0.
*/
static __inline RD_UNUSED void rd_interval_fixed (rd_interval_t *ri,
static RD_INLINE RD_UNUSED void rd_interval_fixed (rd_interval_t *ri,
rd_ts_t fixed_us) {
ri->ri_fixed = fixed_us;
}
Expand All @@ -92,14 +92,14 @@ static __inline RD_UNUSED void rd_interval_fixed (rd_interval_t *ri,
* A disabled interval will never return a positive value from
* rd_interval().
*/
static __inline RD_UNUSED void rd_interval_disable (rd_interval_t *ri) {
static RD_INLINE RD_UNUSED void rd_interval_disable (rd_interval_t *ri) {
/* Set last beat to a large value a long time in the future. */
ri->ri_ts_last = 6000000000000000000LL; /* in about 190000 years */
}

/**
* Returns true if the interval is disabled.
*/
static __inline RD_UNUSED int rd_interval_disabled (const rd_interval_t *ri) {
static RD_INLINE RD_UNUSED int rd_interval_disabled (const rd_interval_t *ri) {
return ri->ri_ts_last == 6000000000000000000LL;
}
2 changes: 1 addition & 1 deletion src/rdkafka.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ static void rd_kafka_destroy_internal (rd_kafka_t *rk) {
/**
* Emit stats for toppar
*/
static __inline void rd_kafka_stats_emit_toppar (char **bufp, size_t *sizep,
static RD_INLINE void rd_kafka_stats_emit_toppar (char **bufp, size_t *sizep,
size_t *ofp,
rd_kafka_toppar_t *rktp,
int first) {
Expand Down
4 changes: 3 additions & 1 deletion src/rdkafka.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ extern "C" {
#include <basetsd.h>
typedef SSIZE_T ssize_t;
#define RD_UNUSED
#define RD_INLINE __inline
#define RD_DEPRECATED
#undef RD_EXPORT
#ifdef LIBRDKAFKA_EXPORTS
Expand All @@ -68,6 +69,7 @@ typedef SSIZE_T ssize_t;

#else
#define RD_UNUSED __attribute__((unused))
#define RD_INLINE inline
#define RD_EXPORT
#define RD_DEPRECATED __attribute__((deprecated))
#endif
Expand Down Expand Up @@ -688,7 +690,7 @@ void rd_kafka_message_destroy(rd_kafka_message_t *rkmessage);
* @brief Returns the error string for an errored rd_kafka_message_t or NULL if
* there was no error.
*/
static __inline const char *
static RD_INLINE const char *
RD_UNUSED
rd_kafka_message_errstr(const rd_kafka_message_t *rkmessage) {
if (!rkmessage->err)
Expand Down
2 changes: 1 addition & 1 deletion src/rdkafka_broker.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ rd_kafka_broker_t *rd_kafka_broker_find_by_nodeid0 (rd_kafka_t *rk,
/**
* Filter out brokers that are currently in a blocking request.
*/
static __inline RD_UNUSED int
static RD_INLINE RD_UNUSED int
rd_kafka_broker_filter_non_blocking (rd_kafka_broker_t *rkb, void *opaque) {
return rd_atomic32_get(&rkb->rkb_blocking_request_cnt) > 0;
}
Expand Down
Loading

0 comments on commit fdeac56

Please sign in to comment.