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
keyString() returned value #3797
Comments
I tend to agree with your reasoning. Background: For some historic reason The problem is distinguishing between errors. How to warn/hint users if they call Using |
Yes, that's also the problem I had - it is actually really hard to find a proper solution for this in my opinion. I tried to explore some options but they come attached with problems of their own. |
Yes, I agree.
The idea was that the person has a guarantee that (s)he gets a string. If you are okay with null pointers, you can use
Yes, then we could return some string but still indicate the error.
Breakage is something we do not need not consider now (except in the sense that somehow it must be possible for us to fix our code base). Now is the time to do any such changes so that 1.0 has better usability.
Which change do you mean? The change of returning null would affect many places (everywhere
I was thinking they are not, thus I made
I don't think they do before calling keyString because it handles the case already.
As said: it does not matter what people currently might do, 1.0 is a huge breaking change anyway. And if someone really relies that |
On the one hand always returning a string allows things like I think the best solution would be:
An alternative would be to always store a zero byte after all key values, even if they are binary (might be done already). Then we can safely return
I don't think so, see #2296 (comment) |
further discussion in #3973 |
This is probably something that has come up numerous times, but I still found it worthy of discussion, especially because I don't know much about the history of this function, as well as the implications of eventual changes to this function.
When using
keyString()
on empty / binary values the return values are the literal strings(null)
/(binary)
[1]. This seems very awkward and unintuitive from a user's perspective.There are several reasons why this is suboptimal.
(null)
for some reason, he could never be sure whether the Key he just queried has the value(null)
or whether he tried getting a NULL value from a string.Because the return value of the function is
const char*
, there are not so many possibilities for a change to this behaviour, as every possible return value - except for a NULL pointer - could just be the value of the string of the Key. Possible changes to this behaviour would be:keyString()
seems like a very elementary function, that should be kept as simple as possible. Also adding a parameter just for this error handling and breaking backwards compatibility in another way seems to be way too big of a change for this function. I just included this option for completeness sake.Of course there are several things to consider before making such a fundamental change
keyIsBinary
/keyIsString
anyway before callingkeyString
/keyValue
?(null)
and(binary)
and be affected by the current situation?[1] https://doc.libelektra.org/api/latest/html/group__keyvalue.html#ga880936f2481d28e6e2acbe7486a21d05
[2] #3737 (comment)
The text was updated successfully, but these errors were encountered: