Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
3d48c931
Commit
3d48c931
authored
Jun 23, 2016
by
Salvatore Sanfilippo
Committed by
GitHub
Jun 23, 2016
Browse files
Merge pull request #3330 from yossigo/fix_const
Use const in Redis Module API where possible.
parents
4b12c6a3
8f3a4df7
Changes
13
Hide whitespace changes
Inline
Side-by-side
src/debug.c
View file @
3d48c931
...
...
@@ -550,7 +550,7 @@ void debugCommand(client *c) {
/* =========================== Crash handling ============================== */
void
_serverAssert
(
char
*
estr
,
char
*
file
,
int
line
)
{
void
_serverAssert
(
const
char
*
estr
,
const
char
*
file
,
int
line
)
{
bugReportStart
();
serverLog
(
LL_WARNING
,
"=== ASSERTION FAILED ==="
);
serverLog
(
LL_WARNING
,
"==> %s:%d '%s' is not true"
,
file
,
line
,
estr
);
...
...
@@ -563,7 +563,7 @@ void _serverAssert(char *estr, char *file, int line) {
*
((
char
*
)
-
1
)
=
'x'
;
}
void
_serverAssertPrintClientInfo
(
client
*
c
)
{
void
_serverAssertPrintClientInfo
(
const
client
*
c
)
{
int
j
;
bugReportStart
();
...
...
@@ -587,7 +587,7 @@ void _serverAssertPrintClientInfo(client *c) {
}
}
void
serverLogObjectDebugInfo
(
robj
*
o
)
{
void
serverLogObjectDebugInfo
(
const
robj
*
o
)
{
serverLog
(
LL_WARNING
,
"Object type: %d"
,
o
->
type
);
serverLog
(
LL_WARNING
,
"Object encoding: %d"
,
o
->
encoding
);
serverLog
(
LL_WARNING
,
"Object refcount: %d"
,
o
->
refcount
);
...
...
@@ -607,23 +607,23 @@ void serverLogObjectDebugInfo(robj *o) {
}
else
if
(
o
->
type
==
OBJ_ZSET
)
{
serverLog
(
LL_WARNING
,
"Sorted set size: %d"
,
(
int
)
zsetLength
(
o
));
if
(
o
->
encoding
==
OBJ_ENCODING_SKIPLIST
)
serverLog
(
LL_WARNING
,
"Skiplist level: %d"
,
(
int
)
((
zset
*
)
o
->
ptr
)
->
zsl
->
level
);
serverLog
(
LL_WARNING
,
"Skiplist level: %d"
,
(
int
)
((
const
zset
*
)
o
->
ptr
)
->
zsl
->
level
);
}
}
void
_serverAssertPrintObject
(
robj
*
o
)
{
void
_serverAssertPrintObject
(
const
robj
*
o
)
{
bugReportStart
();
serverLog
(
LL_WARNING
,
"=== ASSERTION FAILED OBJECT CONTEXT ==="
);
serverLogObjectDebugInfo
(
o
);
}
void
_serverAssertWithInfo
(
client
*
c
,
robj
*
o
,
char
*
estr
,
char
*
file
,
int
line
)
{
void
_serverAssertWithInfo
(
const
client
*
c
,
const
robj
*
o
,
const
char
*
estr
,
const
char
*
file
,
int
line
)
{
if
(
c
)
_serverAssertPrintClientInfo
(
c
);
if
(
o
)
_serverAssertPrintObject
(
o
);
_serverAssert
(
estr
,
file
,
line
);
}
void
_serverPanic
(
char
*
msg
,
char
*
file
,
int
line
)
{
void
_serverPanic
(
const
char
*
msg
,
const
char
*
file
,
int
line
)
{
bugReportStart
();
serverLog
(
LL_WARNING
,
"------------------------------------------------"
);
serverLog
(
LL_WARNING
,
"!!! Software Failure. Press left mouse button to continue"
);
...
...
src/intset.c
View file @
3d48c931
...
...
@@ -272,7 +272,7 @@ uint8_t intsetGet(intset *is, uint32_t pos, int64_t *value) {
}
/* Return intset length */
uint32_t
intsetLen
(
intset
*
is
)
{
uint32_t
intsetLen
(
const
intset
*
is
)
{
return
intrev32ifbe
(
is
->
length
);
}
...
...
src/intset.h
View file @
3d48c931
...
...
@@ -44,7 +44,7 @@ intset *intsetRemove(intset *is, int64_t value, int *success);
uint8_t
intsetFind
(
intset
*
is
,
int64_t
value
);
int64_t
intsetRandom
(
intset
*
is
);
uint8_t
intsetGet
(
intset
*
is
,
uint32_t
pos
,
int64_t
*
value
);
uint32_t
intsetLen
(
intset
*
is
);
uint32_t
intsetLen
(
const
intset
*
is
);
size_t
intsetBlobLen
(
intset
*
is
);
#ifdef REDIS_TEST
...
...
src/module.c
View file @
3d48c931
...
...
@@ -700,7 +700,7 @@ void RM_FreeString(RedisModuleCtx *ctx, RedisModuleString *str) {
/* Given a string module object, this function returns the string pointer
* and length of the string. The returned pointer and length should only
* be used for read only accesses and never modified. */
const
char
*
RM_StringPtrLen
(
RedisModuleString
*
str
,
size_t
*
len
)
{
const
char
*
RM_StringPtrLen
(
const
RedisModuleString
*
str
,
size_t
*
len
)
{
if
(
len
)
*
len
=
sdslen
(
str
->
ptr
);
return
str
->
ptr
;
}
...
...
@@ -709,7 +709,7 @@ const char *RM_StringPtrLen(RedisModuleString *str, size_t *len) {
* Returns REDISMODULE_OK on success. If the string can't be parsed
* as a valid, strict long long (no spaces before/after), REDISMODULE_ERR
* is returned. */
int
RM_StringToLongLong
(
RedisModuleString
*
str
,
long
long
*
ll
)
{
int
RM_StringToLongLong
(
const
RedisModuleString
*
str
,
long
long
*
ll
)
{
return
string2ll
(
str
->
ptr
,
sdslen
(
str
->
ptr
),
ll
)
?
REDISMODULE_OK
:
REDISMODULE_ERR
;
}
...
...
@@ -717,7 +717,7 @@ int RM_StringToLongLong(RedisModuleString *str, long long *ll) {
/* Convert the string into a double, storing it at `*d`.
* Returns REDISMODULE_OK on success or REDISMODULE_ERR if the string is
* not a valid string representation of a double value. */
int
RM_StringToDouble
(
RedisModuleString
*
str
,
double
*
d
)
{
int
RM_StringToDouble
(
const
RedisModuleString
*
str
,
double
*
d
)
{
int
retval
=
getDoubleFromObject
(
str
,
d
);
return
(
retval
==
C_OK
)
?
REDISMODULE_OK
:
REDISMODULE_ERR
;
}
...
...
src/object.c
View file @
3d48c931
...
...
@@ -539,7 +539,7 @@ size_t stringObjectLen(robj *o) {
}
}
int
getDoubleFromObject
(
robj
*
o
,
double
*
target
)
{
int
getDoubleFromObject
(
const
robj
*
o
,
double
*
target
)
{
double
value
;
char
*
eptr
;
...
...
@@ -550,7 +550,7 @@ int getDoubleFromObject(robj *o, double *target) {
if
(
sdsEncodedObject
(
o
))
{
errno
=
0
;
value
=
strtod
(
o
->
ptr
,
&
eptr
);
if
(
isspace
(((
char
*
)
o
->
ptr
)[
0
])
||
if
(
isspace
(((
const
char
*
)
o
->
ptr
)[
0
])
||
eptr
[
0
]
!=
'\0'
||
(
errno
==
ERANGE
&&
(
value
==
HUGE_VAL
||
value
==
-
HUGE_VAL
||
value
==
0
))
||
...
...
src/quicklist.c
View file @
3d48c931
...
...
@@ -149,7 +149,7 @@ REDIS_STATIC quicklistNode *quicklistCreateNode(void) {
}
/* Return cached quicklist count */
unsigned
int
quicklistCount
(
quicklist
*
ql
)
{
return
ql
->
count
;
}
unsigned
int
quicklistCount
(
const
quicklist
*
ql
)
{
return
ql
->
count
;
}
/* Free entire quicklist. */
void
quicklistRelease
(
quicklist
*
quicklist
)
{
...
...
src/quicklist.h
View file @
3d48c931
...
...
@@ -154,7 +154,7 @@ int quicklistPopCustom(quicklist *quicklist, int where, unsigned char **data,
void
*
(
*
saver
)(
unsigned
char
*
data
,
unsigned
int
sz
));
int
quicklistPop
(
quicklist
*
quicklist
,
int
where
,
unsigned
char
**
data
,
unsigned
int
*
sz
,
long
long
*
slong
);
unsigned
int
quicklistCount
(
quicklist
*
ql
);
unsigned
int
quicklistCount
(
const
quicklist
*
ql
);
int
quicklistCompare
(
unsigned
char
*
p1
,
unsigned
char
*
p2
,
int
p2_len
);
size_t
quicklistGetLzf
(
const
quicklistNode
*
node
,
void
**
data
);
...
...
src/redismodule.h
View file @
3d48c931
...
...
@@ -123,7 +123,7 @@ RedisModuleCallReply *REDISMODULE_API_FUNC(RedisModule_CallReplyArrayElement)(Re
RedisModuleString
*
REDISMODULE_API_FUNC
(
RedisModule_CreateString
)(
RedisModuleCtx
*
ctx
,
const
char
*
ptr
,
size_t
len
);
RedisModuleString
*
REDISMODULE_API_FUNC
(
RedisModule_CreateStringFromLongLong
)(
RedisModuleCtx
*
ctx
,
long
long
ll
);
void
REDISMODULE_API_FUNC
(
RedisModule_FreeString
)(
RedisModuleCtx
*
ctx
,
RedisModuleString
*
str
);
const
char
*
REDISMODULE_API_FUNC
(
RedisModule_StringPtrLen
)(
RedisModuleString
*
str
,
size_t
*
len
);
const
char
*
REDISMODULE_API_FUNC
(
RedisModule_StringPtrLen
)(
const
RedisModuleString
*
str
,
size_t
*
len
);
int
REDISMODULE_API_FUNC
(
RedisModule_ReplyWithError
)(
RedisModuleCtx
*
ctx
,
const
char
*
err
);
int
REDISMODULE_API_FUNC
(
RedisModule_ReplyWithSimpleString
)(
RedisModuleCtx
*
ctx
,
const
char
*
msg
);
int
REDISMODULE_API_FUNC
(
RedisModule_ReplyWithArray
)(
RedisModuleCtx
*
ctx
,
long
len
);
...
...
@@ -133,8 +133,8 @@ int REDISMODULE_API_FUNC(RedisModule_ReplyWithString)(RedisModuleCtx *ctx, Redis
int
REDISMODULE_API_FUNC
(
RedisModule_ReplyWithNull
)(
RedisModuleCtx
*
ctx
);
int
REDISMODULE_API_FUNC
(
RedisModule_ReplyWithDouble
)(
RedisModuleCtx
*
ctx
,
double
d
);
int
REDISMODULE_API_FUNC
(
RedisModule_ReplyWithCallReply
)(
RedisModuleCtx
*
ctx
,
RedisModuleCallReply
*
reply
);
int
REDISMODULE_API_FUNC
(
RedisModule_StringToLongLong
)(
RedisModuleString
*
str
,
long
long
*
ll
);
int
REDISMODULE_API_FUNC
(
RedisModule_StringToDouble
)(
RedisModuleString
*
str
,
double
*
d
);
int
REDISMODULE_API_FUNC
(
RedisModule_StringToLongLong
)(
const
RedisModuleString
*
str
,
long
long
*
ll
);
int
REDISMODULE_API_FUNC
(
RedisModule_StringToDouble
)(
const
RedisModuleString
*
str
,
double
*
d
);
void
REDISMODULE_API_FUNC
(
RedisModule_AutoMemory
)(
RedisModuleCtx
*
ctx
);
int
REDISMODULE_API_FUNC
(
RedisModule_Replicate
)(
RedisModuleCtx
*
ctx
,
const
char
*
cmdname
,
const
char
*
fmt
,
...);
int
REDISMODULE_API_FUNC
(
RedisModule_ReplicateVerbatim
)(
RedisModuleCtx
*
ctx
);
...
...
src/server.h
View file @
3d48c931
...
...
@@ -1048,8 +1048,8 @@ struct redisServer {
long
long
latency_monitor_threshold
;
dict
*
latency_events
;
/* Assert & bug reporting */
char
*
assert_failed
;
char
*
assert_file
;
const
char
*
assert_failed
;
const
char
*
assert_file
;
int
assert_line
;
int
bug_report_start
;
/* True if bug report header was already logged. */
int
watchdog_period
;
/* Software watchdog period in ms. 0 = off */
...
...
@@ -1245,7 +1245,7 @@ void addReplyStatusFormat(client *c, const char *fmt, ...);
void
listTypeTryConversion
(
robj
*
subject
,
robj
*
value
);
void
listTypePush
(
robj
*
subject
,
robj
*
value
,
int
where
);
robj
*
listTypePop
(
robj
*
subject
,
int
where
);
unsigned
long
listTypeLength
(
robj
*
subject
);
unsigned
long
listTypeLength
(
const
robj
*
subject
);
listTypeIterator
*
listTypeInitIterator
(
robj
*
subject
,
long
index
,
unsigned
char
direction
);
void
listTypeReleaseIterator
(
listTypeIterator
*
li
);
int
listTypeNext
(
listTypeIterator
*
li
,
listTypeEntry
*
entry
);
...
...
@@ -1305,7 +1305,7 @@ int getLongFromObjectOrReply(client *c, robj *o, long *target, const char *msg);
int
checkType
(
client
*
c
,
robj
*
o
,
int
type
);
int
getLongLongFromObjectOrReply
(
client
*
c
,
robj
*
o
,
long
long
*
target
,
const
char
*
msg
);
int
getDoubleFromObjectOrReply
(
client
*
c
,
robj
*
o
,
double
*
target
,
const
char
*
msg
);
int
getDoubleFromObject
(
robj
*
o
,
double
*
target
);
int
getDoubleFromObject
(
const
robj
*
o
,
double
*
target
);
int
getLongLongFromObject
(
robj
*
o
,
long
long
*
target
);
int
getLongDoubleFromObject
(
robj
*
o
,
long
double
*
target
);
int
getLongDoubleFromObjectOrReply
(
client
*
c
,
robj
*
o
,
long
double
*
target
,
const
char
*
msg
);
...
...
@@ -1406,7 +1406,7 @@ void zzlNext(unsigned char *zl, unsigned char **eptr, unsigned char **sptr);
void
zzlPrev
(
unsigned
char
*
zl
,
unsigned
char
**
eptr
,
unsigned
char
**
sptr
);
unsigned
char
*
zzlFirstInRange
(
unsigned
char
*
zl
,
zrangespec
*
range
);
unsigned
char
*
zzlLastInRange
(
unsigned
char
*
zl
,
zrangespec
*
range
);
unsigned
int
zsetLength
(
robj
*
zobj
);
unsigned
int
zsetLength
(
const
robj
*
zobj
);
void
zsetConvert
(
robj
*
zobj
,
int
encoding
);
void
zsetConvertToZiplistIfNeeded
(
robj
*
zobj
,
size_t
maxelelen
);
int
zsetScore
(
robj
*
zobj
,
sds
member
,
double
*
score
);
...
...
@@ -1479,7 +1479,7 @@ int setTypeNext(setTypeIterator *si, sds *sdsele, int64_t *llele);
sds
setTypeNextObject
(
setTypeIterator
*
si
);
int
setTypeRandomElement
(
robj
*
setobj
,
sds
*
sdsele
,
int64_t
*
llele
);
unsigned
long
setTypeRandomElements
(
robj
*
set
,
unsigned
long
count
,
robj
*
aux_set
);
unsigned
long
setTypeSize
(
robj
*
subject
);
unsigned
long
setTypeSize
(
const
robj
*
subject
);
void
setTypeConvert
(
robj
*
subject
,
int
enc
);
/* Hash data type */
...
...
@@ -1492,7 +1492,7 @@ void hashTypeTryConversion(robj *subject, robj **argv, int start, int end);
void
hashTypeTryObjectEncoding
(
robj
*
subject
,
robj
**
o1
,
robj
**
o2
);
int
hashTypeExists
(
robj
*
o
,
sds
key
);
int
hashTypeDelete
(
robj
*
o
,
sds
key
);
unsigned
long
hashTypeLength
(
robj
*
o
);
unsigned
long
hashTypeLength
(
const
robj
*
o
);
hashTypeIterator
*
hashTypeInitIterator
(
robj
*
subject
);
void
hashTypeReleaseIterator
(
hashTypeIterator
*
hi
);
int
hashTypeNext
(
hashTypeIterator
*
hi
);
...
...
@@ -1799,11 +1799,11 @@ void *realloc(void *ptr, size_t size) __attribute__ ((deprecated));
#endif
/* Debugging stuff */
void
_serverAssertWithInfo
(
client
*
c
,
robj
*
o
,
char
*
estr
,
char
*
file
,
int
line
);
void
_serverAssert
(
char
*
estr
,
char
*
file
,
int
line
);
void
_serverPanic
(
char
*
msg
,
char
*
file
,
int
line
);
void
_serverAssertWithInfo
(
const
client
*
c
,
const
robj
*
o
,
const
char
*
estr
,
const
char
*
file
,
int
line
);
void
_serverAssert
(
const
char
*
estr
,
const
char
*
file
,
int
line
);
void
_serverPanic
(
const
char
*
msg
,
const
char
*
file
,
int
line
);
void
bugReportStart
(
void
);
void
serverLogObjectDebugInfo
(
robj
*
o
);
void
serverLogObjectDebugInfo
(
const
robj
*
o
);
void
sigsegvHandler
(
int
sig
,
siginfo_t
*
info
,
void
*
secret
);
sds
genRedisInfoString
(
char
*
section
);
void
enableWatchdog
(
int
period
);
...
...
src/t_hash.c
View file @
3d48c931
...
...
@@ -308,13 +308,13 @@ int hashTypeDelete(robj *o, sds field) {
}
/* Return the number of elements in a hash. */
unsigned
long
hashTypeLength
(
robj
*
o
)
{
unsigned
long
hashTypeLength
(
const
robj
*
o
)
{
unsigned
long
length
=
ULONG_MAX
;
if
(
o
->
encoding
==
OBJ_ENCODING_ZIPLIST
)
{
length
=
ziplistLen
(
o
->
ptr
)
/
2
;
}
else
if
(
o
->
encoding
==
OBJ_ENCODING_HT
)
{
length
=
dictSize
((
dict
*
)
o
->
ptr
);
length
=
dictSize
((
const
dict
*
)
o
->
ptr
);
}
else
{
serverPanic
(
"Unknown hash encoding"
);
}
...
...
src/t_list.c
View file @
3d48c931
...
...
@@ -71,7 +71,7 @@ robj *listTypePop(robj *subject, int where) {
return
value
;
}
unsigned
long
listTypeLength
(
robj
*
subject
)
{
unsigned
long
listTypeLength
(
const
robj
*
subject
)
{
if
(
subject
->
encoding
==
OBJ_ENCODING_QUICKLIST
)
{
return
quicklistCount
(
subject
->
ptr
);
}
else
{
...
...
src/t_set.c
View file @
3d48c931
...
...
@@ -219,11 +219,11 @@ int setTypeRandomElement(robj *setobj, sds *sdsele, int64_t *llele) {
return
setobj
->
encoding
;
}
unsigned
long
setTypeSize
(
robj
*
subject
)
{
unsigned
long
setTypeSize
(
const
robj
*
subject
)
{
if
(
subject
->
encoding
==
OBJ_ENCODING_HT
)
{
return
dictSize
((
dict
*
)
subject
->
ptr
);
return
dictSize
((
const
dict
*
)
subject
->
ptr
);
}
else
if
(
subject
->
encoding
==
OBJ_ENCODING_INTSET
)
{
return
intsetLen
((
intset
*
)
subject
->
ptr
);
return
intsetLen
((
const
intset
*
)
subject
->
ptr
);
}
else
{
serverPanic
(
"Unknown set encoding"
);
}
...
...
src/t_zset.c
View file @
3d48c931
...
...
@@ -1100,12 +1100,12 @@ unsigned char *zzlDeleteRangeByRank(unsigned char *zl, unsigned int start, unsig
* Common sorted set API
*----------------------------------------------------------------------------*/
unsigned
int
zsetLength
(
robj
*
zobj
)
{
unsigned
int
zsetLength
(
const
robj
*
zobj
)
{
int
length
=
-
1
;
if
(
zobj
->
encoding
==
OBJ_ENCODING_ZIPLIST
)
{
length
=
zzlLength
(
zobj
->
ptr
);
}
else
if
(
zobj
->
encoding
==
OBJ_ENCODING_SKIPLIST
)
{
length
=
((
zset
*
)
zobj
->
ptr
)
->
zsl
->
length
;
length
=
((
const
zset
*
)
zobj
->
ptr
)
->
zsl
->
length
;
}
else
{
serverPanic
(
"Unknown sorted set encoding"
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment