Skip to content

[src] Remove System.nint and System.nuint from .NET. Fixes #10508.#13490

Merged
rolfbjarne merged 8 commits intodotnet:mainfrom
rolfbjarne:nativehandle+nint
Dec 7, 2021
Merged

[src] Remove System.nint and System.nuint from .NET. Fixes #10508.#13490
rolfbjarne merged 8 commits intodotnet:mainfrom
rolfbjarne:nativehandle+nint

Conversation

@rolfbjarne
Copy link
Member

  • Remove System.nint and System.nuint from .NET
  • Add support for C#'s nint/nuint types to the generator.
  • Accept IntPtr/UIntPtr as target types for BindAs attributes for NSNumber conversions.
  • Fix a few APIs to take/return NativeHandle instead of IntPtr.

Fixes #10508.

This PR is probably best reviewed commit-by-commit.

…custom System.nint/System.nuint.

Unfortunately "using X = nint;" doesn't work, so we'll have to use the underlying
type for nint instead in the using statement.
…Ptr parameters in .NET.

In legacy Xamarin, the following code would create an NSNumber:

    NSObject.FromObject ((nint) 123);

and this would create an NSValue:

    NSObject.FromObject ((IntPtr) 123);

In .NET, these two types are the same, so we can't distinguish between them. However, we now have ObjCRuntime.NativeHandle that represents handles, and we're already returning an NSValue for that case:

    NSObject.FromObject ((NativeHandle) (IntPtr) 123);

which means that we can make both of these cases return an NSNumber (for .NET):

    NSObject.FromObject ((nint) 123);
    NSObject.FromObject ((IntPtr) 123);

Fixes this test failure:

    MonoTouchFixtures.Foundation.NSObjectTest
     [FAIL] FromObject_NativeTypes : System.InvalidCastException : Unable to cast object of type 'Foundation.NSValue' to type 'Foundation.NSNumber'.
            at MonoTouchFixtures.Foundation.NSObjectTest.FromObject_NativeTypes() in xamarin-macios/tests/monotouch-test/Foundation/ObjectTest.cs:line 111

which happens with this code:

    var nativeint = (NSNumber) NSObject.FromObject ((nint)(-42));
@rolfbjarne rolfbjarne added not-notes-worthy Ignore for release notes run-dotnet-tests Run all the .NET tests labels Dec 3, 2021
@vs-mobiletools-engineering-service2
Copy link
Collaborator

❌ [PR Build] Tests failed on Build ❌

Tests failed on Build.

API & Generator diff

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

GitHub pages

Results can be found in the following github pages (it might take some time to publish):

Test results

3 tests failed, 134 tests passed.

Failed tests

  • monotouch-test/Mac Catalyst [dotnet]/Debug [dotnet]: Failed (Test run failed.
    Tests run: 2730 Passed: 2502 Inconclusive: 38 Failed: 2 Ignored: 226)
  • Xtro/.NET: BuildFailure
  • Cecil-based tests/NUnit: Failed (Execution failed with exit code 4)

Pipeline on Agent XAMBOT-1101.BigSur'
Merge 867fd0a into 41e700e

@vs-mobiletools-engineering-service2
Copy link
Collaborator

❌ [PR 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 & Generator diff

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

GitHub pages

Results can be found in the following github pages (it might take some time to publish):

Test results

2 tests failed, 135 tests passed.

Failed tests

  • monotouch-test/Mac [dotnet]/Debug (static registrar) [dotnet]: BuildFailure
  • link sdk/Mac Catalyst [dotnet]/Debug [dotnet]: TimedOut (Execution timed out after 1200 seconds.
    No test log file was produced)

Pipeline on Agent XAMBOT-1094.BigSur'
Merge d7d2409 into d238379

@rolfbjarne
Copy link
Member Author

Test failures are unrelated

@rolfbjarne rolfbjarne merged commit 90b8e89 into dotnet:main Dec 7, 2021
@rolfbjarne rolfbjarne deleted the nativehandle+nint branch December 7, 2021 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

not-notes-worthy Ignore for release notes run-dotnet-tests Run all the .NET tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deprecate and remove Xamarin types which conflict with predefined .NET types

5 participants