Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[coretext] Add nullability to (generated and manual) bindings #14978

Merged
merged 19 commits into from
Jun 15, 2022

Conversation

tj-devel709
Copy link
Contributor

This PR aims to bring nullability changes to CoreText.
Following the steps here:

  1. I am adding nullable enable to all manual files that are not "API_SOURCES" in src/frameworks.sources and making the required nullability changes
  2. Changing all throw new ArgumentNullException ("object")); to ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (object)); for size saving optimization as well to mark that this framework contains nullability changes
  3. Changing any == null or != null to is null and is not null

I decided to mark the GetStringConstants that deal with handles with a ! since these GetX (handle) methods tend to be safe with nullability from previous PRs and there were already some files in CoreText following this pattern.
Dlfcn.GetStringConstant (handle, "kCTFontCopyrightNameKey")!;

@tj-devel709 tj-devel709 added the not-notes-worthy Ignore for release notes label May 10, 2022
@tj-devel709 tj-devel709 added this to the Future milestone May 10, 2022
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

src/CoreText/CTBaselineClass.cs Outdated Show resolved Hide resolved
src/CoreText/CTFontManager.cs Outdated Show resolved Hide resolved
src/CoreText/CTFontNameKey.cs Outdated Show resolved Hide resolved
src/CoreText/CTFontTrait.cs Outdated Show resolved Hide resolved
src/CoreText/CTStringAttributes.cs Outdated Show resolved Hide resolved
src/CoreText/ConstructorError.cs Outdated Show resolved Hide resolved
src/CoreText/ConstructorError.cs Outdated Show resolved Hide resolved
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@tj-devel709
Copy link
Contributor Author

tj-devel709 commented May 11, 2022

@rolfbjarne before I go through all the files and make these changes, I wanted to confirm that I am on the right track with this file? https://gist.github.com/tj-devel709/1ad14fd0c52616dd2bd684c07c57ca6a

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

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

Pipeline on Agent XAMBOT-1044.Monterey
Merge 094b3f0 into 22ba05b

@rolfbjarne
Copy link
Member

@rolfbjarne before I go through all the files and make these changes, I wanted to confirm that I am on the right track with this file? gist.github.com/tj-devel709/1ad14fd0c52616dd2bd684c07c57ca6a

Yes, that's on the right track!

I think you can simplify things a bit though:

  1. Make Adapter.GetStringValue return null if the key is null. This should avoid changing numerous getters.
  2. Make Adapter.SetValue throw ArgumentOutOfRangeException if the key is null. This should avoid changing numerous setters.
  3. Maybe add an Adapter.GetObjectValue that checks for null key (and returns null) before getting the entry in the dictionary, this would simplify some getters that don't already call into the Adapter class.
  4. You can't make a struct return type nullable (it's a breaking change) - for lines 465-483 in your diff. That should just return false if there's no entry in the dictionary.

@tj-devel709
Copy link
Contributor Author

@rolfbjarne for the first two suggestions, if I instead add the null checks in the Adapter.GetStringValue and Adapter.SetValue methods, I believe I will need to either change those signatures to say that key can be null and then throw an exception when it is null (which I think is probably not the right way) or put an exclamation for the key argument when calling those methods. Were either of these options what you were intending?

@rolfbjarne
Copy link
Member

rolfbjarne commented May 13, 2022

@tj-devel709 for the first suggestion, you can change the Adapter.GetStringValue to accept a null key (in which case you can return null).

For the second suggestion, I'd put an exclamation on all the callsites to Adapter.SetValue

It's a bit weird that the Get and Set methods have different semantics, but these are internal methods, so it doesn't matter all that much.

@tj-devel709 tj-devel709 added the do-not-merge Do not merge this pull request label May 16, 2022
@tj-devel709
Copy link
Contributor Author

Apologies, did not mean to push yet, not ready to be merged!

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@tj-devel709 tj-devel709 removed the do-not-merge Do not merge this pull request label May 17, 2022
@tj-devel709
Copy link
Contributor Author

@rolfbjarne I think I made all the changes. I wasn't quite sure of where to do the following however:

3. Maybe add an Adapter.GetObjectValue that checks for null key (and returns null) before getting the entry in the dictionary, this would simplify some getters that don't already call into the Adapter class.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

Legacy Xamarin (No breaking changes)
.NET (No breaking changes)

❗ API diff vs stable (Breaking changes)

Legacy Xamarin (No breaking changes)
.NET (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • iOS: vsdrops gist (No breaking changes)
  • tvOS: vsdrops gist (No breaking changes)
  • MacCatalyst: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • macOS: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • Microsoft.iOS vs Microsoft.MacCatalyst: vsdrops gist
Legacy Xamarin (stable) vs .NET

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: eb544046d6de1103f2efadc6a02913a6fa063a19 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

Legacy Xamarin (No breaking changes)
  • iOS (no change detected)
  • tvOS (no change detected)
  • watchOS (no change detected)
  • macOS (no change detected)
NET (empty diffs)
  • iOS: (empty diff detected)
  • tvOS: (empty diff detected)
  • MacCatalyst: (empty diff detected)
  • macOS: (empty diff detected)

✅ API diff vs stable

Legacy Xamarin (No breaking changes)
.NET (No breaking changes)
Legacy Xamarin (stable) vs .NET

✅ Generator diff

Generator diff is empty

Pipeline on Agent
Hash: 5f199c3f6de52106fd6cfaf39a8e12024505c313 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

❌ [PR Build] Tests on macOS M1 - Mac Big Sur (11.5) failed ❌

Tests on macOS M1 - Mac Big Sur (11.5) failed for unknown reasons.

Pipeline on Agent
Hash: 1726846e601c57c879d6bd797607f291beb5edf9 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

Legacy Xamarin (No breaking changes)
  • iOS (no change detected)
  • tvOS (no change detected)
  • watchOS (no change detected)
  • macOS (no change detected)
NET (empty diffs)
  • iOS: (empty diff detected)
  • tvOS: (empty diff detected)
  • MacCatalyst: (empty diff detected)
  • macOS: (empty diff detected)

✅ API diff vs stable

Legacy Xamarin (No breaking changes)
.NET (No breaking changes)
Legacy Xamarin (stable) vs .NET

✅ Generator diff

Generator diff is empty

Pipeline on Agent
Hash: 1726846e601c57c879d6bd797607f291beb5edf9 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [PR Build] Tests on macOS Mac Catalina (10.15) passed 💻

All tests on macOS Mac Catalina (10.15) passed.

Pipeline on Agent
Hash: 1726846e601c57c879d6bd797607f291beb5edf9 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

📚 [PR Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent XAMBOT-1103.Monterey'
Hash: 1726846e601c57c879d6bd797607f291beb5edf9 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build] Tests passed on VSTS: simulator tests iOS. ✅

Tests passed on VSTS: simulator tests iOS.

🎉 All 148 tests passed 🎉

Pipeline on Agent XAMBOT-1108.Monterey'
Merge 1726846 into f2d0a16

@tj-devel709 tj-devel709 merged commit 3e6fdd8 into xamarin:main Jun 15, 2022
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants