[slice] allow inlining of slice ref/unref again (#31158)

* allow inlining of slice ref/unref again

* Automated change: Fix sanity tests

* fix

* fix

* fix

* Automated change: Fix sanity tests

* fix

* fix

* Automated change: Fix sanity tests

* fix

Co-authored-by: ctiller <ctiller@users.noreply.github.com>
pull/31163/head
Craig Tiller 2 years ago committed by GitHub
parent 4874619947
commit c1853ade88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      BUILD
  2. 10
      src/core/ext/filters/client_channel/client_channel.cc
  3. 8
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
  4. 7
      src/core/ext/filters/client_channel/lb_policy/rls/rls.cc
  5. 19
      src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc
  6. 5
      src/core/ext/filters/client_channel/retry_filter.cc
  7. 10
      src/core/ext/transport/chttp2/transport/bin_decoder.cc
  8. 2
      src/core/ext/transport/chttp2/transport/bin_encoder.h
  9. 2
      src/core/ext/transport/chttp2/transport/chttp2_transport.cc
  10. 3
      src/core/ext/transport/chttp2/transport/frame_data.cc
  11. 2
      src/core/ext/transport/cronet/transport/cronet_transport.cc
  12. 3
      src/core/ext/xds/xds_client_grpc.cc
  13. 6
      src/core/ext/xds/xds_transport_grpc.cc
  14. 7
      src/core/lib/channel/channel_trace.cc
  15. 10
      src/core/lib/compression/message_compress.cc
  16. 10
      src/core/lib/event_engine/slice.cc
  17. 4
      src/core/lib/event_engine/slice_buffer.cc
  18. 5
      src/core/lib/http/httpcli.cc
  19. 5
      src/core/lib/iomgr/endpoint_cfstream.cc
  20. 3
      src/core/lib/security/authorization/grpc_authorization_policy_provider.cc
  21. 3
      src/core/lib/security/credentials/external/file_external_account_credentials.cc
  22. 3
      src/core/lib/security/credentials/google_default/google_default_credentials.cc
  23. 9
      src/core/lib/security/credentials/jwt/jwt_verifier.cc
  24. 4
      src/core/lib/security/credentials/oauth2/oauth2_credentials.cc
  25. 10
      src/core/lib/security/credentials/plugin/plugin_credentials.cc
  26. 6
      src/core/lib/security/credentials/plugin/plugin_credentials.h
  27. 5
      src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc
  28. 3
      src/core/lib/security/security_connector/alts/alts_security_connector.cc
  29. 11
      src/core/lib/security/transport/secure_endpoint.cc
  30. 3
      src/core/lib/security/transport/security_handshaker.cc
  31. 4
      src/core/lib/security/transport/server_auth_filter.cc
  32. 5
      src/core/lib/service_config/service_config_impl.cc
  33. 3
      src/core/lib/slice/b64.cc
  34. 6
      src/core/lib/slice/slice.cc
  35. 33
      src/core/lib/slice/slice.h
  36. 18
      src/core/lib/slice/slice_buffer.cc
  37. 17
      src/core/lib/slice/slice_refcount.cc
  38. 3
      src/core/lib/surface/byte_buffer.cc
  39. 6
      src/core/lib/surface/byte_buffer_reader.cc
  40. 7
      src/core/lib/surface/call.cc
  41. 5
      src/core/lib/surface/call_details.cc
  42. 12
      src/core/lib/surface/channel.cc
  43. 6
      src/core/lib/surface/server.cc
  44. 4
      src/core/lib/transport/parsed_metadata.cc
  45. 16
      src/core/tsi/alts/handshaker/alts_handshaker_client.cc
  46. 8
      src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc
  47. 3
      src/core/tsi/alts/handshaker/alts_tsi_utils.cc
  48. 1
      src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc
  49. 5
      src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc
  50. 6
      src/core/tsi/ssl/session_cache/ssl_session_openssl.cc
  51. 4
      tools/run_tests/sanity/core_banned_functions.py

@ -4468,6 +4468,7 @@ grpc_cc_library(
"ref_counted_ptr",
"rls_upb",
"server_address",
"slice",
"slice_refcount",
"subchannel_interface",
"time",
@ -5666,6 +5667,7 @@ grpc_cc_library(
"ref_counted_ptr",
"resolved_address",
"server_address",
"slice",
"sockaddr_utils",
"time",
"uri_parser",
@ -5892,6 +5894,7 @@ grpc_cc_library(
"ref_counted_ptr",
"resolved_address",
"resource_quota",
"slice",
"slice_refcount",
"sockaddr_utils",
"tcp_connect_handshaker",
@ -6114,6 +6117,7 @@ grpc_cc_library(
"iomgr_fwd",
"promise",
"ref_counted_ptr",
"slice",
"slice_refcount",
"tsi_alts_credentials",
"tsi_base",
@ -6194,6 +6198,7 @@ grpc_cc_library(
"iomgr_fwd",
"json",
"ref_counted_ptr",
"slice",
"slice_refcount",
"time",
"unique_type_name",
@ -6247,6 +6252,7 @@ grpc_cc_library(
"promise",
"ref_counted",
"ref_counted_ptr",
"slice",
"slice_refcount",
"tsi_base",
"tsi_ssl_credentials",
@ -6416,6 +6422,7 @@ grpc_cc_library(
"json",
"orphanable",
"ref_counted_ptr",
"slice",
"slice_refcount",
"time",
"uri_parser",
@ -6625,6 +6632,7 @@ grpc_cc_library(
"gpr",
"grpc_base",
"pollset_set",
"slice",
"tsi_base",
"useful",
],
@ -6804,6 +6812,7 @@ grpc_cc_library(
"grpc_trace",
"json",
"ref_counted_ptr",
"slice",
"slice_refcount",
"useful",
],

@ -351,14 +351,14 @@ class DynamicTerminationFilter::CallData {
private:
explicit CallData(const grpc_call_element_args& args)
: path_(grpc_slice_ref(args.path)),
: path_(CSliceRef(args.path)),
deadline_(args.deadline),
arena_(args.arena),
owning_call_(args.call_stack),
call_combiner_(args.call_combiner),
call_context_(args.context) {}
~CallData() { grpc_slice_unref(path_); }
~CallData() { CSliceUnref(path_); }
grpc_slice path_; // Request path.
Timestamp deadline_;
@ -1823,7 +1823,7 @@ ClientChannel::CallData::CallData(grpc_call_element* elem,
GPR_LIKELY(chand.deadline_checking_enabled_)
? args.deadline
: Timestamp::InfFuture()),
path_(grpc_slice_ref(args.path)),
path_(CSliceRef(args.path)),
call_start_time_(args.start_time),
deadline_(args.deadline),
arena_(args.arena),
@ -1836,7 +1836,7 @@ ClientChannel::CallData::CallData(grpc_call_element* elem,
}
ClientChannel::CallData::~CallData() {
grpc_slice_unref(path_);
CSliceUnref(path_);
// Make sure there are no remaining pending batches.
for (size_t i = 0; i < GPR_ARRAY_SIZE(pending_batches_); ++i) {
GPR_ASSERT(pending_batches_[i] == nullptr);
@ -2544,7 +2544,7 @@ ClientChannel::LoadBalancedCall::LoadBalancedCall(
? "LoadBalancedCall"
: nullptr),
chand_(chand),
path_(grpc_slice_ref(args.path)),
path_(CSliceRef(args.path)),
deadline_(args.deadline),
arena_(args.arena),
owning_call_(args.call_stack),

@ -922,7 +922,7 @@ GrpcLb::BalancerCallState::BalancerCallState(
arena.ptr());
send_message_payload_ =
grpc_raw_byte_buffer_create(&request_payload_slice, 1);
grpc_slice_unref(request_payload_slice);
CSliceUnref(request_payload_slice);
// Init other data associated with the LB call.
grpc_metadata_array_init(&lb_initial_metadata_recv_);
grpc_metadata_array_init(&lb_trailing_metadata_recv_);
@ -935,7 +935,7 @@ GrpcLb::BalancerCallState::~BalancerCallState() {
grpc_metadata_array_destroy(&lb_trailing_metadata_recv_);
grpc_byte_buffer_destroy(send_message_payload_);
grpc_byte_buffer_destroy(recv_message_payload_);
grpc_slice_unref(lb_call_status_details_);
CSliceUnref(lb_call_status_details_);
}
void GrpcLb::BalancerCallState::Orphan() {
@ -1090,7 +1090,7 @@ void GrpcLb::BalancerCallState::SendClientLoadReportLocked() {
num_calls_finished_known_received, drop_token_counts.get(), arena.ptr());
send_message_payload_ =
grpc_raw_byte_buffer_create(&request_payload_slice, 1);
grpc_slice_unref(request_payload_slice);
CSliceUnref(request_payload_slice);
// Send the report.
grpc_op op;
memset(&op, 0, sizeof(op));
@ -1291,7 +1291,7 @@ void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked() {
}
}
}
grpc_slice_unref(response_slice);
CSliceUnref(response_slice);
if (!grpclb_policy()->shutting_down_) {
// Keep listening for serverlist updates.
grpc_op op;

@ -94,6 +94,7 @@
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/security/credentials/fake/fake_credentials.h"
#include "src/core/lib/service_config/service_config_impl.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/channel.h"
@ -1790,7 +1791,7 @@ void RlsLb::RlsRequest::OnRlsCallCompleteLocked(grpc_error_handle error) {
grpc_byte_buffer_destroy(recv_message_);
grpc_metadata_array_destroy(&recv_initial_metadata_);
grpc_metadata_array_destroy(&recv_trailing_metadata_);
grpc_slice_unref(status_details_recv_);
CSliceUnref(status_details_recv_);
grpc_call_unref(call_);
call_ = nullptr;
// Return result to cache.
@ -1841,7 +1842,7 @@ grpc_byte_buffer* RlsLb::RlsRequest::MakeRequestProto() {
grpc_lookup_v1_RouteLookupRequest_serialize(req, arena.ptr(), &len);
grpc_slice send_slice = grpc_slice_from_copied_buffer(buf, len);
grpc_byte_buffer* byte_buffer = grpc_raw_byte_buffer_create(&send_slice, 1);
grpc_slice_unref(send_slice);
CSliceUnref(send_slice);
return byte_buffer;
}
@ -1856,7 +1857,7 @@ RlsLb::ResponseInfo RlsLb::RlsRequest::ParseResponseProto() {
grpc_lookup_v1_RouteLookupResponse_parse(
reinterpret_cast<const char*>(GRPC_SLICE_START_PTR(recv_slice)),
GRPC_SLICE_LENGTH(recv_slice), arena.ptr());
grpc_slice_unref(recv_slice);
CSliceUnref(recv_slice);
if (response == nullptr) {
response_info.status = absl::InternalError("cannot parse RLS response");
return response_info;

@ -41,6 +41,7 @@
#include "src/core/lib/iomgr/sockaddr_windows.h"
#include "src/core/lib/iomgr/socket_windows.h"
#include "src/core/lib/iomgr/tcp_windows.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_internal.h"
/* TODO(apolcyn): remove this hack after fixing upstream.
@ -123,8 +124,8 @@ class GrpcPolledFdWindows {
}
~GrpcPolledFdWindows() {
grpc_slice_unref(read_buf_);
grpc_slice_unref(write_buf_);
CSliceUnref(read_buf_);
CSliceUnref(write_buf_);
GPR_ASSERT(read_closure_ == nullptr);
GPR_ASSERT(write_closure_ == nullptr);
grpc_winsocket_destroy(winsocket_);
@ -144,7 +145,7 @@ class GrpcPolledFdWindows {
GPR_ASSERT(read_closure_ == nullptr);
read_closure_ = read_closure;
GPR_ASSERT(GRPC_SLICE_LENGTH(read_buf_) == 0);
grpc_slice_unref(read_buf_);
CSliceUnref(read_buf_);
GPR_ASSERT(!read_buf_has_data_);
read_buf_ = GRPC_SLICE_MALLOC(4192);
if (connect_done_) {
@ -354,12 +355,12 @@ class GrpcPolledFdWindows {
// to write everything inline.
GRPC_CARES_TRACE_LOG("fd:|%s| SendVUDP called", GetName());
GPR_ASSERT(GRPC_SLICE_LENGTH(write_buf_) == 0);
grpc_slice_unref(write_buf_);
CSliceUnref(write_buf_);
write_buf_ = FlattenIovec(iov, iov_count);
DWORD bytes_sent = 0;
int wsa_error_code = 0;
if (SendWriteBuf(&bytes_sent, nullptr, &wsa_error_code) != 0) {
grpc_slice_unref(write_buf_);
CSliceUnref(write_buf_);
write_buf_ = grpc_empty_slice();
wsa_error_ctx->SetWSAError(wsa_error_code);
char* msg = gpr_format_message(wsa_error_code);
@ -387,7 +388,7 @@ class GrpcPolledFdWindows {
case WRITE_IDLE:
tcp_write_state_ = WRITE_REQUESTED;
GPR_ASSERT(GRPC_SLICE_LENGTH(write_buf_) == 0);
grpc_slice_unref(write_buf_);
CSliceUnref(write_buf_);
write_buf_ = FlattenIovec(iov, iov_count);
wsa_error_ctx->SetWSAError(WSAEWOULDBLOCK);
return -1;
@ -410,7 +411,7 @@ class GrpcPolledFdWindows {
GRPC_SLICE_START_PTR(write_buf_)[i]);
total_sent++;
}
grpc_slice_unref(currently_attempted);
CSliceUnref(currently_attempted);
tcp_write_state_ = WRITE_IDLE;
return total_sent;
}
@ -600,7 +601,7 @@ class GrpcPolledFdWindows {
read_buf_, 0, winsocket_->read_info.bytes_transferred);
read_buf_has_data_ = true;
} else {
grpc_slice_unref(read_buf_);
CSliceUnref(read_buf_);
read_buf_ = grpc_empty_slice();
}
GRPC_CARES_TRACE_LOG(
@ -637,7 +638,7 @@ class GrpcPolledFdWindows {
GRPC_CARES_TRACE_LOG("fd:|%s| OnIocpWriteableInner. bytes transferred:%d",
GetName(), winsocket_->write_info.bytes_transferred);
} else {
grpc_slice_unref(write_buf_);
CSliceUnref(write_buf_);
write_buf_ = grpc_empty_slice();
}
ScheduleAndNullWriteClosure(error);

@ -67,6 +67,7 @@
#include "src/core/lib/resource_quota/arena.h"
#include "src/core/lib/service_config/service_config.h"
#include "src/core/lib/service_config/service_config_call_data.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_buffer.h"
#include "src/core/lib/transport/error_utils.h"
#include "src/core/lib/transport/metadata_batch.h"
@ -2151,7 +2152,7 @@ RetryFilter::CallData::CallData(RetryFilter* chand,
.set_max_backoff(retry_policy_ == nullptr
? Duration::Zero()
: retry_policy_->max_backoff())),
path_(grpc_slice_ref(args.path)),
path_(CSliceRef(args.path)),
deadline_(args.deadline),
arena_(args.arena),
owning_call_(args.call_stack),
@ -2169,7 +2170,7 @@ RetryFilter::CallData::CallData(RetryFilter* chand,
RetryFilter::CallData::~CallData() {
FreeAllCachedSendOpData();
grpc_slice_unref(path_);
CSliceUnref(path_);
// Make sure there are no remaining pending batches.
for (size_t i = 0; i < GPR_ARRAY_SIZE(pending_batches_); ++i) {
GPR_ASSERT(pending_batches_[i].batch == nullptr);

@ -25,6 +25,8 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/slice/slice.h"
static uint8_t decode_table[] = {
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
@ -194,7 +196,7 @@ grpc_slice grpc_chttp2_base64_decode(const grpc_slice& input) {
char* s = grpc_slice_to_c_string(input);
gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s);
gpr_free(s);
grpc_slice_unref(output);
grpc_core::CSliceUnref(output);
return grpc_empty_slice();
}
GPR_ASSERT(ctx.output_cur == GRPC_SLICE_END_PTR(output));
@ -215,7 +217,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(const grpc_slice& input,
"grpc_chttp2_base64_decode_with_length has a length of %d, which "
"has a tail of 1 byte.\n",
static_cast<int>(input_length));
grpc_slice_unref(output);
grpc_core::CSliceUnref(output);
return grpc_empty_slice();
}
@ -227,7 +229,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(const grpc_slice& input,
"than the max possible output length %d.\n",
static_cast<int>(output_length),
static_cast<int>(input_length / 4 * 3 + tail_xtra[input_length % 4]));
grpc_slice_unref(output);
grpc_core::CSliceUnref(output);
return grpc_empty_slice();
}
@ -241,7 +243,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(const grpc_slice& input,
char* s = grpc_slice_to_c_string(input);
gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s);
gpr_free(s);
grpc_slice_unref(output);
grpc_core::CSliceUnref(output);
return grpc_empty_slice();
}
GPR_ASSERT(ctx.output_cur == GRPC_SLICE_END_PTR(output));

@ -34,7 +34,7 @@ grpc_slice grpc_chttp2_huffman_compress(const grpc_slice& input);
/* equivalent to:
grpc_slice x = grpc_chttp2_base64_encode(input);
grpc_slice y = grpc_chttp2_huffman_compress(x);
grpc_slice_unref( x);
grpc_core::CSliceUnref( x);
return y; */
grpc_slice grpc_chttp2_base64_encode_and_huffman_compress(
const grpc_slice& input);

@ -1323,7 +1323,7 @@ static void perform_stream_op_locked(void* stream_op,
slices + op_payload->send_message.send_message->Count();
for (grpc_slice* slice = slices; slice != end; slice++) {
grpc_slice_buffer_add(&s->flow_controlled_buffer,
grpc_slice_ref(*slice));
grpc_core::CSliceRef(*slice));
}
int64_t notify_offset = s->next_message_end_offset;

@ -29,6 +29,7 @@
#include <grpc/support/log.h>
#include "src/core/ext/transport/chttp2/transport/internal.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_buffer.h"
#include "src/core/lib/transport/transport.h"
@ -138,7 +139,7 @@ grpc_error_handle grpc_chttp2_data_parser_parse(void* /*parser*/,
grpc_chttp2_stream* s,
const grpc_slice& slice,
int is_last) {
grpc_slice_ref(slice);
grpc_core::CSliceRef(slice);
grpc_slice_buffer_add(&s->frame_storage, slice);
grpc_chttp2_maybe_complete_recv_message(t, s);

@ -770,7 +770,7 @@ class CronetMetadataEncoder {
if (grpc_is_binary_header_internal(key_slice.c_slice())) {
grpc_slice wire_value = grpc_chttp2_base64_encode(value_slice.c_slice());
value = grpc_slice_to_c_string(wire_value);
grpc_slice_unref(wire_value);
grpc_core::CSliceUnref(wire_value);
} else {
value = grpc_slice_to_c_string(value_slice.c_slice());
}

@ -53,6 +53,7 @@
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/transport/error_utils.h"
@ -92,7 +93,7 @@ absl::StatusOr<std::string> GetBootstrapContents(const char* fallback_config) {
grpc_load_file(path->c_str(), /*add_null_terminator=*/true, &contents);
if (!error.ok()) return grpc_error_to_absl_status(error);
std::string contents_str(StringViewFromSlice(contents));
grpc_slice_unref(contents);
CSliceUnref(contents);
return contents_str;
}
// Next, try GRPC_XDS_BOOTSTRAP_CONFIG env var.

@ -137,7 +137,7 @@ GrpcXdsTransportFactory::GrpcXdsTransport::GrpcStreamingCall::
grpc_metadata_array_destroy(&trailing_metadata_recv_);
grpc_byte_buffer_destroy(send_message_payload_);
grpc_byte_buffer_destroy(recv_message_payload_);
grpc_slice_unref(status_details_);
CSliceUnref(status_details_);
GPR_ASSERT(call_ != nullptr);
grpc_call_unref(call_);
}
@ -158,7 +158,7 @@ void GrpcXdsTransportFactory::GrpcXdsTransport::GrpcStreamingCall::SendMessage(
// Create payload.
grpc_slice slice = grpc_slice_from_cpp_string(std::move(payload));
send_message_payload_ = grpc_raw_byte_buffer_create(&slice, 1);
grpc_slice_unref(slice);
CSliceUnref(slice);
// Send the message.
grpc_op op;
memset(&op, 0, sizeof(op));
@ -199,7 +199,7 @@ void GrpcXdsTransportFactory::GrpcXdsTransport::GrpcStreamingCall::
grpc_byte_buffer_destroy(self->recv_message_payload_);
self->recv_message_payload_ = nullptr;
self->event_handler_->OnRecvMessage(StringViewFromSlice(response_slice));
grpc_slice_unref(response_slice);
CSliceUnref(response_slice);
// Keep reading.
grpc_op op;
memset(&op, 0, sizeof(op));

@ -30,6 +30,7 @@
#include "src/core/lib/channel/channelz.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/time.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_internal.h"
namespace grpc_core {
@ -51,7 +52,7 @@ ChannelTrace::TraceEvent::TraceEvent(Severity severity, const grpc_slice& data)
next_(nullptr),
memory_usage_(sizeof(TraceEvent) + grpc_slice_memory_usage(data)) {}
ChannelTrace::TraceEvent::~TraceEvent() { grpc_slice_unref(data_); }
ChannelTrace::TraceEvent::~TraceEvent() { CSliceUnref(data_); }
ChannelTrace::ChannelTrace(size_t max_event_memory)
: num_events_logged_(0),
@ -102,7 +103,7 @@ void ChannelTrace::AddTraceEventHelper(TraceEvent* new_trace_event) {
void ChannelTrace::AddTraceEvent(Severity severity, const grpc_slice& data) {
if (max_event_memory_ == 0) {
grpc_slice_unref(data);
CSliceUnref(data);
return; // tracing is disabled if max_event_memory_ == 0
}
AddTraceEventHelper(new TraceEvent(severity, data));
@ -112,7 +113,7 @@ void ChannelTrace::AddTraceEventWithReference(
Severity severity, const grpc_slice& data,
RefCountedPtr<BaseNode> referenced_entity) {
if (max_event_memory_ == 0) {
grpc_slice_unref(data);
CSliceUnref(data);
return; // tracing is disabled if max_event_memory_ == 0
}
// create and fill up the new event

@ -29,6 +29,8 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/slice/slice.h"
#define OUTPUT_BLOCK_SIZE 1024
static int zlib_body(z_stream* zs, grpc_slice_buffer* input,
@ -80,7 +82,7 @@ static int zlib_body(z_stream* zs, grpc_slice_buffer* input,
return 1;
error:
grpc_slice_unref(outbuf);
grpc_core::CSliceUnref(outbuf);
return 0;
}
@ -107,7 +109,7 @@ static int zlib_compress(grpc_slice_buffer* input, grpc_slice_buffer* output,
r = zlib_body(&zs, input, output, deflate) && output->length < input->length;
if (!r) {
for (i = count_before; i < output->count; i++) {
grpc_slice_unref(output->slices[i]);
grpc_core::CSliceUnref(output->slices[i]);
}
output->count = count_before;
output->length = length_before;
@ -131,7 +133,7 @@ static int zlib_decompress(grpc_slice_buffer* input, grpc_slice_buffer* output,
r = zlib_body(&zs, input, output, inflate);
if (!r) {
for (i = count_before; i < output->count; i++) {
grpc_slice_unref(output->slices[i]);
grpc_core::CSliceUnref(output->slices[i]);
}
output->count = count_before;
output->length = length_before;
@ -143,7 +145,7 @@ static int zlib_decompress(grpc_slice_buffer* input, grpc_slice_buffer* output,
static int copy(grpc_slice_buffer* input, grpc_slice_buffer* output) {
size_t i;
for (i = 0; i < input->count; i++) {
grpc_slice_buffer_add(output, grpc_slice_ref(input->slices[i]));
grpc_slice_buffer_add(output, grpc_core::CSliceRef(input->slices[i]));
}
return 1;
}

@ -14,6 +14,8 @@
#include <grpc/support/port_platform.h>
#include "src/core/lib/slice/slice.h"
#include <stdint.h>
#include <string>
@ -50,7 +52,7 @@ MutableSlice::MutableSlice(const grpc_slice& slice)
GPR_DEBUG_ASSERT(slice.refcount == nullptr || slice.refcount->IsUnique());
}
MutableSlice::~MutableSlice() { grpc_slice_unref(c_slice()); }
MutableSlice::~MutableSlice() { grpc_core::CSliceUnref(c_slice()); }
Slice Slice::TakeOwned() {
if (c_slice().refcount == nullptr) {
@ -69,7 +71,7 @@ Slice Slice::AsOwned() const {
if (c_slice().refcount == grpc_slice_refcount::NoopRefcount()) {
return Slice(grpc_slice_copy(c_slice()));
}
return Slice(grpc_slice_ref(c_slice()));
return Slice(grpc_core::CSliceRef(c_slice()));
}
MutableSlice Slice::TakeMutable() {
@ -83,9 +85,9 @@ MutableSlice Slice::TakeMutable() {
return MutableSlice(grpc_slice_copy(c_slice()));
}
Slice::~Slice() { grpc_slice_unref(c_slice()); }
Slice::~Slice() { grpc_core::CSliceUnref(c_slice()); }
Slice Slice::Ref() const { return Slice(grpc_slice_ref(c_slice())); }
Slice Slice::Ref() const { return Slice(grpc_core::CSliceRef(c_slice())); }
Slice Slice::FromRefcountAndBytes(grpc_slice_refcount* r, const uint8_t* begin,
const uint8_t* end) {

@ -21,6 +21,8 @@
#include <grpc/slice.h>
#include <grpc/slice_buffer.h>
#include "src/core/lib/slice/slice.h"
namespace grpc_event_engine {
namespace experimental {
@ -41,7 +43,7 @@ void SliceBuffer::Prepend(Slice slice) {
}
Slice SliceBuffer::RefSlice(size_t index) {
return Slice(grpc_slice_ref(slice_buffer_.slices[index]));
return Slice(grpc_core::CSliceRef(slice_buffer_.slices[index]));
}
} // namespace experimental

@ -48,6 +48,7 @@
#include "src/core/lib/resource_quota/api.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/security/security_connector/security_connector.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/transport/error_utils.h"
#include "src/core/lib/transport/handshaker_registry.h"
#include "src/core/lib/transport/tcp_connect_handshaker.h"
@ -193,7 +194,7 @@ HttpRequest::~HttpRequest() {
if (own_endpoint_ && ep_ != nullptr) {
grpc_endpoint_destroy(ep_);
}
grpc_slice_unref(request_text_);
CSliceUnref(request_text_);
grpc_iomgr_unregister_object(&iomgr_obj_);
grpc_slice_buffer_destroy(&incoming_);
grpc_slice_buffer_destroy(&outgoing_);
@ -288,7 +289,7 @@ void HttpRequest::ContinueDoneWriteAfterScheduleOnExecCtx(
}
void HttpRequest::StartWrite() {
grpc_slice_ref(request_text_);
CSliceRef(request_text_);
grpc_slice_buffer_add(&outgoing_, request_text_);
Ref().release(); // ref held by pending write
grpc_endpoint_write(ep_, &outgoing_, &done_write_, nullptr,

@ -36,6 +36,7 @@
#import "src/core/lib/iomgr/endpoint_cfstream.h"
#include "src/core/lib/iomgr/error_cfstream.h"
#include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/slice/slice_string_helpers.h"
@ -229,10 +230,10 @@ static void WriteAction(void* arg, grpc_error_handle error) {
gpr_log(GPR_DEBUG, "WRITE %p (peer=%s): %s", ep, ep->peer_string.c_str(),
dump);
gpr_free(dump);
grpc_slice_unref(trace_slice);
grpc_core::CSliceUnref(trace_slice);
}
}
grpc_slice_unref(slice);
grpc_core::CSliceUnref(slice);
}
static void CFStreamRead(grpc_endpoint* ep, grpc_slice_buffer* slices,

@ -34,6 +34,7 @@
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/security/authorization/grpc_authorization_engine.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_internal.h"
namespace grpc_core {
@ -69,7 +70,7 @@ absl::StatusOr<std::string> ReadPolicyFromFile(absl::string_view policy_path) {
return status;
}
std::string policy_contents(StringViewFromSlice(policy_slice));
grpc_slice_unref(policy_slice);
CSliceUnref(policy_slice);
return policy_contents;
}

@ -28,6 +28,7 @@
#include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/json/json.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_internal.h"
namespace grpc_core {
@ -101,7 +102,7 @@ void FileExternalAccountCredentials::RetrieveSubjectToken(
HTTPRequestContext* /*ctx*/, const Options& /*options*/,
std::function<void(std::string, grpc_error_handle)> cb) {
struct SliceWrapper {
~SliceWrapper() { grpc_slice_unref(slice); }
~SliceWrapper() { CSliceUnref(slice); }
grpc_slice slice = grpc_empty_slice();
};
SliceWrapper content_slice;

@ -65,6 +65,7 @@
#include "src/core/lib/security/credentials/jwt/json_token.h"
#include "src/core/lib/security/credentials/jwt/jwt_credentials.h"
#include "src/core/lib/security/credentials/oauth2/oauth2_credentials.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/api_trace.h"
#include "src/core/lib/transport/error_utils.h"
@ -366,7 +367,7 @@ static grpc_error_handle create_default_creds_from_path(
end:
GPR_ASSERT((result == nullptr) + (error.ok()) == 1);
grpc_slice_unref(creds_data);
grpc_core::CSliceUnref(creds_data);
*creds = result;
return error;
}

@ -63,6 +63,7 @@
#include "src/core/lib/iomgr/polling_entity.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/slice/b64.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/uri/uri_parser.h"
#include "src/core/tsi/ssl_types.h"
@ -113,7 +114,7 @@ static Json parse_json_part_from_jwt(const char* str, size_t len) {
}
absl::string_view string = grpc_core::StringViewFromSlice(slice);
auto json = Json::Parse(string);
grpc_slice_unref(slice);
grpc_core::CSliceUnref(slice);
if (!json.ok()) {
gpr_log(GPR_ERROR, "JSON parse error: %s",
json.status().ToString().c_str());
@ -395,8 +396,8 @@ static verifier_cb_ctx* verifier_cb_ctx_create(
void verifier_cb_ctx_destroy(verifier_cb_ctx* ctx) {
if (ctx->audience != nullptr) gpr_free(ctx->audience);
if (ctx->claims != nullptr) grpc_jwt_claims_destroy(ctx->claims);
grpc_slice_unref(ctx->signature);
grpc_slice_unref(ctx->signed_data);
grpc_core::CSliceUnref(ctx->signature);
grpc_core::CSliceUnref(ctx->signed_data);
jose_header_destroy(ctx->header);
for (size_t i = 0; i < HTTP_RESPONSE_COUNT; i++) {
grpc_http_response_destroy(&ctx->responses[i]);
@ -486,7 +487,7 @@ static BIGNUM* bignum_from_base64(const char* b64) {
}
result = BN_bin2bn(GRPC_SLICE_START_PTR(bin),
TSI_SIZE_AS_SIZE(GRPC_SLICE_LENGTH(bin)), nullptr);
grpc_slice_unref(bin);
grpc_core::CSliceUnref(bin);
return result;
}

@ -611,8 +611,8 @@ class StsTokenFetcherCredentials
*body = gpr_strdup(body_str.c_str());
*body_length = body_str.size();
}
grpc_slice_unref(subject_token);
grpc_slice_unref(actor_token);
CSliceUnref(subject_token);
CSliceUnref(actor_token);
return err;
};

@ -95,7 +95,7 @@ grpc_plugin_credentials::PendingRequest::ProcessPluginResult(
for (size_t i = 0; i < num_md; ++i) {
md_->Append(
grpc_core::StringViewFromSlice(md[i].key),
grpc_core::Slice(grpc_slice_ref(md[i].value)),
grpc_core::Slice(grpc_core::CSliceRef(md[i].value)),
[&error](absl::string_view message, const grpc_core::Slice&) {
error = absl::UnavailableError(message);
});
@ -132,8 +132,8 @@ void grpc_plugin_credentials::PendingRequest::RequestMetadataReady(
}
for (size_t i = 0; i < num_md; ++i) {
grpc_metadata p;
p.key = grpc_slice_ref(md[i].key);
p.value = grpc_slice_ref(md[i].value);
p.key = grpc_core::CSliceRef(md[i].key);
p.value = grpc_core::CSliceRef(md[i].value);
r->metadata_.push_back(p);
}
r->error_details_ = error_details == nullptr ? "" : error_details;
@ -191,8 +191,8 @@ grpc_plugin_credentials::GetRequestMetadata(
error_details);
// Clean up.
for (size_t i = 0; i < num_creds_md; ++i) {
grpc_slice_unref(creds_md[i].key);
grpc_slice_unref(creds_md[i].value);
grpc_core::CSliceUnref(creds_md[i].key);
grpc_core::CSliceUnref(creds_md[i].value);
}
gpr_free(const_cast<char*>(error_details));

@ -33,7 +33,6 @@
#include <grpc/grpc_security.h>
#include <grpc/grpc_security_constants.h>
#include <grpc/impl/codegen/grpc_types.h>
#include <grpc/slice.h>
#include <grpc/status.h>
#include "src/core/lib/debug/trace.h"
@ -46,6 +45,7 @@
#include "src/core/lib/promise/poll.h"
#include "src/core/lib/security/credentials/call_creds_util.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/transport/transport.h"
extern grpc_core::TraceFlag grpc_plugin_credentials_trace;
@ -81,8 +81,8 @@ struct grpc_plugin_credentials final : public grpc_call_credentials {
~PendingRequest() override {
grpc_auth_metadata_context_reset(&context_);
for (size_t i = 0; i < metadata_.size(); i++) {
grpc_slice_unref(metadata_[i].key);
grpc_slice_unref(metadata_[i].value);
grpc_core::CSliceUnref(metadata_[i].key);
grpc_core::CSliceUnref(metadata_[i].value);
}
}

@ -43,6 +43,7 @@
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/api_trace.h"
@ -288,7 +289,7 @@ FileWatcherCertificateProvider::ReadRootCertificatesFromFile(
return absl::nullopt;
}
std::string root_cert(StringViewFromSlice(root_slice));
grpc_slice_unref(root_slice);
CSliceUnref(root_slice);
return root_cert;
}
@ -310,7 +311,7 @@ FileWatcherCertificateProvider::ReadIdentityKeyCertPairFromFiles(
const std::string& identity_certificate_path) {
struct SliceWrapper {
grpc_slice slice = grpc_empty_slice();
~SliceWrapper() { grpc_slice_unref(slice); }
~SliceWrapper() { CSliceUnref(slice); }
};
const int kNumRetryAttempts = 3;
for (int i = 0; i < kNumRetryAttempts; ++i) {

@ -51,6 +51,7 @@
#include "src/core/lib/security/credentials/alts/alts_credentials.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/security/transport/security_handshaker.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/transport/handshaker.h"
#include "src/core/lib/transport/transport.h"
#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h"
@ -224,7 +225,7 @@ RefCountedPtr<grpc_auth_context> grpc_alts_auth_context_from_tsi_peer(
rpc_versions_prop->value.data, rpc_versions_prop->value.length);
bool decode_result =
grpc_gcp_rpc_protocol_versions_decode(slice, &peer_versions);
grpc_slice_unref(slice);
CSliceUnref(slice);
if (!decode_result) {
gpr_log(GPR_ERROR, "Invalid peer rpc protocol versions.");
return nullptr;

@ -55,6 +55,7 @@
#include "src/core/lib/resource_quota/resource_quota.h"
#include "src/core/lib/resource_quota/trace.h"
#include "src/core/lib/security/transport/tsi_error.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/tsi/transport_security_grpc.h"
#include "src/core/tsi/transport_security_interface.h"
@ -81,7 +82,7 @@ struct secure_endpoint {
grpc_slice_buffer_init(&leftover_bytes);
for (size_t i = 0; i < leftover_nslices; i++) {
grpc_slice_buffer_add(&leftover_bytes,
grpc_slice_ref(leftover_slices[i]));
grpc_core::CSliceRef(leftover_slices[i]));
}
grpc_slice_buffer_init(&output_buffer);
memory_owner =
@ -111,8 +112,8 @@ struct secure_endpoint {
tsi_zero_copy_grpc_protector_destroy(zero_copy_protector);
grpc_slice_buffer_destroy(&source_buffer);
grpc_slice_buffer_destroy(&leftover_bytes);
grpc_slice_unref(read_staging_buffer);
grpc_slice_unref(write_staging_buffer);
grpc_core::CSliceUnref(read_staging_buffer);
grpc_core::CSliceUnref(write_staging_buffer);
grpc_slice_buffer_destroy(&output_buffer);
grpc_slice_buffer_destroy(&protector_staging_buffer);
gpr_mu_destroy(&protector_mu);
@ -215,8 +216,8 @@ static void maybe_post_reclaimer(secure_endpoint* ep) {
ep->write_staging_buffer = grpc_empty_slice();
ep->write_mu.Unlock();
grpc_slice_unref(temp_read_slice);
grpc_slice_unref(temp_write_slice);
grpc_core::CSliceUnref(temp_read_slice);
grpc_core::CSliceUnref(temp_write_slice);
ep->has_posted_reclaimer.exchange(false, std::memory_order_relaxed);
}
SECURE_ENDPOINT_UNREF(ep, "benign_reclaimer");

@ -58,6 +58,7 @@
#include "src/core/lib/security/context/security_context.h"
#include "src/core/lib/security/transport/secure_endpoint.h"
#include "src/core/lib/security/transport/tsi_error.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/transport/handshaker.h"
#include "src/core/lib/transport/handshaker_factory.h"
@ -320,7 +321,7 @@ void SecurityHandshaker::OnPeerCheckedInner(grpc_error_handle error) {
args_->endpoint = grpc_secure_endpoint_create(
protector, zero_copy_protector, args_->endpoint, &slice,
args_->args.ToC().get(), 1);
grpc_slice_unref(slice);
CSliceUnref(slice);
} else {
args_->endpoint = grpc_secure_endpoint_create(
protector, zero_copy_protector, args_->endpoint, nullptr,

@ -216,8 +216,8 @@ static void on_md_processing_done(
}
// Clean up.
for (size_t i = 0; i < calld->md.count; i++) {
grpc_slice_unref(calld->md.metadata[i].key);
grpc_slice_unref(calld->md.metadata[i].value);
grpc_core::CSliceUnref(calld->md.metadata[i].key);
grpc_core::CSliceUnref(calld->md.metadata[i].value);
}
grpc_metadata_array_destroy(&calld->md);
GRPC_CALL_STACK_UNREF(calld->owning_call, "server_auth_metadata");

@ -36,6 +36,7 @@
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/json/json.h"
#include "src/core/lib/service_config/service_config_parser.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_internal.h"
namespace grpc_core {
@ -79,7 +80,7 @@ ServiceConfigImpl::ServiceConfigImpl(const ChannelArgs& args,
ServiceConfigImpl::~ServiceConfigImpl() {
for (auto& p : parsed_method_configs_map_) {
grpc_slice_unref(p.first);
CSliceUnref(p.first);
}
}
@ -129,7 +130,7 @@ absl::Status ServiceConfigImpl::ParseJsonMethodConfig(const ChannelArgs& args,
"field:name error:multiple method configs with same name");
// The map entry already existed, so we need to unref the
// key we just created.
grpc_slice_unref(key);
CSliceUnref(key);
} else {
value = vector_ptr;
}

@ -27,6 +27,7 @@
#include <grpc/support/log.h>
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/slice/slice.h"
/* --- Constants. --- */
@ -233,6 +234,6 @@ grpc_slice grpc_base64_decode_with_len(const char* b64, size_t b64_len,
return result;
fail:
grpc_slice_unref(result);
grpc_core::CSliceUnref(result);
return grpc_empty_slice();
}

@ -494,3 +494,9 @@ grpc_slice grpc_slice_dup(grpc_slice a) {
GRPC_SLICE_LENGTH(a));
return copy;
}
grpc_slice grpc_slice_ref(grpc_slice slice) {
return grpc_core::CSliceRef(slice);
}
void grpc_slice_unref(grpc_slice slice) { grpc_core::CSliceUnref(slice); }

@ -52,6 +52,19 @@
namespace grpc_core {
inline const grpc_slice& CSliceRef(const grpc_slice& slice) {
if (reinterpret_cast<uintptr_t>(slice.refcount) > 1) {
slice.refcount->Ref();
}
return slice;
}
inline void CSliceUnref(const grpc_slice& slice) {
if (reinterpret_cast<uintptr_t>(slice.refcount) > 1) {
slice.refcount->Unref();
}
}
namespace slice_detail {
// Returns an empty slice.
@ -248,11 +261,7 @@ class MutableSlice : public slice_detail::BaseSlice,
: slice_detail::BaseSlice(slice) {
GPR_DEBUG_ASSERT(slice.refcount == nullptr || slice.refcount->IsUnique());
}
~MutableSlice() {
if (reinterpret_cast<uintptr_t>(c_slice().refcount) > 1) {
c_slice().refcount->Unref();
}
}
~MutableSlice() { CSliceUnref(c_slice()); }
MutableSlice(const MutableSlice&) = delete;
MutableSlice& operator=(const MutableSlice&) = delete;
@ -287,11 +296,8 @@ class Slice : public slice_detail::BaseSlice,
public slice_detail::StaticConstructors<Slice> {
public:
Slice() = default;
~Slice() {
if (reinterpret_cast<uintptr_t>(c_slice().refcount) > 1) {
c_slice().refcount->Unref();
}
}
~Slice() { CSliceUnref(c_slice()); }
explicit Slice(const grpc_slice& slice) : slice_detail::BaseSlice(slice) {}
explicit Slice(slice_detail::BaseSlice&& other)
: slice_detail::BaseSlice(other.TakeCSlice()) {}
@ -372,12 +378,7 @@ class Slice : public slice_detail::BaseSlice,
return Slice(grpc_slice_split_tail(c_slice_ptr(), split));
}
Slice Ref() const {
if (reinterpret_cast<uintptr_t>(c_slice().refcount) > 1) {
c_slice().refcount->Ref();
}
return Slice(c_slice());
}
Slice Ref() const { return Slice(CSliceRef(c_slice())); }
Slice Copy() const { return Slice(grpc_slice_copy(c_slice())); }

@ -51,7 +51,7 @@ void SliceBuffer::Prepend(Slice slice) {
}
Slice SliceBuffer::RefSlice(size_t index) const {
return Slice(grpc_slice_ref(slice_buffer_.slices[index]));
return Slice(CSliceRef(slice_buffer_.slices[index]));
}
std::string SliceBuffer::JoinIntoString() const {
@ -180,7 +180,7 @@ void grpc_slice_buffer_add(grpc_slice_buffer* sb, grpc_slice s) {
back->data.refcounted.length += GRPC_SLICE_LENGTH(s);
sb->length += GRPC_SLICE_LENGTH(s);
// Unref the merged slice.
grpc_slice_unref(s);
grpc_core::CSliceUnref(s);
// early out
return;
}
@ -237,7 +237,7 @@ void grpc_slice_buffer_pop(grpc_slice_buffer* sb) {
void grpc_slice_buffer_reset_and_unref(grpc_slice_buffer* sb) {
size_t i;
for (i = 0; i < sb->count; i++) {
grpc_slice_unref(sb->slices[i]);
grpc_core::CSliceUnref(sb->slices[i]);
}
sb->count = 0;
@ -369,13 +369,13 @@ void grpc_slice_buffer_move_first_into_buffer(grpc_slice_buffer* src, size_t n,
n = 0;
} else if (slice_len == n) {
memcpy(dstp, GRPC_SLICE_START_PTR(slice), n);
grpc_slice_unref(slice);
grpc_core::CSliceUnref(slice);
n = 0;
} else {
memcpy(dstp, GRPC_SLICE_START_PTR(slice), slice_len);
dstp += slice_len;
n -= slice_len;
grpc_slice_unref(slice);
grpc_core::CSliceUnref(slice);
}
}
}
@ -411,14 +411,14 @@ void grpc_slice_buffer_trim_end(grpc_slice_buffer* sb, size_t n,
if (garbage) {
grpc_slice_buffer_add_indexed(garbage, slice);
} else {
grpc_slice_unref(slice);
grpc_core::CSliceUnref(slice);
}
return;
} else if (slice_len == n) {
if (garbage) {
grpc_slice_buffer_add_indexed(garbage, slice);
} else {
grpc_slice_unref(slice);
grpc_core::CSliceUnref(slice);
}
sb->count = idx;
return;
@ -426,7 +426,7 @@ void grpc_slice_buffer_trim_end(grpc_slice_buffer* sb, size_t n,
if (garbage) {
grpc_slice_buffer_add_indexed(garbage, slice);
} else {
grpc_slice_unref(slice);
grpc_core::CSliceUnref(slice);
}
n -= slice_len;
sb->count = idx;
@ -448,7 +448,7 @@ grpc_slice grpc_slice_buffer_take_first(grpc_slice_buffer* sb) {
void grpc_slice_buffer_remove_first(grpc_slice_buffer* sb) {
GPR_DEBUG_ASSERT(sb->count > 0);
sb->length -= GRPC_SLICE_LENGTH(sb->slices[0]);
grpc_slice_unref(sb->slices[0]);
grpc_core::CSliceUnref(sb->slices[0]);
sb->slices++;
if (--sb->count == 0) {
sb->slices = sb->base_slices;

@ -18,10 +18,6 @@
#include <chrono>
#include <grpc/slice.h>
#include "src/core/lib/slice/slice_refcount_base.h"
namespace grpc_core {
uint32_t g_hash_seed = []() {
@ -37,16 +33,3 @@ uint32_t g_hash_seed = []() {
void grpc_test_only_set_slice_hash_seed(uint32_t seed) {
grpc_core::g_hash_seed = seed;
}
grpc_slice grpc_slice_ref(grpc_slice slice) {
if (reinterpret_cast<uintptr_t>(slice.refcount) > 1) {
slice.refcount->Ref();
}
return slice;
}
void grpc_slice_unref(grpc_slice slice) {
if (reinterpret_cast<uintptr_t>(slice.refcount) > 1) {
slice.refcount->Unref();
}
}

@ -28,6 +28,7 @@
#include <grpc/support/alloc.h>
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/slice/slice.h"
grpc_byte_buffer* grpc_raw_byte_buffer_create(grpc_slice* slices,
size_t nslices) {
@ -45,7 +46,7 @@ grpc_byte_buffer* grpc_raw_compressed_byte_buffer_create(
bb->data.raw.compression = compression;
grpc_slice_buffer_init(&bb->data.raw.slice_buffer);
for (i = 0; i < nslices; i++) {
grpc_slice_ref(slices[i]);
grpc_core::CSliceRef(slices[i]);
grpc_slice_buffer_add(&bb->data.raw.slice_buffer, slices[i]);
}
return bb;

@ -28,6 +28,7 @@
#include <grpc/support/log.h>
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/slice/slice.h"
int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader,
grpc_byte_buffer* buffer) {
@ -69,7 +70,8 @@ int grpc_byte_buffer_reader_next(grpc_byte_buffer_reader* reader,
grpc_slice_buffer* slice_buffer;
slice_buffer = &reader->buffer_out->data.raw.slice_buffer;
if (reader->current.index < slice_buffer->count) {
*slice = grpc_slice_ref(slice_buffer->slices[reader->current.index]);
*slice =
grpc_core::CSliceRef(slice_buffer->slices[reader->current.index]);
reader->current.index += 1;
return 1;
}
@ -91,7 +93,7 @@ grpc_slice grpc_byte_buffer_reader_readall(grpc_byte_buffer_reader* reader) {
const size_t slice_length = GRPC_SLICE_LENGTH(in_slice);
memcpy(&(outbuf[bytes_read]), GRPC_SLICE_START_PTR(in_slice), slice_length);
bytes_read += slice_length;
grpc_slice_unref(in_slice);
grpc_core::CSliceUnref(in_slice);
GPR_ASSERT(bytes_read <= input_size);
}

@ -548,7 +548,7 @@ grpc_error_handle FilterStackCall::Create(grpc_call_create_args* args,
call->final_op_.client.status = nullptr;
call->final_op_.client.error_string = nullptr;
GRPC_STATS_INC_CLIENT_CALLS_CREATED();
path = grpc_slice_ref(args->path->c_slice());
path = CSliceRef(args->path->c_slice());
call->send_initial_metadata_.Set(HttpPathMetadata(),
std::move(*args->path));
if (args->authority.has_value()) {
@ -612,7 +612,7 @@ grpc_error_handle FilterStackCall::Create(grpc_call_create_args* args,
}
}
grpc_slice_unref(path);
CSliceUnref(path);
return error;
}
@ -844,8 +844,7 @@ bool FilterStackCall::PrepareApplicationMetadata(size_t count,
// Filter "content-length metadata"
continue;
}
batch->Append(StringViewFromSlice(md->key),
Slice(grpc_slice_ref(md->value)),
batch->Append(StringViewFromSlice(md->key), Slice(CSliceRef(md->value)),
[md](absl::string_view error, const Slice& value) {
gpr_log(GPR_DEBUG, "Append error: %s",
absl::StrCat("key=", StringViewFromSlice(md->key),

@ -24,6 +24,7 @@
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/surface/api_trace.h"
void grpc_call_details_init(grpc_call_details* details) {
@ -35,6 +36,6 @@ void grpc_call_details_init(grpc_call_details* details) {
void grpc_call_details_destroy(grpc_call_details* details) {
GRPC_API_TRACE("grpc_call_details_destroy(details=%p)", 1, (details));
grpc_core::ExecCtx exec_ctx;
grpc_slice_unref(details->method);
grpc_slice_unref(details->host);
grpc_core::CSliceUnref(details->method);
grpc_core::CSliceUnref(details->host);
}

@ -319,9 +319,10 @@ grpc_call* grpc_channel_create_call(grpc_channel* channel,
grpc_core::ExecCtx exec_ctx;
grpc_call* call = grpc_channel_create_call_internal(
channel, parent_call, propagation_mask, completion_queue, nullptr,
grpc_core::Slice(grpc_slice_ref(method)),
host != nullptr ? absl::optional<grpc_core::Slice>(grpc_slice_ref(*host))
: absl::nullopt,
grpc_core::Slice(grpc_core::CSliceRef(method)),
host != nullptr
? absl::optional<grpc_core::Slice>(grpc_core::CSliceRef(*host))
: absl::nullopt,
grpc_core::Timestamp::FromTimespecRoundUp(deadline));
return call;
@ -335,8 +336,9 @@ grpc_call* grpc_channel_create_pollset_set_call(
return grpc_channel_create_call_internal(
channel, parent_call, propagation_mask, nullptr, pollset_set,
grpc_core::Slice(method),
host != nullptr ? absl::optional<grpc_core::Slice>(grpc_slice_ref(*host))
: absl::nullopt,
host != nullptr
? absl::optional<grpc_core::Slice>(grpc_core::CSliceRef(*host))
: absl::nullopt,
deadline);
}

@ -458,7 +458,7 @@ class ChannelBroadcaster {
static void ShutdownCleanup(void* arg, grpc_error_handle /*error*/) {
ShutdownCleanupArgs* a = static_cast<ShutdownCleanupArgs*>(arg);
grpc_slice_unref(a->slice);
CSliceUnref(a->slice);
delete a;
}
@ -1230,8 +1230,8 @@ void Server::CallData::Publish(size_t cq_idx, RequestedCall* rc) {
case RequestedCall::Type::BATCH_CALL:
GPR_ASSERT(host_.has_value());
GPR_ASSERT(path_.has_value());
rc->data.batch.details->host = grpc_slice_ref(host_->c_slice());
rc->data.batch.details->method = grpc_slice_ref(path_->c_slice());
rc->data.batch.details->host = CSliceRef(host_->c_slice());
rc->data.batch.details->method = CSliceRef(path_->c_slice());
rc->data.batch.details->deadline =
deadline_.as_timespec(GPR_CLOCK_MONOTONIC);
break;

@ -24,10 +24,10 @@ std::string MakeDebugString(absl::string_view key, absl::string_view value) {
}
Slice SliceFromBuffer(const Buffer& buffer) {
return Slice(grpc_slice_ref(buffer.slice));
return Slice(CSliceRef(buffer.slice));
}
void DestroySliceValue(const Buffer& value) { grpc_slice_unref(value.slice); }
void DestroySliceValue(const Buffer& value) { CSliceUnref(value.slice); }
void DestroyTrivialMemento(const Buffer&) {}

@ -135,11 +135,11 @@ static void alts_grpc_handshaker_client_unref(
client->send_buffer = nullptr;
client->recv_buffer = nullptr;
grpc_metadata_array_destroy(&client->recv_initial_metadata);
grpc_slice_unref(client->recv_bytes);
grpc_slice_unref(client->target_name);
grpc_core::CSliceUnref(client->recv_bytes);
grpc_core::CSliceUnref(client->target_name);
grpc_alts_credentials_options_destroy(client->options);
gpr_free(client->buffer);
grpc_slice_unref(client->handshake_status_details);
grpc_core::CSliceUnref(client->handshake_status_details);
delete client;
}
}
@ -488,7 +488,7 @@ static grpc_byte_buffer* get_serialized_handshaker_req(
}
grpc_slice slice = grpc_slice_from_copied_buffer(buf, buf_length);
grpc_byte_buffer* byte_buffer = grpc_raw_byte_buffer_create(&slice, 1);
grpc_slice_unref(slice);
grpc_core::CSliceUnref(slice);
return byte_buffer;
}
@ -639,8 +639,8 @@ static tsi_result handshaker_client_next(alts_handshaker_client* c,
}
alts_grpc_handshaker_client* client =
reinterpret_cast<alts_grpc_handshaker_client*>(c);
grpc_slice_unref(client->recv_bytes);
client->recv_bytes = grpc_slice_ref(*bytes_received);
grpc_core::CSliceUnref(client->recv_bytes);
client->recv_bytes = grpc_core::CSliceRef(*bytes_received);
grpc_byte_buffer* buffer = get_serialized_next(bytes_received);
if (buffer == nullptr) {
gpr_log(GPR_ERROR, "get_serialized_next() failed");
@ -741,7 +741,7 @@ alts_handshaker_client* alts_grpc_handshaker_client_create(
channel, nullptr, GRPC_PROPAGATE_DEFAULTS, interested_parties,
grpc_slice_from_static_string(ALTS_SERVICE_METHOD), &slice,
grpc_core::Timestamp::InfFuture(), nullptr);
grpc_slice_unref(slice);
grpc_core::CSliceUnref(slice);
GRPC_CLOSURE_INIT(&client->on_handshaker_service_resp_recv, grpc_cb, client,
grpc_schedule_on_exec_ctx);
GRPC_CLOSURE_INIT(&client->on_status_received, on_status_received, client,
@ -789,7 +789,7 @@ void alts_handshaker_client_set_recv_bytes_for_testing(
GPR_ASSERT(c != nullptr);
alts_grpc_handshaker_client* client =
reinterpret_cast<alts_grpc_handshaker_client*>(c);
client->recv_bytes = grpc_slice_ref(*recv_bytes);
client->recv_bytes = CSliceRef(*recv_bytes);
}
void alts_handshaker_client_set_fields_for_testing(

@ -249,8 +249,8 @@ static void handshaker_result_destroy(tsi_handshaker_result* self) {
gpr_free(result->peer_identity);
gpr_free(result->key_data);
gpr_free(result->unused_bytes);
grpc_slice_unref(result->rpc_versions);
grpc_slice_unref(result->serialized_context);
grpc_core::CSliceUnref(result->rpc_versions);
grpc_core::CSliceUnref(result->serialized_context);
gpr_free(result);
}
@ -481,7 +481,7 @@ static tsi_result alts_tsi_handshaker_continue_handshaker_next(
} else {
ok = alts_handshaker_client_next(handshaker->client, &slice);
}
grpc_slice_unref(slice);
grpc_core::CSliceUnref(slice);
return ok;
}
@ -612,7 +612,7 @@ static void handshaker_destroy(tsi_handshaker* self) {
alts_tsi_handshaker* handshaker =
reinterpret_cast<alts_tsi_handshaker*>(self);
alts_handshaker_client_destroy(handshaker->client);
grpc_slice_unref(handshaker->target_name);
grpc_core::CSliceUnref(handshaker->target_name);
grpc_alts_credentials_options_destroy(handshaker->options);
if (handshaker->channel != nullptr) {
grpc_channel_destroy_internal(handshaker->channel);

@ -22,6 +22,7 @@
#include <grpc/byte_buffer_reader.h>
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_internal.h"
tsi_result alts_tsi_utils_convert_to_tsi_result(grpc_status_code code) {
@ -54,7 +55,7 @@ grpc_gcp_HandshakerResp* alts_tsi_utils_deserialize_response(
buf_size);
grpc_gcp_HandshakerResp* resp = grpc_gcp_HandshakerResp_parse(
reinterpret_cast<char*>(buf), buf_size, arena);
grpc_slice_unref(slice);
grpc_core::CSliceUnref(slice);
grpc_byte_buffer_reader_destroy(&bbr);
if (resp == nullptr) {
gpr_log(GPR_ERROR, "grpc_gcp_handshaker_resp_decode() failed");

@ -25,6 +25,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h"
#include "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h"

@ -23,6 +23,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h"
#include "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h"
@ -61,7 +62,7 @@ static tsi_result alts_grpc_privacy_integrity_protect(
if (status != GRPC_STATUS_OK) {
gpr_log(GPR_ERROR, "Failed to protect, %s", error_details);
gpr_free(error_details);
grpc_slice_unref(protected_slice);
grpc_core::CSliceUnref(protected_slice);
return TSI_INTERNAL_ERROR;
}
grpc_slice_buffer_add(protected_slices, protected_slice);
@ -106,7 +107,7 @@ static tsi_result alts_grpc_privacy_integrity_unprotect(
if (status != GRPC_STATUS_OK) {
gpr_log(GPR_ERROR, "Failed to unprotect, %s", error_details);
gpr_free(error_details);
grpc_slice_unref(unprotected_slice);
grpc_core::CSliceUnref(unprotected_slice);
return TSI_INTERNAL_ERROR;
}
grpc_slice_buffer_reset_and_unref(&rp->header_sb);

@ -26,6 +26,8 @@
#include "absl/memory/memory.h"
#include "src/core/lib/slice/slice.h"
// OpenSSL invalidates SSL_SESSION on SSL destruction making it pointless
// to cache sessions. The workaround is to serialize (relatively expensive)
// session into binary blob and re-create it from blob on every handshake.
@ -49,7 +51,9 @@ class OpenSslCachedSession : public SslCachedSession {
serialized_session_ = slice;
}
virtual ~OpenSslCachedSession() { grpc_slice_unref(serialized_session_); }
virtual ~OpenSslCachedSession() {
grpc_core::CSliceUnref(serialized_session_);
}
SslSessionPtr CopySession() const override {
const unsigned char* data = GRPC_SLICE_START_PTR(serialized_session_);

@ -46,6 +46,10 @@ BANNED_EXCEPT = {
'grpc_closure_list_sched(': ['src/core/lib/iomgr/closure.cc'],
'grpc_error*': ['src/core/lib/iomgr/error.cc'],
'grpc_error_string': ['src/core/lib/iomgr/error.cc'],
# use grpc_core::CSlice{Ref,Unref} instead inside core
# (or prefer grpc_core::Slice!)
'grpc_slice_ref(': ['src/core/lib/slice/slice.cc'],
'grpc_slice_unref(': ['src/core/lib/slice/slice.cc'],
# std::random_device needs /dev/random which is not available on all linuxes that we support.
# Any usage must be optional and opt-in, so that those platforms can use gRPC without problem.
'std::random_device': [

Loading…
Cancel
Save