-
Notifications
You must be signed in to change notification settings - Fork 3k
Improve nsapi_create_stack #12570
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
Improve nsapi_create_stack #12570
Conversation
@kjbracey-arm, thank you for your changes. |
Use tag dispatch to better handle both NetworkInterface and NetworkStack pointers. The previous design was intended to avoid ambiguities when presented with a scenario like class MyDevice : public NetworkInterface, public NetworkStack { }; TCPSocket(&MyDevice); // Need NetworkStack *: use NetworkInterface::get_stack or // cast to NetworkStack? But the previous solution didn't actually work as intended. The overload pair nsapi_create_stack(NetworkStack *); // versus template <class IF> nsapi_create_stack(IF *); would only select the first form if passed an exact match - `NetworkStack *`. If passed a derived class pointer, like `MyDevice *`, it would select the template. This meant that an ambiguity for MyDevice was at least avoided, but in the wrong direction, potentially increasing code size. But in other cases, the system just didn't work at all - you couldn't pass a `MyStack *` pointer, unless you cast it to `NetworkStack *`. Quite a few bits of test code do this. Add a small bit of tag dispatch to prioritise the cast whenever the supplied pointer is convertible to `NetworkStack *`.
astyle struggles a bit with some modern C++ - using |
@ARMmbed/mbed-os-ipcore could we have a review please? |
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.
Any parts of handbook need updating?
We might switch to clang format one day - that should cope better with newer C++ syntax. |
CI started |
Test run: SUCCESSSummary: 7 of 7 test jobs passed |
Final approval needed, please review |
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 really good to me. Thanks for this, @kjbracey-arm .
This ran through ci 9 days ago so will re-run now just to double check |
Test run: FAILEDSummary: 1 of 6 test jobs failed Failed test jobs:
|
CI failures should now be fixed so re-running |
Test run: FAILEDSummary: 1 of 6 test jobs failed Failed test jobs:
|
I fixed pr-head and merge (manual overwrite), test will be restarted once I see it was fixed (or needs a restart) |
Summary of changes
Use tag dispatch to better handle both NetworkInterface and NetworkStack pointers.
The previous design was intended to avoid ambiguities when presented with a scenario like
But the previous solution didn't actually work as intended. The overload pair
would only select the first form if passed an exact match -
NetworkStack *
. If passed a derived class pointer, likeMyDevice *
, it would select the template.This meant that an ambiguity for MyDevice was at least avoided, but in the wrong direction, potentially increasing code size.
But in other cases, the system just didn't work at all - you couldn't pass a
MyStack *
pointer, unless you cast it toNetworkStack *
. Quite a few bits of test code do this.Add a small bit of tag dispatch to prioritise the cast whenever the supplied pointer is convertible to
NetworkStack *
.Remove the now unnecessary casts from some tests.
Impact of changes
Migration actions required
Documentation
None.
Pull request type
Test results
Reviewers