Skip to content

Commit

Permalink
Port unit test logic to C++
Browse files Browse the repository at this point in the history
Add DNCP submodule
Remove built-in COM interop .NET APIs.
  • Loading branch information
AaronRobinsonMSFT committed Jan 29, 2023
1 parent ddf5099 commit c0b50ab
Show file tree
Hide file tree
Showing 16 changed files with 1,908 additions and 2,000 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "external/dncp"]
path = external/dncp
url = https://github.com/AaronRobinsonMSFT/dncp
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ set(CMAKE_INSTALL_PREFIX ./)

add_subdirectory(src/)
add_subdirectory(test/)
add_subdirectory(external/dncp)
1 change: 1 addition & 0 deletions external/dncp
Submodule dncp added at f47da3
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

## Build

> `git submodule init`
> `cmake -S . -B artifacts`
> `cmake --build artifacts --target install`
Expand Down
14 changes: 12 additions & 2 deletions src/interfaces/metadataimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1006,9 +1006,7 @@ HRESULT STDMETHODCALLTYPE MetadataImportRO::FindMember(
{
HRESULT hr = FindMethod(td, szName, pvSigBlob, cbSigBlob, (mdMethodDef*)pmb);
if (hr == CLDB_E_RECORD_NOTFOUND)
{
hr = FindField(td, szName, pvSigBlob, cbSigBlob, (mdFieldDef*)pmb);
}
return hr;
}

Expand Down Expand Up @@ -1150,6 +1148,18 @@ HRESULT STDMETHODCALLTYPE MetadataImportRO::FindMemberRef(
ULONG cbSigBlob,
mdMemberRef* pmr)
{
if (TypeFromToken(td) != mdtTypeRef
&& TypeFromToken(td) != mdtMethodDef
&& TypeFromToken(td) != mdtModuleRef
&& TypeFromToken(td) != mdtTypeDef
&& TypeFromToken(td) != mdtTypeSpec)
{
return E_INVALIDARG;
}

if (szName == nullptr || pmr == nullptr)
return CLDB_E_RECORD_NOTFOUND;

if (IsNilToken(td))
td = MD_GLOBAL_PARENT_TOKEN;

Expand Down
44 changes: 3 additions & 41 deletions test/Common/Dispensers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ namespace Common
{
internal static class Dispensers
{
/// <summary>
/// Get the baseline IMetaDataDispenser implementation.
/// </summary>
public static IMetaDataDispenser Baseline { get; } = GetBaseline();

/// <summary>
/// Get the baseline IMetaDataDispenser implementation as a pointer.
/// </summary>
public static nint BaselineRaw { get; } = GetBaselineRaw();
public static nint Baseline { get; } = GetBaselineRaw();

/// <summary>
/// Directory for NET Framework 2.0
Expand All @@ -31,11 +26,6 @@ internal static class Dispensers
[SupportedOSPlatform("windows")]
public static string NetFx40Dir { get; } = GetNetFx40Install();

/// <summary>
/// Get the current IMetaDataDispenser implementation.
/// </summary>
public static IMetaDataDispenser Current { get; } = GetCurrent();

private static unsafe nint GetBaselineRaw()
{
#if NETFX_20_BASELINE
Expand All @@ -54,8 +44,8 @@ private static unsafe nint GetBaselineRaw()
nint mod = NativeLibrary.Load(baseline);
var getter = (delegate* unmanaged<in Guid, in Guid, out nint, int>)NativeLibrary.GetExport(mod, "MetaDataGetDispenser");

Guid clsid = new("E5CB7A31-7512-11D2-89CE-0080C792E5D8");
Guid iid = typeof(IMetaDataDispenser).GUID;
Guid clsid = new("E5CB7A31-7512-11D2-89CE-0080C792E5D8"); //CLSID_CorMetaDataDispenserRuntime
Guid iid = new("809C652E-7396-11D2-9771-00A0C9B4D50C"); // IID_IMetaDataDispenser
int result = getter(in clsid, in iid, out nint dispenser);
if (result < 0)
{
Expand All @@ -65,34 +55,6 @@ private static unsafe nint GetBaselineRaw()
return dispenser;
}

private static unsafe IMetaDataDispenser GetBaseline()
{
nint ptr = GetBaselineRaw();
var dispenser = (IMetaDataDispenser)Marshal.GetObjectForIUnknown(ptr);
_ = Marshal.Release(ptr);
return dispenser;
}

private static unsafe IMetaDataDispenser GetCurrent()
{
var runtimeName =
OperatingSystem.IsWindows() ? "dnmd_interfaces.dll"
: OperatingSystem.IsMacOS() ? "libdnmd_interfaces.dylib"
: "libdnmd_interfaces.so";

nint mod = NativeLibrary.Load(runtimeName);
var getter = (delegate* unmanaged<in Guid, out IMetaDataDispenser, int>)NativeLibrary.GetExport(mod, "GetDispenser");

Guid iid = typeof(IMetaDataDispenser).GUID;
int result = getter(in iid, out IMetaDataDispenser dispenser);
if (result < 0)
{
Marshal.ThrowExceptionForHR(result);
}

return dispenser;
}

[SupportedOSPlatform("windows")]
private static string GetNetFx20Install()
{
Expand Down
33 changes: 0 additions & 33 deletions test/Common/IMetaDataDispenser.cs

This file was deleted.

228 changes: 0 additions & 228 deletions test/Common/IMetaDataImport2.cs

This file was deleted.

Loading

0 comments on commit c0b50ab

Please sign in to comment.