diff --git a/BUILD b/BUILD index c4ebdbe5fd9..9cdec863296 100644 --- a/BUILD +++ b/BUILD @@ -217,6 +217,7 @@ GRPC_PUBLIC_HDRS = [ "include/grpc/impl/connectivity_state.h", "include/grpc/impl/grpc_types.h", "include/grpc/impl/propagation_bits.h", + "include/grpc/impl/slice_type.h", ] GRPC_PUBLIC_EVENT_ENGINE_HDRS = [ diff --git a/CMakeLists.txt b/CMakeLists.txt index 2553a6d4524..cff8a4c01f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2494,6 +2494,7 @@ foreach(_hdr include/grpc/impl/connectivity_state.h include/grpc/impl/grpc_types.h include/grpc/impl/propagation_bits.h + include/grpc/impl/slice_type.h include/grpc/load_reporting.h include/grpc/slice.h include/grpc/slice_buffer.h @@ -3102,6 +3103,7 @@ foreach(_hdr include/grpc/impl/connectivity_state.h include/grpc/impl/grpc_types.h include/grpc/impl/propagation_bits.h + include/grpc/impl/slice_type.h include/grpc/load_reporting.h include/grpc/slice.h include/grpc/slice_buffer.h @@ -4570,6 +4572,7 @@ foreach(_hdr include/grpc/impl/connectivity_state.h include/grpc/impl/grpc_types.h include/grpc/impl/propagation_bits.h + include/grpc/impl/slice_type.h include/grpc/load_reporting.h include/grpc/slice.h include/grpc/slice_buffer.h diff --git a/Makefile b/Makefile index 3c829ca9959..87ba704fc8c 100644 --- a/Makefile +++ b/Makefile @@ -1715,6 +1715,7 @@ PUBLIC_HEADERS_C += \ include/grpc/impl/connectivity_state.h \ include/grpc/impl/grpc_types.h \ include/grpc/impl/propagation_bits.h \ + include/grpc/impl/slice_type.h \ include/grpc/load_reporting.h \ include/grpc/slice.h \ include/grpc/slice_buffer.h \ @@ -2183,6 +2184,7 @@ PUBLIC_HEADERS_C += \ include/grpc/impl/connectivity_state.h \ include/grpc/impl/grpc_types.h \ include/grpc/impl/propagation_bits.h \ + include/grpc/impl/slice_type.h \ include/grpc/load_reporting.h \ include/grpc/slice.h \ include/grpc/slice_buffer.h \ diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index d379f25fce6..55138cf84fb 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -296,6 +296,7 @@ libs: - include/grpc/impl/connectivity_state.h - include/grpc/impl/grpc_types.h - include/grpc/impl/propagation_bits.h + - include/grpc/impl/slice_type.h - include/grpc/load_reporting.h - include/grpc/slice.h - include/grpc/slice_buffer.h @@ -1894,6 +1895,7 @@ libs: - include/grpc/impl/connectivity_state.h - include/grpc/impl/grpc_types.h - include/grpc/impl/propagation_bits.h + - include/grpc/impl/slice_type.h - include/grpc/load_reporting.h - include/grpc/slice.h - include/grpc/slice_buffer.h @@ -3421,6 +3423,7 @@ libs: - include/grpc/impl/connectivity_state.h - include/grpc/impl/grpc_types.h - include/grpc/impl/propagation_bits.h + - include/grpc/impl/slice_type.h - include/grpc/load_reporting.h - include/grpc/slice.h - include/grpc/slice_buffer.h diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 23255836f27..ba85dbfb058 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -147,6 +147,7 @@ Pod::Spec.new do |s| 'include/grpc/impl/connectivity_state.h', 'include/grpc/impl/grpc_types.h', 'include/grpc/impl/propagation_bits.h', + 'include/grpc/impl/slice_type.h', 'include/grpc/load_reporting.h', 'include/grpc/slice.h', 'include/grpc/slice_buffer.h', diff --git a/grpc.gemspec b/grpc.gemspec index 997df06cdb3..f1286247295 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -90,6 +90,7 @@ Gem::Specification.new do |s| s.files += %w( include/grpc/impl/connectivity_state.h ) s.files += %w( include/grpc/impl/grpc_types.h ) s.files += %w( include/grpc/impl/propagation_bits.h ) + s.files += %w( include/grpc/impl/slice_type.h ) s.files += %w( include/grpc/load_reporting.h ) s.files += %w( include/grpc/slice.h ) s.files += %w( include/grpc/slice_buffer.h ) diff --git a/include/grpc/event_engine/slice_buffer.h b/include/grpc/event_engine/slice_buffer.h index e3a75898b9a..3df3394073c 100644 --- a/include/grpc/event_engine/slice_buffer.h +++ b/include/grpc/event_engine/slice_buffer.h @@ -26,7 +26,6 @@ #include "absl/utility/utility.h" #include -#include #include #include #include diff --git a/include/grpc/impl/codegen/slice.h b/include/grpc/impl/codegen/slice.h index 2bc1e9248b1..db412bf68a1 100644 --- a/include/grpc/impl/codegen/slice.h +++ b/include/grpc/impl/codegen/slice.h @@ -21,92 +21,9 @@ // IWYU pragma: private -#include +#include -#include - -typedef struct grpc_slice grpc_slice; - -/** Slice API - - A slice represents a contiguous reference counted array of bytes. - It is cheap to take references to a slice, and it is cheap to create a - slice pointing to a subset of another slice. - - The data-structure for slices is exposed here to allow non-gpr code to - build slices from whatever data they have available. - - When defining interfaces that handle slices, care should be taken to define - reference ownership semantics (who should call unref?) and mutability - constraints (is the callee allowed to modify the slice?) */ - -/* Inlined half of grpc_slice is allowed to expand the size of the overall type - by this many bytes */ -#define GRPC_SLICE_INLINE_EXTRA_SIZE sizeof(void*) - -#define GRPC_SLICE_INLINED_SIZE \ - (sizeof(size_t) + sizeof(uint8_t*) - 1 + GRPC_SLICE_INLINE_EXTRA_SIZE) - -struct grpc_slice_refcount; -/** A grpc_slice s, if initialized, represents the byte range - s.bytes[0..s.length-1]. - - It can have an associated ref count which has a destruction routine to be run - when the ref count reaches zero (see grpc_slice_new() and grp_slice_unref()). - Multiple grpc_slice values may share a ref count. - - If the slice does not have a refcount, it represents an inlined small piece - of data that is copied by value. - - As a special case, a slice can be given refcount == uintptr_t(1), meaning - that the slice represents external data that is not refcounted. */ -struct grpc_slice { - struct grpc_slice_refcount* refcount; - union grpc_slice_data { - struct grpc_slice_refcounted { - size_t length; - uint8_t* bytes; - } refcounted; - struct grpc_slice_inlined { - uint8_t length; - uint8_t bytes[GRPC_SLICE_INLINED_SIZE]; - } inlined; - } data; -}; - -#define GRPC_SLICE_BUFFER_INLINE_ELEMENTS 8 - -/** Represents an expandable array of slices, to be interpreted as a - single item. */ -typedef struct grpc_slice_buffer { - /** This is for internal use only. External users (i.e any code outside grpc - * core) MUST NOT use this field */ - grpc_slice* base_slices; - - /** slices in the array (Points to the first valid grpc_slice in the array) */ - grpc_slice* slices; - /** the number of slices in the array */ - size_t count; - /** the number of slices allocated in the array. External users (i.e any code - * outside grpc core) MUST NOT use this field */ - size_t capacity; - /** the combined length of all slices in the array */ - size_t length; - /** inlined elements to avoid allocations */ - grpc_slice inlined[GRPC_SLICE_BUFFER_INLINE_ELEMENTS]; -} grpc_slice_buffer; - -#define GRPC_SLICE_START_PTR(slice) \ - ((slice).refcount ? (slice).data.refcounted.bytes \ - : (slice).data.inlined.bytes) -#define GRPC_SLICE_LENGTH(slice) \ - ((slice).refcount ? (slice).data.refcounted.length \ - : (slice).data.inlined.length) -#define GRPC_SLICE_SET_LENGTH(slice, newlen) \ - ((slice).refcount ? ((slice).data.refcounted.length = (size_t)(newlen)) \ - : ((slice).data.inlined.length = (uint8_t)(newlen))) -#define GRPC_SLICE_END_PTR(slice) \ - GRPC_SLICE_START_PTR(slice) + GRPC_SLICE_LENGTH(slice) -#define GRPC_SLICE_IS_EMPTY(slice) (GRPC_SLICE_LENGTH(slice) == 0) +/// TODO(chengyuc): Remove this file after solving compatibility. +#include #endif /* GRPC_IMPL_CODEGEN_SLICE_H */ diff --git a/include/grpc/impl/slice_type.h b/include/grpc/impl/slice_type.h new file mode 100644 index 00000000000..5d618740553 --- /dev/null +++ b/include/grpc/impl/slice_type.h @@ -0,0 +1,112 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_IMPL_SLICE_TYPE_H +#define GRPC_IMPL_SLICE_TYPE_H + +// IWYU pragma: private, include + +#include + +#include + +typedef struct grpc_slice grpc_slice; + +/** Slice API + + A slice represents a contiguous reference counted array of bytes. + It is cheap to take references to a slice, and it is cheap to create a + slice pointing to a subset of another slice. + + The data-structure for slices is exposed here to allow non-gpr code to + build slices from whatever data they have available. + + When defining interfaces that handle slices, care should be taken to define + reference ownership semantics (who should call unref?) and mutability + constraints (is the callee allowed to modify the slice?) */ + +/* Inlined half of grpc_slice is allowed to expand the size of the overall type + by this many bytes */ +#define GRPC_SLICE_INLINE_EXTRA_SIZE sizeof(void*) + +#define GRPC_SLICE_INLINED_SIZE \ + (sizeof(size_t) + sizeof(uint8_t*) - 1 + GRPC_SLICE_INLINE_EXTRA_SIZE) + +struct grpc_slice_refcount; +/** A grpc_slice s, if initialized, represents the byte range + s.bytes[0..s.length-1]. + + It can have an associated ref count which has a destruction routine to be run + when the ref count reaches zero (see grpc_slice_new() and grp_slice_unref()). + Multiple grpc_slice values may share a ref count. + + If the slice does not have a refcount, it represents an inlined small piece + of data that is copied by value. + + As a special case, a slice can be given refcount == uintptr_t(1), meaning + that the slice represents external data that is not refcounted. */ +struct grpc_slice { + struct grpc_slice_refcount* refcount; + union grpc_slice_data { + struct grpc_slice_refcounted { + size_t length; + uint8_t* bytes; + } refcounted; + struct grpc_slice_inlined { + uint8_t length; + uint8_t bytes[GRPC_SLICE_INLINED_SIZE]; + } inlined; + } data; +}; + +#define GRPC_SLICE_BUFFER_INLINE_ELEMENTS 8 + +/** Represents an expandable array of slices, to be interpreted as a + single item. */ +typedef struct grpc_slice_buffer { + /** This is for internal use only. External users (i.e any code outside grpc + * core) MUST NOT use this field */ + grpc_slice* base_slices; + + /** slices in the array (Points to the first valid grpc_slice in the array) */ + grpc_slice* slices; + /** the number of slices in the array */ + size_t count; + /** the number of slices allocated in the array. External users (i.e any code + * outside grpc core) MUST NOT use this field */ + size_t capacity; + /** the combined length of all slices in the array */ + size_t length; + /** inlined elements to avoid allocations */ + grpc_slice inlined[GRPC_SLICE_BUFFER_INLINE_ELEMENTS]; +} grpc_slice_buffer; + +#define GRPC_SLICE_START_PTR(slice) \ + ((slice).refcount ? (slice).data.refcounted.bytes \ + : (slice).data.inlined.bytes) +#define GRPC_SLICE_LENGTH(slice) \ + ((slice).refcount ? (slice).data.refcounted.length \ + : (slice).data.inlined.length) +#define GRPC_SLICE_SET_LENGTH(slice, newlen) \ + ((slice).refcount ? ((slice).data.refcounted.length = (size_t)(newlen)) \ + : ((slice).data.inlined.length = (uint8_t)(newlen))) +#define GRPC_SLICE_END_PTR(slice) \ + GRPC_SLICE_START_PTR(slice) + GRPC_SLICE_LENGTH(slice) +#define GRPC_SLICE_IS_EMPTY(slice) (GRPC_SLICE_LENGTH(slice) == 0) + +#endif /* GRPC_IMPL_SLICE_TYPE_H */ diff --git a/include/grpc/module.modulemap b/include/grpc/module.modulemap index 8dcca5c20d3..31685d2ec7e 100644 --- a/include/grpc/module.modulemap +++ b/include/grpc/module.modulemap @@ -31,6 +31,7 @@ header "byte_buffer.h" header "impl/connectivity_state.h" header "impl/grpc_types.h" header "impl/propagation_bits.h" + header "impl/slice_type.h" header "load_reporting.h" header "slice.h" header "slice_buffer.h" diff --git a/include/grpc/slice.h b/include/grpc/slice.h index 15978fe54c5..7318a0e7157 100644 --- a/include/grpc/slice.h +++ b/include/grpc/slice.h @@ -21,7 +21,7 @@ #include -#include // IWYU pragma: export +#include // IWYU pragma: export #include #ifdef __cplusplus diff --git a/package.xml b/package.xml index a7f1d26aa04..43f59038a95 100644 --- a/package.xml +++ b/package.xml @@ -72,6 +72,7 @@ + diff --git a/src/core/lib/iomgr/python_util.h b/src/core/lib/iomgr/python_util.h index edefc58c4b6..2df411ef662 100644 --- a/src/core/lib/iomgr/python_util.h +++ b/src/core/lib/iomgr/python_util.h @@ -21,7 +21,7 @@ #include -#include +#include #include #include "src/core/lib/iomgr/error.h" diff --git a/test/core/surface/public_headers_must_be_c89.c b/test/core/surface/public_headers_must_be_c89.c index 22da11ceefe..af73ac4d0af 100644 --- a/test/core/surface/public_headers_must_be_c89.c +++ b/test/core/surface/public_headers_must_be_c89.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index 9982f24d680..a06e4cb11f9 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -918,6 +918,7 @@ include/grpc/impl/compression_types.h \ include/grpc/impl/connectivity_state.h \ include/grpc/impl/grpc_types.h \ include/grpc/impl/propagation_bits.h \ +include/grpc/impl/slice_type.h \ include/grpc/load_reporting.h \ include/grpc/slice.h \ include/grpc/slice_buffer.h \ diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index c2f5402c855..cbd2d908e57 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -918,6 +918,7 @@ include/grpc/impl/compression_types.h \ include/grpc/impl/connectivity_state.h \ include/grpc/impl/grpc_types.h \ include/grpc/impl/propagation_bits.h \ +include/grpc/impl/slice_type.h \ include/grpc/load_reporting.h \ include/grpc/slice.h \ include/grpc/slice_buffer.h \ diff --git a/tools/doxygen/Doxyfile.core b/tools/doxygen/Doxyfile.core index 861a2471447..69cf9547508 100644 --- a/tools/doxygen/Doxyfile.core +++ b/tools/doxygen/Doxyfile.core @@ -850,6 +850,7 @@ include/grpc/impl/compression_types.h \ include/grpc/impl/connectivity_state.h \ include/grpc/impl/grpc_types.h \ include/grpc/impl/propagation_bits.h \ +include/grpc/impl/slice_type.h \ include/grpc/load_reporting.h \ include/grpc/slice.h \ include/grpc/slice_buffer.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 2a586264fdc..4a73fde7ce9 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -850,6 +850,7 @@ include/grpc/impl/compression_types.h \ include/grpc/impl/connectivity_state.h \ include/grpc/impl/grpc_types.h \ include/grpc/impl/propagation_bits.h \ +include/grpc/impl/slice_type.h \ include/grpc/load_reporting.h \ include/grpc/slice.h \ include/grpc/slice_buffer.h \