From 7f23a75422aea6181c35857dd6f7936d1523fcd8 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 20 Jul 2015 20:28:28 -0700 Subject: [PATCH] fix bug --- .../Internal/MetadataArraySafeHandleTest.cs | 21 +++++++++++++++++++ src/csharp/ext/grpc_csharp_ext.c | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/csharp/Grpc.Core.Tests/Internal/MetadataArraySafeHandleTest.cs b/src/csharp/Grpc.Core.Tests/Internal/MetadataArraySafeHandleTest.cs index e03e20c4f70..46469113c59 100644 --- a/src/csharp/Grpc.Core.Tests/Internal/MetadataArraySafeHandleTest.cs +++ b/src/csharp/Grpc.Core.Tests/Internal/MetadataArraySafeHandleTest.cs @@ -59,5 +59,26 @@ namespace Grpc.Core.Internal.Tests var nativeMetadata = MetadataArraySafeHandle.Create(metadata); nativeMetadata.Dispose(); } + + [Test] + public void ReadMetadataFromPtrUnsafe() + { + var metadata = new Metadata + { + new Metadata.Entry("host", "somehost"), + new Metadata.Entry("header2", "header value"), + }; + var nativeMetadata = MetadataArraySafeHandle.Create(metadata); + + var copy = MetadataArraySafeHandle.ReadMetadataFromPtrUnsafe(nativeMetadata.Handle); + Assert.AreEqual(2, copy.Count); + + Assert.AreEqual("host", copy[0].Key); + Assert.AreEqual("somehost", copy[0].Value); + Assert.AreEqual("header2", copy[1].Key); + Assert.AreEqual("header value", copy[1].Value); + + nativeMetadata.Dispose(); + } } } diff --git a/src/csharp/ext/grpc_csharp_ext.c b/src/csharp/ext/grpc_csharp_ext.c index cfd96d15f1d..6856d89ff1a 100644 --- a/src/csharp/ext/grpc_csharp_ext.c +++ b/src/csharp/ext/grpc_csharp_ext.c @@ -172,10 +172,10 @@ grpcsharp_metadata_array_count(grpc_metadata_array *array) { return (gpr_intptr) array->count; } -GPR_EXPORT const grpc_metadata *GPR_CALLTYPE +GPR_EXPORT grpc_metadata GPR_CALLTYPE grpcsharp_metadata_array_get(grpc_metadata_array *array, size_t index) { GPR_ASSERT(index < array->count); - return &(array->metadata[index]); + return array->metadata[index]; } /* Move contents of metadata array */