Skip to content
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

Correct test of OptionsImpl argc type (Was: Correct type for std::array size() result) #9290

Merged
merged 3 commits into from
Dec 17, 2019
Merged

Correct test of OptionsImpl argc type (Was: Correct type for std::array size() result) #9290

merged 3 commits into from
Dec 17, 2019

Conversation

wrowe
Copy link
Contributor

@wrowe wrowe commented Dec 9, 2019

Description:
The std::array API uses std::size_t for the size() nelts count.
This is a larger sized int than 'int', which causes this code
to break on Windows compilation.

Follow the conventional declaration of main(int argc, ...
and adjust the tests of OptionsImpl accordingly.

Original Description:

Use the stdcxx type for conformance and portability.

Signed-off-by: Sunjay Bhatia sbhatia@pivotal.io
Signed-off-by: William A Rowe Jr wrowe@pivotal.io

Risk Level: Low
Testing: Local on Windows, Linux gcc
Docs Changes: N/A
Release Notes: N/A

The std::array API uses std::size_t for the size() nelts count.
This is a larger sized int than 'int', which causes this code
to break on Windows compilation.

Use the stdcxx type for conformance and portability.

Signed-off-by: Sunjay Bhatia <sbhatia@pivotal.io>
Signed-off-by: William A Rowe Jr <wrowe@pivotal.io>
Signed-off-by: Sunjay Bhatia <sbhatia@pivotal.io>
Signed-off-by: William A Rowe Jr <wrowe@pivotal.io>
Copy link

@bryce-anderson bryce-anderson left a comment

Choose a reason for hiding this comment

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

This generally seems like the right thing to do when considering array sizes etc but is this the only case where this fails to compile on Windows? There are a lot of examples of for (int i = .. in the code base.

source/server/options_impl.cc Outdated Show resolved Hide resolved
@sunjayBhatia
Copy link
Member

This generally seems like the right thing to do when considering array sizes etc but is this the only case where this fails to compile on Windows? There are a lot of examples of for (int i = .. in the code base.

@bryce-anderson This pattern of changes around std::size_t are not restricted to this PR, there are more but we've been trying to do them in small batches to ensure we don't have big changesets. We've also not delved into all the extension code but will do so.

As for the for (int i = .. portion that was changed, that was required here b/c of the comparison between an int and std::size_t, signed and unsigned types. If we need to continue to change those as they come up we can do so

@bryce-anderson
Copy link

While I'm not a core maintainer so my opinion is mostly for funzies, I generally approve of cleaning up size types to be more consistent with container size types so I'm 👍 on this.

@bryce-anderson This pattern of changes around std::size_t are not restricted to this PR, there are more but we've been trying to do them in small batches to ensure we don't have big changesets. We've also not delved into all the extension code but will do so.

Sounds good. I assumed so, but was curious.

As for the for (int i = .. portion that was changed, that was required here b/c of the comparison between an int and std::size_t, signed and unsigned types. If we need to continue to change those as they come up we can do so

Sorry, I wasn't clear. I understand why you made the change in this commit and was just noting that this should probably be done in most places where there is a for (int i = .., which sounds like part of your plan since they may not compile on windows. 😄

@wrowe
Copy link
Contributor Author

wrowe commented Dec 10, 2019

I [...] was just noting that this should probably be done in most places where there is a for (int i = .., which sounds like part of your plan since they may not compile on windows. 😄

In many cases this is simply not necessary. For example, int can often be the index without ambiguity, it is the size of size_t or smaller, and depending on the comparison the signedness isn't an issue.

We are resolving this in a number of other files, but they don't need to be corrected en-mass.

@wrowe
Copy link
Contributor Author

wrowe commented Dec 11, 2019

We are resolving this in a number of other files, but they don't need to be corrected en-mass.

And sometimes the best solution will be an auto. But not in this case, where it is the declarations of args or retval types that are at issue. The alternate patch to this file is to downcast to int, which introduces it's own set of issues.

- Reverts the prior proposal
- Overrides the std::array in tests to emulate argc/argv from main()

Signed-off-by: William A Rowe Jr <wrowe@pivotal.io>
@wrowe wrowe changed the title Correct type for std::array size() result Correct test of OptionsImpl argc type (Was: Correct type for std::array size() result) Dec 11, 2019
@wrowe
Copy link
Contributor Author

wrowe commented Dec 15, 2019

After looking at your observations, it is pretty clear the main source/ was correct. Our test/ was supposed to emulate main(argc, argv), so I think the current PR is the more correct solution.

@mattklein123 mattklein123 merged commit 6d816ad into envoyproxy:master Dec 17, 2019
@wrowe wrowe deleted the fix-options-impl-size branch December 17, 2019 18:37
spenceral added a commit to spenceral/envoy that referenced this pull request Dec 20, 2019
* master: (167 commits)
  stats: Avoid asserts in fuzz-tests by eliminating arbitrary length limits, using the new MemBlock wrapper for memcpy (envoyproxy#8779)
  Make %UPSTREAM_LOCAL_ADDRESS% access-log format work for HTTP requests. (envoyproxy#9362)
  tools: API boosting support for using decls and enum constants. (envoyproxy#9418)
  Fix incorrect cluster InitializePhase type (envoyproxy#9379)
  build: fix merge race between envoyproxy#9241 and envoyproxy#9413. (envoyproxy#9427)
  fuzz: fix incorrect evaluator test (envoyproxy#9402)
  server: fix bogus startup log message (envoyproxy#9404)
  tools: Add protoxform tests (envoyproxy#9241)
  api: options after import (envoyproxy#9413)
  misc: use std::move instead of constructing a copy (envoyproxy#9415)
  tools: API boosting support for rewriting elaborated types. (envoyproxy#9375)
  docs: fix invalid transport_socket value (envoyproxy#9403)
  fix typo in docs (envoyproxy#9394)
  srds: remove to-de-removed scopes first and then apply additions to avoid scope key conflict. (envoyproxy#9366)
  api: generate whole directory and sync (envoyproxy#9382)
  bazel: Add load statements for proto_library (envoyproxy#9367)
  Fix typo (envoyproxy#9388)
  Correct test of OptionsImpl argc type (Was: Correct type for std::array size() result) (envoyproxy#9290)
  http1 encode trailers in chunk encoding (envoyproxy#8667)
  Add mode to PipeInstance (envoyproxy#8423)
  ...
@sunjayBhatia sunjayBhatia mentioned this pull request Dec 20, 2019
prakhag1 pushed a commit to prakhag1/envoy that referenced this pull request Jan 3, 2020
…ay size() result) (envoyproxy#9290)

The std::array API uses std::size_t for the size() nelts count.
This is a larger sized int than 'int', which causes this code
to break on Windows compilation.

Use the stdcxx type for conformance and portability.

Signed-off-by: Sunjay Bhatia <sbhatia@pivotal.io>
Signed-off-by: William A Rowe Jr <wrowe@pivotal.io>
Signed-off-by: Prakhar <prakhar_au@yahoo.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.

5 participants