-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Further const correctness / String by reference passing cleanups #6571
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
Conversation
Most CI fails are due to arduino-builder crapping out, but the PlatformIO tests do show problems that need fixing in the examples to make this patch work. |
7694328
to
73a63c8
Compare
yep, I am still trying to learn how to replicate what travis is testing locally so that I can fix all of them in one go. for now this is an iterative approach :) |
(edit: submodules are now automatically updated) |
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.
Looks good and makes the interfaces more rational for a lot of things involving String
parameters.
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.
Careful here. I'm all for constness, but we've been bitten before due to differences vs. the Arduino reference, where constness isn't always the best. Specifically, differences in constness vs. the Arduino reference can cause grief for 3rd party lib maintainers.
Please check whether any of the interfaces here are part of the Arduino reference (I didn't look through this whole PR), and if so whether the constness is different. In such cases, if any, I suggest reverting. If there are no such cases, please confirm that and I'll approve.
@devyte all API changes are in classes where their name starts with ESP8266. I would assume there is no 3rd party incompatibility here. There might be corner cases where ESP8266 code is affected, but I can't imagine this to be a very frequent case (to be honest I don't even know how you would notice String vs const String& other than reduced code footprint and better performance). |
0634f52
to
48e9b42
Compare
About CI, you can run mock trivial test locally with
(from |
48e9b42
to
ad5c93a
Compare
@devyte, the only changes I see in the externally visible
Adding a const to the param seems absolutely safe, as the const flows down into the function but not upwards to the caller, right? A char* can be passed into a fcn requiring a const char * without any concern. The & operator is a compiler structure hint, and other than passing by ref and not value user code should need no change, either. The compiler will simply emit a Granted, if you have a blob using these libs the 2nd change will cause trouble, but the ESPRESSIF ones do not use our libs, obviously and we've never guaranteed binary ABI compatibility. |
The constness trouble was encountered by @d-a-v and was related to 3rd party libs that are meant to work across cores for diffrent uCs. In the end, he had to roll back. Like @dirkmueller said, these have the esp8266 prefix and I suspect the signature changes might be ok, but I don't see any assurance, which means this could be a breaking change. |
Ah, I see. The code as-is is safe, but there might be libs which might subclass them. IIRC, @d-a-v's issue was when he adjusted Arduino Client(?) and other libs which were subclasses of it crapped out. |
On further thought, this is a breaking change any way you look at it, because any user with derived classes that override methods will need updating to add constness. I say target for v3. |
@d-a-v overrides are only for virtual methods, which most of them are not. are you okay when we remove that change for public/protected virtual methods? I think the only part that is a change in a virtual function signature is in RequestHandler.h which I think is actually unreleased. I'll double check this part. |
My issues were mostly because of inheritance. |
sorry, wrong completion, I wanted to talk to @devyte |
ad5c93a
to
b9d21de
Compare
No harm, I was answering to @earlephilhower two posts earlier 😆 |
@dirkmueller I think so, but I don't want to just drop the rest either. Please split the virtual ones into a separate pr, and I'll target for v3. |
b9d21de
to
d7bedde
Compare
There are actually several instances where we pass in read-only parameters as pass-by-value, where in the case of String() that is inefficient as it involves copy-constructor/temp string creations. We can avoid that, similarly to single character string concatenations done via string literals instead of char literals.
a92a4f1
to
04b013b
Compare
- Avoid single character String concatenations done via String literals instead of char literals, as this is inefficient because of temporary String creations (esp8266#6571).
- Avoid single character String concatenations done via String literals instead of char literals, as this is inefficient because of temporary String creations (esp8266#6571).
There are actually several instances where we pass in read-only
parameters as pass-by-value, where in the case of String() that
is inefficient as it involves copy-constructor/temp string creations.
We can avoid that, similarly to single character string concatenations
done via string literals instead of char literals.
This is a continuation of #6569.