-
Notifications
You must be signed in to change notification settings - Fork 702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce const_sds for const-content sds #1553
Conversation
Signed-off-by: Viktor Söderqvist <[email protected]>
Signed-off-by: Viktor Söderqvist <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## unstable #1553 +/- ##
=========================================
Coverage 70.94% 70.94%
=========================================
Files 120 120
Lines 65044 65046 +2
=========================================
+ Hits 46143 46147 +4
+ Misses 18901 18899 -2
|
Signed-off-by: Viktor Söderqvist <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this! Looks good to me as-is, but any thoughts on proactively spreading const_sds to other areas of code?
When we have it, it's possible to use it in new code, so we can suggest it in code reviews. Constness has to be added bottom-up, i.e. start in sds.c with functions like sdslen. A non-const value can always be used as a const value, but not vice versa. We could add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM even though I still think that the const should have been applied on the pointer as well like I commented in #1542
IMO we should not allow "assignment" to a const_sds.
We can always evolve to doing this as well I guess
`sds` is a typedef of `char *`. `const sds` means `char * const`, i.e. a const-pointer to non-const content. More often, you would want `const char *`, i.e. a pointer to const-content. Until now, it's not possible to express that. This PR adds `const_sds` which is a pointer to const-content sds. To get a const-pointer to const-content sds, you can use `const const_sds`. In this PR, some uses of `const sds` are replaced by `const_sds`. We can use it more later. Fixes valkey-io#1542 --------- Signed-off-by: Viktor Söderqvist <[email protected]> Signed-off-by: proost <[email protected]>
sds
is a typedef ofchar *
.const sds
meanschar * const
, i.e. a const-pointer to non-const content.More often, you would want
const char *
, i.e. a pointer to const-content. Until now, it's not possible to express that. This PR addsconst_sds
which is a pointer to const-content sds.To get a const-pointer to const-content sds, you can use
const const_sds
.In this PR, some uses of
const sds
are replaced byconst_sds
. We can use it more later.Fixes #1542