mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 17:10:50 +00:00
BITFIELD: refactoring & fix of retval on FAIL.
This commit is contained in:
parent
11745e0981
commit
32289d5719
32
src/bitops.c
32
src/bitops.c
@ -965,8 +965,11 @@ void bitfieldCommand(client *c) {
|
|||||||
|
|
||||||
if ((o = lookupStringForBitCommand(c,bitoffset)) == NULL) return;
|
if ((o = lookupStringForBitCommand(c,bitoffset)) == NULL) return;
|
||||||
|
|
||||||
|
/* We need two different but very similar code paths for signed
|
||||||
|
* and unsigned operations, since the set of functions to get/set
|
||||||
|
* the integers and the used variables types are different. */
|
||||||
if (thisop->sign) {
|
if (thisop->sign) {
|
||||||
int64_t oldval, newval, wrapped;
|
int64_t oldval, newval, wrapped, retval;
|
||||||
int overflow;
|
int overflow;
|
||||||
|
|
||||||
oldval = getSignedBitfield(o->ptr,thisop->offset,
|
oldval = getSignedBitfield(o->ptr,thisop->offset,
|
||||||
@ -977,21 +980,26 @@ void bitfieldCommand(client *c) {
|
|||||||
overflow = checkSignedBitfieldOverflow(oldval,
|
overflow = checkSignedBitfieldOverflow(oldval,
|
||||||
thisop->i64,thisop->bits,thisop->owtype,&wrapped);
|
thisop->i64,thisop->bits,thisop->owtype,&wrapped);
|
||||||
if (overflow) newval = wrapped;
|
if (overflow) newval = wrapped;
|
||||||
addReplyLongLong(c,newval);
|
retval = newval;
|
||||||
} else {
|
} else {
|
||||||
newval = thisop->i64;
|
newval = thisop->i64;
|
||||||
overflow = checkSignedBitfieldOverflow(newval,
|
overflow = checkSignedBitfieldOverflow(newval,
|
||||||
0,thisop->bits,thisop->owtype,&wrapped);
|
0,thisop->bits,thisop->owtype,&wrapped);
|
||||||
if (overflow) newval = wrapped;
|
if (overflow) newval = wrapped;
|
||||||
addReplyLongLong(c,oldval);
|
retval = oldval;
|
||||||
}
|
}
|
||||||
/* If the overflow type is "FAIL", don't write. */
|
|
||||||
|
/* On overflow of type is "FAIL", don't write and return
|
||||||
|
* NULL to signal the condition. */
|
||||||
if (!(overflow && thisop->owtype == BFOVERFLOW_FAIL)) {
|
if (!(overflow && thisop->owtype == BFOVERFLOW_FAIL)) {
|
||||||
|
addReplyLongLong(c,retval);
|
||||||
setSignedBitfield(o->ptr,thisop->offset,
|
setSignedBitfield(o->ptr,thisop->offset,
|
||||||
thisop->bits,newval);
|
thisop->bits,newval);
|
||||||
|
} else {
|
||||||
|
addReply(c,shared.nullbulk);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
uint64_t oldval, newval, wrapped;
|
uint64_t oldval, newval, wrapped, retval;
|
||||||
int overflow;
|
int overflow;
|
||||||
|
|
||||||
oldval = getUnsignedBitfield(o->ptr,thisop->offset,
|
oldval = getUnsignedBitfield(o->ptr,thisop->offset,
|
||||||
@ -1002,15 +1010,23 @@ void bitfieldCommand(client *c) {
|
|||||||
overflow = checkUnsignedBitfieldOverflow(oldval,
|
overflow = checkUnsignedBitfieldOverflow(oldval,
|
||||||
thisop->i64,thisop->bits,thisop->owtype,&wrapped);
|
thisop->i64,thisop->bits,thisop->owtype,&wrapped);
|
||||||
if (overflow) newval = wrapped;
|
if (overflow) newval = wrapped;
|
||||||
addReplyLongLong(c,newval);
|
retval = newval;
|
||||||
} else {
|
} else {
|
||||||
newval = thisop->i64;
|
newval = thisop->i64;
|
||||||
overflow = checkUnsignedBitfieldOverflow(newval,
|
overflow = checkUnsignedBitfieldOverflow(newval,
|
||||||
0,thisop->bits,thisop->owtype,&wrapped);
|
0,thisop->bits,thisop->owtype,&wrapped);
|
||||||
if (overflow) newval = wrapped;
|
if (overflow) newval = wrapped;
|
||||||
addReplyLongLong(c,oldval);
|
retval = oldval;
|
||||||
|
}
|
||||||
|
/* On overflow of type is "FAIL", don't write and return
|
||||||
|
* NULL to signal the condition. */
|
||||||
|
if (!(overflow && thisop->owtype == BFOVERFLOW_FAIL)) {
|
||||||
|
addReplyLongLong(c,retval);
|
||||||
|
setUnsignedBitfield(o->ptr,thisop->offset,
|
||||||
|
thisop->bits,newval);
|
||||||
|
} else {
|
||||||
|
addReply(c,shared.nullbulk);
|
||||||
}
|
}
|
||||||
setUnsignedBitfield(o->ptr,thisop->offset,thisop->bits,newval);
|
|
||||||
}
|
}
|
||||||
changes++;
|
changes++;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user