interoptopus_backend_cpython_cffi 0.2.2

Generates CPython CFFI bindings.
Documentation
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
from cffi import FFI

api_definition = """




const uint8_t CFFI_U8 = 255;
const float CFFI_F32_MIN_POSITIVE = 0.000000000000000000000000000000000000011754944;
const int32_t CFFI_COMPUTED_I32 = -2147483647;

typedef enum cffi_enumdocumented
    {
    CFFI_A = 0,
    CFFI_B = 1,
    } cffi_enumdocumented;

typedef struct cffi_context cffi_context;
typedef struct cffi_generic2u8 cffi_generic2u8;
typedef struct cffi_generic3 cffi_generic3;
typedef struct cffi_opaque cffi_opaque;
typedef struct cffi_simpleservice cffi_simpleservice;
typedef struct cffi_empty cffi_empty;

typedef enum cffi_ffierror
    {
    CFFI_OK = 0,
    CFFI_NULL = 100,
    CFFI_PANIC = 200,
    CFFI_FAIL = 300,
    } cffi_ffierror;

typedef struct cffi_inner
    {
    float x;
    } cffi_inner;

typedef struct cffi_phantomu8
    {
    uint32_t x;
    } cffi_phantomu8;

typedef struct cffi_someforeigntype
    {
    uint32_t x;
    } cffi_someforeigntype;

typedef struct cffi_structdocumented
    {
    float x;
    } cffi_structdocumented;

typedef struct cffi_tupled
    {
    uint8_t x0;
    } cffi_tupled;

typedef struct cffi_useasciistringpattern
    {
    uint8_t* ascii_string;
    } cffi_useasciistringpattern;

typedef struct cffi_vec
    {
    double x;
    double z;
    } cffi_vec;

typedef struct cffi_vec1
    {
    float x;
    float y;
    } cffi_vec1;

typedef struct cffi_vec2
    {
    double x;
    double z;
    } cffi_vec2;

typedef struct cffi_vec3f32
    {
    float x;
    float y;
    float z;
    } cffi_vec3f32;

typedef uint8_t (*cffi_fptr_fn_u8_rval_u8)(uint8_t x0);

typedef uint32_t (*cffi_fptr_fn_u32_rval_u32)(uint32_t x0);

typedef struct cffi_genericu32
    {
    uint32_t* x;
    } cffi_genericu32;

typedef struct cffi_genericu8
    {
    uint8_t* x;
    } cffi_genericu8;

typedef cffi_tupled (*cffi_fptr_fn_Tupled_rval_Tupled)(cffi_tupled x0);

typedef bool (*cffi_fptr_fn_pmut_i64_rval_bool)(int64_t* x0);

typedef struct cffi_ffisliceu32
    {
    uint32_t* data;
    uint64_t len;
    } cffi_ffisliceu32;

typedef struct cffi_ffisliceu8
    {
    uint8_t* data;
    uint64_t len;
    } cffi_ffisliceu8;

typedef struct cffi_ffislicemutu8
    {
    uint8_t* data;
    uint64_t len;
    } cffi_ffislicemutu8;

typedef struct cffi_ffioptioninner
    {
    cffi_inner t;
    uint8_t is_some;
    } cffi_ffioptioninner;

typedef struct cffi_myapiv1
    {
    cffi_fptr_fn_pmut_i64_rval_bool ref_mut_option;
    cffi_fptr_fn_Tupled_rval_Tupled tupled;
    } cffi_myapiv1;

typedef struct cffi_ffislicevec3f32
    {
    cffi_vec3f32* data;
    uint64_t len;
    } cffi_ffislicevec3f32;

typedef uint8_t (*cffi_fptr_fn_FFISliceu8_rval_u8)(cffi_ffisliceu8 x0);

typedef void (*cffi_fptr_fn_FFISliceMutu8)(cffi_ffislicemutu8 x0);

typedef cffi_vec3f32 (*cffi_fptr_fn_FFISliceVec3f32_rval_Vec3f32)(cffi_ffislicevec3f32 x0);


void primitive_void();
void primitive_void2();
bool primitive_bool(bool x);
uint8_t primitive_u8(uint8_t x);
uint16_t primitive_u16(uint16_t x);
uint32_t primitive_u32(uint32_t x);
uint64_t primitive_u64(uint64_t x);
int8_t primitive_i8(int8_t x);
int16_t primitive_i16(int16_t x);
int32_t primitive_i32(int32_t x);
int64_t primitive_i64(int64_t x);
int64_t many_args_5(int64_t x0, int64_t x1, int64_t x2, int64_t x3, int64_t x4);
int64_t many_args_10(int64_t x0, int64_t x1, int64_t x2, int64_t x3, int64_t x4, int64_t x5, int64_t x6, int64_t x7, int64_t x8, int64_t x9);
int64_t* ptr(int64_t* x);
int64_t* ptr_mut(int64_t* x);
int64_t** ptr_ptr(int64_t** x);
int64_t* ref_simple(int64_t* x);
int64_t* ref_mut_simple(int64_t* x);
bool ref_option(int64_t* x);
bool ref_mut_option(int64_t* x);
cffi_tupled tupled(cffi_tupled x);
cffi_ffierror complex_args_1(cffi_vec3f32 _a, cffi_empty* _b);
cffi_opaque* complex_args_2(cffi_someforeigntype _cmplx);
uint8_t callback(cffi_fptr_fn_u8_rval_u8 callback, uint8_t value);
uint32_t generic_1(cffi_genericu32 x, cffi_phantomu8 _y);
uint8_t generic_2(cffi_genericu8 x, cffi_phantomu8 _y);
uint8_t generic_3(cffi_generic2u8* x);
uint8_t generic_4(cffi_generic3* x);
cffi_enumdocumented documented(cffi_structdocumented _x);
cffi_vec1 ambiguous_1(cffi_vec1 x);
cffi_vec2 ambiguous_2(cffi_vec2 x);
bool ambiguous_3(cffi_vec1 x, cffi_vec2 y);
cffi_vec namespaced_type(cffi_vec x);
cffi_ffierror panics();
void sleep(uint64_t millis);
uint32_t pattern_ascii_pointer_1(uint8_t* x);
uint32_t pattern_ascii_pointer_len(uint8_t* x, cffi_useasciistringpattern y);
uint32_t pattern_ffi_slice_1(cffi_ffisliceu32 ffi_slice);
cffi_vec3f32 pattern_ffi_slice_2(cffi_ffislicevec3f32 ffi_slice, int32_t i);
void pattern_ffi_slice_3(cffi_ffislicemutu8 slice, cffi_fptr_fn_FFISliceMutu8 callback);
uint8_t pattern_ffi_slice_delegate(cffi_fptr_fn_FFISliceu8_rval_u8 callback);
cffi_vec3f32 pattern_ffi_slice_delegate_huge(cffi_fptr_fn_FFISliceVec3f32_rval_Vec3f32 callback);
cffi_ffioptioninner pattern_ffi_option_1(cffi_ffioptioninner ffi_slice);
cffi_inner pattern_ffi_option_2(cffi_ffioptioninner ffi_slice);
uint8_t pattern_ffi_bool(uint8_t ffi_bool);
void my_api_init_v1(cffi_myapiv1* api);
uint32_t pattern_callback_1(cffi_fptr_fn_u32_rval_u32 callback, uint32_t x);
cffi_ffierror pattern_service_create(cffi_context** context_ptr, uint32_t value);
cffi_ffierror pattern_service_destroy(cffi_context** context_ptr);
uint32_t pattern_service_method(cffi_context* context);
cffi_ffierror pattern_service_method_success_enum_ok(cffi_context* _context);
cffi_ffierror pattern_service_method_success_enum_fail(cffi_context* _context);
cffi_ffierror simple_service_create(cffi_simpleservice** context_ptr, uint32_t x);
cffi_ffierror simple_service_destroy(cffi_simpleservice** context_ptr);
cffi_ffierror simple_service_result(cffi_simpleservice* context_ptr, uint32_t x);
uint32_t simple_service_value(cffi_simpleservice* context_ptr, uint32_t x);
uint32_t simple_service_mut_self(cffi_simpleservice* context_ptr, uint32_t x);
void simple_service_void(cffi_simpleservice* context_ptr);
uint32_t simple_service_extra_method(cffi_simpleservice* _context);
"""


ffi = FFI()
ffi.cdef(api_definition)
_api = None


def init_api(dll):
    """Initializes this library, call with path to DLL."""
    global _api
    _api = ffi.dlopen(dll)





U8 = 255

F32_MIN_POSITIVE = 0.000000000000000000000000000000000000011754944

COMPUTED_I32 = -2147483647


class EnumDocumented:
    """Documented enum."""
    A = 0
    B = 1


class Empty(object):
    """"""
    def __init__(self):
        global _api, ffi
        self._ctx = ffi.new("cffi_empty[]", 1)

    def array(n):
        global _api, ffi
        return ffi.new("cffi_empty[]", n)

    def ptr(self):
        return self._ctx

class Genericu32(object):
    """"""
    def __init__(self):
        global _api, ffi
        self._ctx = ffi.new("cffi_genericu32[]", 1)

    def array(n):
        global _api, ffi
        return ffi.new("cffi_genericu32[]", n)

    def ptr(self):
        return self._ctx

    @property
    def x(self):
        """"""
        return self._ctx[0].x

    @x.setter
    def x(self, value):
        self._ptr_x = value
        self._ctx[0].x = value

class Genericu8(object):
    """"""
    def __init__(self):
        global _api, ffi
        self._ctx = ffi.new("cffi_genericu8[]", 1)

    def array(n):
        global _api, ffi
        return ffi.new("cffi_genericu8[]", n)

    def ptr(self):
        return self._ctx

    @property
    def x(self):
        """"""
        return self._ctx[0].x

    @x.setter
    def x(self, value):
        self._ptr_x = value
        self._ctx[0].x = value

class Inner(object):
    """"""
    def __init__(self):
        global _api, ffi
        self._ctx = ffi.new("cffi_inner[]", 1)

    def array(n):
        global _api, ffi
        return ffi.new("cffi_inner[]", n)

    def ptr(self):
        return self._ctx

    @property
    def x(self):
        """"""
        return self._ctx[0].x

    @x.setter
    def x(self, value):
        self._ptr_x = value
        self._ctx[0].x = value

class MyAPIv1(object):
    """"""
    def __init__(self):
        global _api, ffi
        self._ctx = ffi.new("cffi_myapiv1[]", 1)

    def array(n):
        global _api, ffi
        return ffi.new("cffi_myapiv1[]", n)

    def ptr(self):
        return self._ctx

    @property
    def ref_mut_option(self):
        """"""
        return self._ctx[0].ref_mut_option

    @ref_mut_option.setter
    def ref_mut_option(self, value):
        self._ptr_ref_mut_option = value
        self._ctx[0].ref_mut_option = value

    @property
    def tupled(self):
        """"""
        return self._ctx[0].tupled

    @tupled.setter
    def tupled(self, value):
        self._ptr_tupled = value
        self._ctx[0].tupled = value

class Phantomu8(object):
    """"""
    def __init__(self):
        global _api, ffi
        self._ctx = ffi.new("cffi_phantomu8[]", 1)

    def array(n):
        global _api, ffi
        return ffi.new("cffi_phantomu8[]", n)

    def ptr(self):
        return self._ctx

    @property
    def x(self):
        """"""
        return self._ctx[0].x

    @x.setter
    def x(self, value):
        self._ptr_x = value
        self._ctx[0].x = value

class SomeForeignType(object):
    """"""
    def __init__(self):
        global _api, ffi
        self._ctx = ffi.new("cffi_someforeigntype[]", 1)

    def array(n):
        global _api, ffi
        return ffi.new("cffi_someforeigntype[]", n)

    def ptr(self):
        return self._ctx

    @property
    def x(self):
        """"""
        return self._ctx[0].x

    @x.setter
    def x(self, value):
        self._ptr_x = value
        self._ctx[0].x = value

class StructDocumented(object):
    """Documented struct."""
    def __init__(self):
        global _api, ffi
        self._ctx = ffi.new("cffi_structdocumented[]", 1)

    def array(n):
        global _api, ffi
        return ffi.new("cffi_structdocumented[]", n)

    def ptr(self):
        return self._ctx

    @property
    def x(self):
        """Documented field."""
        return self._ctx[0].x

    @x.setter
    def x(self, value):
        self._ptr_x = value
        self._ctx[0].x = value

class Tupled(object):
    """"""
    def __init__(self):
        global _api, ffi
        self._ctx = ffi.new("cffi_tupled[]", 1)

    def array(n):
        global _api, ffi
        return ffi.new("cffi_tupled[]", n)

    def ptr(self):
        return self._ctx

    @property
    def x0(self):
        """"""
        return self._ctx[0].x0

    @x0.setter
    def x0(self, value):
        self._ptr_x0 = value
        self._ctx[0].x0 = value

class UseAsciiStringPattern(object):
    """"""
    def __init__(self):
        global _api, ffi
        self._ctx = ffi.new("cffi_useasciistringpattern[]", 1)

    def array(n):
        global _api, ffi
        return ffi.new("cffi_useasciistringpattern[]", n)

    def ptr(self):
        return self._ctx

    @property
    def ascii_string(self):
        """"""
        return self._ctx[0].ascii_string

    @ascii_string.setter
    def ascii_string(self, value):
        self._ptr_ascii_string = value
        self._ctx[0].ascii_string = value

class Vec(object):
    """"""
    def __init__(self):
        global _api, ffi
        self._ctx = ffi.new("cffi_vec[]", 1)

    def array(n):
        global _api, ffi
        return ffi.new("cffi_vec[]", n)

    def ptr(self):
        return self._ctx

    @property
    def x(self):
        """"""
        return self._ctx[0].x

    @x.setter
    def x(self, value):
        self._ptr_x = value
        self._ctx[0].x = value

    @property
    def z(self):
        """"""
        return self._ctx[0].z

    @z.setter
    def z(self, value):
        self._ptr_z = value
        self._ctx[0].z = value

class Vec1(object):
    """"""
    def __init__(self):
        global _api, ffi
        self._ctx = ffi.new("cffi_vec1[]", 1)

    def array(n):
        global _api, ffi
        return ffi.new("cffi_vec1[]", n)

    def ptr(self):
        return self._ctx

    @property
    def x(self):
        """"""
        return self._ctx[0].x

    @x.setter
    def x(self, value):
        self._ptr_x = value
        self._ctx[0].x = value

    @property
    def y(self):
        """"""
        return self._ctx[0].y

    @y.setter
    def y(self, value):
        self._ptr_y = value
        self._ctx[0].y = value

class Vec2(object):
    """"""
    def __init__(self):
        global _api, ffi
        self._ctx = ffi.new("cffi_vec2[]", 1)

    def array(n):
        global _api, ffi
        return ffi.new("cffi_vec2[]", n)

    def ptr(self):
        return self._ctx

    @property
    def x(self):
        """"""
        return self._ctx[0].x

    @x.setter
    def x(self, value):
        self._ptr_x = value
        self._ctx[0].x = value

    @property
    def z(self):
        """"""
        return self._ctx[0].z

    @z.setter
    def z(self, value):
        self._ptr_z = value
        self._ctx[0].z = value

class Vec3f32(object):
    """"""
    def __init__(self):
        global _api, ffi
        self._ctx = ffi.new("cffi_vec3f32[]", 1)

    def array(n):
        global _api, ffi
        return ffi.new("cffi_vec3f32[]", n)

    def ptr(self):
        return self._ctx

    @property
    def x(self):
        """"""
        return self._ctx[0].x

    @x.setter
    def x(self, value):
        self._ptr_x = value
        self._ctx[0].x = value

    @property
    def y(self):
        """"""
        return self._ctx[0].y

    @y.setter
    def y(self, value):
        self._ptr_y = value
        self._ctx[0].y = value

    @property
    def z(self):
        """"""
        return self._ctx[0].z

    @z.setter
    def z(self, value):
        self._ptr_z = value
        self._ctx[0].z = value

class FFIError:
    """"""
    Ok = 0
    Null = 100
    Panic = 200
    Fail = 300




class callbacks:
    """Helpers to define `@ffi.callback`-style callbacks."""
    fn_Tupled_rval_Tupled = "cffi_tupled(cffi_tupled)"
    fn_pmut_i64_rval_bool = "bool(int64_t*)"
    fn_u8_rval_u8 = "uint8_t(uint8_t)"
    fn_FFISliceu8_rval_u8 = "uint8_t(cffi_ffisliceu8)"
    fn_FFISliceVec3f32_rval_Vec3f32 = "cffi_vec3f32(cffi_ffislicevec3f32)"
    fn_FFISliceMutu8 = "void(cffi_ffislicemutu8)"
    fn_u32_rval_u32 = "uint32_t(uint32_t)"




class raw:
    """Raw access to all exported functions."""
    def primitive_void():
        """"""
        global _api
        return _api.primitive_void()

    def primitive_void2():
        """"""
        global _api
        return _api.primitive_void2()

    def primitive_bool(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.primitive_bool(x)

    def primitive_u8(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.primitive_u8(x)

    def primitive_u16(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.primitive_u16(x)

    def primitive_u32(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.primitive_u32(x)

    def primitive_u64(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.primitive_u64(x)

    def primitive_i8(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.primitive_i8(x)

    def primitive_i16(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.primitive_i16(x)

    def primitive_i32(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.primitive_i32(x)

    def primitive_i64(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.primitive_i64(x)

    def many_args_5(x0, x1, x2, x3, x4):
        """"""
        global _api
        if hasattr(x0, "_ctx"):
            x0 = x0._ctx[0]
        if hasattr(x1, "_ctx"):
            x1 = x1._ctx[0]
        if hasattr(x2, "_ctx"):
            x2 = x2._ctx[0]
        if hasattr(x3, "_ctx"):
            x3 = x3._ctx[0]
        if hasattr(x4, "_ctx"):
            x4 = x4._ctx[0]
        return _api.many_args_5(x0, x1, x2, x3, x4)

    def many_args_10(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9):
        """"""
        global _api
        if hasattr(x0, "_ctx"):
            x0 = x0._ctx[0]
        if hasattr(x1, "_ctx"):
            x1 = x1._ctx[0]
        if hasattr(x2, "_ctx"):
            x2 = x2._ctx[0]
        if hasattr(x3, "_ctx"):
            x3 = x3._ctx[0]
        if hasattr(x4, "_ctx"):
            x4 = x4._ctx[0]
        if hasattr(x5, "_ctx"):
            x5 = x5._ctx[0]
        if hasattr(x6, "_ctx"):
            x6 = x6._ctx[0]
        if hasattr(x7, "_ctx"):
            x7 = x7._ctx[0]
        if hasattr(x8, "_ctx"):
            x8 = x8._ctx[0]
        if hasattr(x9, "_ctx"):
            x9 = x9._ctx[0]
        return _api.many_args_10(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9)

    def ptr(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.ptr(x)

    def ptr_mut(x):
        """# Safety

Parameter x must point to valid data."""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.ptr_mut(x)

    def ptr_ptr(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.ptr_ptr(x)

    def ref_simple(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.ref_simple(x)

    def ref_mut_simple(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.ref_mut_simple(x)

    def ref_option(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.ref_option(x)

    def ref_mut_option(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.ref_mut_option(x)

    def tupled(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.tupled(x)

    def complex_args_1(_a, _b):
        """"""
        global _api
        if hasattr(_a, "_ctx"):
            _a = _a._ctx[0]
        if hasattr(_b, "_ctx"):
            _b = _b._ctx[0]
        return _api.complex_args_1(_a, _b)

    def complex_args_2(_cmplx):
        """"""
        global _api
        if hasattr(_cmplx, "_ctx"):
            _cmplx = _cmplx._ctx[0]
        return _api.complex_args_2(_cmplx)

    def callback(callback, value):
        """"""
        global _api
        if hasattr(callback, "_ctx"):
            callback = callback._ctx[0]
        if hasattr(value, "_ctx"):
            value = value._ctx[0]
        return _api.callback(callback, value)

    def generic_1(x, _y):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        if hasattr(_y, "_ctx"):
            _y = _y._ctx[0]
        return _api.generic_1(x, _y)

    def generic_2(x, _y):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        if hasattr(_y, "_ctx"):
            _y = _y._ctx[0]
        return _api.generic_2(x, _y)

    def generic_3(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.generic_3(x)

    def generic_4(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.generic_4(x)

    def documented(_x):
        """This function has documentation."""
        global _api
        if hasattr(_x, "_ctx"):
            _x = _x._ctx[0]
        return _api.documented(_x)

    def ambiguous_1(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.ambiguous_1(x)

    def ambiguous_2(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.ambiguous_2(x)

    def ambiguous_3(x, y):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        if hasattr(y, "_ctx"):
            y = y._ctx[0]
        return _api.ambiguous_3(x, y)

    def namespaced_type(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.namespaced_type(x)

    def panics():
        """"""
        global _api
        return _api.panics()

    def sleep(millis):
        """"""
        global _api
        if hasattr(millis, "_ctx"):
            millis = millis._ctx[0]
        return _api.sleep(millis)

    def pattern_ascii_pointer_1(x):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.pattern_ascii_pointer_1(x)

    def pattern_ascii_pointer_len(x, y):
        """"""
        global _api
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        if hasattr(y, "_ctx"):
            y = y._ctx[0]
        return _api.pattern_ascii_pointer_len(x, y)

    def pattern_ffi_slice_1(ffi_slice):
        """"""
        global _api
        if hasattr(ffi_slice, "_ctx"):
            ffi_slice = ffi_slice._ctx[0]
        return _api.pattern_ffi_slice_1(ffi_slice)

    def pattern_ffi_slice_2(ffi_slice, i):
        """"""
        global _api
        if hasattr(ffi_slice, "_ctx"):
            ffi_slice = ffi_slice._ctx[0]
        if hasattr(i, "_ctx"):
            i = i._ctx[0]
        return _api.pattern_ffi_slice_2(ffi_slice, i)

    def pattern_ffi_slice_3(slice, callback):
        """"""
        global _api
        if hasattr(slice, "_ctx"):
            slice = slice._ctx[0]
        if hasattr(callback, "_ctx"):
            callback = callback._ctx[0]
        return _api.pattern_ffi_slice_3(slice, callback)

    def pattern_ffi_slice_delegate(callback):
        """"""
        global _api
        if hasattr(callback, "_ctx"):
            callback = callback._ctx[0]
        return _api.pattern_ffi_slice_delegate(callback)

    def pattern_ffi_slice_delegate_huge(callback):
        """"""
        global _api
        if hasattr(callback, "_ctx"):
            callback = callback._ctx[0]
        return _api.pattern_ffi_slice_delegate_huge(callback)

    def pattern_ffi_option_1(ffi_slice):
        """"""
        global _api
        if hasattr(ffi_slice, "_ctx"):
            ffi_slice = ffi_slice._ctx[0]
        return _api.pattern_ffi_option_1(ffi_slice)

    def pattern_ffi_option_2(ffi_slice):
        """"""
        global _api
        if hasattr(ffi_slice, "_ctx"):
            ffi_slice = ffi_slice._ctx[0]
        return _api.pattern_ffi_option_2(ffi_slice)

    def pattern_ffi_bool(ffi_bool):
        """"""
        global _api
        if hasattr(ffi_bool, "_ctx"):
            ffi_bool = ffi_bool._ctx[0]
        return _api.pattern_ffi_bool(ffi_bool)

    def my_api_init_v1(api):
        """"""
        global _api
        if hasattr(api, "_ctx"):
            api = api._ctx[0]
        return _api.my_api_init_v1(api)

    def pattern_callback_1(callback, x):
        """"""
        global _api
        if hasattr(callback, "_ctx"):
            callback = callback._ctx[0]
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.pattern_callback_1(callback, x)

    def pattern_service_create(context_ptr, value):
        """"""
        global _api
        if hasattr(context_ptr, "_ctx"):
            context_ptr = context_ptr._ctx[0]
        if hasattr(value, "_ctx"):
            value = value._ctx[0]
        return _api.pattern_service_create(context_ptr, value)

    def pattern_service_destroy(context_ptr):
        """# Safety

This function may only be called with a context returned by a succeeding `pattern_service_create`."""
        global _api
        if hasattr(context_ptr, "_ctx"):
            context_ptr = context_ptr._ctx[0]
        return _api.pattern_service_destroy(context_ptr)

    def pattern_service_method(context):
        """"""
        global _api
        if hasattr(context, "_ctx"):
            context = context._ctx[0]
        return _api.pattern_service_method(context)

    def pattern_service_method_success_enum_ok(_context):
        """"""
        global _api
        if hasattr(_context, "_ctx"):
            _context = _context._ctx[0]
        return _api.pattern_service_method_success_enum_ok(_context)

    def pattern_service_method_success_enum_fail(_context):
        """"""
        global _api
        if hasattr(_context, "_ctx"):
            _context = _context._ctx[0]
        return _api.pattern_service_method_success_enum_fail(_context)

    def simple_service_create(context_ptr, x):
        """"""
        global _api
        if hasattr(context_ptr, "_ctx"):
            context_ptr = context_ptr._ctx[0]
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.simple_service_create(context_ptr, x)

    def simple_service_destroy(context_ptr):
        """"""
        global _api
        if hasattr(context_ptr, "_ctx"):
            context_ptr = context_ptr._ctx[0]
        return _api.simple_service_destroy(context_ptr)

    def simple_service_result(context_ptr, x):
        """"""
        global _api
        if hasattr(context_ptr, "_ctx"):
            context_ptr = context_ptr._ctx[0]
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.simple_service_result(context_ptr, x)

    def simple_service_value(context_ptr, x):
        """"""
        global _api
        if hasattr(context_ptr, "_ctx"):
            context_ptr = context_ptr._ctx[0]
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.simple_service_value(context_ptr, x)

    def simple_service_mut_self(context_ptr, x):
        """"""
        global _api
        if hasattr(context_ptr, "_ctx"):
            context_ptr = context_ptr._ctx[0]
        if hasattr(x, "_ctx"):
            x = x._ctx[0]
        return _api.simple_service_mut_self(context_ptr, x)

    def simple_service_void(context_ptr):
        """"""
        global _api
        if hasattr(context_ptr, "_ctx"):
            context_ptr = context_ptr._ctx[0]
        return _api.simple_service_void(context_ptr)

    def simple_service_extra_method(_context):
        """An extra exposed method."""
        global _api
        if hasattr(_context, "_ctx"):
            _context = _context._ctx[0]
        return _api.simple_service_extra_method(_context)





class Context(object):
    def __init__(self, value):
        """"""
        global _api, ffi
        if hasattr(value, "_ctx"):
            value = value._ctx
        self.ctx = ffi.new("cffi_context**")
        rval = raw.pattern_service_create(self.ctx, value)
        if rval == FFIError.Ok:
            return None
        else:
            raise Exception(f"return value ${rval}")

    def __del__(self):
        global _api, ffi
        rval = raw.pattern_service_destroy(self.ctx, )
        if rval == FFIError.Ok:
            return None
        else:
            raise Exception(f"return value ${rval}")

    def method(self, ):
        """"""
        global raw
        return _api.pattern_service_method(self.ctx[0], )

    def method_success_enum_ok(self, ):
        """"""
        global raw
        rval = raw.pattern_service_method_success_enum_ok(self.ctx[0], )
        if rval == FFIError.Ok:
            return None
        else:
            raise Exception(f"return value ${rval}")

    def method_success_enum_fail(self, ):
        """"""
        global raw
        rval = raw.pattern_service_method_success_enum_fail(self.ctx[0], )
        if rval == FFIError.Ok:
            return None
        else:
            raise Exception(f"return value ${rval}")



class SimpleService(object):
    def __init__(self, x):
        """"""
        global _api, ffi
        if hasattr(x, "_ctx"):
            x = x._ctx
        self.ctx = ffi.new("cffi_simpleservice**")
        rval = raw.simple_service_create(self.ctx, x)
        if rval == FFIError.Ok:
            return None
        else:
            raise Exception(f"return value ${rval}")

    def __del__(self):
        global _api, ffi
        rval = raw.simple_service_destroy(self.ctx, )
        if rval == FFIError.Ok:
            return None
        else:
            raise Exception(f"return value ${rval}")

    def result(self, x):
        """"""
        global raw
        rval = raw.simple_service_result(self.ctx[0], x)
        if rval == FFIError.Ok:
            return None
        else:
            raise Exception(f"return value ${rval}")

    def value(self, x):
        """"""
        global raw
        return _api.simple_service_value(self.ctx[0], x)

    def mut_self(self, x):
        """"""
        global raw
        return _api.simple_service_mut_self(self.ctx[0], x)

    def void(self, ):
        """"""
        global raw
        return _api.simple_service_void(self.ctx[0], )

    def extra_method(self, ):
        """An extra exposed method."""
        global raw
        return _api.simple_service_extra_method(self.ctx[0], )





def ascii_string(x):
    """Must be called with a b"my_string"."""
    global ffi
    return ffi.new("char[]", x)