Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Makefile
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ HDRS= rdkafka.h
OBJS= $(SRCS:.c=.o)
DEPS= ${OBJS:%.o=%.d}

CFLAGS+=-O2 -Wall -Werror -Wfloat-equal -Wpointer-arith -fPIC -I.
CFLAGS+=-O2 -Wall -Werror -Wfloat-equal -Wpointer-arith -I.
CFLAGS+=-g

# Clang warnings to ignore
Expand All @@ -29,7 +29,11 @@ CFLAGS+=-DSG
#CFLAGS += -pg
#LDFLAGS += -pg

LDFLAGS+=-g -fPIC
LDFLAGS+= -g
ifneq ($(shell uname -o),Cygwin)
LDFLAGS+=-fPIC
CFLAGS+=-fPIC
endif

.PHONY:

Expand Down
2 changes: 2 additions & 0 deletions endian_compat.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <sys/endian.h>
#elif defined __linux__
#include <endian.h>
#elif defined __CYGWIN__
#include <endian.h>
#elif defined __BSD__
#include <sys/endian.h>
#elif defined __APPLE__
Expand Down
2 changes: 1 addition & 1 deletion examples/rdkafka_example.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static void hexdump (FILE *fp, const char *name, const void *ptr, size_t len) {
for (i = of ; i < of + 16 && i < len ; i++) {
hof += sprintf(hexen+hof, "%02x ", p[i] & 0xff);
cof += sprintf(charen+cof, "%c",
isprint(p[i]) ? p[i] : '.');
isprint((int)p[i]) ? p[i] : '.');
}
fprintf(fp, "%08x: %-48s %-16s\n",
of, hexen, charen);
Expand Down
18 changes: 9 additions & 9 deletions rdkafka_defaultconf.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,12 @@ static rd_kafka_conf_res_t
rd_kafka_anyconf_set_prop0 (int scope, void *conf,
const struct rd_kafka_property *prop,
const char *istr, int ival) {
#define _PTR(TYPE,BASE,OFFSET) (TYPE)(((char *)(BASE))+(OFFSET))
#define _RK_PTR(TYPE,BASE,OFFSET) (TYPE)(((char *)(BASE))+(OFFSET))
switch (prop->type)
{
case _RK_C_STR:
{
char **str = _PTR(char **, conf, prop->offset);
char **str = _RK_PTR(char **, conf, prop->offset);
if (*str)
free(*str);
*str = strdup(istr);
Expand All @@ -255,7 +255,7 @@ rd_kafka_anyconf_set_prop0 (int scope, void *conf,
case _RK_C_S2I:
case _RK_C_S2F:
{
int *val = _PTR(int *, conf, prop->offset);
int *val = _RK_PTR(int *, conf, prop->offset);

if (prop->type == _RK_C_S2F) {
/* Flags: OR it in */
Expand All @@ -272,7 +272,7 @@ rd_kafka_anyconf_set_prop0 (int scope, void *conf,
assert(!*"unknown conf type");
}

#undef PTR
#undef _RK_PTR

/* unreachable */
return RD_KAFKA_CONF_INVALID;
Expand Down Expand Up @@ -351,11 +351,11 @@ rd_kafka_anyconf_set_prop (int scope, void *conf,


/* Left trim */
while (s < t && isspace(*s))
while (s < t && isspace((int)*s))
s++;

/* Right trim */
while (t > s && isspace(*t))
while (t > s && isspace((int)*t))
t--;

/* Empty string? */
Expand Down Expand Up @@ -490,12 +490,12 @@ rd_kafka_conf_res_t rd_kafka_topic_conf_set (rd_kafka_topic_conf_t *conf,
static void rd_kafka_anyconf_clear (void *conf,
const struct rd_kafka_property *prop) {

#define _PTR(TYPE,BASE,OFFSET) (TYPE)(((char *)(BASE))+(OFFSET))
#define _RK_PTR(TYPE,BASE,OFFSET) (TYPE)(((char *)(BASE))+(OFFSET))
switch (prop->type)
{
case _RK_C_STR:
{
char **str = _PTR(char **, conf, prop->offset);
char **str = _RK_PTR(char **, conf, prop->offset);
if (*str) {
free(*str);
*str = NULL;
Expand All @@ -506,7 +506,7 @@ static void rd_kafka_anyconf_clear (void *conf,
default:
break;
}
#undef _PTR
#undef _RK_PTR

}

Expand Down
96 changes: 1 addition & 95 deletions rdlog.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -36,100 +36,6 @@




#define RD_DBG_CTXS_MAX 32
static __thread char *rd_dbg_ctxs[RD_DBG_CTXS_MAX];
static __thread int rd_dbg_ctx_idx = 0;
static __thread int rd_dbg_ctx_wanted_idx = 0;

static int rd_dbg_on = 0;

void rd_dbg_set (int onoff) {
rd_dbg_on = onoff;
}


void rd_dbg_ctx_push (const char *fmt, ...) {
va_list ap;
char *buf;

rd_dbg_ctx_wanted_idx++;

if (rd_dbg_ctx_idx + 1 == RD_DBG_CTXS_MAX)
return;

buf = malloc(64);

va_start(ap, fmt);
vsnprintf(buf, 64, "%s", ap);
va_end(ap);

rd_dbg_ctx_idx++;
}

void rd_dbg_ctx_pop (void) {
assert(rd_dbg_ctx_wanted_idx-- > 0);
assert(rd_dbg_ctx_idx-- > 0);
free(rd_dbg_ctxs[rd_dbg_ctx_idx]);
}

void rd_dbg_ctx_clear (void) {
while (rd_dbg_ctx_idx > 0)
rd_dbg_ctx_pop();
}



void rdputs0 (const char *file, const char *func, int line,
const char *fmt, ...) {
va_list ap;
char buf[4096];
int of = 0;
int i;
int r RD_UNUSED;
rd_ts_t now;
static __thread char thrname[16];

if (!rd_dbg_on)
return;

now = rd_clock();

if (unlikely(!rd_currthread && !*thrname))
snprintf(thrname, sizeof(thrname), "thr:%x",
(int)pthread_self());

of += snprintf(buf+of, sizeof(buf)-of,
"|%"PRIu64".%06"PRIu64"|%s:%i|%s| ",
now / (uint64_t)1000000,
now % (uint64_t)1000000,
func, line,
rd_currthread ? rd_currthread->rdt_name : thrname);

if (rd_dbg_ctx_idx > 0) {
for (i = 0 ; i < rd_dbg_ctx_idx ; i++)
of += snprintf(buf+of, sizeof(buf)-of, "%s[%s]",
i ? "->" : "",
rd_dbg_ctxs[i]);

of += snprintf(buf+of, sizeof(buf)-of, " ");
}


va_start(ap, fmt);
of += vsnprintf(buf+of, sizeof(buf)-of, fmt, ap);
va_end(ap);

buf[of++] = '\n';
buf[of] = '\0';

r = write(STDOUT_FILENO, buf, of);
}





void rd_hexdump (FILE *fp, const char *name, const void *ptr, size_t len) {
const char *p = (const char *)ptr;
int of = 0;
Expand All @@ -149,7 +55,7 @@ void rd_hexdump (FILE *fp, const char *name, const void *ptr, size_t len) {
for (i = of ; i < of + 16 && i < len ; i++) {
hof += sprintf(hexen+hof, "%02x ", p[i] & 0xff);
cof += sprintf(charen+cof, "%c",
isprint(p[i]) ? p[i] : '.');
isprint((int)p[i]) ? p[i] : '.');
}
fprintf(fp, "%08x: %-48s %-16s\n",
of, hexen, charen);
Expand Down
12 changes: 0 additions & 12 deletions rdlog.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,4 @@

#pragma once

void rdputs0 (const char *file, const char *func, int line,
const char *fmt, ...)
__attribute__((format (printf, 4, 5)));

#define rdbg(fmt...) rdputs0(__FILE__,__FUNCTION__,__LINE__,fmt)

void rd_dbg_ctx_push (const char *fmt, ...);
void rd_dbg_ctx_pop (void);
void rd_dbg_ctx_clear (void);
void rd_dbg_set (int onoff);


void rd_hexdump (FILE *fp, const char *name, const void *ptr, size_t len);