Skip to content

Commit

Permalink
Each lib includes internally its own deps/redis/*.o
Browse files Browse the repository at this point in the history
  • Loading branch information
moticless committed Oct 17, 2023
1 parent 3de9f03 commit 130bf3e
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 73 deletions.
5 changes: 2 additions & 3 deletions deps/redis/crc64.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
#define CRC64_H

#include <stdint.h>
#include "librdb-hidden-api.h"

_LIBRDB_HIDDEN_API void crc64_init(void);
_LIBRDB_HIDDEN_API uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l);
void crc64_init(void);
uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l);

#ifdef REDIS_TEST
int crc64Test(int argc, char *argv[], int flags);
Expand Down
27 changes: 0 additions & 27 deletions deps/redis/librdb-hidden-api.h

This file was deleted.

17 changes: 8 additions & 9 deletions deps/redis/rax.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#define RAX_H

#include <stdint.h>
#include "librdb-hidden-api.h"

/* Representation of a radix tree as implemented in this file, that contains
* the strings "foo", "foobar" and "footer" after the insertion of each
Expand Down Expand Up @@ -187,19 +186,19 @@ typedef struct raxIterator {
} raxIterator;

/* A special pointer returned for not found items. */
_LIBRDB_HIDDEN_API extern void *raxNotFound;
extern void *raxNotFound;

/* Exported API. */
_LIBRDB_HIDDEN_API rax *raxNew(void);
rax *raxNew(void);
int raxInsert(rax *rax, unsigned char *s, size_t len, void *data, void **old);
_LIBRDB_HIDDEN_API int raxTryInsert(rax *rax, unsigned char *s, size_t len, void *data, void **old);
int raxTryInsert(rax *rax, unsigned char *s, size_t len, void *data, void **old);
int raxRemove(rax *rax, unsigned char *s, size_t len, void **old);
_LIBRDB_HIDDEN_API void *raxFind(rax *rax, unsigned char *s, size_t len);
_LIBRDB_HIDDEN_API void raxFree(rax *rax);
void *raxFind(rax *rax, unsigned char *s, size_t len);
void raxFree(rax *rax);
void raxFreeWithCallback(rax *rax, void (*free_callback)(void*));
_LIBRDB_HIDDEN_API void raxStart(raxIterator *it, rax *rt);
_LIBRDB_HIDDEN_API int raxSeek(raxIterator *it, const char *op, unsigned char *ele, size_t len);
_LIBRDB_HIDDEN_API int raxNext(raxIterator *it);
void raxStart(raxIterator *it, rax *rt);
int raxSeek(raxIterator *it, const char *op, unsigned char *ele, size_t len);
int raxNext(raxIterator *it);
int raxPrev(raxIterator *it);
//int raxRandomWalk(raxIterator *it, size_t steps);
int raxCompare(raxIterator *iter, const char *op, unsigned char *key, size_t key_len);
Expand Down
5 changes: 2 additions & 3 deletions deps/redis/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define LIBRDB_UTIL_H

#include <stdint.h>
#include "librdb-hidden-api.h"

#ifdef __GNUC__
#define likely(x) __builtin_expect(!!(x), 1)
Expand All @@ -20,7 +19,7 @@
#define MAX_D2STRING_CHARS 128

int string2ll(const char *s, size_t slen, long long *value);
_LIBRDB_HIDDEN_API int ll2string(char *s, size_t len, long long value);
int ll2string(char *s, size_t len, long long value);
int ull2string(char *s, size_t len, unsigned long long value);
int lpStringToInt64(const char *s, unsigned long slen, int64_t *value);
unsigned int getEnvVar(const char* varName, unsigned int defaultVal);
Expand All @@ -30,6 +29,6 @@ unsigned int getEnvVar(const char* varName, unsigned int defaultVal);
* incompatibilities as you can also convert double to string that results in
* loss of precision, or it might not represent inf, -inf or nan values
* similar to this function output. */
_LIBRDB_HIDDEN_API int d2string(char *buf, size_t len, double value);
int d2string(char *buf, size_t len, double value);

#endif /*LIBRDB_UTIL_H*/
11 changes: 8 additions & 3 deletions src/ext/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ TARGET_LIB_STATIC_EXT = $(LIB_DIR)/lib$(LIB_NAME_EXT).a
SOURCES = $(notdir $(basename $(wildcard *.c)))
OBJECTS = $(patsubst %,%.o,$(SOURCES))

# Source files in deps/redis directory. For now, librdb.so and librdb-ext.so,
# each will have its own copy. Take care not to pass Redis structs from one lib
# to another!
REDIS_SOURCES = $(notdir $(basename $(wildcard ../../deps/redis/*.c)))
REDIS_OBJECTS = $(patsubst %,../../deps/redis/%.o,$(REDIS_SOURCES))

OPTIMIZATION?=-O3
LIBRDB_DEBUG?=0
Expand All @@ -32,14 +37,14 @@ endif
all: $(TARGET_LIB_EXT) $(TARGET_LIB_STATIC_EXT)
@echo "Done.";

$(TARGET_LIB_EXT): $(OBJECTS)
$(TARGET_LIB_EXT): $(OBJECTS) $(REDIS_OBJECTS)
$(CC) -o $@ -shared ${LDFLAGS} $^ $(LIBS)

$(TARGET_LIB_STATIC_EXT): $(OBJECTS)
$(TARGET_LIB_STATIC_EXT): $(OBJECTS) $(REDIS_OBJECTS)
ar rcs $@ $^

# Include object file dependencies
-include $(OBJECTS:.o=.d)
-include $(OBJECTS:.o=.d) $(REDIS_OBJECTS:.o=.d)

%.o: %.c
$(CC) $(CFLAGS) -c $*.c -o $*.o $(DEBUG)
Expand Down
30 changes: 30 additions & 0 deletions src/ext/common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "common.h"


#include <stdio.h>
#include <pthread.h>
#include "../../deps/redis/rax.h"
#include "../../deps/redis/util.h"

/* Example:: Input: length=123 return: buf="\r\n$123\r\n" */
void iov_length(struct iovec *iov, long long length, char *buf, int bufsize) {
int len = 0;
buf[0] = '\r';
buf[1] = '\n';
buf[2] = '$';
len = ll2string(buf+3, bufsize-5, length);
buf[len + 3] = '\r';
buf[len + 4] = '\n';
iov_plain(iov, buf, len+5);
}

/* For value 123 the function will return in buf: "123\r\n" */
int iov_value(struct iovec *iov, long long value, char *buf, int bufsize) {
int len = 0;
len = ll2string(buf, bufsize-2, value); /* -2 for: 'r' and '\n' */
buf[len] = '\r';
buf[len+1] = '\n';
iov_plain(iov, buf, len+2);
return len;
}

6 changes: 4 additions & 2 deletions src/ext/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ static inline void unused(void *dummy, ...) { (void)(dummy);}
#define unlikely(x) (x)
#endif

#define IF_NOT_OK_RETURN(cmd) do {RdbRes s; s = cmd; if (unlikely(s!=RDB_OK)) return s;} while (0)

/*** IOVEC manipulation ***/
// INPUT: str="ABC" OUTPUT: iov={ "ABC" , 3 }
#define IOV_CONST(iov, str) iov_plain(iov, str, sizeof(str)-1)
Expand All @@ -41,11 +43,11 @@ static inline void unused(void *dummy, ...) { (void)(dummy);}

int iov_value(struct iovec *iov, long long count, char *buf, int bufsize);

void iov_length(struct iovec *iov, long long length, char *buf, int bufsize);

static inline void iov_plain(struct iovec *iov, const char *s, size_t l) {
iov->iov_base = (void *) s;
iov->iov_len = l;
}

#define IF_NOT_OK_RETURN(cmd) do {RdbRes s; s = cmd; if (unlikely(s!=RDB_OK)) return s;} while (0)

#endif /*define RDBX_COMMON_H*/
1 change: 0 additions & 1 deletion src/ext/handlersToJson.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

struct RdbxToJson;


#define _STDOUT_STR "<stdout>"

typedef enum
Expand Down
31 changes: 7 additions & 24 deletions src/ext/handlersToResp.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,28 +142,6 @@ static void deleteRdbToRespCtx(RdbParser *p, void *context) {
RDB_free(p, ctx);
}

/* Example:: Input: length=123 return: buf="\r\n$123\r\n" */
static void iov_length(struct iovec *iov, long long length, char *buf, int bufsize) {
int len = 0;
buf[0] = '\r';
buf[1] = '\n';
buf[2] = '$';
len = ll2string(buf+3, bufsize-5, length);
buf[len + 3] = '\r';
buf[len + 4] = '\n';
iov_plain(iov, buf, len+5);
}

/* For value 123 the function will return in buf: "123\r\n" */
int iov_value(struct iovec *iov, long long value, char *buf, int bufsize) {
int len = 0;
len = ll2string(buf, bufsize-2, value); /* -2 for: 'r' and '\n' */
buf[len] = '\r';
buf[len+1] = '\n';
iov_plain(iov, buf, len+2);
return len;
}

static int setRdbVerFromDestRedisVer(RdbxToResp *ctx) {

const char *ver = ctx->conf.dstRedisVersion;
Expand Down Expand Up @@ -725,8 +703,7 @@ static RdbRes toRespStreamCGroupPendingEntry(RdbParser *p, void *userData, RdbSt

memcpy(pe, pendingEntry, sizeof(RdbStreamPendingEntry));

if (!raxTryInsert(ctx->streamCtx.groupPel, (unsigned char *) &(pe->id),
sizeof(pe->id), pe, NULL))
if (!raxTryInsert(ctx->streamCtx.groupPel, (unsigned char *) &(pe->id), sizeof(pe->id), pe, NULL))
return (RdbRes) RDBX_ERR_STREAM_DUPLICATE_PEL;

return RDB_OK;
Expand Down Expand Up @@ -930,6 +907,12 @@ static RdbRes toRespRestoreFragEnd(RdbParser *p, void *userData) {

_LIBRDB_API RdbxToResp *RDBX_createHandlersToResp(RdbParser *p, RdbxToRespConf *conf) {
RdbxToResp *ctx;
static int crcInitalized = 0;

if (!crcInitalized) {
++crcInitalized;
crc64_init();
}

/* Verify table is aligned with LIBRDB_SUPPORT_MAX_RDB_VER */
assert(redisToRdbVersion[0].rdb == RDB_getMaxSuppportRdbVersion());
Expand Down
4 changes: 3 additions & 1 deletion src/lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ TARGET_LIB_STATIC = $(LIB_DIR)/lib$(LIB_NAME).a
SOURCES = $(notdir $(basename $(wildcard *.c)))
OBJECTS = $(patsubst %,%.o,$(SOURCES))

# Source files in deps/redis directory
# Source files in deps/redis directory. For now, librdb.so and librdb-ext.so,
# each will have its own copy. Take care not to pass Redis structs from one lib
# to another!
REDIS_SOURCES = $(notdir $(basename $(wildcard ../../deps/redis/*.c)))
REDIS_OBJECTS = $(patsubst %,../../deps/redis/%.o,$(REDIS_SOURCES))

Expand Down

0 comments on commit 130bf3e

Please sign in to comment.