Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
Remove functions in class CoreCodegen (grpc#31767)
Browse files Browse the repository at this point in the history
* Clean up `grpc_byte_buffer_copy()`

* Clean up `grpc_byte_buffer_destroy()`

* Clean up `grpc_byte_buffer_length()`

* Clean up `grpc_byte_buffer_reader_init()`

* Clean up `grpc_byte_buffer_reader_destroy()`

* Clean up `grpc_byte_buffer_reader_next()`

* Clean up `grpc_byte_buffer_reader_peek()`

* Clean up `grpc_raw_byte_buffer_create()`

* Clean up `grpc_slice_new_with_user_data()`

* Clean up `grpc_slice_new_with_len()`

* Clean up `grpc_call_start_batch()`

* Clean up `grpc_call_cancel_with_status()`

* Clean up `grpc_call_failed_before_recv_message()`

* Clean up `grpc_call_ref()`

* Clean up `grpc_call_unref()`

* Clean up `grpc_call_error_to_string()`

* Fix typos

* Automated change: Fix sanity tests
  • Loading branch information
ralphchung authored Dec 2, 2022
1 parent 5933b52 commit 1d968a3
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 276 deletions.
19 changes: 10 additions & 9 deletions include/grpcpp/impl/call_op_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <map>
#include <memory>

#include <grpc/grpc.h>
#include <grpc/impl/codegen/grpc_types.h>
#include <grpc/impl/compression_types.h>
#include <grpc/support/alloc.h>
Expand Down Expand Up @@ -892,7 +893,7 @@ class CallOpSet : public CallOpSetInterface,

void FillOps(Call* call) override {
done_intercepting_ = false;
g_core_codegen_interface->grpc_call_ref(call->call());
grpc_call_ref(call->call());
call_ =
*call; // It's fine to create a copy of call since it's just pointers

Expand All @@ -913,7 +914,7 @@ class CallOpSet : public CallOpSetInterface,
// run
*tag = return_tag_;
*status = saved_status_;
g_core_codegen_interface->grpc_call_unref(call_.call());
grpc_call_unref(call_.call());
return true;
}

Expand All @@ -926,7 +927,7 @@ class CallOpSet : public CallOpSetInterface,
saved_status_ = *status;
if (RunInterceptorsPostRecv()) {
*tag = return_tag_;
g_core_codegen_interface->grpc_call_unref(call_.call());
grpc_call_unref(call_.call());
return true;
}
// Interceptors are going to be run, so we can't return the tag just yet.
Expand Down Expand Up @@ -967,15 +968,15 @@ class CallOpSet : public CallOpSetInterface,
this->Op5::AddOp(ops, &nops);
this->Op6::AddOp(ops, &nops);

grpc_call_error err = g_core_codegen_interface->grpc_call_start_batch(
call_.call(), ops, nops, core_cq_tag(), nullptr);
grpc_call_error err =
grpc_call_start_batch(call_.call(), ops, nops, core_cq_tag(), nullptr);

if (err != GRPC_CALL_OK) {
// A failure here indicates an API misuse; for example, doing a Write
// while another Write is already pending on the same RPC or invoking
// WritesDone multiple times
gpr_log(GPR_ERROR, "API misuse of type %s observed",
g_core_codegen_interface->grpc_call_error_to_string(err));
grpc_call_error_to_string(err));
GPR_CODEGEN_ASSERT(false);
}
}
Expand All @@ -986,9 +987,9 @@ class CallOpSet : public CallOpSetInterface,
done_intercepting_ = true;
// The following call_start_batch is internally-generated so no need for an
// explanatory log on failure.
GPR_CODEGEN_ASSERT(g_core_codegen_interface->grpc_call_start_batch(
call_.call(), nullptr, 0, core_cq_tag(), nullptr) ==
GRPC_CALL_OK);
GPR_CODEGEN_ASSERT(grpc_call_start_batch(call_.call(), nullptr, 0,
core_cq_tag(),
nullptr) == GRPC_CALL_OK);
}

private:
Expand Down
33 changes: 0 additions & 33 deletions include/grpcpp/impl/codegen/core_codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,6 @@ namespace grpc {
/// Implementation of the core codegen interface.
class CoreCodegen final : public CoreCodegenInterface {
private:
grpc_call_error grpc_call_start_batch(grpc_call* call, const grpc_op* ops,
size_t nops, void* tag,
void* reserved) override;
grpc_call_error grpc_call_cancel_with_status(grpc_call* call,
grpc_status_code status,
const char* description,
void* reserved) override;
int grpc_call_failed_before_recv_message(const grpc_call* c) override;
void grpc_call_ref(grpc_call* call) override;
void grpc_call_unref(grpc_call* call) override;
void* grpc_call_arena_alloc(grpc_call* call, size_t length) override;
const char* grpc_call_error_to_string(grpc_call_error error) override;

grpc_byte_buffer* grpc_byte_buffer_copy(grpc_byte_buffer* bb) override;
void grpc_byte_buffer_destroy(grpc_byte_buffer* bb) override;
size_t grpc_byte_buffer_length(grpc_byte_buffer* bb) override;

int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader,
grpc_byte_buffer* buffer) override;
void grpc_byte_buffer_reader_destroy(
grpc_byte_buffer_reader* reader) override;
int grpc_byte_buffer_reader_next(grpc_byte_buffer_reader* reader,
grpc_slice* slice) override;
int grpc_byte_buffer_reader_peek(grpc_byte_buffer_reader* reader,
grpc_slice** slice) override;

grpc_byte_buffer* grpc_raw_byte_buffer_create(grpc_slice* slice,
size_t nslices) override;
grpc_slice grpc_slice_new_with_user_data(void* p, size_t len,
void (*destroy)(void*),
void* user_data) override;
grpc_slice grpc_slice_new_with_len(void* p, size_t len,
void (*destroy)(void*, size_t)) override;
grpc_slice grpc_empty_slice() override;
grpc_slice grpc_slice_malloc(size_t length) override;
void grpc_slice_unref(grpc_slice slice) override;
Expand Down
35 changes: 0 additions & 35 deletions include/grpcpp/impl/codegen/core_codegen_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,6 @@ class CoreCodegenInterface {
virtual void assert_fail(const char* failed_assertion, const char* file,
int line) = 0;

virtual grpc_byte_buffer* grpc_byte_buffer_copy(grpc_byte_buffer* bb) = 0;
virtual void grpc_byte_buffer_destroy(grpc_byte_buffer* bb) = 0;
virtual size_t grpc_byte_buffer_length(grpc_byte_buffer* bb)
GRPC_MUST_USE_RESULT = 0;

virtual int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader,
grpc_byte_buffer* buffer)
GRPC_MUST_USE_RESULT = 0;
virtual void grpc_byte_buffer_reader_destroy(
grpc_byte_buffer_reader* reader) = 0;
virtual int grpc_byte_buffer_reader_next(grpc_byte_buffer_reader* reader,
grpc_slice* slice) = 0;
virtual int grpc_byte_buffer_reader_peek(grpc_byte_buffer_reader* reader,
grpc_slice** slice) = 0;

virtual grpc_byte_buffer* grpc_raw_byte_buffer_create(grpc_slice* slice,
size_t nslices) = 0;
virtual grpc_slice grpc_slice_new_with_user_data(void* p, size_t len,
void (*destroy)(void*),
void* user_data) = 0;
virtual grpc_slice grpc_slice_new_with_len(void* p, size_t len,
void (*destroy)(void*,
size_t)) = 0;
virtual grpc_call_error grpc_call_start_batch(grpc_call* call,
const grpc_op* ops, size_t nops,
void* tag, void* reserved) = 0;
virtual grpc_call_error grpc_call_cancel_with_status(grpc_call* call,
grpc_status_code status,
const char* description,
void* reserved) = 0;
virtual int grpc_call_failed_before_recv_message(const grpc_call* c) = 0;
virtual void grpc_call_ref(grpc_call* call) = 0;
virtual void grpc_call_unref(grpc_call* call) = 0;
virtual void* grpc_call_arena_alloc(grpc_call* call, size_t length) = 0;
virtual const char* grpc_call_error_to_string(grpc_call_error error) = 0;
virtual grpc_slice grpc_empty_slice() = 0;
virtual grpc_slice grpc_slice_malloc(size_t length) = 0;
virtual void grpc_slice_unref(grpc_slice slice) = 0;
Expand Down
52 changes: 26 additions & 26 deletions include/grpcpp/impl/server_callback_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef GRPCPP_IMPL_SERVER_CALLBACK_HANDLERS_H
#define GRPCPP_IMPL_SERVER_CALLBACK_HANDLERS_H

#include <grpc/grpc.h>
#include <grpcpp/impl/rpc_service_method.h>
#include <grpcpp/server_context.h>
#include <grpcpp/support/message_allocator.h>
Expand All @@ -43,13 +44,13 @@ class CallbackUnaryHandler : public grpc::internal::MethodHandler {

void RunHandler(const HandlerParameter& param) final {
// Arena allocate a controller structure (that includes request/response)
grpc::g_core_codegen_interface->grpc_call_ref(param.call->call());
grpc_call_ref(param.call->call());
auto* allocator_state =
static_cast<MessageHolder<RequestType, ResponseType>*>(
param.internal_data);

auto* call = new (grpc::g_core_codegen_interface->grpc_call_arena_alloc(
param.call->call(), sizeof(ServerCallbackUnaryImpl)))
auto* call = new (grpc_call_arena_alloc(param.call->call(),
sizeof(ServerCallbackUnaryImpl)))
ServerCallbackUnaryImpl(
static_cast<grpc::CallbackServerContext*>(param.server_context),
param.call, allocator_state, param.call_requester);
Expand All @@ -66,8 +67,8 @@ class CallbackUnaryHandler : public grpc::internal::MethodHandler {

if (reactor == nullptr) {
// if deserialization or reactor creator failed, we need to fail the call
reactor = new (grpc::g_core_codegen_interface->grpc_call_arena_alloc(
param.call->call(), sizeof(UnimplementedUnaryReactor)))
reactor = new (grpc_call_arena_alloc(param.call->call(),
sizeof(UnimplementedUnaryReactor)))
UnimplementedUnaryReactor(
grpc::Status(grpc::StatusCode::UNIMPLEMENTED, ""));
}
Expand All @@ -85,10 +86,9 @@ class CallbackUnaryHandler : public grpc::internal::MethodHandler {
if (allocator_ != nullptr) {
allocator_state = allocator_->AllocateMessages();
} else {
allocator_state =
new (grpc::g_core_codegen_interface->grpc_call_arena_alloc(
call, sizeof(DefaultMessageHolder<RequestType, ResponseType>)))
DefaultMessageHolder<RequestType, ResponseType>();
allocator_state = new (grpc_call_arena_alloc(
call, sizeof(DefaultMessageHolder<RequestType, ResponseType>)))
DefaultMessageHolder<RequestType, ResponseType>();
}
*handler_data = allocator_state;
request = allocator_state->request();
Expand Down Expand Up @@ -208,7 +208,7 @@ class CallbackUnaryHandler : public grpc::internal::MethodHandler {
ctx_->context_allocator()->Release(ctx_);
}
this->~ServerCallbackUnaryImpl(); // explicitly call destructor
grpc::g_core_codegen_interface->grpc_call_unref(call);
grpc_call_unref(call);
call_requester();
}

Expand Down Expand Up @@ -256,10 +256,10 @@ class CallbackClientStreamingHandler : public grpc::internal::MethodHandler {
: get_reactor_(std::move(get_reactor)) {}
void RunHandler(const HandlerParameter& param) final {
// Arena allocate a reader structure (that includes response)
grpc::g_core_codegen_interface->grpc_call_ref(param.call->call());
grpc_call_ref(param.call->call());

auto* reader = new (grpc::g_core_codegen_interface->grpc_call_arena_alloc(
param.call->call(), sizeof(ServerCallbackReaderImpl)))
auto* reader = new (grpc_call_arena_alloc(param.call->call(),
sizeof(ServerCallbackReaderImpl)))
ServerCallbackReaderImpl(
static_cast<grpc::CallbackServerContext*>(param.server_context),
param.call, param.call_requester);
Expand All @@ -282,7 +282,7 @@ class CallbackClientStreamingHandler : public grpc::internal::MethodHandler {

if (reactor == nullptr) {
// if deserialization or reactor creator failed, we need to fail the call
reactor = new (grpc::g_core_codegen_interface->grpc_call_arena_alloc(
reactor = new (grpc_call_arena_alloc(
param.call->call(), sizeof(UnimplementedReadReactor<RequestType>)))
UnimplementedReadReactor<RequestType>(
grpc::Status(grpc::StatusCode::UNIMPLEMENTED, ""));
Expand Down Expand Up @@ -405,7 +405,7 @@ class CallbackClientStreamingHandler : public grpc::internal::MethodHandler {
ctx_->context_allocator()->Release(ctx_);
}
this->~ServerCallbackReaderImpl(); // explicitly call destructor
grpc::g_core_codegen_interface->grpc_call_unref(call);
grpc_call_unref(call);
call_requester();
}

Expand Down Expand Up @@ -447,10 +447,10 @@ class CallbackServerStreamingHandler : public grpc::internal::MethodHandler {
: get_reactor_(std::move(get_reactor)) {}
void RunHandler(const HandlerParameter& param) final {
// Arena allocate a writer structure
grpc::g_core_codegen_interface->grpc_call_ref(param.call->call());
grpc_call_ref(param.call->call());

auto* writer = new (grpc::g_core_codegen_interface->grpc_call_arena_alloc(
param.call->call(), sizeof(ServerCallbackWriterImpl)))
auto* writer = new (grpc_call_arena_alloc(param.call->call(),
sizeof(ServerCallbackWriterImpl)))
ServerCallbackWriterImpl(
static_cast<grpc::CallbackServerContext*>(param.server_context),
param.call, static_cast<RequestType*>(param.request),
Expand All @@ -473,7 +473,7 @@ class CallbackServerStreamingHandler : public grpc::internal::MethodHandler {
}
if (reactor == nullptr) {
// if deserialization or reactor creator failed, we need to fail the call
reactor = new (grpc::g_core_codegen_interface->grpc_call_arena_alloc(
reactor = new (grpc_call_arena_alloc(
param.call->call(), sizeof(UnimplementedWriteReactor<ResponseType>)))
UnimplementedWriteReactor<ResponseType>(
grpc::Status(grpc::StatusCode::UNIMPLEMENTED, ""));
Expand All @@ -486,8 +486,8 @@ class CallbackServerStreamingHandler : public grpc::internal::MethodHandler {
grpc::Status* status, void** /*handler_data*/) final {
grpc::ByteBuffer buf;
buf.set_buffer(req);
auto* request = new (grpc::g_core_codegen_interface->grpc_call_arena_alloc(
call, sizeof(RequestType))) RequestType();
auto* request =
new (grpc_call_arena_alloc(call, sizeof(RequestType))) RequestType();
*status =
grpc::SerializationTraits<RequestType>::Deserialize(&buf, request);
buf.Release();
Expand Down Expand Up @@ -630,7 +630,7 @@ class CallbackServerStreamingHandler : public grpc::internal::MethodHandler {
ctx_->context_allocator()->Release(ctx_);
}
this->~ServerCallbackWriterImpl(); // explicitly call destructor
grpc::g_core_codegen_interface->grpc_call_unref(call);
grpc_call_unref(call);
call_requester();
}

Expand Down Expand Up @@ -672,9 +672,9 @@ class CallbackBidiHandler : public grpc::internal::MethodHandler {
get_reactor)
: get_reactor_(std::move(get_reactor)) {}
void RunHandler(const HandlerParameter& param) final {
grpc::g_core_codegen_interface->grpc_call_ref(param.call->call());
grpc_call_ref(param.call->call());

auto* stream = new (grpc::g_core_codegen_interface->grpc_call_arena_alloc(
auto* stream = new (grpc_call_arena_alloc(
param.call->call(), sizeof(ServerCallbackReaderWriterImpl)))
ServerCallbackReaderWriterImpl(
static_cast<grpc::CallbackServerContext*>(param.server_context),
Expand All @@ -697,7 +697,7 @@ class CallbackBidiHandler : public grpc::internal::MethodHandler {

if (reactor == nullptr) {
// if deserialization or reactor creator failed, we need to fail the call
reactor = new (grpc::g_core_codegen_interface->grpc_call_arena_alloc(
reactor = new (grpc_call_arena_alloc(
param.call->call(),
sizeof(UnimplementedBidiReactor<RequestType, ResponseType>)))
UnimplementedBidiReactor<RequestType, ResponseType>(
Expand Down Expand Up @@ -846,7 +846,7 @@ class CallbackBidiHandler : public grpc::internal::MethodHandler {
ctx_->context_allocator()->Release(ctx_);
}
this->~ServerCallbackReaderWriterImpl(); // explicitly call destructor
grpc::g_core_codegen_interface->grpc_call_unref(call);
grpc_call_unref(call);
call_requester();
}

Expand Down
4 changes: 2 additions & 2 deletions include/grpcpp/server_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <type_traits>
#include <vector>

#include <grpc/grpc.h>
#include <grpc/impl/compression_types.h>
#include <grpcpp/impl/call.h>
#include <grpcpp/impl/call_op_set.h>
Expand Down Expand Up @@ -441,8 +442,7 @@ class ServerContextBase {
}

void MaybeMarkCancelledOnRead() {
if (g_core_codegen_interface->grpc_call_failed_before_recv_message(
call_.call)) {
if (grpc_call_failed_before_recv_message(call_.call)) {
marked_cancelled_.store(true, std::memory_order_release);
}
}
Expand Down
7 changes: 4 additions & 3 deletions include/grpcpp/server_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <grpc/support/port_platform.h>

#include <grpc/grpc.h>
#include <grpc/impl/codegen/grpc_types.h>
#include <grpcpp/impl/call.h>
#include <grpcpp/impl/call_hook.h>
Expand Down Expand Up @@ -272,9 +273,9 @@ class ServerInterface : public internal::CallHook {
// a new instance of ourselves to request another call. We then
// return false, which prevents the call from being returned to
// the application.
g_core_codegen_interface->grpc_call_cancel_with_status(
call_, GRPC_STATUS_INTERNAL, "Unable to parse request", nullptr);
g_core_codegen_interface->grpc_call_unref(call_);
grpc_call_cancel_with_status(call_, GRPC_STATUS_INTERNAL,
"Unable to parse request", nullptr);
grpc_call_unref(call_);
new PayloadAsyncRequest(registered_method_, server_, context_,
stream_, call_cq_, notification_cq_, tag_,
request_);
Expand Down
Loading

0 comments on commit 1d968a3

Please sign in to comment.