Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tezc committed Sep 28, 2023
1 parent a135c99 commit f4df607
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
9 changes: 0 additions & 9 deletions deps/redis/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,6 @@ int lpStringToInt64(const char *s, unsigned long slen, int64_t *value) {
return 1;
}

double zzlStrtod(unsigned char *vstr, unsigned int vlen) {
char buf[128];
if (vlen > sizeof(buf) - 1)
vlen = sizeof(buf) - 1;
memcpy(buf,vstr,vlen);
buf[vlen] = '\0';
return strtod(buf,NULL);
}

/* Returns 1 if the double value can safely be represented in long long without
* precision loss, in which case the corresponding long long is stored in the out variable. */
static int double2ll(double d, long long *out) {
Expand Down
11 changes: 10 additions & 1 deletion deps/redis/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@
/* Bytes needed for long -> str + '\0' */
#define LONG_STR_SIZE 21

/* The maximum number of characters needed to for d2string/fpconv_dtoa call.
* Since it uses %g and not %f, some 40 chars should be enough. */
#define MAX_D2STRING_CHARS 128

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);
double zzlStrtod(unsigned char *vstr, unsigned int vlen);

/* This is the exact function that is used in redis zset implementation for
* double <-> string conversions. Using some other function may result in
* 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. */
int d2string(char *buf, size_t len, double value);

#endif /*LIBRDB_UTIL_H*/
2 changes: 1 addition & 1 deletion src/ext/handlersToJson.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ static RdbRes toJsonSet(RdbParser *p, void *userData, RdbBulk member) {
static RdbRes toJsonZset(RdbParser *p, void *userData, RdbBulk member, double score) {
RdbxToJson *ctx = userData;

char score_str[64];
char score_str[MAX_D2STRING_CHARS];
int len = d2string(score_str, sizeof(score_str), score);

if (ctx->state == R2J_IN_KEY) {
Expand Down
2 changes: 1 addition & 1 deletion src/ext/handlersToResp.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ static RdbRes toRespZset(RdbParser *p, void *userData, RdbBulk member, double sc
IOV_CONST(&iov[3], "\r\n$");

/* write score */
char score_str[256];
char score_str[MAX_D2STRING_CHARS];
int len = d2string(score_str, sizeof(score_str), score);
assert(len != 0);
IOV_VALUE(&iov[4], len, scoreLenStr);
Expand Down
8 changes: 4 additions & 4 deletions src/lib/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "../../deps/redis/zipmap.h"
#include "../../deps/redis/intset.h"
#include "../../deps/redis/lzf.h"
#include "../../deps/redis/t_zset.h"

#define DONE_FILL_BULK SIZE_MAX

Expand Down Expand Up @@ -2036,7 +2037,7 @@ RdbStatus rdbLoadDoubleValue(RdbParser *p, double *val) {

/* Try to read double value and then copy it to the destination including one
* byte prefix. See rdbLoadDoubleValue() for details. */
RdbStatus rdbLoadDoubleValueToDest(RdbParser *p, char *dst, int *written) {
RdbStatus rdbLoadDoubleValueToBuff(RdbParser *p, char *dst, int *written) {
double val;
unsigned char len;
BulkInfo *binfo;
Expand All @@ -2053,11 +2054,10 @@ RdbStatus rdbLoadDoubleValueToDest(RdbParser *p, char *dst, int *written) {
case 253: /* NAN */
return RDB_STATUS_OK;
default:
IF_NOT_OK_RETURN(rdbLoad(p, len, RQ_ALLOC, NULL, &binfo));
if (sscanf(binfo->ref, "%lg", &val) != 1)
IF_NOT_OK_RETURN(rdbLoad(p, len, RQ_ALLOC_REF, dst, &binfo));
if (sscanf(dst, "%lg", &val) != 1)
return RDB_STATUS_ERROR;

memcpy(dst, binfo->ref, len);
*written += len;
return RDB_STATUS_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ void subElementCallEnd(RdbParser *p, RdbBulk *bulkResult, size_t *len);
RdbStatus rdbLoadFloatValue(RdbParser *p, float *val);
RdbStatus rdbLoadBinaryDoubleValue(RdbParser *p, double *val);
RdbStatus rdbLoadDoubleValue(RdbParser *p, double *val);
RdbStatus rdbLoadDoubleValueToDest(RdbParser *p, char *dst, int *written);
RdbStatus rdbLoadDoubleValueToBuff(RdbParser *p, char *dst, int *written);
RdbStatus rdbLoadLen(RdbParser *p, int *isencoded, uint64_t *lenptr, unsigned char* outbuff, int *outbufflen);
RdbStatus rdbLoadInteger(RdbParser *p, int enctype, AllocTypeRq type, char *refBuf, BulkInfo **out);
RdbStatus rdbLoadString(RdbParser *p, AllocTypeRq type, char *refBuf, BulkInfo **out);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/parserRaw.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ RdbStatus elementRawZset(RdbParser *p) {
IF_NOT_OK_RETURN(aggUpdateWritten(p, sizeof(double)));
} else {
int written;
IF_NOT_OK_RETURN(rdbLoadDoubleValueToDest(p, rawCtx->at, &written));
IF_NOT_OK_RETURN(rdbLoadDoubleValueToBuff(p, rawCtx->at, &written));
IF_NOT_OK_RETURN(aggUpdateWritten(p, written));
}

Expand Down

0 comments on commit f4df607

Please sign in to comment.