Repository navigation
Expand file tree
/
Copy pathPythonCApi.cs
More file actions
786 lines (533 loc) · 41.3 KB
/
Copy pathPythonCApi.cs
File metadata and controls
786 lines (533 loc) · 41.3 KB
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
namespace Python.Runtime.Native {
using System;
using System.Runtime.InteropServices;
/// <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 static class PythonCApi {
const string _PythonDll = "FAKE";
/// <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(BorrowedObject 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(BorrowedObject 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 PythonInterpreterHandle Py_NewInterpreter();
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void Py_EndInterpreter(PythonInterpreterHandle threadState);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyThreadState_New(PythonInterpreterHandle interpreter);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyThreadState_Get();
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyThread_get_key_value(BorrowedObject 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(BorrowedObject key, BorrowedObject value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyThreadState_Swap(BorrowedObject key);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyGILState_Ensure();
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void PyGILState_Release(BorrowedObject gs);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject 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(BorrowedObject tstate);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void PyEval_ReleaseThread(BorrowedObject tstate);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyEval_SaveThread();
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void PyEval_RestoreThread(BorrowedObject tstate);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyEval_GetBuiltins();
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyEval_GetGlobals();
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyEval_GetLocals();
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject Py_GetProgramName();
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void Py_SetProgramName(BorrowedObject name);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject Py_GetPythonHome();
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void Py_SetPythonHome(BorrowedObject home);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject Py_GetPath();
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void Py_SetPath(BorrowedObject home);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject Py_GetVersion();
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject Py_GetPlatform();
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject Py_GetCopyright();
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject Py_GetCompiler();
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject Py_GetBuildInfo();
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyRun_SimpleString(string code);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyRun_String(string code, BorrowedObject st, BorrowedObject globals, BorrowedObject locals);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyEval_EvalCode(BorrowedObject co, BorrowedObject globals, BorrowedObject locals);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject Py_CompileString(string code, string file, BorrowedObject tok);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyImport_ExecCodeModule(string name, BorrowedObject code);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyCFunction_NewEx(BorrowedObject ml, BorrowedObject self, BorrowedObject mod);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyCFunction_Call(BorrowedObject func, BorrowedObject args, BorrowedObject kw);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyInstance_New(BorrowedObject cls, BorrowedObject args, BorrowedObject kw);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyInstance_NewRaw(BorrowedObject cls, BorrowedObject dict);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyMethod_New(BorrowedObject func, BorrowedObject self, BorrowedObject cls);
//====================================================================
// Python abstract object API
//====================================================================
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyObject_HasAttrString(BorrowedObject pointer, string name);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyObject_GetAttrString(BorrowedObject pointer, string name);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyObject_SetAttrString(BorrowedObject pointer, string name, BorrowedObject value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyObject_HasAttr(BorrowedObject pointer, BorrowedObject name);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyObject_GetAttr(BorrowedObject pointer, BorrowedObject name);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyObject_SetAttr(BorrowedObject pointer, BorrowedObject name, BorrowedObject value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyObject_GetItem(BorrowedObject pointer, BorrowedObject key);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyObject_SetItem(BorrowedObject pointer, BorrowedObject key, BorrowedObject value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyObject_DelItem(BorrowedObject pointer, BorrowedObject key);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyObject_GetIter(BorrowedObject op);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyObject_Call(BorrowedObject pointer, BorrowedObject args, BorrowedObject kw);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyObject_CallObject(BorrowedObject pointer, BorrowedObject args);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyObject_RichCompareBool(BorrowedObject value1, BorrowedObject value2, int opid);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyObject_IsInstance(BorrowedObject ob, BorrowedObject type);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyObject_IsSubclass(BorrowedObject ob, BorrowedObject type);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyCallable_Check(BorrowedObject pointer);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyObject_IsTrue(BorrowedObject pointer);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyObject_Not(BorrowedObject pointer);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyObject_Size")]
private static extern BorrowedObject _PyObject_Size(BorrowedObject pointer);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyObject_Hash(BorrowedObject op);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyObject_Repr(BorrowedObject pointer);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyObject_Str(BorrowedObject pointer);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "PyObject_Str")]
internal static extern BorrowedObject PyObject_Unicode(BorrowedObject pointer);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyObject_Dir(BorrowedObject pointer);
//====================================================================
// Python number API
//====================================================================
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "PyNumber_Long")]
internal static extern BorrowedObject PyNumber_Int(BorrowedObject ob);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_Long(BorrowedObject ob);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_Float(BorrowedObject ob);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern bool PyNumber_Check(BorrowedObject ob);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "PyLong_FromLong")]
private static extern BorrowedObject PyInt_FromLong(BorrowedObject value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "PyLong_AsLong")]
internal static extern int PyInt_AsLong(BorrowedObject value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "PyLong_FromString")]
internal static extern BorrowedObject PyInt_FromString(string value, BorrowedObject end, int radix);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyLong_FromLong(long value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "PyLong_FromUnsignedLong")]
internal static extern BorrowedObject PyLong_FromUnsignedLong32(uint value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "PyLong_FromUnsignedLong")]
internal static extern BorrowedObject PyLong_FromUnsignedLong64(ulong value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyLong_FromDouble(double value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyLong_FromLongLong(long value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyLong_FromUnsignedLongLong(ulong value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyLong_FromString(string value, BorrowedObject end, int radix);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyLong_AsLong(BorrowedObject value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "PyLong_AsUnsignedLong")]
internal static extern uint PyLong_AsUnsignedLong32(BorrowedObject value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "PyLong_AsUnsignedLong")]
internal static extern ulong PyLong_AsUnsignedLong64(BorrowedObject value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern long PyLong_AsLongLong(BorrowedObject value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern ulong PyLong_AsUnsignedLongLong(BorrowedObject value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyFloat_FromDouble(double value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyFloat_FromString(BorrowedObject value, BorrowedObject junk);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern double PyFloat_AsDouble(BorrowedObject ob);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_Add(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_Subtract(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_Multiply(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_TrueDivide(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_And(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_Xor(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_Or(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_Lshift(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_Rshift(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_Power(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_Remainder(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_InPlaceAdd(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_InPlaceSubtract(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_InPlaceMultiply(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_InPlaceTrueDivide(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_InPlaceAnd(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_InPlaceXor(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_InPlaceOr(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_InPlaceLshift(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_InPlaceRshift(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_InPlacePower(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_InPlaceRemainder(BorrowedObject o1, BorrowedObject o2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_Negative(BorrowedObject o1);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_Positive(BorrowedObject o1);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyNumber_Invert(BorrowedObject o1);
//====================================================================
// Python sequence API
//====================================================================
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern bool PySequence_Check(BorrowedObject pointer);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern BorrowedObject PySequence_GetItem(BorrowedObject pointer, BorrowedObject index);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern int PySequence_SetItem(BorrowedObject pointer, BorrowedObject index, BorrowedObject value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern int PySequence_DelItem(BorrowedObject pointer, BorrowedObject index);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern BorrowedObject PySequence_GetSlice(BorrowedObject pointer, BorrowedObject i1, BorrowedObject i2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern int PySequence_SetSlice(BorrowedObject pointer, BorrowedObject i1, BorrowedObject i2, BorrowedObject v);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern int PySequence_DelSlice(BorrowedObject pointer, BorrowedObject i1, BorrowedObject i2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PySequence_Size")]
private static extern BorrowedObject _PySequence_Size(BorrowedObject pointer);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PySequence_Contains(BorrowedObject pointer, BorrowedObject item);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PySequence_Concat(BorrowedObject pointer, BorrowedObject other);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern BorrowedObject PySequence_Repeat(BorrowedObject pointer, BorrowedObject count);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PySequence_Index(BorrowedObject pointer, BorrowedObject item);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PySequence_Count")]
private static extern BorrowedObject _PySequence_Count(BorrowedObject pointer, BorrowedObject value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PySequence_Tuple(BorrowedObject pointer);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PySequence_List(BorrowedObject pointer);
//====================================================================
// Python string API
//====================================================================
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyBytes_FromString(string op);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyBytes_Size")]
private static extern BorrowedObject _PyBytes_Size(BorrowedObject op);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "PyUnicode_FromStringAndSize")]
internal static extern BorrowedObject _PyString_FromStringAndSize(
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string value,
BorrowedObject size
);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern BorrowedObject PyUnicode_FromStringAndSize(BorrowedObject value, BorrowedObject size);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyUnicode_FromObject(BorrowedObject ob);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyUnicode_FromEncodedObject(BorrowedObject ob, BorrowedObject enc, BorrowedObject err);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern BorrowedObject PyUnicode_FromKindAndData(
int kind,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UcsMarshaler))] string s,
BorrowedObject size
);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyUnicode_GetSize")]
private static extern BorrowedObject _PyUnicode_GetSize(BorrowedObject ob);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyUnicode_AsUnicode(BorrowedObject ob);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyUnicode_FromOrdinal(int c);
//====================================================================
// Python dictionary API
//====================================================================
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyDict_New();
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyDictProxy_New(BorrowedObject dict);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyDict_GetItem(BorrowedObject pointer, BorrowedObject key);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyDict_GetItemString(BorrowedObject pointer, string key);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyDict_SetItem(BorrowedObject pointer, BorrowedObject key, BorrowedObject value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyDict_SetItemString(BorrowedObject pointer, string key, BorrowedObject value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyDict_DelItem(BorrowedObject pointer, BorrowedObject key);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyDict_DelItemString(BorrowedObject pointer, string key);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyMapping_HasKey(BorrowedObject pointer, BorrowedObject key);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyDict_Keys(BorrowedObject pointer);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyDict_Values(BorrowedObject pointer);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyDict_Items(BorrowedObject pointer);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyDict_Copy(BorrowedObject pointer);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyDict_Update(BorrowedObject pointer, BorrowedObject other);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void PyDict_Clear(BorrowedObject pointer);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyDict_Size")]
internal static extern BorrowedObject _PyDict_Size(BorrowedObject pointer);
//====================================================================
// Python list API
//====================================================================
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern BorrowedObject PyList_New(BorrowedObject size);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyList_AsTuple(BorrowedObject pointer);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern BorrowedObject PyList_GetItem(BorrowedObject pointer, BorrowedObject index);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern int PyList_SetItem(BorrowedObject pointer, BorrowedObject index, BorrowedObject value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern int PyList_Insert(BorrowedObject pointer, BorrowedObject index, BorrowedObject value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyList_Append(BorrowedObject pointer, BorrowedObject value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyList_Reverse(BorrowedObject pointer);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyList_Sort(BorrowedObject pointer);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern BorrowedObject PyList_GetSlice(BorrowedObject pointer, BorrowedObject start, BorrowedObject end);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern int PyList_SetSlice(BorrowedObject pointer, BorrowedObject start, BorrowedObject end, BorrowedObject value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyList_Size")]
private static extern BorrowedObject _PyList_Size(BorrowedObject pointer);
//====================================================================
// Python tuple API
//====================================================================
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern BorrowedObject PyTuple_New(BorrowedObject size);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern BorrowedObject PyTuple_GetItem(BorrowedObject pointer, BorrowedObject index);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern int PyTuple_SetItem(BorrowedObject pointer, BorrowedObject index, BorrowedObject value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern BorrowedObject PyTuple_GetSlice(BorrowedObject pointer, BorrowedObject start, BorrowedObject end);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyTuple_Size")]
private static extern BorrowedObject _PyTuple_Size(BorrowedObject pointer);
//====================================================================
// Python iterator API
//====================================================================
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyIter_Next(BorrowedObject pointer);
//====================================================================
// Python module API
//====================================================================
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyModule_New(string name);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern string PyModule_GetName(BorrowedObject module);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyModule_GetDict(BorrowedObject module);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern string PyModule_GetFilename(BorrowedObject module);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyModule_Create2(BorrowedObject module, int apiver);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyImport_Import(BorrowedObject name);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyImport_ImportModule(string name);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyImport_ReloadModule(BorrowedObject module);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyImport_AddModule(string name);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyImport_GetModuleDict();
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void PySys_SetArgvEx(
int argc,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(StrArrayMarshaler))] string[] argv,
int updatepath
);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PySys_GetObject(string name);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PySys_SetObject(string name, BorrowedObject ob);
//====================================================================
// Python type object API
//====================================================================
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void PyType_Modified(BorrowedObject type);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern bool PyType_IsSubtype(BorrowedObject t1, BorrowedObject t2);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyType_GenericNew(BorrowedObject type, BorrowedObject args, BorrowedObject kw);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern BorrowedObject PyType_GenericAlloc(BorrowedObject type, BorrowedObject n);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyType_Ready(BorrowedObject type);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject _PyType_Lookup(BorrowedObject type, BorrowedObject name);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyObject_GenericGetAttr(BorrowedObject obj, BorrowedObject name);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyObject_GenericSetAttr(BorrowedObject obj, BorrowedObject name, BorrowedObject value);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject _PyObject_GetDictPtr(BorrowedObject obj);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyObject_GC_New(BorrowedObject tp);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void PyObject_GC_Del(BorrowedObject tp);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void PyObject_GC_Track(BorrowedObject tp);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void PyObject_GC_UnTrack(BorrowedObject tp);
//====================================================================
// Python memory API
//====================================================================
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern BorrowedObject PyMem_Malloc(BorrowedObject size);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern BorrowedObject PyMem_Realloc(BorrowedObject ptr, BorrowedObject size);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void PyMem_Free(BorrowedObject ptr);
//====================================================================
// Python exception API
//====================================================================
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void PyErr_SetString(BorrowedObject ob, string message);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void PyErr_SetObject(BorrowedObject ob, BorrowedObject message);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyErr_SetFromErrno(BorrowedObject ob);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void PyErr_SetNone(BorrowedObject ob);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyErr_ExceptionMatches(BorrowedObject exception);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyErr_GivenExceptionMatches(BorrowedObject ob, BorrowedObject val);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void PyErr_NormalizeException(BorrowedObject ob, BorrowedObject val, BorrowedObject tb);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyErr_Occurred();
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void PyErr_Fetch(ref BorrowedObject ob, ref BorrowedObject val, ref BorrowedObject tb);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void PyErr_Restore(BorrowedObject ob, BorrowedObject val, BorrowedObject tb);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void PyErr_Clear();
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void PyErr_Print();
//====================================================================
// Miscellaneous
//====================================================================
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyMethod_Self(BorrowedObject ob);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedObject PyMethod_Function(BorrowedObject ob);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int Py_AddPendingCall(BorrowedObject func, BorrowedObject arg);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int Py_MakePendingCalls();
}
}