FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet-rawsvnmig/pythonnet/src/runtime/classbase.cs at master · pythonnet/pythonnet-rawsvnmig · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on Jun 4, 2019. It is now read-only.
pythonnet
/
pythonnet-rawsvnmig
Public archive
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet-rawsvnmig
/
pythonnet
/
src
/
runtime
/
classbase.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
170 lines (132 loc) · 6.11 KB
Breadcrumbs
pythonnet-rawsvnmig
/
pythonnet
/
src
/
runtime
/
classbase.cs
Copy path
File metadata and controls
170 lines (132 loc) · 6.11 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// ==========================================================================
// This software is subject to the provisions of the Zope Public License,
// Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
// THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
// WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
// FOR A PARTICULAR PURPOSE.
// ==========================================================================
using
System
;
using
System
.
Collections
;
using
System
.
Reflection
;
using
System
.
Security
;
using
System
.
Runtime
.
InteropServices
;
namespace
Python
.
Runtime
{
/// <summary>
/// Base class for Python types that reflect managed types / classes.
/// Concrete subclasses include ClassObject and DelegateObject. This
/// class provides common attributes and common machinery for doing
/// class initialization (initialization of the class __dict__). The
/// concrete subclasses provide slot implementations appropriate for
/// each variety of reflected type.
/// </summary>
internal
class
ClassBase
:
ManagedType
{
internal
Indexer
indexer
;
internal
Type
type
;
internal
ClassBase
(
Type
tp
)
:
base
(
)
{
indexer
=
null
;
type
=
tp
;
}
internal
virtual
bool
CanSubclass
(
)
{
return
(
!
this
.
type
.
IsEnum
)
;
}
//====================================================================
// Implements __init__ for reflected classes and value types.
//====================================================================
public
static
int
tp_init
(
IntPtr
ob
,
IntPtr
args
,
IntPtr
kw
)
{
return
0
;
}
//====================================================================
// Default implementation of [] semantics for reflected types.
//====================================================================
public
virtual
IntPtr
type_subscript
(
IntPtr
idx
)
{
return
Exceptions
.
RaiseTypeError
(
"unsubscriptable object"
)
;
}
//====================================================================
// Standard comparison implementation for instances of reflected types.
//====================================================================
public
static
int
tp_compare
(
IntPtr
ob
,
IntPtr
other
)
{
if
(
ob
==
other
)
{
return
0
;
}
CLRObject
co1
=
GetManagedObject
(
ob
)
as
CLRObject
;
CLRObject
co2
=
GetManagedObject
(
other
)
as
CLRObject
;
Object
o1
=
co1
.
inst
;
Object
o2
=
co2
.
inst
;
if
(
Object
.
Equals
(
o1
,
o2
)
)
{
return
0
;
}
return
-
1
;
}
//====================================================================
// Standard iteration support for instances of reflected types. This
// allows natural iteration over objects that either are IEnumerable
// or themselves support IEnumerator directly.
//====================================================================
public
static
IntPtr
tp_iter
(
IntPtr
ob
)
{
CLRObject
co
=
GetManagedObject
(
ob
)
as
CLRObject
;
if
(
co
==
null
)
{
return
Exceptions
.
RaiseTypeError
(
"invalid object"
)
;
}
IEnumerable
e
=
co
.
inst
as
IEnumerable
;
IEnumerator
o
;
if
(
e
!=
null
)
{
o
=
e
.
GetEnumerator
(
)
;
}
else
{
o
=
co
.
inst
as
IEnumerator
;
if
(
o
==
null
)
{
string
message
=
"iteration over non-sequence"
;
return
Exceptions
.
RaiseTypeError
(
message
)
;
}
}
return
new
Iterator
(
o
)
.
pyHandle
;
}
//====================================================================
// Standard __hash__ implementation for instances of reflected types.
//====================================================================
public
static
IntPtr
tp_hash
(
IntPtr
ob
)
{
CLRObject
co
=
GetManagedObject
(
ob
)
as
CLRObject
;
if
(
co
==
null
)
{
return
Exceptions
.
RaiseTypeError
(
"unhashable type"
)
;
}
return
new
IntPtr
(
co
.
inst
.
GetHashCode
(
)
)
;
}
//====================================================================
// Standard __str__ implementation for instances of reflected types.
//====================================================================
public
static
IntPtr
tp_str
(
IntPtr
ob
)
{
CLRObject
co
=
GetManagedObject
(
ob
)
as
CLRObject
;
if
(
co
==
null
)
{
return
Exceptions
.
RaiseTypeError
(
"invalid object"
)
;
}
return
Runtime
.
PyString_FromString
(
co
.
inst
.
ToString
(
)
)
;
}
//====================================================================
// Default implementations for required Python GC support.
//====================================================================
public
static
int
tp_traverse
(
IntPtr
ob
,
IntPtr
func
,
IntPtr
args
)
{
return
0
;
}
public
static
int
tp_clear
(
IntPtr
ob
)
{
return
0
;
}
public
static
int
tp_is_gc
(
IntPtr
type
)
{
return
1
;
}
//====================================================================
// Standard dealloc implementation for instances of reflected types.
//====================================================================
public
static
void
tp_dealloc
(
IntPtr
ob
)
{
ManagedType
self
=
GetManagedObject
(
ob
)
;
IntPtr
dict
=
Marshal
.
ReadIntPtr
(
ob
,
ObjectOffset
.
ob_dict
)
;
if
(
dict
!=
IntPtr
.
Zero
)
{
Runtime
.
Decref
(
dict
)
;
}
Runtime
.
PyObject_GC_UnTrack
(
self
.
pyHandle
)
;
Runtime
.
PyObject_GC_Del
(
self
.
pyHandle
)
;
Runtime
.
Decref
(
self
.
tpHandle
)
;
self
.
gcHandle
.
Free
(
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL