FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpython/Objects/interpreteridobject.c at doc-link-https · 180909/cpython · GitHub
180909
/
cpython
Public
forked from
python/cpython
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
5
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpython
/
Objects
/
interpreteridobject.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
294 lines (266 loc) · 8.75 KB
Breadcrumbs
cpython
/
Objects
/
interpreteridobject.c
Copy path
File metadata and controls
294 lines (266 loc) · 8.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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/* InterpreterID object */
#include
"Python.h"
#include
"pycore_abstract.h"
// _PyIndex_Check()
#include
"pycore_interp.h"
// _PyInterpreterState_LookUpID()
#include
"pycore_interpreteridobject.h"
typedef
struct
interpid
{
PyObject_HEAD
int64_t
id
;
}
interpid
;
static
interpid
*
newinterpid
(
PyTypeObject
*
cls
,
int64_t
id
,
int
force
)
{
PyInterpreterState
*
interp
=
_PyInterpreterState_LookUpID
(
id
);
if
(
interp
==
NULL
) {
if
(
force
) {
PyErr_Clear
();
}
else
{
return
NULL
;
}
}
if
(
interp
!=
NULL
) {
if
(
_PyInterpreterState_IDIncref
(
interp
)
<
0
) {
return
NULL
;
}
}
interpid
*
self
=
PyObject_New
(
interpid
,
cls
);
if
(
self
==
NULL
) {
if
(
interp
!=
NULL
) {
_PyInterpreterState_IDDecref
(
interp
);
}
return
NULL
;
}
self
->
id
=
id
;
return
self
;
}
static
int
interp_id_converter
(
PyObject
*
arg
,
void
*
ptr
)
{
int64_t
id
;
if
(
PyObject_TypeCheck
(
arg
,
&
_PyInterpreterID_Type
)) {
id
=
((
interpid
*
)
arg
)
->
id
;
}
else
if
(
_PyIndex_Check
(
arg
)) {
id
=
PyLong_AsLongLong
(
arg
);
if
(
id
==
-1
&&
PyErr_Occurred
()) {
return
0
;
}
if
(
id
<
0
) {
PyErr_Format
(
PyExc_ValueError
,
"interpreter ID must be a non-negative int, got %R"
,
arg
);
return
0
;
}
}
else
{
PyErr_Format
(
PyExc_TypeError
,
"interpreter ID must be an int, got %.100s"
,
Py_TYPE
(
arg
)
->
tp_name
);
return
0
;
}
*
(
int64_t
*
)
ptr
=
id
;
return
1
;
}
static
PyObject
*
interpid_new
(
PyTypeObject
*
cls
,
PyObject
*
args
,
PyObject
*
kwds
)
{
static
char
*
kwlist
[]
=
{
"id"
,
"force"
,
NULL
};
int64_t
id
;
int
force
=
0
;
if
(!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"O&|$p:InterpreterID.__init__"
,
kwlist
,
interp_id_converter
,
&
id
,
&
force
)) {
return
NULL
;
}
return
(
PyObject
*
)
newinterpid
(
cls
,
id
,
force
);
}
static
void
interpid_dealloc
(
PyObject
*
v
)
{
int64_t
id
=
((
interpid
*
)
v
)
->
id
;
PyInterpreterState
*
interp
=
_PyInterpreterState_LookUpID
(
id
);
if
(
interp
!=
NULL
) {
_PyInterpreterState_IDDecref
(
interp
);
}
else
{
// already deleted
PyErr_Clear
();
}
Py_TYPE
(
v
)
->
tp_free
(
v
);
}
static
PyObject
*
interpid_repr
(
PyObject
*
self
)
{
PyTypeObject
*
type
=
Py_TYPE
(
self
);
const
char
*
name
=
_PyType_Name
(
type
);
interpid
*
id
=
(
interpid
*
)
self
;
return
PyUnicode_FromFormat
(
"%s(%"
PRId64
")"
,
name
,
id
->
id
);
}
static
PyObject
*
interpid_str
(
PyObject
*
self
)
{
interpid
*
id
=
(
interpid
*
)
self
;
return
PyUnicode_FromFormat
(
"%"
PRId64
""
,
id
->
id
);
}
static
PyObject
*
interpid_int
(
PyObject
*
self
)
{
interpid
*
id
=
(
interpid
*
)
self
;
return
PyLong_FromLongLong
(
id
->
id
);
}
static
PyNumberMethods
interpid_as_number
=
{
0
,
/* nb_add */
0
,
/* nb_subtract */
0
,
/* nb_multiply */
0
,
/* nb_remainder */
0
,
/* nb_divmod */
0
,
/* nb_power */
0
,
/* nb_negative */
0
,
/* nb_positive */
0
,
/* nb_absolute */
0
,
/* nb_bool */
0
,
/* nb_invert */
0
,
/* nb_lshift */
0
,
/* nb_rshift */
0
,
/* nb_and */
0
,
/* nb_xor */
0
,
/* nb_or */
(
unaryfunc
)
interpid_int
,
/* nb_int */
0
,
/* nb_reserved */
0
,
/* nb_float */
0
,
/* nb_inplace_add */
0
,
/* nb_inplace_subtract */
0
,
/* nb_inplace_multiply */
0
,
/* nb_inplace_remainder */
0
,
/* nb_inplace_power */
0
,
/* nb_inplace_lshift */
0
,
/* nb_inplace_rshift */
0
,
/* nb_inplace_and */
0
,
/* nb_inplace_xor */
0
,
/* nb_inplace_or */
0
,
/* nb_floor_divide */
0
,
/* nb_true_divide */
0
,
/* nb_inplace_floor_divide */
0
,
/* nb_inplace_true_divide */
(
unaryfunc
)
interpid_int
,
/* nb_index */
};
static
Py_hash_t
interpid_hash
(
PyObject
*
self
)
{
interpid
*
id
=
(
interpid
*
)
self
;
PyObject
*
obj
=
PyLong_FromLongLong
(
id
->
id
);
if
(
obj
==
NULL
) {
return
-1
;
}
Py_hash_t
hash
=
PyObject_Hash
(
obj
);
Py_DECREF
(
obj
);
return
hash
;
}
static
PyObject
*
interpid_richcompare
(
PyObject
*
self
,
PyObject
*
other
,
int
op
)
{
if
(
op
!=
Py_EQ
&&
op
!=
Py_NE
) {
Py_RETURN_NOTIMPLEMENTED
;
}
if
(!
PyObject_TypeCheck
(
self
,
&
_PyInterpreterID_Type
)) {
Py_RETURN_NOTIMPLEMENTED
;
}
interpid
*
id
=
(
interpid
*
)
self
;
int
equal
;
if
(
PyObject_TypeCheck
(
other
,
&
_PyInterpreterID_Type
)) {
interpid
*
otherid
=
(
interpid
*
)
other
;
equal
=
(
id
->
id
==
otherid
->
id
);
}
else
if
(
PyLong_CheckExact
(
other
)) {
/* Fast path */
int
overflow
;
long long
otherid
=
PyLong_AsLongLongAndOverflow
(
other
,
&
overflow
);
if
(
otherid
==
-1
&&
PyErr_Occurred
()) {
return
NULL
;
}
equal
=
!
overflow
&&
(
otherid
>=
0
)
&&
(
id
->
id
==
otherid
);
}
else
if
(
PyNumber_Check
(
other
)) {
PyObject
*
pyid
=
PyLong_FromLongLong
(
id
->
id
);
if
(
pyid
==
NULL
) {
return
NULL
;
}
PyObject
*
res
=
PyObject_RichCompare
(
pyid
,
other
,
op
);
Py_DECREF
(
pyid
);
return
res
;
}
else
{
Py_RETURN_NOTIMPLEMENTED
;
}
if
((
op
==
Py_EQ
&&
equal
)
||
(
op
==
Py_NE
&&
!
equal
)) {
Py_RETURN_TRUE
;
}
Py_RETURN_FALSE
;
}
PyDoc_STRVAR
(
interpid_doc
,
"A interpreter ID identifies a interpreter and may be used as an int."
);
PyTypeObject
_PyInterpreterID_Type
=
{
PyVarObject_HEAD_INIT
(
&
PyType_Type
,
0
)
"InterpreterID"
,
/* tp_name */
sizeof
(
interpid
),
/* tp_basicsize */
0
,
/* tp_itemsize */
(
destructor
)
interpid_dealloc
,
/* tp_dealloc */
0
,
/* tp_vectorcall_offset */
0
,
/* tp_getattr */
0
,
/* tp_setattr */
0
,
/* tp_as_async */
(
reprfunc
)
interpid_repr
,
/* tp_repr */
&
interpid_as_number
,
/* tp_as_number */
0
,
/* tp_as_sequence */
0
,
/* tp_as_mapping */
interpid_hash
,
/* tp_hash */
0
,
/* tp_call */
(
reprfunc
)
interpid_str
,
/* tp_str */
0
,
/* tp_getattro */
0
,
/* tp_setattro */
0
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_BASETYPE
,
/* tp_flags */
interpid_doc
,
/* tp_doc */
0
,
/* tp_traverse */
0
,
/* tp_clear */
interpid_richcompare
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iternext */
0
,
/* tp_methods */
0
,
/* tp_members */
0
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_dict */
0
,
/* tp_descr_get */
0
,
/* tp_descr_set */
0
,
/* tp_dictoffset */
0
,
/* tp_init */
0
,
/* tp_alloc */
interpid_new
,
/* tp_new */
};
PyObject
*
_PyInterpreterID_New
(
int64_t
id
)
{
return
(
PyObject
*
)
newinterpid
(
&
_PyInterpreterID_Type
,
id
,
0
);
}
PyObject
*
_PyInterpreterState_GetIDObject
(
PyInterpreterState
*
interp
)
{
if
(
_PyInterpreterState_IDInitref
(
interp
)
!=
0
) {
return
NULL
;
};
int64_t
id
=
PyInterpreterState_GetID
(
interp
);
if
(
id
<
0
) {
return
NULL
;
}
return
(
PyObject
*
)
newinterpid
(
&
_PyInterpreterID_Type
,
id
,
0
);
}
PyInterpreterState
*
_PyInterpreterID_LookUp
(
PyObject
*
requested_id
)
{
int64_t
id
;
if
(!
interp_id_converter
(
requested_id
,
&
id
)) {
return
NULL
;
}
return
_PyInterpreterState_LookUpID
(
id
);
}
Back
|
FazBrowse Home
|
New Git URL