-
Notifications
You must be signed in to change notification settings - Fork 123
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
Low-Level API Improvements #2979
Comments
Initially, we used
I think this would be the first candidate to be fixed.
Why? In general I think it is a good idea that methods do nothing on errors. Is this somewhere inconsistent?
Yes, you are right, it would be more consistent. The reason behind returning the key is that this allows for checking of identity. But actually, also with a returned value one could check for identity (at least with the current implementation. If we optimize mmap it might be not the case anymore.). One idea is that we simply return a meta key set and do not provide a separate API for meta data.
What do you mean? They always return something?
I am not sure if non-C++/Rust programmers know what ownership is. Please feel free to improve the docu, it is better when we discuss this on a concrete suggestion.
Afaik it does not say, please add.
Yes, this is poorly described. It is about keys with empty name. You can extend the PR also with the other docu issues. Everything what you described here can be improved. |
If we don't set a binary value, the key shouldn't be marked as binary. Especially since, storage plugins might rely on this metakey (via
That is an oddity indeed... Changing it would, however, be a very major breaking change. We could introduce
If we return an actual
I agree that "ownership" is not clearly defined in C. If we use the term, we should clarify what it means to own a key. |
Yes, good idea. Especially if it is only in libmeta (#2983) it would be nice to have it.
see #2983 |
let binary_content: [u8; 0] = [];
let mut key = BinaryKey::new("user/test/binary").unwrap();
key.set_value(&binary_content);
println!("{}", key.is_binary()); This prints false. Is that intended? It's not really an error to set an empty array of bytes. This is partly specific to Rust because of the introduction of StringKey and BinaryKey, but I had to add checks to return an empty bytes array if someone called
Functions that can return something useful do that. But for
Is there no typical C "language" to talk about this concept? Else I'll try to find come up with something and add it to the PR. |
tests/abi/testabi_key.c line 939 But yes, Always setting binary regardless of success, however, is not a good idea.
Not really, in C usually some method needs to be called to free something. So docu only describes if such a method should be called (or not). |
I would also like to add a few more possible API improvements:
|
Yes, this works and I changed it. Should I make it part of #2980 or a new pr, since it's not technically part of the published bindings?
With the above changes this is not necessary. |
@kodebach wrote:
Could you please move this to two new issue, as this issue is already too broad. (ksExtract, however, would be a new feature which does not have high priority, as it is not really relevant for 1.0.)
You can add it there. |
In regards to my comment about
I tried changing the signature of Key * const next = ksNext(ks);
next = keyNew("user/otherkey", 0); However if the caller just leaves off the const in his declaration of I would propose this change for |
It's just how C works. char x[10] = "abc";
char * a;
a = x; // changing address is valid
*a = 'c'; // changing data at address is valid
const char * b;
b = x; // changing address is valid
// *b = 'c'; !!! changing data at address is NOT valid
char * const c;
// c = x; !!! changing address is NOT valid
*c = 'c'; // changing data at address is valid
const char * const d;
// d = x; !!! changing address is valid
// *d = 'c'; !!! changing data at address is valid
a = b; // warning, because you make data at address writable
a = c; // no warning, because nothing actually changes Copying the value of Copying the value of |
Right, so I guess |
While writing the Rust Bindings (#2730), @markus2330 asked me to look for improvements in the C-API, so here are my findings.
Some typos, will be fixed in doc: Fix typos in documentation #2978
As already mentioned in 2730, many methods return -1 for multiple errors. The caller cannot distinguish between errors. Examples are
keySetName
,keyGetBinary
.keySetBinary
only marks the key as binary if the function does not return -1. I think it should set the flag regardless.From how
keySetMeta
works, I intuitively assumedkeyGetMeta
would just take a metaName and return the appropriate value. Ideally, these would mirror each other. But I'm sure there's a reason for this.ksCopy
,ksRewind
(maybe others) return 1 on success. Isn't it unusual to return something on success, rather than on error?ksAppendKey
: "-1 if insertion failed, the key will be deleted then". Isn't that an implementation detail? I think it's enough to say that the function takes ownership of the provided key, and that means it handles the rest of its lifecycle no matter if it suceeds or fails. This is a bit confusing, as is.ksCurrent
orksNext
: The note says "You must not delete or change the key".So change here means change where the pointer points, right, not modify the key itself?
Key * const
instead of the currentKey *
? Then the note could just say "Don't delete".ksTail
should have this note too, but it doesn't.I'm not sure that the documentation mentions anywhere that keyset cursors can simply be incremented and decremented.
keyDup
: Like for a new key after keyNew() a subsequent ksAppend() makes a KeySet to take care of the lifecycle of the key., this should link to
ksAppendKey`.keyAddName
: "-1 if key is a null pointer or did not have a valid name before". Isn't that an invariant of a key, that it always has a valid name?The text was updated successfully, but these errors were encountered: