Skip to content

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

Merged
merged 3 commits into from
Mar 31, 2020
Merged

Improve nsapi_create_stack #12570

merged 3 commits into from
Mar 31, 2020

Conversation

kjbracey
Copy link
Contributor

@kjbracey kjbracey commented Mar 4, 2020

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

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 *.

Remove the now unnecessary casts from some tests.

Impact of changes

Migration actions required

Documentation

None.


Pull request type

[X] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[X] Tests / results supplied as part of this PR

Reviewers


@mergify mergify bot added the needs: work label Mar 4, 2020
@ciarmcom ciarmcom requested review from a team March 4, 2020 16:00
@ciarmcom
Copy link
Member

ciarmcom commented Mar 4, 2020

@kjbracey-arm, thank you for your changes.
@ARMmbed/mbed-os-ipcore @ARMmbed/mbed-os-maintainers please review.

kjbracey added 3 commits March 5, 2020 16:45
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 *`.
@kjbracey
Copy link
Contributor Author

kjbracey commented Mar 5, 2020

astyle struggles a bit with some modern C++ - using {} to initialise confuses it.

@adbridge
Copy link
Contributor

@ARMmbed/mbed-os-ipcore could we have a review please?

Copy link
Member

@bulislaw bulislaw left a 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?

@0xc0170
Copy link
Contributor

0xc0170 commented Mar 16, 2020

astyle struggles a bit with some modern C++ - using {} to initialise confuses it.

We might switch to clang format one day - that should cope better with newer C++ syntax.

@0xc0170
Copy link
Contributor

0xc0170 commented Mar 16, 2020

CI started

@mbed-ci
Copy link

mbed-ci commented Mar 16, 2020

Test run: SUCCESS

Summary: 7 of 7 test jobs passed
Build number : 1
Build artifacts

@0xc0170
Copy link
Contributor

0xc0170 commented Mar 16, 2020

@ARMmbed/mbed-os-ipcore could we have a review please?

Final approval needed, please review

Copy link
Contributor

@michalpasztamobica michalpasztamobica left a 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 .

@adbridge
Copy link
Contributor

This ran through ci 9 days ago so will re-run now just to double check

@mbed-ci
Copy link

mbed-ci commented Mar 26, 2020

Test run: FAILED

Summary: 1 of 6 test jobs failed
Build number : 2
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_greentea-test

@adbridge
Copy link
Contributor

CI failures should now be fixed so re-running

@mbed-ci
Copy link

mbed-ci commented Mar 27, 2020

Test run: FAILED

Summary: 1 of 6 test jobs failed
Build number : 3
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_greentea-test

@0xc0170
Copy link
Contributor

0xc0170 commented Mar 30, 2020

I fixed pr-head and merge (manual overwrite), test will be restarted once I see it was fixed (or needs a restart)

@0xc0170 0xc0170 merged commit dba3962 into ARMmbed:master Mar 31, 2020
@mergify mergify bot removed the ready for merge label Mar 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants