Skip to content

Commit

Permalink
Use collection expressions for UnmanagedCallConv.CallConvs (#97017)
Browse files Browse the repository at this point in the history
More succint syntax. Related to #96964
  • Loading branch information
jkotas authored Jan 16, 2024
1 parent afb0d69 commit 1c860e2
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ internal static void RhCollect(int generation, InternalGCCollectionMode mode, bo
}

[DllImport(Redhawk.BaseName)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
private static extern void RhpCollect(int generation, InternalGCCollectionMode mode, Interop.BOOL lowMemoryP);

[RuntimeExport("RhGetGcTotalMemory")]
Expand All @@ -76,7 +76,7 @@ internal static long RhGetGcTotalMemory()
}

[DllImport(Redhawk.BaseName)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
private static extern long RhpGetGcTotalMemory();

[RuntimeExport("RhStartNoGCRegion")]
Expand Down Expand Up @@ -278,28 +278,28 @@ internal static extern unsafe IntPtr RhpCallPropagateExceptionCallback(
// Block the current thread until at least one object needs to be finalized (returns true) or
// memory is low (returns false and the finalizer thread should initiate a garbage collection).
[DllImport(Redhawk.BaseName)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
internal static extern uint RhpWaitForFinalizerRequest();

// Indicate that the current round of finalizations is complete.
[DllImport(Redhawk.BaseName)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
internal static extern void RhpSignalFinalizationComplete(uint fCount);

[DllImport(Redhawk.BaseName)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
internal static extern ulong RhpGetTickCount64();

// Enters a no GC region, possibly doing a blocking GC if there is not enough
// memory available to satisfy the caller's request.
[DllImport(Redhawk.BaseName)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
internal static extern int RhpStartNoGCRegion(long totalSize, Interop.BOOL hasLohSize, long lohSize, Interop.BOOL disallowFullBlockingGC);

// Exits a no GC region, possibly doing a GC to clean up the garbage that
// the caller allocated.
[DllImport(Redhawk.BaseName)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
internal static extern int RhpEndNoGCRegion();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public static unsafe int RhGetCurrentThreadStackTrace(IntPtr[] outputBuffer)

#pragma warning disable SYSLIB1054 // Use DllImport here instead of LibraryImport because this file is used by Test.CoreLib.
[DllImport(Redhawk.BaseName)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
private static extern unsafe int RhpGetCurrentThreadStackTrace(IntPtr* pOutputBuffer, uint outputBufferLength, UIntPtr addressInCurrentFrame);
#pragma warning restore SYSLIB1054

Expand Down

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/libraries/Common/src/Interop/Interop.HostPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ internal delegate void corehost_resolve_component_dependencies_result_fn(IntPtr
#else
[LibraryImport(Libraries.HostPolicy, StringMarshalling = StringMarshalling.Utf8)]
#endif
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(System.Runtime.CompilerServices.CallConvCdecl)])]
internal static partial int corehost_resolve_component_dependencies(string componentMainAssemblyPath,
corehost_resolve_component_dependencies_result_fn result);

[LibraryImport(Libraries.HostPolicy)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(System.Runtime.CompilerServices.CallConvCdecl)])]
internal static partial IntPtr corehost_set_error_writer(IntPtr errorWriter);
#pragma warning restore CS3016 // Arrays as attribute arguments is not CLS-compliant
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,39 @@

using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

internal static partial class Interop
{
internal static unsafe partial class Ucrtbase
{
#pragma warning disable CS3016 // Arrays as attribute arguments is not CLS-compliant
[LibraryImport(Libraries.Ucrtbase)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
internal static partial void* _aligned_malloc(nuint size, nuint alignment);

[LibraryImport(Libraries.Ucrtbase)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
internal static partial void _aligned_free(void* ptr);

[LibraryImport(Libraries.Ucrtbase)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
internal static partial void* _aligned_realloc(void* ptr, nuint size, nuint alignment);

[LibraryImport(Libraries.Ucrtbase)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
internal static partial void* calloc(nuint num, nuint size);

[LibraryImport(Libraries.Ucrtbase)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
internal static partial void free(void* ptr);

[LibraryImport(Libraries.Ucrtbase)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
internal static partial void* malloc(nuint size);

[LibraryImport(Libraries.Ucrtbase)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
internal static partial void* realloc(void* ptr, nuint new_size);
#pragma warning restore CS3016 // Arrays as attribute arguments is not CLS-compliant
}
Expand Down
31 changes: 16 additions & 15 deletions src/libraries/Common/src/Interop/Windows/Wldap32/Interop.Ber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,71 @@

using System;
using System.DirectoryServices.Protocols;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Ldap
{
[LibraryImport(Libraries.Wldap32, EntryPoint = "ber_free", StringMarshalling = StringMarshalling.Utf16)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial IntPtr ber_free(IntPtr berelement, int option);

[LibraryImport(Libraries.Wldap32, EntryPoint = "ber_alloc_t", StringMarshalling = StringMarshalling.Utf16)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial IntPtr ber_alloc(int option);

[LibraryImport(Libraries.Wldap32, EntryPoint = "ber_printf", StringMarshalling = StringMarshalling.Utf16)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int ber_printf(SafeBerHandle berElement, string format, IntPtr value);

[LibraryImport(Libraries.Wldap32, EntryPoint = "ber_printf", StringMarshalling = StringMarshalling.Utf16)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int ber_printf(SafeBerHandle berElement, string format, HGlobalMemHandle value, uint length);

[LibraryImport(Libraries.Wldap32, EntryPoint = "ber_printf", StringMarshalling = StringMarshalling.Utf16)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int ber_printf(SafeBerHandle berElement, string format);

[LibraryImport(Libraries.Wldap32, EntryPoint = "ber_printf", StringMarshalling = StringMarshalling.Utf16)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int ber_printf(SafeBerHandle berElement, string format, int value);

[LibraryImport(Libraries.Wldap32, EntryPoint = "ber_printf", StringMarshalling = StringMarshalling.Utf16)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int ber_printf(SafeBerHandle berElement, string format, uint tag);

[LibraryImport(Libraries.Wldap32, EntryPoint = "ber_flatten", StringMarshalling = StringMarshalling.Utf16)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int ber_flatten(SafeBerHandle berElement, ref IntPtr value);

[LibraryImport(Libraries.Wldap32, EntryPoint = "ber_init", StringMarshalling = StringMarshalling.Utf16)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial IntPtr ber_init(BerVal value);

[LibraryImport(Libraries.Wldap32, EntryPoint = "ber_scanf", StringMarshalling = StringMarshalling.Utf16)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int ber_scanf(SafeBerHandle berElement, string format);

[LibraryImport(Libraries.Wldap32, EntryPoint = "ber_scanf", StringMarshalling = StringMarshalling.Utf16)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int ber_scanf(SafeBerHandle berElement, string format, ref IntPtr ptrResult, ref uint bitLength);

[LibraryImport(Libraries.Wldap32, EntryPoint = "ber_scanf", StringMarshalling = StringMarshalling.Utf16)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int ber_scanf(SafeBerHandle berElement, string format, ref int result);

[LibraryImport(Libraries.Wldap32, EntryPoint = "ber_scanf", StringMarshalling = StringMarshalling.Utf16)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int ber_scanf(SafeBerHandle berElement, string format, ref IntPtr value);

[LibraryImport(Libraries.Wldap32, EntryPoint = "ber_bvfree", StringMarshalling = StringMarshalling.Utf16)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int ber_bvfree(IntPtr value);

[LibraryImport(Libraries.Wldap32, EntryPoint = "ber_bvecfree", StringMarshalling = StringMarshalling.Utf16)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int ber_bvecfree(IntPtr value);
}
}
Loading

0 comments on commit 1c860e2

Please sign in to comment.