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

Automated fix for refs/heads/status-x-test #40

Open
wants to merge 5 commits into
base: status-x-test
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion include/grpc/impl/codegen/port_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
/*
* Defines GRPC_ERROR_IS_ABSEIL_STATUS to use absl::Status for grpc_error_handle
*/
// #define GRPC_ERROR_IS_ABSEIL_STATUS 1
#define GRPC_ERROR_IS_ABSEIL_STATUS 1

/* Get windows.h included everywhere (we need it) */
#if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ void AresDnsResolver::OnResolved(void* arg, grpc_error_handle error) {
void AresDnsResolver::OnResolvedLocked(grpc_error_handle error) {
GPR_ASSERT(resolving_);
resolving_ = false;
gpr_free(pending_request_);
delete pending_request_;
pending_request_ = nullptr;
if (shutdown_initiated_) {
Unref(DEBUG_LOCATION, "OnResolvedLocked() shutdown");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,6 @@ grpc_core::TraceFlag grpc_trace_cares_address_sorting(false,

grpc_core::TraceFlag grpc_trace_cares_resolver(false, "cares_resolver");

typedef struct grpc_ares_ev_driver grpc_ares_ev_driver;

struct grpc_ares_request {
/** indicates the DNS server to use, if specified */
struct ares_addr_port_node dns_server_addr;
/** following members are set in grpc_resolve_address_ares_impl */
/** closure to call when the request completes */
grpc_closure* on_done;
/** the pointer to receive the resolved addresses */
std::unique_ptr<grpc_core::ServerAddressList>* addresses_out;
/** the pointer to receive the resolved balancer addresses */
std::unique_ptr<grpc_core::ServerAddressList>* balancer_addresses_out;
/** the pointer to receive the service config in JSON */
char** service_config_json_out;
/** the evernt driver used by this request */
grpc_ares_ev_driver* ev_driver;
/** number of ongoing queries */
size_t pending_queries;

/** the errors explaining query failures, appended to in query callbacks */
grpc_error_handle error;
};

typedef struct fd_node {
/** the owner of this fd node */
grpc_ares_ev_driver* ev_driver;
Expand Down Expand Up @@ -717,8 +694,7 @@ static void on_hostbyname_done_locked(void* arg, int status, int /*timeouts*/,
hr->qtype, hr->host, hr->is_balancer, ares_strerror(status));
GRPC_CARES_TRACE_LOG("request:%p on_hostbyname_done_locked: %s", r,
error_msg.c_str());
grpc_error_handle error =
GRPC_ERROR_CREATE_FROM_CPP_STRING(std::move(error_msg));
grpc_error_handle error = GRPC_ERROR_CREATE_FROM_CPP_STRING(error_msg);
r->error = grpc_error_add_child(error, r->error);
}
destroy_hostbyname_request_locked(hr);
Expand Down Expand Up @@ -762,8 +738,7 @@ static void on_srv_query_done_locked(void* arg, int status, int /*timeouts*/,
ares_strerror(status));
GRPC_CARES_TRACE_LOG("request:%p on_srv_query_done_locked: %s", r,
error_msg.c_str());
grpc_error_handle error =
GRPC_ERROR_CREATE_FROM_CPP_STRING(std::move(error_msg));
grpc_error_handle error = GRPC_ERROR_CREATE_FROM_CPP_STRING(error_msg);
r->error = grpc_error_add_child(error, r->error);
}
delete q;
Expand Down Expand Up @@ -822,7 +797,7 @@ static void on_txt_done_locked(void* arg, int status, int /*timeouts*/,
q->name(), ares_strerror(status));
GRPC_CARES_TRACE_LOG("request:%p on_txt_done_locked %s", r,
error_msg.c_str());
error = GRPC_ERROR_CREATE_FROM_CPP_STRING(std::move(error_msg));
error = GRPC_ERROR_CREATE_FROM_CPP_STRING(error_msg);
r->error = grpc_error_add_child(error, r->error);
}

Expand Down Expand Up @@ -1059,15 +1034,13 @@ static grpc_ares_request* grpc_dns_lookup_ares_locked_impl(
std::unique_ptr<grpc_core::ServerAddressList>* balancer_addrs,
char** service_config_json, int query_timeout_ms,
std::shared_ptr<grpc_core::WorkSerializer> work_serializer) {
grpc_ares_request* r =
static_cast<grpc_ares_request*>(gpr_zalloc(sizeof(grpc_ares_request)));
grpc_ares_request* r = new grpc_ares_request();
memset(&r->dns_server_addr, 0, sizeof(r->dns_server_addr));
r->ev_driver = nullptr;
r->on_done = on_done;
r->addresses_out = addrs;
r->balancer_addresses_out = balancer_addrs;
r->service_config_json_out = service_config_json;
r->error = GRPC_ERROR_NONE;
r->pending_queries = 0;
GRPC_CARES_TRACE_LOG(
"request:%p c-ares grpc_dns_lookup_ares_locked_impl name=%s, "
"default_port=%s",
Expand Down Expand Up @@ -1163,7 +1136,7 @@ typedef struct grpc_resolve_address_ares_request {

static void on_dns_lookup_done_locked(grpc_resolve_address_ares_request* r,
grpc_error_handle error) {
gpr_free(r->ares_request);
delete r->ares_request;
grpc_resolved_addresses** resolved_addresses = r->addrs_out;
if (r->addresses == nullptr || r->addresses->empty()) {
*resolved_addresses = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,27 @@ extern grpc_core::TraceFlag grpc_trace_cares_resolver;
} \
} while (0)

typedef struct grpc_ares_request grpc_ares_request;
typedef struct grpc_ares_ev_driver grpc_ares_ev_driver;

struct grpc_ares_request {
/** indicates the DNS server to use, if specified */
struct ares_addr_port_node dns_server_addr;
/** following members are set in grpc_resolve_address_ares_impl */
/** closure to call when the request completes */
grpc_closure* on_done = nullptr;
/** the pointer to receive the resolved addresses */
std::unique_ptr<grpc_core::ServerAddressList>* addresses_out;
/** the pointer to receive the resolved balancer addresses */
std::unique_ptr<grpc_core::ServerAddressList>* balancer_addresses_out;
/** the pointer to receive the service config in JSON */
char** service_config_json_out = nullptr;
/** the evernt driver used by this request */
grpc_ares_ev_driver* ev_driver = nullptr;
/** number of ongoing queries */
size_t pending_queries = 0;
/** the errors explaining query failures, appended to in query callbacks */
grpc_error_handle error = GRPC_ERROR_NONE;
};

/* Asynchronously resolve \a name. Use \a default_port if a port isn't
designated in \a name, otherwise use the port in \a name. grpc_ares_init()
Expand Down
2 changes: 1 addition & 1 deletion src/core/ext/transport/chttp2/server/chttp2_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ grpc_error_handle Chttp2ServerAddPort(Server* server, const char* addr,
}
return GRPC_ERROR_NONE;
}(); // lambda end
for (grpc_error_handle error : error_list) {
for (const grpc_error_handle& error : error_list) {
GRPC_ERROR_UNREF(error);
}
grpc_channel_args_destroy(args);
Expand Down
21 changes: 11 additions & 10 deletions src/core/ext/transport/chttp2/transport/chttp2_transport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1227,26 +1227,27 @@ void grpc_chttp2_complete_closure_step(grpc_chttp2_transport* t,
write_state_name(t->write_state));
}
if (error != GRPC_ERROR_NONE) {
if (closure->error_data.error == GRPC_ERROR_NONE) {
closure->error_data.error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
if (*closure->error_data.error == GRPC_ERROR_NONE) {
*closure->error_data.error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"Error in HTTP transport completing operation");
closure->error_data.error =
grpc_error_set_str(closure->error_data.error,
*closure->error_data.error =
grpc_error_set_str(*closure->error_data.error,
GRPC_ERROR_STR_TARGET_ADDRESS, t->peer_string);
}
closure->error_data.error =
grpc_error_add_child(closure->error_data.error, error);
*closure->error_data.error =
grpc_error_add_child(*closure->error_data.error, error);
}
if (closure->next_data.scratch < CLOSURE_BARRIER_FIRST_REF_BIT) {
if ((t->write_state == GRPC_CHTTP2_WRITE_STATE_IDLE) ||
!(closure->next_data.scratch & CLOSURE_BARRIER_MAY_COVER_WRITE)) {
// Using GRPC_CLOSURE_SCHED instead of GRPC_CLOSURE_RUN to avoid running
// closures earlier than when it is safe to do so.
grpc_core::ExecCtx::Run(DEBUG_LOCATION, closure,
closure->error_data.error);
grpc_error_handle run_error = *closure->error_data.error;
*closure->error_data.error = GRPC_ERROR_NONE;
grpc_core::ExecCtx::Run(DEBUG_LOCATION, closure, run_error);
} else {
grpc_closure_list_append(&t->run_after_write, closure,
closure->error_data.error);
*closure->error_data.error);
}
}
}
Expand Down Expand Up @@ -1394,7 +1395,7 @@ static void perform_stream_op_locked(void* stream_op,
// This batch has send ops. Use final_data as a barrier until enqueue time;
// the initial counter is dropped at the end of this function.
on_complete->next_data.scratch = CLOSURE_BARRIER_FIRST_REF_BIT;
on_complete->error_data.error = GRPC_ERROR_NONE;
*on_complete->error_data.error = GRPC_ERROR_NONE;
}

if (op->cancel_stream) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/gprpp/status_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ std::string StatusToString(const absl::Status& status) {

namespace internal {

google_rpc_Status* StatusToProto(absl::Status status, upb_arena* arena) {
google_rpc_Status* StatusToProto(const absl::Status& status, upb_arena* arena) {
google_rpc_Status* msg = google_rpc_Status_new(arena);
google_rpc_Status_set_code(msg, int32_t(status.code()));
google_rpc_Status_set_message(
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/gprpp/status_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ namespace internal {

/// Builds a upb message, google_rpc_Status from a status
/// This is for internal implementation & test only
google_rpc_Status* StatusToProto(absl::Status status,
google_rpc_Status* StatusToProto(const absl::Status& status,
upb_arena* arena) GRPC_MUST_USE_RESULT;

/// Builds a status from a upb message, google_rpc_Status
Expand Down
8 changes: 5 additions & 3 deletions src/core/lib/iomgr/call_combiner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void CallCombiner::Start(grpc_closure* closure, grpc_error_handle error,
gpr_log(GPR_INFO, " QUEUING");
}
// Queue was not empty, so add closure to queue.
closure->error_data.error = error;
*closure->error_data.error = error;
queue_.Push(
reinterpret_cast<MultiProducerSingleConsumerQueue::Node*>(closure));
}
Expand Down Expand Up @@ -189,9 +189,11 @@ void CallCombiner::Stop(DEBUG_ARGS const char* reason) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
gpr_log(GPR_INFO, " EXECUTING FROM QUEUE: closure=%p error=%s",
closure,
grpc_error_std_string(closure->error_data.error).c_str());
grpc_error_std_string(*closure->error_data.error).c_str());
}
ScheduleClosure(closure, closure->error_data.error);
grpc_error_handle error = *closure->error_data.error;
*closure->error_data.error = GRPC_ERROR_NONE;
ScheduleClosure(closure, error);
break;
}
} else if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
Expand Down
28 changes: 19 additions & 9 deletions src/core/lib/iomgr/closure.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct grpc_closure {

/** Once queued, the result of the closure. Before then: scratch space */
union {
grpc_error_handle error;
grpc_core::ManualConstructor<grpc_error_handle> error;
uintptr_t scratch;
} error_data;

Expand All @@ -98,7 +98,7 @@ inline grpc_closure* grpc_closure_init(grpc_closure* closure,
#endif
closure->cb = cb;
closure->cb_arg = cb_arg;
closure->error_data.error = GRPC_ERROR_NONE;
closure->error_data.error.Init(GRPC_ERROR_NONE);
#ifndef NDEBUG
closure->scheduled = false;
closure->file_initiated = nullptr;
Expand Down Expand Up @@ -172,16 +172,12 @@ inline void grpc_closure_list_init(grpc_closure_list* closure_list) {
}

/** add \a closure to the end of \a list
and set \a closure's result to \a error
Returns true if \a list becomes non-empty */
inline bool grpc_closure_list_append(grpc_closure_list* closure_list,
grpc_closure* closure,
grpc_error_handle error) {
grpc_closure* closure) {
if (closure == nullptr) {
GRPC_ERROR_UNREF(error);
return false;
}
closure->error_data.error = error;
closure->next_data.next = nullptr;
bool was_empty = (closure_list->head == nullptr);
if (was_empty) {
Expand All @@ -193,12 +189,26 @@ inline bool grpc_closure_list_append(grpc_closure_list* closure_list,
return was_empty;
}

/** add \a closure to the end of \a list
and set \a closure's result to \a error
Returns true if \a list becomes non-empty */
inline bool grpc_closure_list_append(grpc_closure_list* closure_list,
grpc_closure* closure,
grpc_error_handle error) {
if (closure == nullptr) {
GRPC_ERROR_UNREF(error);
return false;
}
*closure->error_data.error = error;
return grpc_closure_list_append(closure_list, closure);
}

/** force all success bits in \a list to false */
inline void grpc_closure_list_fail_all(grpc_closure_list* list,
grpc_error_handle forced_failure) {
for (grpc_closure* c = list->head; c != nullptr; c = c->next_data.next) {
if (c->error_data.error == GRPC_ERROR_NONE) {
c->error_data.error = GRPC_ERROR_REF(forced_failure);
if (*c->error_data.error == GRPC_ERROR_NONE) {
*c->error_data.error = GRPC_ERROR_REF(forced_failure);
}
}
GRPC_ERROR_UNREF(forced_failure);
Expand Down
14 changes: 9 additions & 5 deletions src/core/lib/iomgr/combiner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static void combiner_exec(grpc_core::Combiner* lock, grpc_closure* cl,
}
GPR_ASSERT(last & STATE_UNORPHANED); // ensure lock has not been destroyed
assert(cl->cb);
cl->error_data.error = error;
*cl->error_data.error = error;
lock->queue.Push(cl->next_data.mpscq_node.get());
}

Expand Down Expand Up @@ -221,11 +221,13 @@ bool grpc_combiner_continue_exec_ctx() {
return true;
}
grpc_closure* cl = reinterpret_cast<grpc_closure*>(n);
grpc_error_handle cl_err = cl->error_data.error;
grpc_error_handle cl_err = std::move(*cl->error_data.error);
cl->error_data.error.Destroy();
cl->error_data.error.Init();
#ifndef NDEBUG
cl->scheduled = false;
#endif
cl->cb(cl->cb_arg, cl_err);
cl->cb(cl->cb_arg, std::move(cl_err));
GRPC_ERROR_UNREF(cl_err);
} else {
grpc_closure* c = lock->final_list.head;
Expand All @@ -236,11 +238,13 @@ bool grpc_combiner_continue_exec_ctx() {
GRPC_COMBINER_TRACE(
gpr_log(GPR_INFO, "C:%p execute_final[%d] c=%p", lock, loops, c));
grpc_closure* next = c->next_data.next;
grpc_error_handle error = c->error_data.error;
grpc_error_handle error = std::move(*c->error_data.error);
c->error_data.error.Destroy();
c->error_data.error.Init();
#ifndef NDEBUG
c->scheduled = false;
#endif
c->cb(c->cb_arg, error);
c->cb(c->cb_arg, std::move(error));
GRPC_ERROR_UNREF(error);
c = next;
}
Expand Down
20 changes: 11 additions & 9 deletions src/core/lib/iomgr/exec_ctx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/profiling/timers.h"

static void exec_ctx_run(grpc_closure* closure, grpc_error_handle error) {
static void exec_ctx_run(grpc_closure* closure) {
#ifndef NDEBUG
closure->scheduled = false;
if (grpc_trace_closure.enabled()) {
Expand All @@ -37,7 +37,10 @@ static void exec_ctx_run(grpc_closure* closure, grpc_error_handle error) {
closure->line_initiated);
}
#endif
closure->cb(closure->cb_arg, error);
grpc_error_handle error = std::move(*closure->error_data.error);
closure->error_data.error.Destroy();
closure->error_data.error.Init();
closure->cb(closure->cb_arg, std::move(error));
#ifndef NDEBUG
if (grpc_trace_closure.enabled()) {
gpr_log(GPR_DEBUG, "closure %p finished", closure);
Expand All @@ -46,9 +49,8 @@ static void exec_ctx_run(grpc_closure* closure, grpc_error_handle error) {
GRPC_ERROR_UNREF(error);
}

static void exec_ctx_sched(grpc_closure* closure, grpc_error_handle error) {
grpc_closure_list_append(grpc_core::ExecCtx::Get()->closure_list(), closure,
error);
static void exec_ctx_sched(grpc_closure* closure) {
grpc_closure_list_append(grpc_core::ExecCtx::Get()->closure_list(), closure);
}

static gpr_timespec g_start_time;
Expand Down Expand Up @@ -151,9 +153,8 @@ bool ExecCtx::Flush() {
closure_list_.head = closure_list_.tail = nullptr;
while (c != nullptr) {
grpc_closure* next = c->next_data.next;
grpc_error_handle error = c->error_data.error;
did_something = true;
exec_ctx_run(c, error);
exec_ctx_run(c);
c = next;
}
} else if (!grpc_combiner_continue_exec_ctx()) {
Expand Down Expand Up @@ -195,7 +196,8 @@ void ExecCtx::Run(const DebugLocation& location, grpc_closure* closure,
closure->run = false;
GPR_ASSERT(closure->cb != nullptr);
#endif
exec_ctx_sched(closure, error);
*closure->error_data.error = std::move(error);
exec_ctx_sched(closure);
}

void ExecCtx::RunList(const DebugLocation& location, grpc_closure_list* list) {
Expand All @@ -218,7 +220,7 @@ void ExecCtx::RunList(const DebugLocation& location, grpc_closure_list* list) {
c->run = false;
GPR_ASSERT(c->cb != nullptr);
#endif
exec_ctx_sched(c, c->error_data.error);
exec_ctx_sched(c);
c = next;
}
list->head = list->tail = nullptr;
Expand Down
Loading