Clarify borrowed ada_string lifetime and add owned host accessor#1091
Clarify borrowed ada_string lifetime and add owned host accessor#1091rootvector2 wants to merge 3 commits intoada-url:mainfrom
Conversation
include/ada_c.h
Outdated
|
|
||
| // Returns a heap-allocated copy of ada_get_host(result). | ||
| // Caller must free with ada_free_owned_string. | ||
| ada_owned_string ada_get_host_owned(ada_url result); |
There was a problem hiding this comment.
Why do we need this? Should we also add ada_get_hostname_owned or all other variants? It doesn't make sense to me.
|
I’ll keep this PR focused on clarifying the lifetime documentation and remove If needed, I can propose a separate follow-up for a consistent owned-getter approach across all relevant getters. |
include/ada_c.h
Outdated
| // string that is owned by the ada_url instance | ||
| // | ||
| // Lifetime rules: | ||
| // - This pointer is borrowed from the underlying ada_url object. |
There was a problem hiding this comment.
It is not borrowed. It is a pointer to a string in the ada_url instance.
There was a problem hiding this comment.
Here is what grok says:
The phrase "a pointer is borrowed" almost always refers to the ownership and borrowing model in the Rust programming language.
include/ada_c.h
Outdated
| // url_aggregator getters | ||
| // if ada_is_valid(result)) is false, an empty string is returned | ||
| // | ||
| // Important: all ada_string results below are borrowed views into internal |
There was a problem hiding this comment.
I don't think that this is correct. ada_get_origin Returns an ada_owned_string which you own (as the name implies). You can mutate the source ada_url all you want, it won't matter.
Fixes a lifetime issue in the C API where
ada_stringreturned from getters is a borrowed view into internal storage and becomes invalid after mutation.ada_stringinada_c.hada_get_host_ownedto provide a safe, owned copyNo breaking changes.