Skip to content

http: use std::function for headermap iteration#12103

Merged
mattklein123 merged 7 commits intoenvoyproxy:masterfrom
akonradi:header-map-iterate
Jul 17, 2020
Merged

http: use std::function for headermap iteration#12103
mattklein123 merged 7 commits intoenvoyproxy:masterfrom
akonradi:header-map-iterate

Conversation

@akonradi
Copy link
Contributor

@akonradi akonradi commented Jul 15, 2020

The existing cast-to-void*-then-back method for passing in a context is type-unsafe and can make for hard-to-locate errors. By using a std::function instead of a function pointer, the caller can get compilation error instead of runtime errors, and doesn't have to do any sort of bundling dance with std::pair or a custom struct to pass multiple context items in.

Commit Message: Make HeaderMap::ConstIterateCb a std::function
Additional Description:
Remove the type-unsafe void* context parameter since it can be bundled, with type checking, into a std::function object instead.

Risk Level: low
Testing: ran unit and integration tests
Docs Changes: none
Release Notes: none

The existing cast-to-void*-then-back method for passing in a context is
type-unsafe and can make for hard-to-locate errors. By using a
std::function instead of a function pointer, the caller can get
compilation error instead of runtime errors, and doesn't have to do any
sort of bundling dance with std::pair or a custom struct to pass
multiple context items in.

Signed-off-by: Alex Konradi <akonradi@google.com>
@akonradi akonradi changed the title Make HeaderMap::ConstIterateCb a std::function http: use std::function for headermap iteration Jul 15, 2020
@akonradi akonradi force-pushed the header-map-iterate branch from 297130d to 3e63d74 Compare July 15, 2020 15:22
@mattklein123 mattklein123 self-assigned this Jul 15, 2020
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recall why I wrote the code originally the way it was, but I think this is a fine change, and I'm guessing in most cases with SVO there won't be any heap allocation for the function. Can you kick CI somehow?

/wait

Signed-off-by: Alex Konradi <akonradi@google.com>
@mattklein123
Copy link
Member

Coverage error is maybe legit?

/wait

@akonradi
Copy link
Contributor Author

Running the coverage again locally, but my guess is that this made the tested code less verbose so now the untested portion is a larger percentage by LOC 😿. Worst case I'll add some test cases.

This case was not covered and was causing coverage runs to fail

Signed-off-by: Alex Konradi <akonradi@google.com>
Signed-off-by: Alex Konradi <akonradi@google.com>
Signed-off-by: Alex Konradi <akonradi@google.com>
Add the references that were supposed to be included in the previous
commit

Signed-off-by: Alex Konradi <akonradi@google.com>
mattklein123
mattklein123 previously approved these changes Jul 16, 2020
@mattklein123
Copy link
Member

Sorry do you mind fixing the remaining tidy issues? Some of them are pre-existing but should be pretty simple.

/wait

Signed-off-by: Alex Konradi <akonradi@google.com>
@mattklein123 mattklein123 merged commit bfab9ed into envoyproxy:master Jul 17, 2020
@akonradi akonradi deleted the header-map-iterate branch July 17, 2020 17:37
rebello95 added a commit to envoyproxy/envoy-mobile that referenced this pull request Jul 22, 2020
- Update bazel to 3.4.1 (depends on envoyproxy/envoy#12123)
- Update envoy upstream to include ^
- Update rules apple and rules swift
- Update our header map iteration to fix breaking changes upstream from envoyproxy/envoy#12103

Signed-off-by: Michael Rebello <me@michaelrebello.com>
KBaichoo pushed a commit to KBaichoo/envoy that referenced this pull request Jul 30, 2020
The existing cast-to-void*-then-back method for passing in a context is
type-unsafe and can make for hard-to-locate errors. By using a
std::function instead of a function pointer, the caller can get
compilation error instead of runtime errors, and doesn't have to do any
sort of bundling dance with std::pair or a custom struct to pass
multiple context items in.

Signed-off-by: Alex Konradi <akonradi@google.com>
Signed-off-by: Kevin Baichoo <kbaichoo@google.com>
scheler pushed a commit to scheler/envoy that referenced this pull request Aug 4, 2020
The existing cast-to-void*-then-back method for passing in a context is
type-unsafe and can make for hard-to-locate errors. By using a
std::function instead of a function pointer, the caller can get
compilation error instead of runtime errors, and doesn't have to do any
sort of bundling dance with std::pair or a custom struct to pass
multiple context items in.

Signed-off-by: Alex Konradi <akonradi@google.com>
Signed-off-by: scheler <santosh.cheler@appdynamics.com>
jpsim pushed a commit that referenced this pull request Nov 28, 2022
- Update bazel to 3.4.1 (depends on #12123)
- Update envoy upstream to include ^
- Update rules apple and rules swift
- Update our header map iteration to fix breaking changes upstream from #12103

Signed-off-by: Michael Rebello <me@michaelrebello.com>
Signed-off-by: JP Simard <jp@jpsim.com>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
- Update bazel to 3.4.1 (depends on #12123)
- Update envoy upstream to include ^
- Update rules apple and rules swift
- Update our header map iteration to fix breaking changes upstream from #12103

Signed-off-by: Michael Rebello <me@michaelrebello.com>
Signed-off-by: JP Simard <jp@jpsim.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants