Skip to content

Commit

Permalink
[ObjCRuntime] Add explicit conversion operators between NativeHandle …
Browse files Browse the repository at this point in the history
…and void*. Fixes #13867. (#13929)

Fixes #13867.
  • Loading branch information
rolfbjarne authored Jan 28, 2022
1 parent d2ef297 commit 43d74fb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/ObjCRuntime/NativeHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ public static implicit operator NativeHandle (IntPtr value)
return new NativeHandle (value);
}

public unsafe static explicit operator void* (NativeHandle value)
{
return (void *) (IntPtr) value;
}

public unsafe static explicit operator NativeHandle (void * value)
{
return new NativeHandle ((IntPtr) value);
}

public override bool Equals (object? o)
{
if (o is NativeHandle nh)
Expand Down
26 changes: 26 additions & 0 deletions tests/monotouch-test/ObjCRuntime/NativeHandleTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;

using Foundation;
using ObjCRuntime;

using NUnit.Framework;

#if NET

namespace MonoTouchFixtures.ObjCRuntime {
[TestFixture]
[Preserve (AllMembers = true)]
public class NativeHandleTest {
[Test]
public unsafe void Operators ()
{
IntPtr value = new IntPtr (0xdadf00d);

Assert.AreEqual (value, ((NativeHandle) value).Handle, "IntPtr -> NativeHandle");
Assert.AreEqual (value, (IntPtr) new NativeHandle (value), "NativeHandle -> IntPtr");
Assert.AreEqual (value, ((NativeHandle) ((void *) value)).Handle, "void* -> NativeHandle");
Assert.AreEqual (value, (IntPtr) (void *) new NativeHandle (value), "NativeHandle -> void*");
}
}
}
#endif

5 comments on commit 43d74fb

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ [CI Build] Tests failed on Build ❌

Tests failed on Build.

API diff

✅ API Diff from stable

View API diff
View dotnet API diff
View dotnet legacy API diff
View dotnet iOS-MacCatalayst API diff

API Current PR diff

ℹ️ API Diff (from PR only) (please review changes)

View API diff
View dotnet API diff
View dotnet legacy API diff
View dotnet iOS-MacCatalayst API diff

Generator diff

Generator Diff (no change)

Packages generated

View packages

Test results

5 tests failed, 230 tests passed.

Failed tests

  • monotouch-test/Mac Catalyst [dotnet]/Debug [dotnet]: Failed (Test run failed.
    Tests run: 2765 Passed: 2572 Inconclusive: 11 Failed: 1 Ignored: 192)
  • introspection/iOS Unified 64-bits - simulator/Debug (iOS 12.4) [dotnet]: Failed
  • introspection/iOS Unified 64-bits - simulator/Debug (iOS 12.4): Failed
  • introspection/tvOS - simulator/Debug (tvOS 12.4) [dotnet]: Failed
  • introspection/tvOS - simulator/Debug (tvOS 12.4): Failed

Pipeline on Agent XAMBOT-1017.BigSur'
[ObjCRuntime] Add explicit conversion operators between NativeHandle and void*. Fixes #13867. (#13929)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 Tests failed catastrophically on VSTS: device tests tvOS (no summary found). 🔥

Result file D:\a\1\s\Reports\TestSummary-tvos\TestSummary.md not found.

Pipeline on Agent
[ObjCRuntime] Add explicit conversion operators between NativeHandle and void*. Fixes #13867. (#13929)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Tests failed on macOS Mac Catalina (10.15) ❌

Tests failed on Mac Catalina (10.15).

Failed tests are:

  • introspection

Pipeline on Agent
[ObjCRuntime] Add explicit conversion operators between NativeHandle and void*. Fixes #13867. (#13929)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Tests passed on macOS M1 - Mac Big Sur (11.5) ✅

Tests passed

All tests on macOS X M1 - Mac Big Sur (11.5) passed.

Pipeline on Agent
[ObjCRuntime] Add explicit conversion operators between NativeHandle and void*. Fixes #13867. (#13929)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 Tests failed catastrophically on VSTS: device tests iOS (no summary found). 🔥

Result file D:\a\1\s\Reports\TestSummary-iOS64\TestSummary.md not found.

Pipeline on Agent
[ObjCRuntime] Add explicit conversion operators between NativeHandle and void*. Fixes #13867. (#13929)

Please sign in to comment.