Skip to content

Fix: Define GPR_ASSERT macro for compatibility #660

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions grpc-sys/grpc_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
#define GPR_CALLTYPE
#endif

#ifndef GPR_ASSERT
#include <assert.h>
Copy link
Member

Choose a reason for hiding this comment

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

How about switching to absl check just like what upstream did?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the suggestion, haven't thought of that.

Observations:

  • absl/log/absl_check.h has a static assert that the C++ variant is at least C++14
  • ABSL_CHECK depends on using string_view = std::string_view which is only available in C++17.

Attempted a prototype #661 which upgrades C++ to C++14, but can't make it compile.

A different prototype #662 upgrades C++ to C++17 and it compiles.

Here is what happens with a C++14 upgrade:

% cargo build
   Compiling grpcio-sys v0.13.0+1.56.2-patched (/home/nkurtov/code/grpc-rs/grpc-sys)
warning: [email protected]+1.56.2-patched: In file included from /usr/include/absl/log/internal/nullstream.h:37,
warning: [email protected]+1.56.2-patched:                  from /usr/include/absl/log/internal/check_op.h:40,
warning: [email protected]+1.56.2-patched:                  from /usr/include/absl/log/internal/check_impl.h:19,
warning: [email protected]+1.56.2-patched:                  from /usr/include/absl/log/absl_check.h:38,
warning: [email protected]+1.56.2-patched:                  from grpc_wrap.cc:71:
warning: [email protected]+1.56.2-patched: /usr/include/absl/strings/string_view.h:53:26: error: 'string_view' in namespace 'std' does not name a type
warning: [email protected]+1.56.2-patched:    53 | using string_view = std::string_view;
warning: [email protected]+1.56.2-patched:       |                          ^~~~~~~~~~~
warning: [email protected]+1.56.2-patched: /usr/include/absl/strings/string_view.h:53:21: note: 'std::string_view' is only available from C++17 onwards
warning: [email protected]+1.56.2-patched:    53 | using string_view = std::string_view;
warning: [email protected]+1.56.2-patched:       |                     ^~~

Copy link
Member

Choose a reason for hiding this comment

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

I see. Upgrading C++ standard will introduce breaking change, let's keep it this way for now.

#define GPR_ASSERT assert
#endif

grpc_byte_buffer* string_to_byte_buffer(const char* buffer, size_t len) {
grpc_slice slice = grpc_slice_from_copied_buffer(buffer, len);
grpc_byte_buffer* bb = grpc_raw_byte_buffer_create(&slice, 1);
Expand Down
Loading