Skip to content

Commit

Permalink
[src] Make a few P/Invokes stragglers have blittable signatures. (#20675
Browse files Browse the repository at this point in the history
)

Contributes towards #15684.
  • Loading branch information
rolfbjarne authored Jun 4, 2024
1 parent aa25b1e commit 05a9b08
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
13 changes: 10 additions & 3 deletions src/AudioUnit/AUGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ internal AUGraph (NativeHandle handle, bool owns)

static IntPtr Create ()
{
int err = NewAUGraph (out var handle);
IntPtr handle;
int err;
unsafe {
err = NewAUGraph (&handle);
}
if (err != 0)
throw new InvalidOperationException (String.Format ("Cannot create new AUGraph. Error code: {0}", err));
return handle;
Expand All @@ -101,7 +105,10 @@ public AUGraph ()

public static AUGraph? Create (out int errorCode)
{
errorCode = NewAUGraph (out var handle);
IntPtr handle;
unsafe {
errorCode = NewAUGraph (&handle);
}

if (errorCode != 0)
return null;
Expand Down Expand Up @@ -483,7 +490,7 @@ protected override void Dispose (bool disposing)
}

[DllImport (Constants.AudioToolboxLibrary, EntryPoint = "NewAUGraph")]
static extern int /* OSStatus */ NewAUGraph (out IntPtr outGraph);
unsafe static extern int /* OSStatus */ NewAUGraph (IntPtr* outGraph);

[DllImport (Constants.AudioToolboxLibrary, EntryPoint = "AUGraphOpen")]
static extern int /* OSStatus */ AUGraphOpen (IntPtr inGraph);
Expand Down
15 changes: 13 additions & 2 deletions src/ObjCRuntime/Selector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,21 @@ public static Selector Register (NativeHandle handle)
[DllImport (Messaging.LIBOBJC_DYLIB)]
extern static /* const char* */ IntPtr sel_getName (/* SEL */ IntPtr sel);

// objc/runtime.h
[DllImport (Messaging.LIBOBJC_DYLIB)]
extern static /* SEL */ IntPtr sel_registerName (/* const char* */ IntPtr name);

// objc/runtime.h
// Selector.GetHandle is optimized by the AOT compiler, and the current implementation only supports IntPtr, so we can't switch to NativeHandle quite yet (the AOT compiler crashes).
[DllImport (Messaging.LIBOBJC_DYLIB, EntryPoint = "sel_registerName")]
public extern static /* SEL */ IntPtr GetHandle (/* const char* */ string name);
public static IntPtr GetHandle (string name)
{
var ptr = Marshal.StringToHGlobalAnsi (name);
try {
return sel_registerName (ptr);
} finally {
Marshal.FreeHGlobal (ptr);
}
}

// objc/objc.h
[DllImport (Messaging.LIBOBJC_DYLIB)]
Expand Down
8 changes: 6 additions & 2 deletions src/Security/Certificate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ public bool VerifySignature (SecKeyAlgorithm algorithm, NSData signedData, NSDat
[SupportedOSPlatform ("maccatalyst")]
#endif
[DllImport (Constants.SecurityLibrary)]
static extern /* CFDataRef _Nullable */ IntPtr SecKeyCreateEncryptedData (/* SecKeyRef */ IntPtr key, /* SecKeyAlgorithm */ IntPtr algorithm, /* CFDataRef */ IntPtr plaintext, /* CFErrorRef* */ out IntPtr error);
unsafe static extern /* CFDataRef _Nullable */ IntPtr SecKeyCreateEncryptedData (/* SecKeyRef */ IntPtr key, /* SecKeyAlgorithm */ IntPtr algorithm, /* CFDataRef */ IntPtr plaintext, /* CFErrorRef* */ IntPtr* error);

#if NET
[SupportedOSPlatform ("tvos")]
Expand All @@ -1219,7 +1219,11 @@ public bool VerifySignature (SecKeyAlgorithm algorithm, NSData signedData, NSDat
if (plaintext is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (plaintext));

var data = SecKeyCreateEncryptedData (Handle, algorithm.GetConstant ().GetHandle (), plaintext.Handle, out var err);
IntPtr data;
IntPtr err;
unsafe {
data = SecKeyCreateEncryptedData (Handle, algorithm.GetConstant ().GetHandle (), plaintext.Handle, &err);
}
error = Runtime.GetNSObject<NSError> (err);
return Runtime.GetNSObject<NSData> (data, true);
}
Expand Down
3 changes: 0 additions & 3 deletions tests/cecil-tests/BlittablePInvokes.KnownFailures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ public partial class BlittablePInvokes {
"AVFoundation.AVSampleCursorSyncInfo ObjCRuntime.Messaging::AVSampleCursorSyncInfo_objc_msgSend(System.IntPtr,System.IntPtr)",
"AVFoundation.AVSampleCursorSyncInfo ObjCRuntime.Messaging::AVSampleCursorSyncInfo_objc_msgSendSuper_stret(System.IntPtr,System.IntPtr)",
"AVFoundation.AVSampleCursorSyncInfo ObjCRuntime.Messaging::AVSampleCursorSyncInfo_objc_msgSendSuper(System.IntPtr,System.IntPtr)",
"System.Int32 AudioUnit.AUGraph::NewAUGraph(System.IntPtr&)",
"System.IntPtr ObjCRuntime.Selector::GetHandle(System.String)",
"System.IntPtr Security.SecKey::SecKeyCreateEncryptedData(System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr&)",
"System.Void ObjCRuntime.Messaging::void_objc_msgSend_GCDualSenseAdaptiveTriggerPositionalAmplitudes_float(System.IntPtr,System.IntPtr,GameController.GCDualSenseAdaptiveTriggerPositionalAmplitudes,System.Single)",
"System.Void ObjCRuntime.Messaging::void_objc_msgSend_GCDualSenseAdaptiveTriggerPositionalResistiveStrengths(System.IntPtr,System.IntPtr,GameController.GCDualSenseAdaptiveTriggerPositionalResistiveStrengths)",
"System.Void ObjCRuntime.Messaging::void_objc_msgSendSuper_GCDualSenseAdaptiveTriggerPositionalAmplitudes_float(System.IntPtr,System.IntPtr,GameController.GCDualSenseAdaptiveTriggerPositionalAmplitudes,System.Single)",
Expand Down

12 comments on commit 05a9b08

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.