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

[Rgen] Add the needed code to make the objc_msgSend signatures. #22029

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

mandel-macaque
Copy link
Member

@mandel-macaque mandel-macaque commented Jan 23, 2025

Add the code that will calculate the signature needed in the objc_msgSend which will be the method that calls the native objc message.

Extra context

When we create a binding for a native type we need to be able to send 'messages' to the objc objects. From a C# developer perspective a message can be considered a method. So for example, the following objc code:

[object foo:bar];

Can be translated to:

objc_msgSend(object, sel_getUid("foo:"), bar);

We can say this process is similar to reflection and the Invoke method. Our bindings provide methods around objc_msgsend which we use to send the messaged with the arguments needed by the message. For example, a property with a NSString backing fields defined as:

[Export ("text")]
public string? Text { get; set; }

Results in the following generated code:

[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
public virtual string? Text {
	[Export ("text")]
	get {
		global::UIKit.UIApplication.EnsureUIThread ();
		if (IsDirectBinding) {
			return CFString.FromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSend (this.Handle, Selector.GetHandle ("text")), false)!;
		} else {
			return CFString.FromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSendSuper (this.SuperHandle, Selector.GetHandle ("text")), false)!;
		}
	}
	[Export ("setText:")]
	set {
		global::UIKit.UIApplication.EnsureUIThread ();
		var nsvalue = CFString.CreateNative (value);
		if (IsDirectBinding) {
			global::ObjCRuntime.Messaging.void_objc_msgSend_NativeHandle (this.Handle, Selector.GetHandle ("setText:"), nsvalue);
		} else {
			global::ObjCRuntime.Messaging.void_objc_msgSendSuper_NativeHandle (this.SuperHandle, Selector.GetHandle ("setText:"), nsvalue);
		}
		CFString.ReleaseNative (nsvalue);
	}
}

Our objc_msgSend method signatures are calculated based on the method parameters and live in the runtime. These objc_msgSend calls are generated by https://github.com/xamarin/xamarin-macios/blob/main/runtime/bindings-generator.cs#L20 For example a objc_msgSend signature for a method that takes a string and returns a string would be:

IntPtr_objc_msgSend_IntPtr

But this is a simplifications because there is a diff between sending a message to a super class (prefix super) or if it deals with a structure (stret).

More info can be found in the Apple documentation.

mandel-macaque and others added 2 commits January 22, 2025 19:26
Add the code that will calculate the signature needed in the
objc_msgSend which will be the method that calls the native objc
message.
Copy link
Contributor

⚠️ Your code has been reformatted. ⚠️

If this is not desired, add the actions-disable-autoformat label, and revert the reformatting commit.

If files unrelated to your change were modified, try reverting the reformatting commit + merging with the target branch (and push those changes).

@mandel-macaque mandel-macaque added the actions-disable-autoformat Disable autoformatting C# code according to our style guidelines label Jan 23, 2025
Copy link
Contributor

⚠️ Your code has been reformatted. ⚠️

If this is not desired, add the actions-disable-autoformat label, and revert the reformatting commit.

If files unrelated to your change were modified, try reverting the reformatting commit + merging with the target branch (and push those changes).

@mandel-macaque mandel-macaque force-pushed the dev/mandel/objc_msgSend_factory branch from 2a80edc to 6ad32da Compare January 23, 2025 01:11
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 5 out of 18 changed files in this pull request and generated 6 comments.

Files not reviewed (13)
  • src/rgen/Microsoft.Macios.Transformer/Microsoft.Macios.Transformer.csproj: Language not supported
  • src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Generator/DataModel/TypeInfoComparer.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Generator/Formatters/TypeInfoFormatter.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Generator/DataModel/TypeInfo.Generator.cs: Evaluated as low risk
  • tests/rgen/Microsoft.Macios.Generator.Tests/TestDataFactory.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.Dlfcn.cs: Evaluated as low risk
  • tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/TypeInfoComparerTests.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Generator/Formatters/ParameterFormatter.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Generator/DataModel/Property.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Generator/DataModel/TypeInfo.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Generator/Extensions/SpecialTypeExtensions.cs: Evaluated as low risk
  • tests/rgen/Microsoft.Macios.Generator.Tests/Emitters/GetObjCMessageSendMethodNameTests.cs: Evaluated as low risk

Copy link
Contributor

⚠️ Your code has been reformatted. ⚠️

If this is not desired, add the actions-disable-autoformat label, and revert the reformatting commit.

If files unrelated to your change were modified, try reverting the reformatting commit + merging with the target branch (and push those changes).

@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

✅ [PR Build] Build passed (Build packages) ✅

Pipeline on Agent
Hash: d6c77b130249f1d853597ddac8b34dfd68be505b [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [PR Build] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: d6c77b130249f1d853597ddac8b34dfd68be505b [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

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

✅ [PR Build] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 66016ce903d102c9c05b02a33da2c9d511f16d9c [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

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

.NET ( No breaking changes )

❗ API diff vs stable (Breaking changes)

.NET ( ❗ Breaking changes ❗ )

ℹ️ Generator diff

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

Pipeline on Agent
Hash: d6c77b130249f1d853597ddac8b34dfd68be505b [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [PR Build] Tests on macOS M1 - Mac Monterey (12) passed 💻

All tests on macOS M1 - Mac Monterey (12) passed.

Pipeline on Agent
Hash: 66016ce903d102c9c05b02a33da2c9d511f16d9c [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build] Windows Integration Tests passed 💻

All Windows Integration Tests passed.

Pipeline on Agent
Hash: db167d5914806bf3615c3e4e23f41919bf3e1222 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [PR Build] Tests on macOS X64 - Mac Sonoma (14) passed 💻

All tests on macOS X64 - Mac Sonoma (14) passed.

Pipeline on Agent
Hash: 66016ce903d102c9c05b02a33da2c9d511f16d9c [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [PR Build] Tests on macOS arm64 - Mac Sequoia (15) passed 💻

All tests on macOS arm64 - Mac Sequoia (15) passed.

Pipeline on Agent
Hash: 66016ce903d102c9c05b02a33da2c9d511f16d9c [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [PR Build] Tests on macOS M1 - Mac Ventura (13) passed 💻

All tests on macOS M1 - Mac Ventura (13) passed.

Pipeline on Agent
Hash: 66016ce903d102c9c05b02a33da2c9d511f16d9c [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🔥 [CI Build] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

0 tests crashed, 2 tests failed, 113 tests passed.

Failures

❌ generator tests

1 tests failed, 4 tests passed.
  • Roslyn Generator tests: Failed (Execution failed with exit code 1)

Html Report (VSDrops) Download

❌ monotouch tests (macOS)

1 tests failed, 11 tests passed.
  • monotouch-test/macOS/Debug (ARM64): Failed (Test run failed.
    Tests run: 3107 Passed: 2886 Inconclusive: 4 Failed: 1 Ignored: 220)

Html Report (VSDrops) Download

Successes

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 8 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 8 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 15a79c6e8813d7483bda6fb83fe0ca4ee8a4e0a7 [PR build]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actions-disable-autoformat Disable autoformatting C# code according to our style guidelines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants