FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/src/runtime/native/ABI.cs at master · saroad2/pythonnet · GitHub
saroad2
pythonnet
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet
/
src
/
runtime
/
native
/
ABI.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
52 lines (46 loc) · 2.25 KB
Breadcrumbs
pythonnet
/
src
/
runtime
/
native
/
ABI.cs
Copy path
File metadata and controls
52 lines (46 loc) · 2.25 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
namespace
Python
.
Runtime
.
Native
{
using
System
;
using
System
.
Globalization
;
using
System
.
Linq
;
using
System
.
Reflection
;
static
class
ABI
{
public
static
int
RefCountOffset
{
get
;
}
=
GetRefCountOffset
(
)
;
public
static
int
ObjectHeadOffset
=>
RefCountOffset
;
internal
static
void
Initialize
(
Version
version
,
BorrowedReference
pyType
)
{
string
offsetsClassSuffix
=
string
.
Format
(
CultureInfo
.
InvariantCulture
,
"{0}{1}"
,
version
.
Major
,
version
.
Minor
)
;
var
thisAssembly
=
Assembly
.
GetExecutingAssembly
(
)
;
const
string
nativeTypeOffsetClassName
=
"Python.Runtime.NativeTypeOffset"
;
string
className
=
"Python.Runtime.TypeOffset"
+
offsetsClassSuffix
;
Type
nativeOffsetsClass
=
thisAssembly
.
GetType
(
nativeTypeOffsetClassName
,
throwOnError
:
false
)
;
Type
typeOffsetsClass
=
// Try platform native offsets first. It is only present when generated by setup.py
nativeOffsetsClass
??
thisAssembly
.
GetType
(
className
,
throwOnError
:
false
)
;
if
(
typeOffsetsClass
is
null
)
{
var
types
=
thisAssembly
.
GetTypes
(
)
.
Select
(
type
=>
type
.
Name
)
.
Where
(
name
=>
name
.
StartsWith
(
"TypeOffset"
)
)
;
string
message
=
$
"Searching for
{
className
}
, found
{
string
.
Join
(
","
,
types
)
}
."
;
throw
new
NotSupportedException
(
$
"Python ABI v
{
version
}
is not supported:
{
message
}
"
)
;
}
var
typeOffsets
=
(
ITypeOffsets
)
Activator
.
CreateInstance
(
typeOffsetsClass
)
;
TypeOffset
.
Use
(
typeOffsets
,
nativeOffsetsClass
==
null
?
ObjectHeadOffset
:
0
)
;
}
static
unsafe
int
GetRefCountOffset
(
)
{
IntPtr
tempObject
=
Runtime
.
PyList_New
(
0
)
;
IntPtr
*
tempPtr
=
(
IntPtr
*
)
tempObject
;
int
offset
=
0
;
while
(
tempPtr
[
offset
]
!=
(
IntPtr
)
1
)
{
offset
++
;
if
(
offset
>
100
)
throw
new
InvalidProgramException
(
"PyObject_HEAD could not be found withing reasonable distance from the start of PyObject"
)
;
}
Runtime
.
XDecref
(
tempObject
)
;
return
offset
*
IntPtr
.
Size
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL