FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet-rawsvnmig/pythonnet/src/runtime/interop.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
/
interop.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
545 lines (480 loc) · 20.7 KB
Breadcrumbs
pythonnet-rawsvnmig
/
pythonnet
/
src
/
runtime
/
interop.cs
Copy path
File metadata and controls
545 lines (480 loc) · 20.7 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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
// ==========================================================================
// 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
.
Collections
.
Specialized
;
using
System
.
Runtime
.
InteropServices
;
using
System
.
Reflection
;
namespace
Python
.
Runtime
{
//=======================================================================
// This file defines objects to support binary interop with the Python
// runtime. Generally, the definitions here need to be kept up to date
// when moving to new Python versions.
//=======================================================================
[
Serializable
(
)
]
[
AttributeUsage
(
AttributeTargets
.
All
)
]
public
class
DocStringAttribute
:
Attribute
{
public
DocStringAttribute
(
string
docStr
)
{
DocString
=
docStr
;
}
public
string
DocString
{
get
{
return
docStr
;
}
set
{
docStr
=
value
;
}
}
private
string
docStr
;
}
[
Serializable
(
)
]
[
AttributeUsage
(
AttributeTargets
.
Method
|
AttributeTargets
.
Delegate
)
]
internal
class
PythonMethodAttribute
:
Attribute
{
public
PythonMethodAttribute
(
)
{
}
}
[
Serializable
(
)
]
[
AttributeUsage
(
AttributeTargets
.
Method
|
AttributeTargets
.
Delegate
)
]
internal
class
ModuleFunctionAttribute
:
Attribute
{
public
ModuleFunctionAttribute
(
)
{
}
}
[
Serializable
(
)
]
[
AttributeUsage
(
AttributeTargets
.
Method
|
AttributeTargets
.
Delegate
)
]
internal
class
ForbidPythonThreadsAttribute
:
Attribute
{
public
ForbidPythonThreadsAttribute
(
)
{
}
}
[
Serializable
(
)
]
[
AttributeUsage
(
AttributeTargets
.
Property
)
]
internal
class
ModulePropertyAttribute
:
Attribute
{
public
ModulePropertyAttribute
(
)
{
}
}
[
StructLayout
(
LayoutKind
.
Sequential
,
CharSet
=
CharSet
.
Ansi
)
]
internal
class
ObjectOffset
{
static
ObjectOffset
(
)
{
int
size
=
IntPtr
.
Size
;
int
n
=
0
;
// Py_TRACE_REFS add two pointers to PyObject_HEAD
#if
(
Py_DEBUG
)
_ob_next
=
0
;
_ob_prev
=
1
*
size
;
n
=
2
;
#endif
ob_refcnt
=
(
n
+
0
)
*
size
;
ob_type
=
(
n
+
1
)
*
size
;
ob_dict
=
(
n
+
2
)
*
size
;
ob_data
=
(
n
+
3
)
*
size
;
}
public
static
int
magic
(
)
{
return
ob_data
;
}
public
static
int
Size
(
)
{
#if
(
Py_DEBUG
)
return
6
*
IntPtr
.
Size
;
#else
return
4
*
IntPtr
.
Size
;
#endif
}
#if
(
Py_DEBUG
)
public
static
int
_ob_next
;
public
static
int
_ob_prev
;
#endif
public
static
int
ob_refcnt
;
public
static
int
ob_type
;
public
static
int
ob_dict
;
public
static
int
ob_data
;
}
[
StructLayout
(
LayoutKind
.
Sequential
,
CharSet
=
CharSet
.
Ansi
)
]
internal
class
TypeOffset
{
static
TypeOffset
(
)
{
Type
type
=
typeof
(
TypeOffset
)
;
FieldInfo
[
]
fi
=
type
.
GetFields
(
)
;
int
size
=
IntPtr
.
Size
;
for
(
int
i
=
0
;
i
<
fi
.
Length
;
i
++
)
{
fi
[
i
]
.
SetValue
(
null
,
i
*
size
)
;
}
}
public
static
int
magic
(
)
{
return
ob_size
;
}
/* The *real* layout of a type object when allocated on the heap */
//typedef struct _heaptypeobject {
#if
(
Py_DEBUG
)
// #ifdef Py_TRACE_REFS
/* _PyObject_HEAD_EXTRA defines pointers to support a doubly-linked list of all live heap objects. */
public
static
int
_ob_next
=
0
;
public
static
int
_ob_prev
=
0
;
#endif
// PyObject_VAR_HEAD {
// PyObject_HEAD {
public
static
int
ob_refcnt
=
0
;
public
static
int
ob_type
=
0
;
// }
public
static
int
ob_size
=
0
;
/* Number of items in _VAR_iable part */
// }
public
static
int
tp_name
=
0
;
/* For printing, in format "<module>.<name>" */
public
static
int
tp_basicsize
=
0
;
/* For allocation */
public
static
int
tp_itemsize
=
0
;
/* Methods to implement standard operations */
public
static
int
tp_dealloc
=
0
;
public
static
int
tp_print
=
0
;
public
static
int
tp_getattr
=
0
;
public
static
int
tp_setattr
=
0
;
public
static
int
tp_compare
=
0
;
public
static
int
tp_repr
=
0
;
/* Method suites for standard classes */
public
static
int
tp_as_number
=
0
;
public
static
int
tp_as_sequence
=
0
;
public
static
int
tp_as_mapping
=
0
;
/* More standard operations (here for binary compatibility) */
public
static
int
tp_hash
=
0
;
public
static
int
tp_call
=
0
;
public
static
int
tp_str
=
0
;
public
static
int
tp_getattro
=
0
;
public
static
int
tp_setattro
=
0
;
/* Functions to access object as input/output buffer */
public
static
int
tp_as_buffer
=
0
;
/* Flags to define presence of optional/expanded features */
public
static
int
tp_flags
=
0
;
public
static
int
tp_doc
=
0
;
/* Documentation string */
/* Assigned meaning in release 2.0 */
/* call function for all accessible objects */
public
static
int
tp_traverse
=
0
;
/* delete references to contained objects */
public
static
int
tp_clear
=
0
;
/* Assigned meaning in release 2.1 */
/* rich comparisons */
public
static
int
tp_richcompare
=
0
;
/* weak reference enabler */
public
static
int
tp_weaklistoffset
=
0
;
/* Added in release 2.2 */
/* Iterators */
public
static
int
tp_iter
=
0
;
public
static
int
tp_iternext
=
0
;
/* Attribute descriptor and subclassing stuff */
public
static
int
tp_methods
=
0
;
public
static
int
tp_members
=
0
;
public
static
int
tp_getset
=
0
;
public
static
int
tp_base
=
0
;
public
static
int
tp_dict
=
0
;
public
static
int
tp_descr_get
=
0
;
public
static
int
tp_descr_set
=
0
;
public
static
int
tp_dictoffset
=
0
;
public
static
int
tp_init
=
0
;
public
static
int
tp_alloc
=
0
;
public
static
int
tp_new
=
0
;
public
static
int
tp_free
=
0
;
/* Low-level free-memory routine */
public
static
int
tp_is_gc
=
0
;
/* For PyObject_IS_GC */
public
static
int
tp_bases
=
0
;
public
static
int
tp_mro
=
0
;
/* method resolution order */
public
static
int
tp_cache
=
0
;
public
static
int
tp_subclasses
=
0
;
public
static
int
tp_weaklist
=
0
;
public
static
int
tp_del
=
0
;
#if
(
PYTHON26
||
PYTHON27
)
/* Type attribute cache version tag. Added in version 2.6 */
public
static
int
tp_version_tag
;
#endif
// COUNT_ALLOCS adds some more stuff to PyTypeObject
#if
(
Py_COUNT_ALLOCS
)
/* these must be last and never explicitly initialized */
public
static
int
tp_allocs
=
0
;
public
static
int
tp_frees
=
0
;
public
static
int
tp_maxalloc
=
0
;
public
static
int
tp_prev
=
0
;
public
static
int
tp_next
=
0
;
#endif
//} PyTypeObject;
//typedef struct {
public
static
int
nb_add
=
0
;
public
static
int
nb_subtract
=
0
;
public
static
int
nb_multiply
=
0
;
public
static
int
nb_divide
=
0
;
public
static
int
nb_remainder
=
0
;
public
static
int
nb_divmod
=
0
;
public
static
int
nb_power
=
0
;
public
static
int
nb_negative
=
0
;
public
static
int
nb_positive
=
0
;
public
static
int
nb_absolute
=
0
;
public
static
int
nb_nonzero
=
0
;
public
static
int
nb_invert
=
0
;
public
static
int
nb_lshift
=
0
;
public
static
int
nb_rshift
=
0
;
public
static
int
nb_and
=
0
;
public
static
int
nb_xor
=
0
;
public
static
int
nb_or
=
0
;
public
static
int
nb_coerce
=
0
;
public
static
int
nb_int
=
0
;
public
static
int
nb_long
=
0
;
public
static
int
nb_float
=
0
;
public
static
int
nb_oct
=
0
;
public
static
int
nb_hex
=
0
;
/* Added in release 2.0 */
public
static
int
nb_inplace_add
=
0
;
public
static
int
nb_inplace_subtract
=
0
;
public
static
int
nb_inplace_multiply
=
0
;
public
static
int
nb_inplace_divide
=
0
;
public
static
int
nb_inplace_remainder
=
0
;
public
static
int
nb_inplace_power
=
0
;
public
static
int
nb_inplace_lshift
=
0
;
public
static
int
nb_inplace_rshift
=
0
;
public
static
int
nb_inplace_and
=
0
;
public
static
int
nb_inplace_xor
=
0
;
public
static
int
nb_inplace_or
=
0
;
/* Added in release 2.2 */
/* The following require the Py_TPFLAGS_HAVE_CLASS flag */
public
static
int
nb_floor_divide
=
0
;
public
static
int
nb_true_divide
=
0
;
public
static
int
nb_inplace_floor_divide
=
0
;
public
static
int
nb_inplace_true_divide
=
0
;
#if
(
PYTHON25
||
PYTHON26
||
PYTHON27
)
/* Added in release 2.5 */
public
static
int
nb_index
=
0
;
#endif
//} PyNumberMethods;
//typedef struct {
public
static
int
mp_length
=
0
;
public
static
int
mp_subscript
=
0
;
public
static
int
mp_ass_subscript
=
0
;
//} PyMappingMethods;
//typedef struct {
public
static
int
sq_length
=
0
;
public
static
int
sq_concat
=
0
;
public
static
int
sq_repeat
=
0
;
public
static
int
sq_item
=
0
;
public
static
int
sq_slice
=
0
;
public
static
int
sq_ass_item
=
0
;
public
static
int
sq_ass_slice
=
0
;
public
static
int
sq_contains
=
0
;
/* Added in release 2.0 */
public
static
int
sq_inplace_concat
=
0
;
public
static
int
sq_inplace_repeat
=
0
;
//} PySequenceMethods;
//typedef struct {
public
static
int
bf_getreadbuffer
=
0
;
public
static
int
bf_getwritebuffer
=
0
;
public
static
int
bf_getsegcount
=
0
;
public
static
int
bf_getcharbuffer
=
0
;
#if
(
PYTHON26
||
PYTHON27
)
// This addition is not actually noted in the 2.6.5 object.h
public
static
int
bf_getbuffer
=
0
;
public
static
int
bf_releasebuffer
=
0
;
//} PyBufferProcs;
#endif
//PyObject *ht_name, *ht_slots;
public
static
int
name
=
0
;
public
static
int
slots
=
0
;
/* here are optional user slots, followed by the members. */
public
static
int
members
=
0
;
}
/// <summary>
/// TypeFlags(): The actual bit values for the Type Flags stored
/// in a class.
/// Note that the two values reserved for stackless have been put
/// to good use as PythonNet specific flags (Managed and Subclass)
/// </summary>
internal
class
TypeFlags
{
public
static
int
HaveGetCharBuffer
=
(
1
<<
0
)
;
public
static
int
HaveSequenceIn
=
(
1
<<
1
)
;
public
static
int
GC
=
0
;
public
static
int
HaveInPlaceOps
=
(
1
<<
3
)
;
public
static
int
CheckTypes
=
(
1
<<
4
)
;
public
static
int
HaveRichCompare
=
(
1
<<
5
)
;
public
static
int
HaveWeakRefs
=
(
1
<<
6
)
;
public
static
int
HaveIter
=
(
1
<<
7
)
;
public
static
int
HaveClass
=
(
1
<<
8
)
;
public
static
int
HeapType
=
(
1
<<
9
)
;
public
static
int
BaseType
=
(
1
<<
10
)
;
public
static
int
Ready
=
(
1
<<
12
)
;
public
static
int
Readying
=
(
1
<<
13
)
;
public
static
int
HaveGC
=
(
1
<<
14
)
;
// 15 and 16 are reserved for stackless
public
static
int
HaveStacklessExtension
=
0
;
/* XXX Reusing reserved constants */
public
static
int
Managed
=
(
1
<<
15
)
;
// PythonNet specific
public
static
int
Subclass
=
(
1
<<
16
)
;
// PythonNet specific
#if
(
PYTHON25
||
PYTHON26
||
PYTHON27
)
public
static
int
HaveIndex
=
(
1
<<
17
)
;
#endif
#if
(
PYTHON26
||
PYTHON27
)
/* Objects support nb_index in PyNumberMethods */
public
static
int
HaveVersionTag
=
(
1
<<
18
)
;
public
static
int
ValidVersionTag
=
(
1
<<
19
)
;
public
static
int
IsAbstract
=
(
1
<<
20
)
;
public
static
int
HaveNewBuffer
=
(
1
<<
21
)
;
// TODO: Implement FastSubclass functions
public
static
int
IntSubclass
=
(
1
<<
23
)
;
public
static
int
LongSubclass
=
(
1
<<
24
)
;
public
static
int
ListSubclass
=
(
1
<<
25
)
;
public
static
int
TupleSubclass
=
(
1
<<
26
)
;
public
static
int
StringSubclass
=
(
1
<<
27
)
;
public
static
int
UnicodeSubclass
=
(
1
<<
28
)
;
public
static
int
DictSubclass
=
(
1
<<
29
)
;
public
static
int
BaseExceptionSubclass
=
(
1
<<
30
)
;
public
static
int
TypeSubclass
=
(
1
<<
31
)
;
#endif
public
static
int
Default
=
(
HaveGetCharBuffer
|
HaveSequenceIn
|
HaveInPlaceOps
|
HaveRichCompare
|
HaveWeakRefs
|
HaveIter
|
HaveClass
|
HaveStacklessExtension
|
#if
(
PYTHON25
||
PYTHON26
||
PYTHON27
)
HaveIndex
|
#endif
0
)
;
}
// This class defines the function prototypes (delegates) used for low
// level integration with the CPython runtime. It also provides name
// based lookup of the correct prototype for a particular Python type
// slot and utilities for generating method thunks for managed methods.
internal
class
Interop
{
static
ArrayList
keepAlive
;
static
Hashtable
pmap
;
static
Interop
(
)
{
// Here we build a mapping of PyTypeObject slot names to the
// appropriate prototype (delegate) type to use for the slot.
Type
[
]
items
=
typeof
(
Interop
)
.
GetNestedTypes
(
)
;
Hashtable
p
=
new
Hashtable
(
)
;
for
(
int
i
=
0
;
i
<
items
.
Length
;
i
++
)
{
Type
item
=
items
[
i
]
;
p
[
item
.
Name
]
=
item
;
}
keepAlive
=
new
ArrayList
(
)
;
Marshal
.
AllocHGlobal
(
IntPtr
.
Size
)
;
pmap
=
new
Hashtable
(
)
;
pmap
[
"tp_dealloc"
]
=
p
[
"DestructorFunc"
]
;
pmap
[
"tp_print"
]
=
p
[
"PrintFunc"
]
;
pmap
[
"tp_getattr"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"tp_setattr"
]
=
p
[
"ObjObjArgFunc"
]
;
pmap
[
"tp_compare"
]
=
p
[
"ObjObjFunc"
]
;
pmap
[
"tp_repr"
]
=
p
[
"UnaryFunc"
]
;
pmap
[
"tp_hash"
]
=
p
[
"UnaryFunc"
]
;
pmap
[
"tp_call"
]
=
p
[
"TernaryFunc"
]
;
pmap
[
"tp_str"
]
=
p
[
"UnaryFunc"
]
;
pmap
[
"tp_getattro"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"tp_setattro"
]
=
p
[
"ObjObjArgFunc"
]
;
pmap
[
"tp_traverse"
]
=
p
[
"ObjObjArgFunc"
]
;
pmap
[
"tp_clear"
]
=
p
[
"InquiryFunc"
]
;
pmap
[
"tp_richcompare"
]
=
p
[
"RichCmpFunc"
]
;
pmap
[
"tp_iter"
]
=
p
[
"UnaryFunc"
]
;
pmap
[
"tp_iternext"
]
=
p
[
"UnaryFunc"
]
;
pmap
[
"tp_descr_get"
]
=
p
[
"TernaryFunc"
]
;
pmap
[
"tp_descr_set"
]
=
p
[
"ObjObjArgFunc"
]
;
pmap
[
"tp_init"
]
=
p
[
"ObjObjArgFunc"
]
;
pmap
[
"tp_alloc"
]
=
p
[
"IntArgFunc"
]
;
pmap
[
"tp_new"
]
=
p
[
"TernaryFunc"
]
;
pmap
[
"tp_free"
]
=
p
[
"DestructorFunc"
]
;
pmap
[
"tp_is_gc"
]
=
p
[
"InquiryFunc"
]
;
pmap
[
"nb_add"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_subtract"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_multiply"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_divide"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_remainder"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_divmod"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_power"
]
=
p
[
"TernaryFunc"
]
;
pmap
[
"nb_negative"
]
=
p
[
"UnaryFunc"
]
;
pmap
[
"nb_positive"
]
=
p
[
"UnaryFunc"
]
;
pmap
[
"nb_absolute"
]
=
p
[
"UnaryFunc"
]
;
pmap
[
"nb_nonzero"
]
=
p
[
"InquiryFunc"
]
;
pmap
[
"nb_invert"
]
=
p
[
"UnaryFunc"
]
;
pmap
[
"nb_lshift"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_rshift"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_and"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_xor"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_or"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_coerce"
]
=
p
[
"ObjObjFunc"
]
;
pmap
[
"nb_int"
]
=
p
[
"UnaryFunc"
]
;
pmap
[
"nb_long"
]
=
p
[
"UnaryFunc"
]
;
pmap
[
"nb_float"
]
=
p
[
"UnaryFunc"
]
;
pmap
[
"nb_oct"
]
=
p
[
"UnaryFunc"
]
;
pmap
[
"nb_hex"
]
=
p
[
"UnaryFunc"
]
;
pmap
[
"nb_inplace_add"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_inplace_subtract"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_inplace_multiply"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_inplace_divide"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_inplace_remainder"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_inplace_power"
]
=
p
[
"TernaryFunc"
]
;
pmap
[
"nb_inplace_lshift"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_inplace_rshift"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_inplace_and"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_inplace_xor"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_inplace_or"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_floor_divide"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_true_divide"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_inplace_floor_divide"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"nb_inplace_true_divide"
]
=
p
[
"BinaryFunc"
]
;
#if
(
PYTHON25
||
PYTHON26
||
PYTHON27
)
pmap
[
"nb_index"
]
=
p
[
"UnaryFunc"
]
;
#endif
pmap
[
"sq_length"
]
=
p
[
"InquiryFunc"
]
;
pmap
[
"sq_concat"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"sq_repeat"
]
=
p
[
"IntArgFunc"
]
;
pmap
[
"sq_item"
]
=
p
[
"IntArgFunc"
]
;
pmap
[
"sq_slice"
]
=
p
[
"IntIntArgFunc"
]
;
pmap
[
"sq_ass_item"
]
=
p
[
"IntObjArgFunc"
]
;
pmap
[
"sq_ass_slice"
]
=
p
[
"IntIntObjArgFunc"
]
;
pmap
[
"sq_contains"
]
=
p
[
"ObjObjFunc"
]
;
pmap
[
"sq_inplace_concat"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"sq_inplace_repeat"
]
=
p
[
"IntArgFunc"
]
;
pmap
[
"mp_length"
]
=
p
[
"InquiryFunc"
]
;
pmap
[
"mp_subscript"
]
=
p
[
"BinaryFunc"
]
;
pmap
[
"mp_ass_subscript"
]
=
p
[
"ObjObjArgFunc"
]
;
pmap
[
"bf_getreadbuffer"
]
=
p
[
"IntObjArgFunc"
]
;
pmap
[
"bf_getwritebuffer"
]
=
p
[
"IntObjArgFunc"
]
;
pmap
[
"bf_getsegcount"
]
=
p
[
"ObjObjFunc"
]
;
pmap
[
"bf_getcharbuffer"
]
=
p
[
"IntObjArgFunc"
]
;
pmap
[
"__import__"
]
=
p
[
"TernaryFunc"
]
;
}
internal
static
Type
GetPrototype
(
string
name
)
{
return
pmap
[
name
]
as
Type
;
}
internal
static
IntPtr
GetThunk
(
MethodInfo
method
)
{
Type
dt
=
Interop
.
GetPrototype
(
method
.
Name
)
;
if
(
dt
!=
null
)
{
IntPtr
tmp
=
Marshal
.
AllocHGlobal
(
IntPtr
.
Size
)
;
Delegate
d
=
Delegate
.
CreateDelegate
(
dt
,
method
)
;
Thunk
cb
=
new
Thunk
(
d
)
;
Marshal
.
StructureToPtr
(
cb
,
tmp
,
false
)
;
IntPtr
fp
=
Marshal
.
ReadIntPtr
(
tmp
,
0
)
;
Marshal
.
FreeHGlobal
(
tmp
)
;
keepAlive
.
Add
(
d
)
;
return
fp
;
}
return
IntPtr
.
Zero
;
}
[
UnmanagedFunctionPointer
(
CallingConvention
.
Cdecl
)
]
public
delegate
IntPtr
UnaryFunc
(
IntPtr
ob
)
;
[
UnmanagedFunctionPointer
(
CallingConvention
.
Cdecl
)
]
public
delegate
IntPtr
BinaryFunc
(
IntPtr
ob
,
IntPtr
arg
)
;
[
UnmanagedFunctionPointer
(
CallingConvention
.
Cdecl
)
]
public
delegate
IntPtr
TernaryFunc
(
IntPtr
ob
,
IntPtr
a1
,
IntPtr
a2
)
;
[
UnmanagedFunctionPointer
(
CallingConvention
.
Cdecl
)
]
public
delegate
int
InquiryFunc
(
IntPtr
ob
)
;
[
UnmanagedFunctionPointer
(
CallingConvention
.
Cdecl
)
]
public
delegate
IntPtr
IntArgFunc
(
IntPtr
ob
,
int
arg
)
;
[
UnmanagedFunctionPointer
(
CallingConvention
.
Cdecl
)
]
public
delegate
IntPtr
IntIntArgFunc
(
IntPtr
ob
,
int
a1
,
int
a2
)
;
[
UnmanagedFunctionPointer
(
CallingConvention
.
Cdecl
)
]
public
delegate
int
IntObjArgFunc
(
IntPtr
ob
,
int
a1
,
IntPtr
a2
)
;
[
UnmanagedFunctionPointer
(
CallingConvention
.
Cdecl
)
]
public
delegate
int
IntIntObjArgFunc
(
IntPtr
o
,
int
a
,
int
b
,
IntPtr
c
)
;
[
UnmanagedFunctionPointer
(
CallingConvention
.
Cdecl
)
]
public
delegate
int
ObjObjArgFunc
(
IntPtr
o
,
IntPtr
a
,
IntPtr
b
)
;
[
UnmanagedFunctionPointer
(
CallingConvention
.
Cdecl
)
]
public
delegate
int
ObjObjFunc
(
IntPtr
ob
,
IntPtr
arg
)
;
[
UnmanagedFunctionPointer
(
CallingConvention
.
Cdecl
)
]
public
delegate
void
DestructorFunc
(
IntPtr
ob
)
;
[
UnmanagedFunctionPointer
(
CallingConvention
.
Cdecl
)
]
public
delegate
int
PrintFunc
(
IntPtr
ob
,
IntPtr
a
,
int
b
)
;
[
UnmanagedFunctionPointer
(
CallingConvention
.
Cdecl
)
]
public
delegate
IntPtr
RichCmpFunc
(
IntPtr
ob
,
IntPtr
a
,
int
b
)
;
}
[
StructLayout
(
LayoutKind
.
Sequential
,
CharSet
=
CharSet
.
Ansi
)
]
internal
struct
Thunk
{
public
Delegate
fn
;
public
Thunk
(
Delegate
d
)
{
fn
=
d
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL