From 8ad2b146ed5caa995c89726de59c375935145cb4 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 30 Jul 2019 17:38:08 -0700 Subject: [PATCH] fix grpcsharp_create_byte_buffer_from_stolen_slices --- src/csharp/ext/grpc_csharp_ext.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/csharp/ext/grpc_csharp_ext.c b/src/csharp/ext/grpc_csharp_ext.c index abddbc0e7a1..82fa81abf7d 100644 --- a/src/csharp/ext/grpc_csharp_ext.c +++ b/src/csharp/ext/grpc_csharp_ext.c @@ -41,26 +41,15 @@ #define GPR_CALLTYPE #endif -//grpc_byte_buffer* string_to_byte_buffer(const char* buffer, size_t len) { -// grpc_slice slice = grpc_slice_from_copied_buffer(buffer, len); -// grpc_byte_buffer* bb = grpc_raw_byte_buffer_create(&slice, 1); -// grpc_slice_unref(slice); -// return bb; -//} - static grpc_byte_buffer* grpcsharp_create_byte_buffer_from_stolen_slices(grpc_slice_buffer* slice_buffer) { grpc_byte_buffer* bb = - (grpc_byte_buffer*)gpr_malloc(sizeof(grpc_byte_buffer)); + (grpc_byte_buffer*)gpr_malloc(sizeof(grpc_byte_buffer)); memset(bb, 0, sizeof(grpc_byte_buffer)); bb->type = GRPC_BB_RAW; bb->data.raw.compression = GRPC_COMPRESS_NONE; - bb->data.raw.slice_buffer = *slice_buffer; - // TODO: just use move slice_buffer... + grpc_slice_buffer_init(&bb->data.raw.slice_buffer); - // we transferred the ownership of members from the slice buffer to the - // the internals of byte buffer, so we just overwrite the original slice buffer with - // default values. - grpc_slice_buffer_init(slice_buffer); // TODO: need to reset available_tail_space after this.. + grpc_slice_buffer_swap(&bb->data.raw.slice_buffer, slice_buffer); return bb; }