FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/Python.Runtime.Native/LibPythonPInvoke.cs at modernisation · akamotaco/pythonnet · GitHub
akamotaco
pythonnet
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet
/
Python.Runtime.Native
/
LibPythonPInvoke.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
1054 lines (758 loc) · 47.2 KB
Breadcrumbs
pythonnet
/
Python.Runtime.Native
/
LibPythonPInvoke.cs
Copy path
File metadata and controls
1054 lines (758 loc) · 47.2 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
;
using
System
.
Runtime
.
InteropServices
;
using
System
.
Security
;
using
System
.
Text
;
using
System
.
Threading
;
using
System
.
Collections
.
Generic
;
using
Python
.
Runtime
.
Interfaces
;
namespace
Python
.
Runtime
.
Native
{
public
partial
class
LibPythonPInvoke
:
ILibPython
{
// 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
!
UCS2
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_"
;
#else
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_"
;
#endif
internal
const
string
_PythonDll
=
"__Internal"
;
// set to true when python is finalizing
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
;
/// <summary>
/// Encoding to use to convert Unicode to/from Managed to Native
/// </summary>
internal
static
readonly
Encoding
PyEncoding
=
_UCS
==
2
?
Encoding
.
Unicode
:
Encoding
.
UTF32
;
/// <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
(
)
;
#if
!
PYTHON2
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
public
static
extern
int
Py_Main
(
int
argc
,
[
MarshalAs
(
UnmanagedType
.
CustomMarshaler
,
MarshalTypeRef
=
typeof
(
StrArrayMarshaler
)
)
]
string
[
]
argv
)
;
#else
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
public
static
extern
int
Py_Main
(
int
argc
,
string
[
]
argv
)
;
#endif
[
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
IntPtr
PyRun_String
(
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
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
Py_CompileString
(
string
code
,
string
file
,
IntPtr
tok
)
;
[
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
)
;
#if
PYTHON2
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
PyClass_New
(
IntPtr
bases
,
IntPtr
dict
,
IntPtr
name
)
;
#endif
[
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
)
)
)
;
}
[
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
)
;
[
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
)
;
[
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
)
;
#if
!
PYTHON2
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"PyObject_Str"
)
]
internal
static
extern
IntPtr PyObject_Unicode
(
IntPtr
pointer
)
;
#else
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyObject_Unicode
(
IntPtr
pointer
)
;
#endif
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyObject_Dir
(
IntPtr
pointer
)
;
//====================================================================
// Python number API
//====================================================================
#if
!
PYTHON2
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"PyNumber_Long"
)
]
internal
static
extern
IntPtr PyNumber_Int
(
IntPtr
ob
)
;
#else
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_Int
(
IntPtr
ob
)
;
#endif
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_Long
(
IntPtr
ob
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_Float
(
IntPtr
ob
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
bool
PyNumber_Check
(
IntPtr
ob
)
;
#if
!
PYTHON2
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"PyLong_FromLong"
)
]
private
static
extern
IntPtr PyInt_FromLong
(
IntPtr
value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"PyLong_AsLong"
)
]
internal
static
extern
int
PyInt_AsLong
(
IntPtr
value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"PyLong_FromString"
)
]
internal
static
extern
IntPtr PyInt_FromString
(
string
value
,
IntPtr
end
,
int
radix
)
;
#else
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
IntPtr PyInt_FromLong
(
IntPtr
value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyInt_AsLong
(
IntPtr
value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyInt_FromString
(
string
value
,
IntPtr
end
,
int
radix
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyInt_GetMax
(
)
;
#endif
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyLong_FromLong
(
long
value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"PyLong_FromUnsignedLong"
)
]
internal
static
extern
IntPtr PyLong_FromUnsignedLong32
(
uint
value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"PyLong_FromUnsignedLong"
)
]
internal
static
extern
IntPtr PyLong_FromUnsignedLong64
(
ulong
value
)
;
internal
static
IntPtr PyLong_FromUnsignedLong
(
object
value
)
{
if
(
Is32Bit
||
IsWindows
)
return PyLong_FromUnsignedLong32
(
Convert
.
ToUInt32
(
value
)
)
;
else
return
PyLong_FromUnsignedLong64
(
Convert
.
ToUInt64
(
value
)
)
;
}
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyLong_FromDouble
(
double
value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyLong_FromLongLong
(
long
value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyLong_FromUnsignedLongLong
(
ulong
value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyLong_FromString
(
string
value
,
IntPtr
end
,
int
radix
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyLong_AsLong
(
IntPtr
value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"PyLong_AsUnsignedLong"
)
]
internal
static
extern
uint
PyLong_AsUnsignedLong32
(
IntPtr
value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"PyLong_AsUnsignedLong"
)
]
internal
static
extern
ulong
PyLong_AsUnsignedLong64
(
IntPtr
value
)
;
internal
static
object
PyLong_AsUnsignedLong
(
IntPtr
value
)
{
if
(
Is32Bit
||
IsWindows
)
return PyLong_AsUnsignedLong32
(
value
)
;
else
return
PyLong_AsUnsignedLong64
(
value
)
;
}
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
long
PyLong_AsLongLong
(
IntPtr
value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
ulong
PyLong_AsUnsignedLongLong
(
IntPtr
value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyFloat_FromDouble
(
double
value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyFloat_FromString
(
IntPtr
value
,
IntPtr
junk
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
double
PyFloat_AsDouble
(
IntPtr
ob
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_Add
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_Subtract
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_Multiply
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_TrueDivide
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_And
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_Xor
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_Or
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_Lshift
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_Rshift
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_Power
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_Remainder
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_InPlaceAdd
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_InPlaceSubtract
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_InPlaceMultiply
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_InPlaceTrueDivide
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_InPlaceAnd
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_InPlaceXor
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_InPlaceOr
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_InPlaceLshift
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_InPlaceRshift
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_InPlacePower
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_InPlaceRemainder
(
IntPtr
o1
,
IntPtr
o2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_Negative
(
IntPtr
o1
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_Positive
(
IntPtr
o1
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyNumber_Invert
(
IntPtr
o1
)
;
//====================================================================
// Python sequence API
//====================================================================
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
bool
PySequence_Check
(
IntPtr
pointer
)
;
internal
static
IntPtr PySequence_GetItem
(
IntPtr
pointer
,
long
index
)
{
return
PySequence_GetItem
(
pointer
,
new
IntPtr
(
index
)
)
;
}
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
IntPtr PySequence_GetItem
(
IntPtr
pointer
,
IntPtr
index
)
;
internal
static
int
PySequence_SetItem
(
IntPtr
pointer
,
long
index
,
IntPtr
value
)
{
return
PySequence_SetItem
(
pointer
,
new
IntPtr
(
index
)
,
value
)
;
}
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
int
PySequence_SetItem
(
IntPtr
pointer
,
IntPtr
index
,
IntPtr
value
)
;
internal
static
int
PySequence_DelItem
(
IntPtr
pointer
,
long
index
)
{
return
PySequence_DelItem
(
pointer
,
new
IntPtr
(
index
)
)
;
}
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
int
PySequence_DelItem
(
IntPtr
pointer
,
IntPtr
index
)
;
internal
static
IntPtr PySequence_GetSlice
(
IntPtr
pointer
,
long
i1
,
long
i2
)
{
return
PySequence_GetSlice
(
pointer
,
new
IntPtr
(
i1
)
,
new
IntPtr
(
i2
)
)
;
}
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
IntPtr PySequence_GetSlice
(
IntPtr
pointer
,
IntPtr
i1
,
IntPtr
i2
)
;
internal
static
int
PySequence_SetSlice
(
IntPtr
pointer
,
long
i1
,
long
i2
,
IntPtr
v
)
{
return
PySequence_SetSlice
(
pointer
,
new
IntPtr
(
i1
)
,
new
IntPtr
(
i2
)
,
v
)
;
}
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
int
PySequence_SetSlice
(
IntPtr
pointer
,
IntPtr
i1
,
IntPtr
i2
,
IntPtr
v
)
;
internal
static
int
PySequence_DelSlice
(
IntPtr
pointer
,
long
i1
,
long
i2
)
{
return
PySequence_DelSlice
(
pointer
,
new
IntPtr
(
i1
)
,
new
IntPtr
(
i2
)
)
;
}
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
int
PySequence_DelSlice
(
IntPtr
pointer
,
IntPtr
i1
,
IntPtr
i2
)
;
internal
static
long
PySequence_Size
(
IntPtr
pointer
)
{
return
(
long
)
_PySequence_Size
(
pointer
)
;
}
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"PySequence_Size"
)
]
private
static
extern
IntPtr
_PySequence_Size
(
IntPtr
pointer
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PySequence_Contains
(
IntPtr
pointer
,
IntPtr
item
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
PySequence_Concat
(
IntPtr
pointer
,
IntPtr
other
)
;
internal
static
IntPtr
PySequence_Repeat
(
IntPtr
pointer
,
long
count
)
{
return
PySequence_Repeat
(
pointer
,
new
IntPtr
(
count
)
)
;
}
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
IntPtr PySequence_Repeat
(
IntPtr
pointer
,
IntPtr
count
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PySequence_Index
(
IntPtr
pointer
,
IntPtr
item
)
;
internal
static
long
PySequence_Count
(
IntPtr
pointer
,
IntPtr
value
)
{
return
(
long
)
_PySequence_Count
(
pointer
,
value
)
;
}
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"PySequence_Count"
)
]
private
static
extern
IntPtr
_PySequence_Count
(
IntPtr
pointer
,
IntPtr
value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
PySequence_Tuple
(
IntPtr
pointer
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
PySequence_List
(
IntPtr
pointer
)
;
//====================================================================
// Python string API
//====================================================================
internal
static
IntPtr
PyString_FromString
(
string
value
)
{
#if
!
PYTHON2
return
PyUnicode_FromKindAndData
(
_UCS
,
value
,
value
.
Length
)
;
#else
return
PyString_FromStringAndSize
(
value
,
value
.
Length
)
;
#endif
}
#if
!
PYTHON2
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyBytes_FromString
(
string
op
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"PyBytes_Size"
)
]
private
static
extern
IntPtr _PyBytes_Size
(
IntPtr
op
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"PyUnicode_FromStringAndSize"
)
]
internal
static
extern
IntPtr _PyString_FromStringAndSize
(
[
MarshalAs
(
UnmanagedType
.
CustomMarshaler
,
MarshalTypeRef
=
typeof
(
Utf8Marshaler
)
)
]
string
value
,
IntPtr
size
)
;
internal
static
IntPtr PyUnicode_FromStringAndSize
(
IntPtr
value
,
long
size
)
{
return
PyUnicode_FromStringAndSize
(
value
,
new
IntPtr
(
size
)
)
;
}
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
IntPtr PyUnicode_FromStringAndSize
(
IntPtr
value
,
IntPtr
size
)
;
#else
internal
static
IntPtr PyString_FromStringAndSize
(
string
value
,
long
size
)
{
return
PyString_FromStringAndSize
(
value
,
new
IntPtr
(
size
)
)
;
}
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
IntPtr PyString_FromStringAndSize
(
string
value
,
IntPtr
size
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyString_AsString
(
IntPtr
op
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyString_Size
(
IntPtr
pointer
)
;
#endif
#if
!
PYTHON2
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyUnicode_FromObject
(
IntPtr
ob
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyUnicode_FromEncodedObject
(
IntPtr
ob
,
IntPtr
enc
,
IntPtr
err
)
;
internal
static
IntPtr PyUnicode_FromKindAndData
(
int
kind
,
string
s
,
long
size
)
{
return
PyUnicode_FromKindAndData
(
kind
,
s
,
new
IntPtr
(
size
)
)
;
}
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
IntPtr PyUnicode_FromKindAndData
(
int
kind
,
[
MarshalAs
(
UnmanagedType
.
CustomMarshaler
,
MarshalTypeRef
=
typeof
(
UcsMarshaler
)
)
]
string
s
,
IntPtr size
)
;
internal
static
IntPtr PyUnicode_FromUnicode
(
string
s
,
long
size
)
{
return
PyUnicode_FromKindAndData
(
_UCS
,
s
,
size
)
;
}
internal
static
long
PyUnicode_GetSize
(
IntPtr
ob
)
{
return
(
long
)
_PyUnicode_GetSize
(
ob
)
;
}
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"PyUnicode_GetSize"
)
]
private
static
extern
IntPtr
_PyUnicode_GetSize
(
IntPtr
ob
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
PyUnicode_AsUnicode
(
IntPtr
ob
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr
PyUnicode_FromOrdinal
(
int
c
)
;
#else
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
PyUnicodeEntryPoint
+
"FromObject"
)
]
internal
static
extern
IntPtr
PyUnicode_FromObject
(
IntPtr
ob
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
PyUnicodeEntryPoint
+
"FromEncodedObject"
)
]
internal
static
extern
IntPtr
PyUnicode_FromEncodedObject
(
IntPtr
ob
,
IntPtr
enc
,
IntPtr
err
)
;
internal
static
IntPtr
PyUnicode_FromUnicode
(
string
s
,
long
size
)
{
return
PyUnicode_FromUnicode
(
s
,
new
IntPtr
(
size
)
)
;
}
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
PyUnicodeEntryPoint
+
"FromUnicode"
)
]
private
static
extern
IntPtr PyUnicode_FromUnicode
(
[
MarshalAs
(
UnmanagedType
.
CustomMarshaler
,
MarshalTypeRef
=
typeof
(
UcsMarshaler
)
)
]
string
s
,
IntPtr size
)
;
internal
static
long
PyUnicode_GetSize
(
IntPtr ob
)
{
return
(
long
)
_PyUnicode_GetSize
(
ob
)
;
}
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
PyUnicodeEntryPoint
+
"GetSize"
)
]
internal
static
extern
IntPtr _PyUnicode_GetSize
(
IntPtr ob
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
PyUnicodeEntryPoint
+
"AsUnicode"
)
]
internal
static
extern
IntPtr PyUnicode_AsUnicode
(
IntPtr ob
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
PyUnicodeEntryPoint
+
"FromOrdinal"
)
]
internal
static
extern
IntPtr PyUnicode_FromOrdinal
(
int
c
)
;
#endif
//====================================================================
// Python dictionary API
//====================================================================
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyDict_New
(
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyDictProxy_New
(
IntPtr dict
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyDict_GetItem
(
IntPtr pointer
,
IntPtr key
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyDict_GetItemString
(
IntPtr pointer
,
string
key
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyDict_SetItem
(
IntPtr pointer
,
IntPtr key
,
IntPtr value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyDict_SetItemString
(
IntPtr pointer
,
string
key
,
IntPtr value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyDict_DelItem
(
IntPtr pointer
,
IntPtr key
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyDict_DelItemString
(
IntPtr pointer
,
string
key
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyMapping_HasKey
(
IntPtr pointer
,
IntPtr key
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyDict_Keys
(
IntPtr pointer
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyDict_Values
(
IntPtr pointer
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyDict_Items
(
IntPtr pointer
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyDict_Copy
(
IntPtr pointer
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyDict_Update
(
IntPtr pointer
,
IntPtr other
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
PyDict_Clear
(
IntPtr pointer
)
;
internal
static
long
PyDict_Size
(
IntPtr pointer
)
{
return
(
long
)
_PyDict_Size
(
pointer
)
;
}
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"PyDict_Size"
)
]
internal
static
extern
IntPtr _PyDict_Size
(
IntPtr pointer
)
;
//====================================================================
// Python list API
//====================================================================
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
IntPtr PyList_New
(
IntPtr size
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyList_AsTuple
(
IntPtr pointer
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
IntPtr PyList_GetItem
(
IntPtr pointer
,
IntPtr index
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
int
PyList_SetItem
(
IntPtr pointer
,
IntPtr index
,
IntPtr value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
int
PyList_Insert
(
IntPtr pointer
,
IntPtr index
,
IntPtr value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyList_Append
(
IntPtr pointer
,
IntPtr value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyList_Reverse
(
IntPtr pointer
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyList_Sort
(
IntPtr pointer
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
IntPtr PyList_GetSlice
(
IntPtr pointer
,
IntPtr start
,
IntPtr end
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
int
PyList_SetSlice
(
IntPtr pointer
,
IntPtr start
,
IntPtr end
,
IntPtr value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"PyList_Size"
)
]
private
static
extern
IntPtr _PyList_Size
(
IntPtr pointer
)
;
//====================================================================
// Python tuple API
//====================================================================
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
IntPtr PyTuple_New
(
IntPtr size
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
IntPtr PyTuple_GetItem
(
IntPtr pointer
,
IntPtr index
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
int
PyTuple_SetItem
(
IntPtr pointer
,
IntPtr index
,
IntPtr value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
IntPtr PyTuple_GetSlice
(
IntPtr pointer
,
IntPtr start
,
IntPtr end
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"PyTuple_Size"
)
]
private
static
extern
IntPtr _PyTuple_Size
(
IntPtr pointer
)
;
//====================================================================
// Python iterator API
//====================================================================
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyIter_Next
(
IntPtr pointer
)
;
//====================================================================
// Python module API
//====================================================================
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyModule_New
(
string
name
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
string
PyModule_GetName
(
IntPtr module
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyModule_GetDict
(
IntPtr module
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
string
PyModule_GetFilename
(
IntPtr module
)
;
#if
!
PYTHON2
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyModule_Create2
(
IntPtr module
,
int
apiver
)
;
#endif
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyImport_Import
(
IntPtr name
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyImport_ImportModule
(
string
name
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyImport_ReloadModule
(
IntPtr module
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyImport_AddModule
(
string
name
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyImport_GetModuleDict
(
)
;
#if
!
PYTHON2
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
PySys_SetArgvEx
(
int
argc
,
[
MarshalAs
(
UnmanagedType
.
CustomMarshaler
,
MarshalTypeRef
=
typeof
(
StrArrayMarshaler
)
)
]
string
[
]
argv
,
int
updatepath
)
;
#else
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
PySys_SetArgvEx
(
int
argc
,
string
[
]
argv
,
int
updatepath
)
;
#endif
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PySys_GetObject
(
string
name
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PySys_SetObject
(
string
name
,
IntPtr ob
)
;
//====================================================================
// Python type object API
//====================================================================
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
PyType_Modified
(
IntPtr type
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
bool
PyType_IsSubtype
(
IntPtr t1
,
IntPtr t2
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyType_GenericNew
(
IntPtr type
,
IntPtr args
,
IntPtr kw
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
IntPtr PyType_GenericAlloc
(
IntPtr type
,
IntPtr n
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyType_Ready
(
IntPtr type
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr _PyType_Lookup
(
IntPtr type
,
IntPtr name
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyObject_GenericGetAttr
(
IntPtr obj
,
IntPtr name
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyObject_GenericSetAttr
(
IntPtr obj
,
IntPtr name
,
IntPtr value
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr _PyObject_GetDictPtr
(
IntPtr obj
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyObject_GC_New
(
IntPtr tp
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
PyObject_GC_Del
(
IntPtr tp
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
PyObject_GC_Track
(
IntPtr tp
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
PyObject_GC_UnTrack
(
IntPtr tp
)
;
//====================================================================
// Python memory API
//====================================================================
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
IntPtr PyMem_Malloc
(
IntPtr size
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
private
static
extern
IntPtr PyMem_Realloc
(
IntPtr ptr
,
IntPtr size
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
PyMem_Free
(
IntPtr ptr
)
;
//====================================================================
// Python exception API
//====================================================================
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
PyErr_SetString
(
IntPtr ob
,
string
message
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
PyErr_SetObject
(
IntPtr ob
,
IntPtr message
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
IntPtr PyErr_SetFromErrno
(
IntPtr ob
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
void
PyErr_SetNone
(
IntPtr ob
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyErr_ExceptionMatches
(
IntPtr exception
)
;
[
DllImport
(
_PythonDll
,
CallingConvention
=
CallingConvention
.
Cdecl
)
]
internal
static
extern
int
PyErr_GivenExceptionMatches
(
IntPtr ob
,
IntPtr val
)
;
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL