Revert "synchornizing changes from RediSearch. @mnunberge please next time reflect these changes on the main repo"

This reverts commit 755ecf306b.

We'll add the AoF routines back properly...
master
Mark Nunberg 7 years ago
parent 755ecf306b
commit 69f750a9df

@ -2,6 +2,7 @@
#include <sys/param.h> #include <sys/param.h>
#include <ctype.h> #include <ctype.h>
#include "strings.h" #include "strings.h"
#include "alloc.h"
#include "sds.h" #include "sds.h"
@ -68,3 +69,13 @@ void RMUtil_StringToUpper(RedisModuleString *s) {
++c; ++c;
} }
} }
void RMUtil_StringConvert(RedisModuleString **rs, const char **ss, size_t n, int options) {
for (size_t ii = 0; ii < n; ++ii) {
const char *p = RedisModule_StringPtrLen(rs[ii], NULL);
if (options & RMUTIL_STRINGCONVERT_COPY) {
p = strdup(p);
}
ss[ii] = p;
}
}

@ -25,4 +25,14 @@ void RMUtil_StringToLower(RedisModuleString *s);
/* Converts a redis string to uppercase in place without reallocating anything */ /* Converts a redis string to uppercase in place without reallocating anything */
void RMUtil_StringToUpper(RedisModuleString *s); void RMUtil_StringToUpper(RedisModuleString *s);
// If set, copy the strings using strdup rather than simply storing pointers.
#define RMUTIL_STRINGCONVERT_COPY 1
/**
* Convert one or more RedisModuleString objects into `const char*`.
* Both rs and ss are arrays, and should be of <n> length.
* Options may be 0 or `RMUTIL_STRINGCONVERT_COPY`
*/
void RMUtil_StringConvert(RedisModuleString **rs, const char **ss, size_t n, int options);
#endif #endif

@ -3,7 +3,7 @@
#include <unistd.h> #include <unistd.h>
#include "periodic.h" #include "periodic.h"
#include "assert.h" #include "assert.h"
#include "test_util.h" #include "test.h"
void timerCb(RedisModuleCtx *ctx, void *p) { void timerCb(RedisModuleCtx *ctx, void *p) {
int *x = p; int *x = p;

@ -1,69 +1,67 @@
#ifndef __TESTUTIL_H__ #ifndef __TEST_UTIL_H__
#define __TESTUTIL_H__ #define __TEST_UTIL_H__
#include <assert.h> #include "util.h"
#include <stdio.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
static int numTests = 0;
static int numAsserts = 0;
#define TESTFUNC(f) \ #define RMUtil_Test(f) \
printf(" Testing %s\t\t", __STRING(f)); \ if (argc < 2 || RMUtil_ArgExists(__STRING(f), argv, argc, 1)) { \
numTests++; \ int rc = f(ctx); \
fflush(stdout); \ if (rc != REDISMODULE_OK) { \
if (f()) { \ RedisModule_ReplyWithError(ctx, "Test " __STRING(f) " FAILED"); \
printf(" %s FAILED!\n", __STRING(f)); \ return REDISMODULE_ERR;\
exit(1); \
} else \
printf("[PASS]\n");
#define ASSERTM(expr, ...) \
if (!(expr)) { \
fprintf(stderr, "%s:%d: Assertion '%s' Failed: " __VA_ARGS__ "\n", __FILE__, __LINE__, \
__STRING(expr)); \
return -1; \
}\ }\
numAsserts++; }
#define ASSERT(expr) \
if (!(expr)) { \
fprintf(stderr, "%s:%d Assertion '%s' Failed\n", __FILE__, __LINE__, __STRING(expr)); \
return -1; \
} \
numAsserts++;
#define ASSERT_STRING_EQ(s1, s2) ASSERT(!strcmp(s1, s2)); #define RMUtil_Assert(expr) if (!(expr)) { fprintf (stderr, "Assertion '%s' Failed\n", __STRING(expr)); return REDISMODULE_ERR; }
#define ASSERT_EQUAL(x, y, ...) \ #define RMUtil_AssertReplyEquals(rep, cstr) RMUtil_Assert( \
if (x != y) { \ RMUtil_StringEquals(RedisModule_CreateStringFromCallReply(rep), RedisModule_CreateString(ctx, cstr, strlen(cstr))) \
fprintf(stderr, "%s:%d: ", __FILE__, __LINE__); \ )
fprintf(stderr, "%g != %g: " __VA_ARGS__ "\n", (double)x, (double)y); \ #
return -1; \
} \
numAsserts++;
#define FAIL(fmt, ...) \ /**
{ \ * Create an arg list to pass to a redis command handler manually, based on the format in fmt.
fprintf(stderr, "%s:%d: FAIL: " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__); \ * The accepted format specifiers are:
return -1; \ * c - for null terminated c strings
} * s - for RedisModuleString* objects
* l - for longs
*
* Example: RMUtil_MakeArgs(ctx, &argc, "clc", "hello", 1337, "world");
*
* Returns an array of RedisModuleString pointers. The size of the array is store in argcp
*/
RedisModuleString **RMUtil_MakeArgs(RedisModuleCtx *ctx, int *argcp, const char *fmt, ...) {
#define RETURN_TEST_SUCCESS return 0; va_list ap;
#define TEST_CASE(x, block) \ va_start(ap, fmt);
int x { \ RedisModuleString **argv = calloc(strlen(fmt), sizeof(RedisModuleString*));
block; \ int argc = 0;
return 0 \ const char *p = fmt;
while(*p) {
if (*p == 'c') {
char *cstr = va_arg(ap,char*);
argv[argc++] = RedisModule_CreateString(ctx, cstr, strlen(cstr));
} else if (*p == 's') {
argv[argc++] = va_arg(ap,void*);;
} else if (*p == 'l') {
long ll = va_arg(ap,long long);
argv[argc++] = RedisModule_CreateStringFromLongLong(ctx, ll);
} else {
goto fmterr;
} }
p++;
}
*argcp = argc;
#define PRINT_TEST_SUMMARY printf("\nTotal: %d tests and %d assertions OK\n", numTests, numAsserts); return argv;
fmterr:
#define TEST_MAIN(body) \ free(argv);
int main(int argc, char **argv) { \ return NULL;
printf("Starting Test '%s'...\n", argv[0]); \
body; \
PRINT_TEST_SUMMARY; \
printf("\n--------------------\n\n"); \
return 0; \
} }
#endif #endif

@ -1,6 +1,6 @@
#include "vector.h" #include "vector.h"
#include <stdio.h> #include <stdio.h>
#include "test_util.h" #include "test.h"
int testVector() { int testVector() {

@ -275,18 +275,3 @@ RedisModuleString **RMUtil_ParseVarArgs(RedisModuleString **argv, int argc, int
*nargs = n; *nargs = n;
return argv + 1; return argv + 1;
} }
void RMUtil_DefaultAofRewrite(RedisModuleIO *aof, RedisModuleString *key, void *value) {
RedisModuleCallReply *rep =
RedisModule_Call(RedisModule_GetContextFromIO(aof), "DUMP", "%s", key);
if (rep != NULL && RedisModule_CallReplyType(rep) == REDISMODULE_REPLY_STRING) {
size_t n;
const char *s = RedisModule_CallReplyStringPtr(rep, &n);
RedisModule_EmitAOF(aof, "RESTORE", "%sb", key, s, n);
} else {
RedisModule_Log(RedisModule_GetContextFromIO(aof), "warning", "Failed to emit AOF");
}
if (rep != NULL) {
RedisModule_FreeCallReply(rep);
}
}

@ -72,13 +72,6 @@ int rmutil_vparseArgs(RedisModuleString **argv, int argc, int offset, const char
RedisModuleString **RMUtil_ParseVarArgs(RedisModuleString **argv, int argc, int offset, RedisModuleString **RMUtil_ParseVarArgs(RedisModuleString **argv, int argc, int offset,
const char *keyword, size_t *nargs); const char *keyword, size_t *nargs);
/**
* Default implementation of an AoF rewrite function that simply calls DUMP/RESTORE
* internally. To use this function, pass it as the .aof_rewrite value in
* RedisModuleTypeMethods
*/
void RMUtil_DefaultAofRewrite(RedisModuleIO *aof, RedisModuleString *key, void *value);
// A single key/value entry in a redis info map // A single key/value entry in a redis info map
typedef struct { typedef struct {
const char *key; const char *key;

@ -2,6 +2,7 @@
#define __VECTOR_H__ #define __VECTOR_H__
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdarg.h>
/* /*
* Generic resizable vector that can be used if you just want to store stuff * Generic resizable vector that can be used if you just want to store stuff

Loading…
Cancel
Save