Skip to content

Commit

Permalink
Don’t use KeyValuePair in marshaling because it’s overloaded on UWP (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
fealebenpae authored Sep 5, 2023
1 parent 2b2821f commit 5b1a7c2
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

### Fixed
* Fixed the message of the `MissingMemberException` being thrown when attempting to access a non-existent property with the dynamic API. (PR [#3432](https://github.com/realm/realm-dotnet/pull/3432))
* Fixed a `Cannot marshal generic Windows Runtime types with a non Windows Runtime type as a generic type argument` build error when using .NET Native. (Issue [#3434](https://github.com/realm/realm-dotnet/issues/3434), since 11.4.0)

### Compatibility
* Realm Studio: 13.0.0 or later.
Expand Down
8 changes: 4 additions & 4 deletions Realm/Realm/Native/HttpClientTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private readonly struct HttpClientRequest

public readonly UInt64 timeout_ms;

public readonly MarshaledVector<KeyValuePair<StringValue, StringValue>> headers;
public readonly MarshaledVector<MarshaledPair<StringValue, StringValue>> headers;

private readonly StringValue body;

Expand Down Expand Up @@ -91,7 +91,7 @@ private struct HttpClientResponse

public CustomErrorCode custom_status_code;

public MarshaledVector<KeyValuePair<StringValue, StringValue>> headers;
public MarshaledVector<MarshaledPair<StringValue, StringValue>> headers;

public StringValue body;
}
Expand Down Expand Up @@ -148,13 +148,13 @@ private static async void ExecuteRequest(HttpClientRequest request, IntPtr callb
var response = await httpClient.SendAsync(message, cts.Token).ConfigureAwait(false);

var headers = response.Headers.Concat(response.Content.Headers)
.Select(h => new KeyValuePair<StringValue, StringValue>(StringValue.AllocateFrom(h.Key, arena), StringValue.AllocateFrom(h.Value.FirstOrDefault(), arena)))
.Select(h => new MarshaledPair<StringValue, StringValue>(StringValue.AllocateFrom(h.Key, arena), StringValue.AllocateFrom(h.Value.FirstOrDefault(), arena)))
.ToArray();

var nativeResponse = new HttpClientResponse
{
http_status_code = (int)response.StatusCode,
headers = MarshaledVector<KeyValuePair<StringValue, StringValue>>.AllocateFrom(headers, arena),
headers = MarshaledVector<MarshaledPair<StringValue, StringValue>>.AllocateFrom(headers, arena),
body = StringValue.AllocateFrom(await response.Content.ReadAsStringAsync().ConfigureAwait(false), arena),
};

Expand Down
45 changes: 45 additions & 0 deletions Realm/Realm/Native/MarshaledPair.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2023 Realm Inc.
//
// 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.
//
////////////////////////////////////////////////////////////////////////////

using System.Collections.Generic;

namespace Realms.Native
{
internal struct MarshaledPair<TKey, TValue>
where TKey : unmanaged
where TValue : unmanaged
{
public TKey Key;

public TValue Value;

public MarshaledPair(TKey key, TValue value)
{
Key = key;
Value = value;
}

public void Deconstruct(out TKey key, out TValue value)
{
key = Key;
value = Value;
}

public static implicit operator KeyValuePair<TKey, TValue>(MarshaledPair<TKey, TValue> pair) => new (pair.Key, pair.Value);
}
}
2 changes: 1 addition & 1 deletion Realm/Realm/Native/SyncError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal struct SyncError
[MarshalAs(UnmanagedType.U1)]
public bool is_client_reset;

public MarshaledVector<KeyValuePair<StringValue, StringValue>> user_info_pairs;
public MarshaledVector<MarshaledPair<StringValue, StringValue>> user_info_pairs;

public MarshaledVector<CompensatingWriteInfo> compensating_writes;

Expand Down

0 comments on commit 5b1a7c2

Please sign in to comment.