Remove deprecated score::StringLiteral - #745
Conversation
d50e760 to
263c6ca
Compare
limdor
left a comment
There was a problem hiding this comment.
const char * has multiple problems and I do not think this should be the substitute for StringLiteral.
- An
std::stringcan be converted implicitly fromconst char *ending with dynamic memory allocation const char*has the problem that it could be a pointer to characters or a pointer to an array of bytes.charmeaning is way too overloaded in the standard- The fact that it is a pointer, it can end up in all the issues with pointer decay
- It has no notion of being null terminated or not
Because of that, my proposal would be to go for better alternatives.
- For main arguments, go with a container of null terminated string views. We can use https://github.com/eclipse-score/baselibs/tree/main/score/language/safecpp/string_view and https://github.com/eclipse-score/baselibs/blob/main/score/string_manipulation/arguments/arguments.h for that.
- For global constant string literals with internal linkage, we can use zstring_view https://github.com/eclipse-score/baselibs/tree/main/score/language/safecpp/string_view
- For the rest, I would propose to take a look one by one, depending if they are owning or not, and depending if they are null terminated or not.
Additional note: I saw that in several places you removed the usage of StringLiteral, but the dependency to the target and the include is still there. If we remove StringLiteral we should remove it completly and also remove the include files. Of course it can happen that we break some code if someone relies on the transitive dependency but imho this is a price the users need to pay if they did not have proper includes.
| constexpr auto kDeprecatedConfigurationPathCommandLineKey = std::string_view{"-service_instance_manifest"}; | ||
| constexpr auto kConfigurationPathCommandLineKey = std::string_view{"--service_instance_manifest"}; | ||
|
|
||
| void VerifyNullTermination(const std::int32_t argc, const char* argv[]) |
There was a problem hiding this comment.
This is something that you cannot do. The problem of this is that if it is null terminated, you will find it, but if it is not null terminated, you hit undefined behavior.
In the second case, it could even be that you hit some null character in memory that it is totally unrelated.
LittleHuba
left a comment
There was a problem hiding this comment.
Please use C++ infrastructure. E.g. zstring_view or Arguments helper in baselibs.
|
OK. I guess, I will close this PR then. The thing is: All the usage of @limdor , @LittleHuba : Maybe I'm wrong, but to me it seems, that all your input means/can only solved via changng the PUBLIC interface. I.e. require the user NOT to hand over the |
|
Yes, it means breaking public API. But the first step would be to provide a second overload that allows the user to use a container of zstring_view and deprecate the API that uses |
263c6ca to
9476fed
Compare
ee86368 to
0758124
Compare
limdor
left a comment
There was a problem hiding this comment.
For the moment I reviewed all changes in the design folder. I think it would be better to move them in a separate PR becasue how I see them is that none of them is related to an API change, it is just because the puml was wrong.
Then for the API additions, I did not review yet. But I assume we will have to update some puml files.
| - Runtime(std::pair<Configuration&&, std::optional<tracing::TracingFilterConfig>&&> configs) | ||
| {static} + Initialize() : void | ||
| {static} + Initialize(const score::cpp::span<const score::StringLiteral> arguments) : void | ||
| {static} + Initialize(const score::cpp::span<const char*> arguments) : void |
There was a problem hiding this comment.
Why this change? This seems to already be wrong in the main branch.
Can you fix this in advance in a separate PR? It should only be one Initialize method
communication/score/mw/com/impl/runtime.h
Line 77 in e8abf72
| __ | ||
| {static} + Initialize() : void | ||
| {static} + Initialize(arguments : score::cpp::span<const score::StringLiteral>) : void | ||
| {static} + Initialize(arguments : score::cpp::span<const char*>) : void |
There was a problem hiding this comment.
| {static} +Initialize() : void | ||
| {static} +Initialize(int argc, score::StringLiteral argv) : void | ||
| {static} +Initialize(std::string const&) : void | ||
| {static} +Initialize(runtime::RuntimeConfiguration&) : void |
There was a problem hiding this comment.
Can we move this changes to a separate PR together with https://github.com/eclipse-score/communication/pull/745/changes#r3656356347? That is not really a change in the API, it is just fixing the puml that was wrong.
| -binding_runtimes_ : std::unordered_map<BindingType, std::unique_ptr<IBindingRuntime>> | ||
| +{static} Initialize() : void | ||
| +{static} Initialize(int argc, score::StringLiteral argv) : void | ||
| +{static} Initialize(int argc, const char* argv) : void |
There was a problem hiding this comment.
|
|
||
| class "<< Stereotype >>\nglobal function" as GlobalFunction { | ||
| +MakeError(code : ComErrc, message : score::StringLiteral) : score::result::Error | ||
| +MakeError(code : ComErrc, message : const char*) : score::result::Error |
There was a problem hiding this comment.
| +MakeError(code : ComErrc, message : const char*) : score::result::Error | |
| +MakeError(code : ComErrc, message : const std::string_view) : score::result::Error |
I believe this should be std::string_view. This is what we have in the implementation
communication/score/mw/com/impl/com_error.h
Line 224 in e8abf72
Because this is just fixing the puml, it would be good if we can move it out of this PR, because this is not an API change but fixing a mismatch in the puml.
Another thing about this but it was already there before your change, it seems that this says in the puml that it is a global function but it does not seem to mention the namespace. Not sure how you reflect that in puml, I'm not very familiar with it yet.
|
|
||
| class "<< Stereotype >>\nglobal function" as GlobalFunction { | ||
| +MakeError(code : ComErrc, message : score::StringLiteral) : score::result::Error | ||
| +MakeError(code : ComErrc, message : std::string_view) : score::result::Error |
There was a problem hiding this comment.
Updated structural and binding model diagrams to reflect current code correctly.
Removed usage of deprecated score::StringLiteral in Runtime. Replaced with const safecpp::zstring_view on implementation level. Public/user facing APIs using StringLiteral or char* have been marked deprecated and overloads taking safecpp::zstring_view have been introduced. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
0758124 to
9667138
Compare
Fixed wrong/outdated structural diagrams.
Removed usage of deprecated score::StringLiteral in Runtime.
Replaced with const safecpp::zstring_view on implementation
level. Public/user facing APIs using StringLiteral or char*
have been marked deprecated and overloads taking
safecpp::zstring_view have been introduced.