committing local changes to rmutil

master
Dvir Volk 7 years ago
parent 121f189a7a
commit af5796d5bb

@ -41,10 +41,11 @@ char *rmalloc_strndup(const char *s, size_t n);
#define strndup(s, n) rmalloc_strndup(s, n)
#else
#endif /* REDIS_MODULE_TARGET */
/* This function shold be called if you are working with malloc-patched code
* ouside of redis, usually for unit tests. Call it once when entering your unit
* tests' main() */
void RMUTil_InitAlloc();
#endif /* REDIS_MODULE_TARGET */
#endif /* __RMUTIL_ALLOC__ */

@ -36,6 +36,11 @@
* the include of your alternate allocator if needed (not needed in order
* to use the default libc allocator). */
#if defined(__MACH__)
#include <stdlib.h>
#else
#include <malloc.h>
#endif
//#include "zmalloc.h"
#define s_malloc malloc
#define s_realloc realloc

@ -3,7 +3,6 @@
#include <ctype.h>
#include "strings.h"
#include "sds.h"
// RedisModuleString *RMUtil_CreateFormattedString(RedisModuleCtx *ctx, const char *fmt, ...) {
@ -21,7 +20,6 @@
int RMUtil_StringEquals(RedisModuleString *s1, RedisModuleString *s2) {
const char *c1, *c2;
size_t l1, l2;
c1 = RedisModule_StringPtrLen(s1, &l1);
@ -33,7 +31,6 @@ int RMUtil_StringEquals(RedisModuleString *s1, RedisModuleString *s2) {
int RMUtil_StringEqualsC(RedisModuleString *s1, const char *s2) {
const char *c1;
size_t l1, l2 = strlen(s2);
c1 = RedisModule_StringPtrLen(s1, &l1);
@ -41,6 +38,15 @@ int RMUtil_StringEqualsC(RedisModuleString *s1, const char *s2) {
return strncmp(c1, s2, l1) == 0;
}
int RMUtil_StringEqualsCaseC(RedisModuleString *s1, const char *s2) {
const char *c1;
size_t l1, l2 = strlen(s2);
c1 = RedisModule_StringPtrLen(s1, &l1);
if (l1 != l2) return 0;
return strncasecmp(c1, s2, l1) == 0;
}
void RMUtil_StringToLower(RedisModuleString *s) {
@ -51,7 +57,6 @@ void RMUtil_StringToLower(RedisModuleString *s) {
*c = tolower(*c);
++c;
}
}
void RMUtil_StringToUpper(RedisModuleString *s) {
@ -62,6 +67,4 @@ void RMUtil_StringToUpper(RedisModuleString *s) {
*c = toupper(*c);
++c;
}
}

@ -8,16 +8,18 @@
* Note that RedisModuleString objects CANNOT be used as formatting arguments.
*/
// DEPRECATED since it was added to the RedisModule API. Replaced with a macro below
//RedisModuleString *RMUtil_CreateFormattedString(RedisModuleCtx *ctx, const char *fmt, ...);
// RedisModuleString *RMUtil_CreateFormattedString(RedisModuleCtx *ctx, const char *fmt, ...);
#define RMUtil_CreateFormattedString RedisModule_CreateStringPrintf
/* Return 1 if the two strings are equal. Case *sensitive* */
int RMUtil_StringEquals(RedisModuleString *s1, RedisModuleString *s2);
/* Return 1 if the string is equal to a C NULL terminated string. Case *sensitive* */
int RMUtil_StringEqualsC(RedisModuleString *s1, const char *s2);
/* Return 1 if the string is equal to a C NULL terminated string. Case *insensitive* */
int RMUtil_StringEqualsCaseC(RedisModuleString *s1, const char *s2);
/* Converts a redis string to lowercase in place without reallocating anything */
void RMUtil_StringToLower(RedisModuleString *s);

@ -71,7 +71,6 @@ RMUtilInfo *RMUtil_GetRedisInfo(RedisModuleCtx *ctx) {
char *key = strsep(&line, ":");
info->entries[i].key = key;
info->entries[i].val = line;
//printf("Got info '%s' = '%s'\n", key, line);
i++;
if (i >= cap) {
cap *= 2;
@ -123,7 +122,6 @@ int RMUtilInfo_GetDouble(RMUtilInfo *info, const char *key, double *d) {
}
*d = strtod(p, NULL);
//printf("p: %s, d: %f\n", p, *d);
if ((errno == ERANGE && (*d == HUGE_VAL || *d == -HUGE_VAL)) || (errno != 0 && *d == 0)) {
return 0;
}

@ -6,7 +6,7 @@ inline int __vector_PushPtr(Vector *v, void *elem) {
Vector_Resize(v, v->cap ? v->cap * 2 : 1);
}
__vector_PutPtr(v, v->top, elem);
__vector_PutPtr(v, v->top++, elem);
return v->top;
}
@ -43,7 +43,7 @@ inline int __vector_PutPtr(Vector *v, size_t pos, void *elem) {
} else {
memset(v->data + pos * v->elemSize, 0, v->elemSize);
}
// move the end offset to pos + 1 if we grew
// move the end offset to pos if we grew
if (pos >= v->top) {
v->top = pos + 1;
}
@ -80,6 +80,8 @@ void Vector_Free(Vector *v) {
free(v);
}
/* return the used size of the vector, regardless of capacity */
inline int Vector_Size(Vector *v) { return v->top; }
/* return the actual capacity */

@ -47,13 +47,11 @@ int Vector_Pop(Vector *v, void *ptr);
* Put an element at pos.
* Note: If pos is outside the vector capacity, we resize it accordingly
*/
#define Vector_Put(v, pos, elem) \
__vector_PutPtr(v, pos, elem ? &(typeof(elem)){elem} : NULL)
#define Vector_Put(v, pos, elem) __vector_PutPtr(v, pos, elem ? &(typeof(elem)){elem} : NULL)
/* Push an element at the end of v, resizing it if needed. This macro wraps
* __vector_PushPtr */
#define Vector_Push(v, elem) \
__vector_PushPtr(v, elem ? &(typeof(elem)){elem} : NULL)
#define Vector_Push(v, elem) __vector_PushPtr(v, elem ? &(typeof(elem)){elem} : NULL)
int __vector_PushPtr(Vector *v, void *elem);

Loading…
Cancel
Save