FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/src/runtime/nativecall.cs at master · AdsTable/pythonnet · GitHub
AdsTable
pythonnet
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet
/
src
/
runtime
/
nativecall.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
54 lines (47 loc) · 1.75 KB
Breadcrumbs
pythonnet
/
src
/
runtime
/
nativecall.cs
Copy path
File metadata and controls
54 lines (47 loc) · 1.75 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using
System
;
using
System
.
Reflection
;
using
System
.
Reflection
.
Emit
;
using
System
.
Runtime
.
InteropServices
;
using
System
.
Threading
;
namespace
Python
.
Runtime
{
/// <summary>
/// Provides support for calling native code indirectly through
/// function pointers. Most of the important parts of the Python
/// C API can just be wrapped with p/invoke, but there are some
/// situations (specifically, calling functions through Python
/// type structures) where we need to call functions indirectly.
/// </summary>
internal
class
NativeCall
{
[
UnmanagedFunctionPointer
(
CallingConvention
.
Cdecl
)
]
private
delegate
void
Void_1_Delegate
(
IntPtr
a1
)
;
[
UnmanagedFunctionPointer
(
CallingConvention
.
Cdecl
)
]
private
delegate
int
Int_3_Delegate
(
IntPtr
a1
,
IntPtr
a2
,
IntPtr
a3
)
;
public
static
void
Void_Call_1
(
IntPtr
fp
,
IntPtr
a1
)
{
var
d
=
GetDelegate
<
Interop
.
DestructorFunc
>
(
fp
)
;
d
(
a1
)
;
}
public
static
IntPtr
Call_3
(
IntPtr
fp
,
IntPtr
a1
,
IntPtr
a2
,
IntPtr
a3
)
{
var
d
=
GetDelegate
<
Interop
.
TernaryFunc
>
(
fp
)
;
return
d
(
a1
,
a2
,
a3
)
;
}
public
static
int
Int_Call_3
(
IntPtr
fp
,
IntPtr
a1
,
IntPtr
a2
,
IntPtr
a3
)
{
var
d
=
GetDelegate
<
Interop
.
ObjObjArgFunc
>
(
fp
)
;
return
d
(
a1
,
a2
,
a3
)
;
}
internal
static
T
GetDelegate
<
T
>
(
IntPtr
fp
)
where
T
:
Delegate
{
Delegate
d
=
null
;
if
(
!
Interop
.
allocatedThunks
.
TryGetValue
(
fp
,
out
d
)
)
{
// We don't cache this delegate because this is a pure delegate ot unmanaged.
d
=
Marshal
.
GetDelegateForFunctionPointer
<
T
>
(
fp
)
;
}
return
(
T
)
d
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL