Skip to content

Commit 30ebddd

Browse files
authored
Add support to process pointer parameters (#220)
1 parent 23df405 commit 30ebddd

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

MetadataProcessor.Shared/Utility/NativeMethodsCrc.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,18 @@ internal static string GetNanoCLRTypeName(TypeReference parameterType)
191191
// check if it's generic
192192
return "DATATYPE_GENERICTYPE";
193193
}
194-
else
194+
else if(parameterType.IsPointer)
195195
{
196-
// this is not a generic, get full qualified type name
197-
string typeName = parameterType.FullName.Replace(".", String.Empty);
198-
199-
return CleanupGenericName(typeName);
196+
if (nanoSignaturesTable.PrimitiveTypes.TryGetValue(parameterType.GetElementType().FullName, out myType))
197+
{
198+
return $"{myType}ptr";
199+
}
200200
}
201+
202+
// last attempt: get full qualified type name
203+
string typeName = parameterType.FullName.Replace(".", string.Empty);
204+
205+
return CleanupGenericName(typeName);
201206
}
202207
}
203208

MetadataProcessor.Tests/StubsGenerationTestNFApp/NativeMethodGeneration.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@ public void Method()
2727

2828
[MethodImpl(MethodImplOptions.InternalCall)]
2929
private static extern byte NativeStaticMethodReturningByte(char charParam);
30+
31+
[MethodImpl(MethodImplOptions.InternalCall)]
32+
public extern unsafe void MethodWithPointerParm(void* pointer, int length);
3033
}
31-
}
34+
}

MetadataProcessor.Tests/StubsGenerationTestNFApp/StubsGenerationTestNFApp.nfproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<RootNamespace>StubsGenerationTestNFApp</RootNamespace>
1616
<AssemblyName>StubsGenerationTestNFApp</AssemblyName>
1717
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
18+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1819
</PropertyGroup>
1920
<PropertyGroup Label="nanoFramework">
2021
<NFMDP_GENERATE_STUBS>True</NFMDP_GENERATE_STUBS>
@@ -35,4 +36,4 @@
3536
<ProjectConfigurationsDeclaredAsItems />
3637
</ProjectCapabilities>
3738
</ProjectExtensions>
38-
</Project>
39+
</Project>

0 commit comments

Comments
 (0)