FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/src/runtime/runtime.cs at drop-python2 · filmor/pythonnet · GitHub
filmor
/
pythonnet
Public
forked from
pythonnet/pythonnet
Notifications
You must be signed in to change notification settings
Fork
1
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet
/
src
/
runtime
/
runtime.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
1905 lines (1490 loc) · 75 KB
Breadcrumbs
pythonnet
/
src
/
runtime
/
runtime.cs
Copy path
File metadata and controls
1905 lines (1490 loc) · 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
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
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using
System
.
Reflection
.
Emit
;
using
System
;
using
System
.
Diagnostics
.
Contracts
;
using
System
.
Runtime
.
InteropServices
;
using
System
.
Security
;
using
System
.
Text
;
using
System
.
Threading
;
using
System
.
Collections
.
Generic
;
using
Python
.
Runtime
.
Platform
;
namespace
Python
.
Runtime
{
/// <summary>
/// Encapsulates the low-level Python C API. Note that it is
/// the responsibility of the caller to have acquired the GIL
/// before calling any of these methods.
/// </summary>
public
class
Runtime
{
// C# compiler copies constants to the assemblies that references this library.
// We needs to replace all public constants to static readonly fields to allow
// binary substitution of different Python.Runtime.dll builds in a target application.
public
static
int
UCS
=>
_UCS
;
#if
UCS4
internal
const
int
_UCS
=
4
;
/// <summary>
/// EntryPoint to be used in DllImport to map to correct Unicode
/// methods prior to PEP393. Only used for PY27.
/// </summary>
private
const
string
PyUnicodeEntryPoint
=
"PyUnicodeUCS4_"
;
#elif
UCS2
internal
const
int
_UCS
=
2
;
/// <summary>
/// EntryPoint to be used in DllImport to map to correct Unicode
/// methods prior to PEP393. Only used for PY27.
/// </summary>
private
const
string
PyUnicodeEntryPoint
=
"PyUnicodeUCS2_"
;
#else
#error You must define either UCS2 or UCS4!
#endif
#if
PYTHON34
const
string
_minor
=
"4"
;
#elif
PYTHON35
const
string
_minor
=
"5"
;
#elif
PYTHON36
const
string
_minor
=
"6"
;
#elif
PYTHON37
const
string
_minor
=
"7"
;
#elif
PYTHON38
const
string
_minor
=
"8"
;
#else
#error You must define one of PYTHON34 to PYTHON38
#endif
#if
WINDOWS
internal
const
string
dllBase
=
"python3"
+
_minor
;
#else
internal
const
string
dllBase
=
"python3."
+
_minor
;
#endif
#if
PYTHON_WITH_PYDEBUG
internal
const
string
dllWithPyDebug
=
"d"
;
#else
internal
const
string
dllWithPyDebug
=
""
;
#endif
#if
PYTHON_WITH_PYMALLOC
internal
const
string
dllWithPyMalloc
=
"m"
;
#else
internal
const
string
dllWithPyMalloc
=
""
;
#endif
// C# compiler copies constants to the assemblies that references this library.
// We needs to replace all public constants to static readonly fields to allow
// binary substitution of different Python.Runtime.dll builds in a target application.
public
static
readonly
string
PythonDLL
=
_PythonDll
;
#if
PYTHON_WITHOUT_ENABLE_SHARED
&&
!
NETSTANDARD
internal
const
string
_PythonDll
=
"__Internal"
;
#else
internal
const
string
_PythonDll
=
dllBase
+
dllWithPyDebug
+
dllWithPyMalloc
;
#endif
// set to true when python is finalizing
internal
static
object
IsFinalizingLock
=
new
object
(
)
;
internal
static
bool
IsFinalizing
;
internal
static
bool
Is32Bit
=>
IntPtr
.
Size
==
4
;
// .NET core: System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
internal
static
bool
IsWindows
=
Environment
.
OSVersion
.
Platform
==
PlatformID
.
Win32NT
;
static
readonly
Dictionary
<
string
,
OperatingSystemType
>
OperatingSystemTypeMapping
=
new
Dictionary
<
string
,
OperatingSystemType
>
(
)
{
{
"Windows"
,
OperatingSystemType
.
Windows
}
,
{
"Darwin"
,
OperatingSystemType
.
Darwin
}
,
{
"Linux"
,
OperatingSystemType
.
Linux
}
,
}
;
[
Obsolete
]
public
static
string
OperatingSystemName
=>
OperatingSystem
.
ToString
(
)
;
[
Obsolete
]
public
static
string
MachineName
=>
Machine
.
ToString
(
)
;
/// <summary>
/// Gets the operating system as reported by python's platform.system().
/// </summary>
public
static
OperatingSystemType
OperatingSystem
{
get
;
private
set
;
}
/// <summary>
/// Map lower-case version of the python machine name to the processor
/// type. There are aliases, e.g. x86_64 and amd64 are two names for
/// the same thing. Make sure to lower-case the search string, because
/// capitalization can differ.
/// </summary>
static
readonly
Dictionary
<
string
,
MachineType
>
MachineTypeMapping
=
new
Dictionary
<
string
,
MachineType
>
(
)
{
[
"i386"
]
=
MachineType
.
i386
,
[
"i686"
]
=
MachineType
.
i386
,
[
"x86"
]
=
MachineType
.
i386
,
[
"x86_64"
]
=
MachineType
.
x86_64
,
[
"amd64"
]
=
MachineType
.
x86_64
,
[
"x64"
]
=
MachineType
.
x86_64
,
[
"em64t"
]
=
MachineType
.
x86_64
,
[
"armv7l"
]
=
MachineType
.
armv7l
,
[
"armv8"
]
=
MachineType
.
armv8
,
[
"aarch64"
]
=
MachineType
.
aarch64
,
}
;
/// <summary>
/// Gets the machine architecture as reported by python's platform.machine().
/// </summary>
public
static
MachineType
Machine
{
get
;
private
set
;
}
/* set in Initialize using python's platform.machine */
public
static
int
MainManagedThreadId
{
get
;
private
set
;
}
/// <summary>
/// Encoding to use to convert Unicode to/from Managed to Native
/// </summary>
internal
static
readonly
Encoding
PyEncoding
=
_UCS
==
2
?
Encoding
.
Unicode
:
Encoding
.
UTF32
;
private
static
PyReferenceCollection
_pyRefs
=
new
PyReferenceCollection
(
)
;
/// <summary>
/// Initialize the runtime...
/// </summary>
internal
static
void
Initialize
(
bool
initSigs
=
false
)
{
if
(
Py_IsInitialized
(
)
==
0
)
{
Py_InitializeEx
(
initSigs
?
1
:
0
)
;
MainManagedThreadId
=
Thread
.
CurrentThread
.
ManagedThreadId
;
}
if
(
PyEval_ThreadsInitialized
(
)
==
0
)
{
PyEval_InitThreads
(
)
;
}
IsFinalizing
=
false
;
GenericUtil
.
Reset
(
)
;
PyScopeManager
.
Reset
(
)
;
ClassManager
.
Reset
(
)
;
ClassDerivedObject
.
Reset
(
)
;
TypeManager
.
Reset
(
)
;
IntPtr
op
;
{
var
builtins
=
GetBuiltins
(
)
;
SetPyMember
(
ref
PyNotImplemented
,
PyObject_GetAttrString
(
builtins
,
"NotImplemented"
)
,
(
)
=>
PyNotImplemented
=
IntPtr
.
Zero
)
;
SetPyMember
(
ref
PyBaseObjectType
,
PyObject_GetAttrString
(
builtins
,
"object"
)
,
(
)
=>
PyBaseObjectType
=
IntPtr
.
Zero
)
;
SetPyMember
(
ref
PyNone
,
PyObject_GetAttrString
(
builtins
,
"None"
)
,
(
)
=>
PyNone
=
IntPtr
.
Zero
)
;
SetPyMember
(
ref
PyTrue
,
PyObject_GetAttrString
(
builtins
,
"True"
)
,
(
)
=>
PyTrue
=
IntPtr
.
Zero
)
;
SetPyMember
(
ref
PyFalse
,
PyObject_GetAttrString
(
builtins
,
"False"
)
,
(
)
=>
PyFalse
=
IntPtr
.
Zero
)
;
SetPyMember
(
ref
PyBoolType
,
PyObject_Type
(
PyTrue
)
,
(
)
=>
PyBoolType
=
IntPtr
.
Zero
)
;
SetPyMember
(
ref
PyNoneType
,
PyObject_Type
(
PyNone
)
,
(
)
=>
PyNoneType
=
IntPtr
.
Zero
)
;
SetPyMember
(
ref
PyTypeType
,
PyObject_Type
(
PyNoneType
)
,
(
)
=>
PyTypeType
=
IntPtr
.
Zero
)
;
op
=
PyObject_GetAttrString
(
builtins
,
"len"
)
;
SetPyMember
(
ref
PyMethodType
,
PyObject_Type
(
op
)
,
(
)
=>
PyMethodType
=
IntPtr
.
Zero
)
;
XDecref
(
op
)
;
// For some arcane reason, builtins.__dict__.__setitem__ is *not*
// a wrapper_descriptor, even though dict.__setitem__ is.
//
// object.__init__ seems safe, though.
op
=
PyObject_GetAttrString
(
PyBaseObjectType
,
"__init__"
)
;
SetPyMember
(
ref
PyWrapperDescriptorType
,
PyObject_Type
(
op
)
,
(
)
=>
PyWrapperDescriptorType
=
IntPtr
.
Zero
)
;
XDecref
(
op
)
;
SetPyMember
(
ref
PySuper_Type
,
PyObject_GetAttrString
(
builtins
,
"super"
)
,
(
)
=>
PySuper_Type
=
IntPtr
.
Zero
)
;
XDecref
(
builtins
)
;
}
op
=
PyString_FromString
(
"string"
)
;
SetPyMember
(
ref
PyStringType
,
PyObject_Type
(
op
)
,
(
)
=>
PyStringType
=
IntPtr
.
Zero
)
;
XDecref
(
op
)
;
op
=
PyUnicode_FromString
(
"unicode"
)
;
SetPyMember
(
ref
PyUnicodeType
,
PyObject_Type
(
op
)
,
(
)
=>
PyUnicodeType
=
IntPtr
.
Zero
)
;
XDecref
(
op
)
;
op
=
PyBytes_FromString
(
"bytes"
)
;
SetPyMember
(
ref
PyBytesType
,
PyObject_Type
(
op
)
,
(
)
=>
PyBytesType
=
IntPtr
.
Zero
)
;
XDecref
(
op
)
;
op
=
PyTuple_New
(
0
)
;
SetPyMember
(
ref
PyTupleType
,
PyObject_Type
(
op
)
,
(
)
=>
PyTupleType
=
IntPtr
.
Zero
)
;
XDecref
(
op
)
;
op
=
PyList_New
(
0
)
;
SetPyMember
(
ref
PyListType
,
PyObject_Type
(
op
)
,
(
)
=>
PyListType
=
IntPtr
.
Zero
)
;
XDecref
(
op
)
;
op
=
PyDict_New
(
)
;
SetPyMember
(
ref
PyDictType
,
PyObject_Type
(
op
)
,
(
)
=>
PyDictType
=
IntPtr
.
Zero
)
;
XDecref
(
op
)
;
op
=
PyInt_FromInt32
(
0
)
;
SetPyMember
(
ref
PyIntType
,
PyObject_Type
(
op
)
,
(
)
=>
PyIntType
=
IntPtr
.
Zero
)
;
XDecref
(
op
)
;
op
=
PyLong_FromLong
(
0
)
;
SetPyMember
(
ref
PyLongType
,
PyObject_Type
(
op
)
,
(
)
=>
PyLongType
=
IntPtr
.
Zero
)
;
XDecref
(
op
)
;
op
=
PyFloat_FromDouble
(
0
)
;
SetPyMember
(
ref
PyFloatType
,
PyObject_Type
(
op
)
,
(
)
=>
PyFloatType
=
IntPtr
.
Zero
)
;
XDecref
(
op
)
;
PyClassType
=
IntPtr
.
Zero
;
PyInstanceType
=
IntPtr
.
Zero
;
Error
=
new
IntPtr
(
-
1
)
;
// Initialize data about the platform we're running on. We need
// this for the type manager and potentially other details. Must
// happen after caching the python types, above.
InitializePlatformData
(
)
;
IntPtr
dllLocal
=
IntPtr
.
Zero
;
var
loader
=
LibraryLoader
.
Get
(
OperatingSystem
)
;
if
(
_PythonDll
!=
"__Internal"
)
{
dllLocal
=
loader
.
Load
(
_PythonDll
)
;
}
_PyObject_NextNotImplemented
=
loader
.
GetFunction
(
dllLocal
,
"_PyObject_NextNotImplemented"
)
;
PyModuleType
=
loader
.
GetFunction
(
dllLocal
,
"PyModule_Type"
)
;
if
(
dllLocal
!=
IntPtr
.
Zero
)
{
loader
.
Free
(
dllLocal
)
;
}
// Initialize modules that depend on the runtime class.
AssemblyManager
.
Initialize
(
)
;
PyCLRMetaType
=
MetaType
.
Initialize
(
)
;
Exceptions
.
Initialize
(
)
;
ImportHook
.
Initialize
(
)
;
// Need to add the runtime directory to sys.path so that we
// can find built-in assemblies like System.Data, et. al.
string
rtdir
=
RuntimeEnvironment
.
GetRuntimeDirectory
(
)
;
IntPtr
path
=
PySys_GetObject
(
"path"
)
;
IntPtr
item
=
PyString_FromString
(
rtdir
)
;
PyList_Append
(
new
BorrowedReference
(
path
)
,
item
)
;
XDecref
(
item
)
;
AssemblyManager
.
UpdatePath
(
)
;
}
/// <summary>
/// Initializes the data about platforms.
///
/// This must be the last step when initializing the runtime:
/// GetManagedString needs to have the cached values for types.
/// But it must run before initializing anything outside the runtime
/// because those rely on the platform data.
/// </summary>
private
static
void
InitializePlatformData
(
)
{
#if
!
NETSTANDARD
IntPtr
op
;
IntPtr
fn
;
IntPtr
platformModule
=
PyImport_ImportModule
(
"platform"
)
;
IntPtr
emptyTuple
=
PyTuple_New
(
0
)
;
fn
=
PyObject_GetAttrString
(
platformModule
,
"system"
)
;
op
=
PyObject_Call
(
fn
,
emptyTuple
,
IntPtr
.
Zero
)
;
string
operatingSystemName
=
GetManagedString
(
op
)
;
XDecref
(
op
)
;
XDecref
(
fn
)
;
fn
=
PyObject_GetAttrString
(
platformModule
,
"machine"
)
;
op
=
PyObject_Call
(
fn
,
emptyTuple
,
IntPtr
.
Zero
)
;
string
machineName
=
GetManagedString
(
op
)
;
XDecref
(
op
)
;
XDecref
(
fn
)
;
XDecref
(
emptyTuple
)
;
XDecref
(
platformModule
)
;
// Now convert the strings into enum values so we can do switch
// statements rather than constant parsing.
OperatingSystemType
OSType
;
if
(
!
OperatingSystemTypeMapping
.
TryGetValue
(
operatingSystemName
,
out
OSType
)
)
{
OSType
=
OperatingSystemType
.
Other
;
}
OperatingSystem
=
OSType
;
MachineType
MType
;
if
(
!
MachineTypeMapping
.
TryGetValue
(
machineName
.
ToLower
(
)
,
out
MType
)
)
{
MType
=
MachineType
.
Other
;
}
Machine
=
MType
;
#else
if
(
RuntimeInformation
.
IsOSPlatform
(
OSPlatform
.
Linux
)
)
OperatingSystem
=
OperatingSystemType
.
Linux
;
else
if
(
RuntimeInformation
.
IsOSPlatform
(
OSPlatform
.
OSX
)
)
OperatingSystem
=
OperatingSystemType
.
Darwin
;
else
if
(
RuntimeInformation
.
IsOSPlatform
(
OSPlatform
.
Windows
)
)
OperatingSystem
=
OperatingSystemType
.
Windows
;
else
OperatingSystem
=
OperatingSystemType
.
Other
;
switch
(
RuntimeInformation
.
ProcessArchitecture
)
{
case
Architecture
.
X86
:
Machine
=
MachineType
.
i386
;
break
;
case
Architecture
.
X64
:
Machine
=
MachineType
.
x86_64
;
break
;
case
Architecture
.
Arm
:
Machine
=
MachineType
.
armv7l
;
break
;
case
Architecture
.
Arm64
:
Machine
=
MachineType
.
aarch64
;
break
;
default
:
Machine
=
MachineType
.
Other
;
break
;
}
#endif
}
internal
static
void
Shutdown
(
)
{
AssemblyManager
.
Shutdown
(
)
;
Exceptions
.
Shutdown
(
)
;
ImportHook
.
Shutdown
(
)
;
Finalizer
.
Shutdown
(
)
;
// TOOD: PyCLRMetaType's release operation still in #958
PyCLRMetaType
=
IntPtr
.
Zero
;
ResetPyMembers
(
)
;
Py_Finalize
(
)
;
}
// called *without* the GIL acquired by clr._AtExit
internal
static
int
AtExit
(
)
{
lock
(
IsFinalizingLock
)
{
IsFinalizing
=
true
;
}
return
0
;
}
private
static
void
SetPyMember
(
ref
IntPtr
obj
,
IntPtr
value
,
Action
onRelease
)
{
// XXX: For current usages, value should not be null.
PythonException
.
ThrowIfIsNull
(
value
)
;
obj
=
value
;
_pyRefs
.
Add
(
value
,
onRelease
)
;
}
private
static
void
ResetPyMembers
(
)
{
_pyRefs
.
Release
(
)
;
}
internal
static
IntPtr
Py_single_input
=
(
IntPtr
)
256
;
internal
static
IntPtr
Py_file_input
=
(
IntPtr
)
257
;
internal
static
IntPtr
Py_eval_input
=
(
IntPtr
)
258
;
internal
static
IntPtr
PyBaseObjectType
;
internal
static
IntPtr
PyModuleType
;
internal
static
IntPtr
PyClassType
;
internal
static
IntPtr
PyInstanceType
;
internal
static
IntPtr
PySuper_Type
;
internal
static
IntPtr
PyCLRMetaType
;
internal
static
IntPtr
PyMethodType
;
internal
static
IntPtr
PyWrapperDescriptorType
;
internal
static
IntPtr
PyUnicodeType
;
internal
static
IntPtr
PyStringType
;
internal
static
IntPtr
PyTupleType
;
internal
static
IntPtr
PyListType
;
internal
static
IntPtr
PyDictType
;
internal
static
IntPtr
PyIntType
;
internal
static
IntPtr
PyLongType
;
internal
static
IntPtr
PyFloatType
;
internal
static
IntPtr
PyBoolType
;
internal
static
IntPtr
PyNoneType
;
internal
static
IntPtr
PyTypeType
;
internal
static
IntPtr
Py_NoSiteFlag
;
internal
static
IntPtr
PyBytesType
;
internal
static
IntPtr
_PyObject_NextNotImplemented
;
internal
static
IntPtr
PyNotImplemented
;
internal
const
int
Py_LT
=
0
;
internal
const
int
Py_LE
=
1
;
internal
const
int
Py_EQ
=
2
;
internal
const
int
Py_NE
=
3
;
internal
const
int
Py_GT
=
4
;
internal
const
int
Py_GE
=
5
;
internal
static
IntPtr
PyTrue
;
internal
static
IntPtr
PyFalse
;
internal
static
IntPtr
PyNone
;
internal
static
IntPtr
Error
;
public
static
PyObject
None
{
get
{
var
none
=
Runtime
.
PyNone
;
Runtime
.
XIncref
(
none
)
;
return
new
PyObject
(
none
)
;
}
}
/// <summary>
/// Check if any Python Exceptions occurred.
/// If any exist throw new PythonException.
/// </summary>
/// <remarks>
/// Can be used instead of `obj == IntPtr.Zero` for example.
/// </remarks>
internal
static
void
CheckExceptionOccurred
(
)
{
if
(
PyErr_Occurred
(
)
!=
IntPtr
.
Zero
)
{
throw
new
PythonException
(
)
;
}
}
internal
static
IntPtr
ExtendTuple
(
IntPtr
t
,
params
IntPtr
[
]
args
)
{
var
size
=
PyTuple_Size
(
t
)
;
int
add
=
args
.
Length
;
IntPtr
item
;
IntPtr
items
=
PyTuple_New
(
size
+
add
)
;
for
(
var
i
=
0
;
i
<
size
;
i
++
)
{
item
=
PyTuple_GetItem
(
t
,
i
)
;
XIncref
(
item
)
;
PyTuple_SetItem
(
items
,
i
,
item
)
;
}
for
(
var
n
=
0
;
n
<
add
;
n
++
)
{
item
=
args
[
n
]
;
XIncref
(
item
)
;
PyTuple_SetItem
(
items
,
size
+
n
,
item
)
;
}
return
items
;
}
internal
static
Type
[
]
PythonArgsToTypeArray
(
IntPtr
arg
)
{
return
PythonArgsToTypeArray
(
arg
,
false
)
;
}
internal
static
Type
[
]
PythonArgsToTypeArray
(
IntPtr
arg
,
bool
mangleObjects
)
{
// Given a PyObject * that is either a single type object or a
// tuple of (managed or unmanaged) type objects, return a Type[]
// containing the CLR Type objects that map to those types.
IntPtr
args
=
arg
;
var
free
=
false
;
if
(
!
PyTuple_Check
(
arg
)
)
{
args
=
PyTuple_New
(
1
)
;
XIncref
(
arg
)
;
PyTuple_SetItem
(
args
,
0
,
arg
)
;
free
=
true
;
}
var
n
=
PyTuple_Size
(
args
)
;
var
types
=
new
Type
[
n
]
;
Type
t
=
null
;
for
(
var
i
=
0
;
i
<
n
;
i
++
)
{
IntPtr
op
=
PyTuple_GetItem
(
args
,
i
)
;
if
(
mangleObjects
&&
(
!
PyType_Check
(
op
)
)
)
{
op
=
PyObject_TYPE
(
op
)
;
}
ManagedType
mt
=
ManagedType
.
GetManagedObject
(
op
)
;
if
(
mt
is
ClassBase
)
{
t
=
(
(
ClassBase
)
mt
)
.
type
;
}
else
if
(
mt
is
CLRObject
)
{
object
inst
=
(
(
CLRObject
)
mt
)
.
inst
;
if
(
inst
is
Type
)
{
t
=
inst
as
Type
;
}
}
else
{
t
=
Converter
.
GetTypeByAlias
(
op
)
;
}
if
(
t
==
null
)
{
types
=
null
;
break
;
}
types
[
i
]
=
t
;
}
if
(
free
)
{
XDecref
(
args
)
;
}
return
types
;
}
/// <summary>
/// Managed exports of the Python C API. Where appropriate, we do
/// some optimization to avoid managed <--> unmanaged transitions
/// (mostly for heavily used methods).
/// </summary>
internal
static
unsafe
void
XIncref
(
IntPtr
op
)
{
#if
PYTHON_WITH_PYDEBUG
||
NETSTANDARD
Py_IncRef
(
op
)
;
return
;
#else
var
p
=
(
void
*
)
op
;
if
(
(
void
*
)
0
!=
p
)
{
if
(
Is32Bit
)
{
(
*
(
int
*
)
p
)
++
;
}
else
{
(
*
(
long
*
)
p
)
++
;
}
}
#endif
}
/// <summary>
/// Increase Python's ref counter for the given object, and get the object back.
/// </summary>
internal
static
IntPtr
SelfIncRef
(
IntPtr
op
)
{
XIncref
(
op
)
;
return
op
;
}
internal
static
unsafe
void
XDecref
(
IntPtr
op
)
{
#if
PYTHON_WITH_PYDEBUG
||
NETSTANDARD
Py_DecRef
(
op
)
;
return
;
#else
var
p
=
(
void
*
)
op
;
if
(
(
void
*
)
0
!=
p
)
{
if
(
Is32Bit
)
{
--
(
*
(
int
*
)
p
)
;
}
else
{
--
(
*
(
long
*
)
p
)
;
}
if
(
(
*
(
int
*
)
p
)
==
0
)
{
// PyObject_HEAD: struct _typeobject *ob_type
void
*
t
=
Is32Bit
?
(
void
*
)
(
*
(
(
uint
*
)
p
+
1
)
)
:
(
void
*
)
(
*
(
(
ulong
*
)
p
+
1
)
)
;
// PyTypeObject: destructor tp_dealloc
void
*
f
=
Is32Bit
?
(
void
*
)
(
*
(
(
uint
*
)
t
+
6
)
)
:
(
void
*
)
(
*
(
(
ulong
*
)
t
+
6
)
)
;
if
(
(
void
*
)
0
==
f
)
{
return
;
}
NativeCall
.
Impl
.
Void_Call_1
(
new
IntPtr
(
f
)
,
op
)
;
}
}
#endif
}
[
Pure
]
internal
static
unsafe
long
Refcount
(
IntPtr
op
)
{
var p
=
(
void
*
)
op
;
if
(
(
void
*
)
0
==
p
)
{
return
0
;
}
return
Is32Bit
?
(
*
(
int
*
)
p
)
:
(
*
(
long
*
)
p
)
;
}
/// <summary>
/// Export of Macro Py_XIncRef. Use XIncref instead.
/// Limit this function usage for Testing and Py_Debug builds
/// </summary>
/// <param name="ob">PyObject Ptr</param>
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
Py_IncRef
(
IntPtr
ob
)
;
/// <summary>
/// Export of Macro Py_XDecRef. Use XDecref instead.
/// Limit this function usage for Testing and Py_Debug builds
/// </summary>
/// <param name="ob">PyObject Ptr</param>
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
Py_DecRef
(
IntPtr
ob
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
Py_Initialize
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
Py_InitializeEx
(
int
initsigs
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
Py_IsInitialized
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
Py_Finalize
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr Py_NewInterpreter
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
Py_EndInterpreter
(
IntPtr
threadState
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyThreadState_New
(
IntPtr
istate
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyThreadState_Get
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyThread_get_key_value
(
IntPtr
key
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyThread_get_thread_ident
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyThread_set_key_value
(
IntPtr
key
,
IntPtr
value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyThreadState_Swap
(
IntPtr
key
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyGILState_Ensure
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
PyGILState_Release
(
IntPtr
gs
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyGILState_GetThisThreadState
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
public
static
extern
int
Py_Main
(
int
argc
,
[
MarshalAs
(
UnmanagedType
.
CustomMarshaler
,
MarshalTypeRef
=
typeof
(
StrArrayMarshaler
)
)
]
string
[
]
argv
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
PyEval_InitThreads
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyEval_ThreadsInitialized
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
PyEval_AcquireLock
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
PyEval_ReleaseLock
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
PyEval_AcquireThread
(
IntPtr
tstate
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
PyEval_ReleaseThread
(
IntPtr
tstate
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
PyEval_SaveThread
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
PyEval_RestoreThread
(
IntPtr
tstate
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
PyEval_GetBuiltins
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
PyEval_GetGlobals
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
PyEval_GetLocals
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
Py_GetProgramName
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
Py_SetProgramName
(
IntPtr
name
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
Py_GetPythonHome
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
Py_SetPythonHome
(
IntPtr
home
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
Py_GetPath
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
Py_SetPath
(
IntPtr
home
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
Py_GetVersion
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
Py_GetPlatform
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
Py_GetCopyright
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
Py_GetCompiler
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
Py_GetBuildInfo
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyRun_SimpleString
(
string
code
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
NewReference
PyRun_String
(
[
MarshalAs
(
UnmanagedType
.
CustomMarshaler
,
MarshalTypeRef
=
typeof
(
Utf8Marshaler
)
)
]
string
code
,
IntPtr
st
,
IntPtr
globals
,
IntPtr
locals
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
PyEval_EvalCode
(
IntPtr
co
,
IntPtr
globals
,
IntPtr
locals
)
;
/// <summary>
/// Return value: New reference.
/// This is a simplified interface to Py_CompileStringFlags() below, leaving flags set to NULL.
/// </summary>
internal
static
IntPtr
Py_CompileString
(
string
str
,
string
file
,
int
start
)
{
return
Py_CompileStringFlags
(
str
,
file
,
start
,
IntPtr
.
Zero
)
;
}
/// <summary>
/// Return value: New reference.
/// This is a simplified interface to Py_CompileStringExFlags() below, with optimize set to -1.
/// </summary>
internal
static
IntPtr
Py_CompileStringFlags
(
string
str
,
string
file
,
int
start
,
IntPtr
flags
)
{
return
Py_CompileStringExFlags
(
str
,
file
,
start
,
flags
,
-
1
)
;
}
/// <summary>
/// Return value: New reference.
/// Like Py_CompileStringObject(), but filename is a byte string decoded from the filesystem encoding(os.fsdecode()).
/// </summary>
/// <returns></returns>
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern IntPtr Py_CompileStringExFlags
(
string
str
,
string
file
,
int
start
,
IntPtr
flags
,
int
optimize
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
PyImport_ExecCodeModule
(
string
name
,
IntPtr
code
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
PyCFunction_NewEx
(
IntPtr
ml
,
IntPtr
self
,
IntPtr
mod
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
PyCFunction_Call
(
IntPtr
func
,
IntPtr
args
,
IntPtr
kw
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
PyInstance_New
(
IntPtr
cls
,
IntPtr
args
,
IntPtr
kw
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
PyInstance_NewRaw
(
IntPtr
cls
,
IntPtr
dict
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
PyMethod_New
(
IntPtr
func
,
IntPtr
self
,
IntPtr
cls
)
;
//====================================================================
// Python abstract object API
//====================================================================
/// <summary>
/// A macro-like method to get the type of a Python object. This is
/// designed to be lean and mean in IL & avoid managed <-> unmanaged
/// transitions. Note that this does not incref the type object.
/// </summary>
internal
static
unsafe
IntPtr
PyObject_TYPE
(
IntPtr
op
)
{
var
p
=
(
void
*
)
op
;
if
(
(
void
*
)
0
==
p
)
{
return
IntPtr
.
Zero
;
}
#if
PYTHON_WITH_PYDEBUG
var
n
=
3
;
#else
var
n
=
1
;
#endif
return
Is32Bit
?
new
IntPtr
(
(
void
*
)
(
*
(
(
uint
*
)
p
+
n
)
)
)
:
new
IntPtr
(
(
void
*
)
(
*
(
(
ulong
*
)
p
+
n
)
)
)
;
}
/// <summary>
/// Managed version of the standard Python C API PyObject_Type call.
/// This version avoids a managed <-> unmanaged transition.
/// This one does incref the returned type object.
/// </summary>
internal
static
IntPtr PyObject_Type
(
IntPtr
op
)
{
IntPtr tp
=
PyObject_TYPE
(
op
)
;
XIncref
(
tp
)
;
return
tp
;
}
internal
static
string
PyObject_GetTypeName
(
IntPtr
op
)
{
IntPtr pyType
=
Marshal
.
ReadIntPtr
(
op
,
ObjectOffset
.
ob_type
)
;
IntPtr
ppName
=
Marshal
.
ReadIntPtr
(
pyType
,
TypeOffset
.
tp_name
)
;
return
Marshal
.
PtrToStringAnsi
(
ppName
)
;
}
/// <summary>
/// Test whether the Python object is an iterable.
/// </summary>
internal
static
bool
PyObject_IsIterable
(
IntPtr
pointer
)
{
var
ob_type
=
Marshal
.
ReadIntPtr
(
pointer
,
ObjectOffset
.
ob_type
)
;
IntPtr
tp_iter
=
Marshal
.
ReadIntPtr
(
ob_type
,
TypeOffset
.
tp_iter
)
;
return
tp_iter
!=
IntPtr
.
Zero
;
}
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyObject_HasAttrString
(
IntPtr
pointer
,
string
name
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
PyObject_GetAttrString
(
IntPtr
pointer
,
string
name
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyObject_SetAttrString
(
IntPtr
pointer
,
string
name
,
IntPtr
value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyObject_HasAttr
(
IntPtr
pointer
,
IntPtr
name
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
PyObject_GetAttr
(
IntPtr
pointer
,
IntPtr
name
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyObject_SetAttr
(
IntPtr
pointer
,
IntPtr
name
,
IntPtr
value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
PyObject_GetItem
(
IntPtr
pointer
,
IntPtr
key
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyObject_SetItem
(
IntPtr
pointer
,
IntPtr
key
,
IntPtr
value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyObject_DelItem
(
IntPtr pointer
,
IntPtr
key
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyObject_GetIter
(
IntPtr op
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyObject_Call
(
IntPtr pointer
,
IntPtr args
,
IntPtr kw
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyObject_CallObject
(
IntPtr pointer
,
IntPtr args
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyObject_RichCompareBool
(
IntPtr value1
,
IntPtr value2
,
int
opid
)
;
internal
static
int
PyObject_Compare
(
IntPtr value1
,
IntPtr value2
)
{
int
res
;
res
=
PyObject_RichCompareBool
(
value1
,
value2
,
Py_LT
)
;
if
(
-
1
==
res
)
return
-
1
;
else
if
(
1
==
res
)
return
-
1
;
res
=
PyObject_RichCompareBool
(
value1
,
value2
,
Py_EQ
)
;
if
(
-
1
==
res
)
return
-
1
;
else
if
(
1
==
res
)
return
0
;
res
=
PyObject_RichCompareBool
(
value1
,
value2
,
Py_GT
)
;
if
(
-
1
==
res
)
return
-
1
;
else
if
(
1
==
res
)
return
1
;
Exceptions
.
SetError
(
Exceptions
.
SystemError
,
"Error comparing objects"
)
;
return
-
1
;
}
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyObject_IsInstance
(
IntPtr ob
,
IntPtr type
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyObject_IsSubclass
(
IntPtr ob
,
IntPtr type
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyCallable_Check
(
IntPtr pointer
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyObject_IsTrue
(
IntPtr pointer
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyObject_Not
(
IntPtr pointer
)
;
internal
static
long
PyObject_Size
(
IntPtr pointer
)
{
return
(
long
)
_PyObject_Size
(
pointer
)
;
}
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"PyObject_Size"
)
]
private
static
extern
IntPtr _PyObject_Size
(
IntPtr pointer
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyObject_Hash
(
IntPtr op
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyObject_Repr
(
IntPtr pointer
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyObject_Str
(
IntPtr pointer
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"PyObject_Str"
)
]
internal
static
extern
IntPtr PyObject_Unicode
(
IntPtr pointer
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyObject_Dir
(
IntPtr pointer
)
;
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL