@@ -12,19 +12,27 @@ exception UnexpectedExternCallException of string
12
12
13
13
module DllManager =
14
14
15
+ type dllImportInfo =
16
+ {
17
+ dllName : string
18
+ entryPoint : string
19
+ }
20
+
15
21
let private dllImportAttribute = lazy AssemblyManager.NormalizeType( typeof< DllImportAttribute>)
16
22
17
23
let private getDllImportNameAndEntry ( attr : Attribute ) =
18
24
let dllNameField = dllImportAttribute.Value.GetField( " dllName" )
19
25
let entryPointField = dllImportAttribute.Value.GetField( " EntryPoint" )
20
- dllNameField.GetValue( attr) :?> string, entryPointField.GetValue( attr) :?> string
26
+ let dllName = dllNameField.GetValue( attr) :?> string
27
+ let entryPoint = entryPointField.GetValue( attr) :?> string
28
+ { dllName = dllName; entryPoint = entryPoint }
21
29
22
30
let parseDllImport ( m : MethodBase ) =
23
31
// Case for assembly, loaded via default load context (F# internal calls)
24
32
let findViaDefault ( attr : Attribute ) =
25
33
match attr with
26
34
| :? DllImportAttribute as attr ->
27
- Some ( attr.Value, attr.EntryPoint)
35
+ Some { dllName = attr.Value; entryPoint = attr.EntryPoint }
28
36
| _ -> None
29
37
30
38
// Case for assembly, loaded via VSharp load context (C# internal calls)
@@ -36,7 +44,7 @@ module DllManager =
36
44
37
45
let isQCall ( m : MethodBase ) =
38
46
match parseDllImport m with
39
- | Some( libName, _) -> libName.Equals( " QCall" )
47
+ | Some { dllName = libName } -> libName.Equals( " QCall" )
40
48
| None -> false
41
49
42
50
module ExtMocking =
@@ -168,11 +176,11 @@ module ExtMocking =
168
176
let methodToPatch = mockType.MockedMethod
169
177
let ptrFrom =
170
178
if Reflection.isExternalMethod methodToPatch then
171
- let libName , methodName =
179
+ let dllImportInfo =
172
180
match DllManager.parseDllImport methodToPatch with
173
181
| Some p -> p
174
182
| None -> internalfail " External method without DllImport attribute"
175
- ExternMocker.GetExternPtr( libName , methodName )
183
+ ExternMocker.GetExternPtr( dllImportInfo.dllName , dllImportInfo.entryPoint )
176
184
else
177
185
methodToPatch.MethodHandle.GetFunctionPointer()
178
186
0 commit comments