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

Added GRPC_USE_CPP_STD_LIB flag #20059

Merged
merged 1 commit into from
Aug 26, 2019
Merged

Added GRPC_USE_CPP_STD_LIB flag #20059

merged 1 commit into from
Aug 26, 2019

Conversation

veblush
Copy link
Contributor

@veblush veblush commented Aug 23, 2019

Added the global flag GRPC_USE_CPP_STD_LIB enabling C++ standard library. When this is enabled,

  • gpr::Map is mapped to std::map instead of in-house map.
  • GRPC_ABSTRACT is replaced with = 0 making legit pure virtual function.

This flag is by default disabled. New test is added to "Bazel Basic build for C/C++" verifying grpc is built with the flag enabled.

Copy link
Member

@AspirinSJL AspirinSJL left a comment

Choose a reason for hiding this comment

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

LGTM on client_channel/

@veblush veblush force-pushed the cppflag branch 2 times, most recently from 39325c5 to 55553be Compare August 23, 2019 23:21
Copy link
Member

@markdroth markdroth left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! Comments are all fairly minor.

// This is a workaround for the case where some compilers cannot build
// move-assignment of map with non-copyable but movable key.
// https://stackoverflow.com/questions/36475497/error-by-move-assignment-of-map-with-non-copyable-but-movable-key
swap(snapshot.dropped_requests, dropped_requests_);
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be std::swap()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@@ -315,7 +315,11 @@ grpc_slice XdsLrsRequestCreateAndEncode(const char* server_name) {
namespace {

void LocalityStatsPopulate(envoy_api_v2_endpoint_UpstreamLocalityStats* output,
#if GRPC_USE_CPP_STD_LIB
Pair<const RefCountedPtr<XdsLocalityName>,
Copy link
Member

Choose a reason for hiding this comment

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

This smells like a bug in our existing grpc_core::Map<> implementation. Can we try to fix it such that it has the same API as std::map<>, so that this conditional is not required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I tried to change this to follow the standard but it seemed to require a significant amount of change so I didn't do that. Also it will be removed once C++ stdlib is successfully linked.

Copy link
Member

Choose a reason for hiding this comment

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

It might be worth checking with @mhaidrygoog about the changes that would be needed in the current map implementation. He might be able to figure out a fairly quick way to do this.

Failing that, I'm fine with this conditional as a temporary thing, but please add a TODO indicating that it should go away once we've switched to always using the C++ standard library.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the comment. My plan is removing all #else blocks of GRPC_USE_CPP_STD_LIB once C++ stdlib is fully enabled.


#if GRPC_USE_CPP_STD_LIB

TEST(MapTest, Nop) {}
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't these tests pass regardless of whether we're using std::map<>?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't work because test code depends on implementation details of Map such as Entry.

@veblush veblush force-pushed the cppflag branch 3 times, most recently from f37c836 to 7a28845 Compare August 26, 2019 17:13
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 26, 2019

CLA Check
The committers are authorized under a signed CLA.

@veblush veblush merged commit 1ff545e into grpc:master Aug 26, 2019
@veblush veblush deleted the cppflag branch August 26, 2019 22:11
@lock lock bot locked as resolved and limited conversation to collaborators Nov 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang/c++ lang/core release notes: no Indicates if PR should not be in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants