-
Notifications
You must be signed in to change notification settings - Fork 27
/
Interop.cs
1456 lines (1225 loc) · 53.1 KB
/
Interop.cs
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
// Automatically generated by Interoptopus.
#pragma warning disable 0105
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using My.Company;
using My.Company.Common;
#pragma warning restore 0105
namespace My.Company
{
public static partial class Interop
{
public const string NativeLib = "interoptopus_reference_project";
static Interop()
{
var api_version = Interop.pattern_api_guard();
if (api_version != 16012698009278542425ul)
{
throw new TypeLoadException($"API reports hash {api_version} which differs from hash in bindings (16012698009278542425). You probably forgot to update / copy either the bindings or the library.");
}
}
public const byte U8 = (byte) 255;
public const float F32_MIN_POSITIVE = (float) 0.000000000000000000000000000000000000011754944;
public const int COMPUTED_I32 = (int) -2147483647;
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "primitive_void")]
public static extern void primitive_void();
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "primitive_void2")]
public static extern void primitive_void2();
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "primitive_bool")]
public static extern bool primitive_bool(bool x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "primitive_u8")]
public static extern byte primitive_u8(byte x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "primitive_u16")]
public static extern ushort primitive_u16(ushort x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "primitive_u32")]
public static extern uint primitive_u32(uint x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "primitive_u64")]
public static extern ulong primitive_u64(ulong x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "primitive_i8")]
public static extern sbyte primitive_i8(sbyte x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "primitive_i16")]
public static extern short primitive_i16(short x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "primitive_i32")]
public static extern int primitive_i32(int x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "primitive_i64")]
public static extern long primitive_i64(long x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "boolean_alignment")]
public static extern BooleanAlignment boolean_alignment(BooleanAlignment x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "boolean_alignment2")]
public static extern BooleanAlignment boolean_alignment2(bool rval);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "aligned_to_packed1")]
public static extern Packed1 aligned_to_packed1(Aligned1 a);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "aligned_to_packed2")]
public static extern Packed2 aligned_to_packed2(Aligned2 a);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "many_args_5")]
public static extern long many_args_5(long x0, long x1, long x2, long x3, long x4);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "many_args_10")]
public static extern long many_args_10(long x0, long x1, long x2, long x3, long x4, long x5, long x6, long x7, long x8, long x9);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ptr")]
public static extern IntPtr ptr(ref long x);
/// # Safety
///
/// Parameter x must point to valid data.
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ptr_mut")]
public static extern IntPtr ptr_mut(out long x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ptr_ptr")]
public static extern IntPtr ptr_ptr(ref IntPtr x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ref_simple")]
public static extern IntPtr ref_simple(ref long x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ref_mut_simple")]
public static extern IntPtr ref_mut_simple(out long x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ref_option")]
public static extern bool ref_option(ref long x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ref_mut_option")]
public static extern bool ref_mut_option(out long x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "tupled")]
public static extern Tupled tupled(Tupled x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "complex_args_1")]
public static extern FFIError complex_args_1(Vec3f32 a, ref Tupled b);
public static void complex_args_1_checked(Vec3f32 a, ref Tupled b)
{
var rval = complex_args_1(a, ref b);;
if (rval != FFIError.Ok)
{
throw new InteropException<FFIError>(rval);
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "complex_args_2")]
public static extern IntPtr complex_args_2(SomeForeignType cmplx);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "callback")]
public static extern byte callback(InteropDelegate_fn_u8_rval_u8 callback, byte value);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "generic_1a")]
public static extern uint generic_1a(Genericu32 x, Phantomu8 y);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "generic_1b")]
public static extern byte generic_1b(Genericu8 x, Phantomu8 y);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "generic_1c")]
public static extern byte generic_1c(ref Genericu8 x, ref Genericu8 y);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "generic_2")]
public static extern byte generic_2(IntPtr x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "generic_3")]
public static extern byte generic_3(IntPtr x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "generic_4")]
public static extern byte generic_4(IntPtr x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "array_1")]
public static extern byte array_1(Array x);
/// This function has documentation.
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "documented")]
public static extern EnumDocumented documented(StructDocumented x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ambiguous_1")]
public static extern Vec1 ambiguous_1(Vec1 x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ambiguous_2")]
public static extern Vec2 ambiguous_2(Vec2 x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ambiguous_3")]
public static extern bool ambiguous_3(Vec1 x, Vec2 y);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "namespaced_type")]
public static extern Vec namespaced_type(Vec x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "namespaced_inner_option")]
public static extern OptionVec namespaced_inner_option(OptionVec x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "namespaced_inner_slice")]
public static extern SliceVec namespaced_inner_slice(SliceVec x);
public static SliceVec namespaced_inner_slice(Vec[] x)
{
var x_pinned = GCHandle.Alloc(x, GCHandleType.Pinned);
var x_slice = new SliceVec(x_pinned, (ulong) x.Length);
try
{
return namespaced_inner_slice(x_slice);;
}
finally
{
x_pinned.Free();
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "namespaced_inner_slice_mut")]
public static extern SliceMutVec namespaced_inner_slice_mut(SliceMutVec x);
public static SliceMutVec namespaced_inner_slice_mut(Vec[] x)
{
var x_pinned = GCHandle.Alloc(x, GCHandleType.Pinned);
var x_slice = new SliceMutVec(x_pinned, (ulong) x.Length);
try
{
return namespaced_inner_slice_mut(x_slice);;
}
finally
{
x_pinned.Free();
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "panics")]
public static extern FFIError panics();
public static void panics_checked()
{
var rval = panics();;
if (rval != FFIError.Ok)
{
throw new InteropException<FFIError>(rval);
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "renamed")]
public static extern EnumRenamed renamed(StructRenamed x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "sleep")]
public static extern void sleep(ulong millis);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "weird_1")]
public static extern bool weird_1(Weird1u32 x, Weird2u8 y);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "visibility")]
public static extern void visibility(Visibility1 x, Visibility2 y);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "repr_transparent")]
public static extern Tupled repr_transparent(Tupled x, ref Tupled r);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_ascii_pointer_1")]
public static extern uint pattern_ascii_pointer_1(string x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_ascii_pointer_2")]
public static extern IntPtr pattern_ascii_pointer_2();
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_ascii_pointer_len")]
public static extern uint pattern_ascii_pointer_len(string x, UseAsciiStringPattern y);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_ascii_pointer_return_slice")]
public static extern SliceUseAsciiStringPattern pattern_ascii_pointer_return_slice();
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_ffi_slice_1")]
public static extern uint pattern_ffi_slice_1(Sliceu32 ffi_slice);
public static uint pattern_ffi_slice_1(uint[] ffi_slice)
{
var ffi_slice_pinned = GCHandle.Alloc(ffi_slice, GCHandleType.Pinned);
var ffi_slice_slice = new Sliceu32(ffi_slice_pinned, (ulong) ffi_slice.Length);
try
{
return pattern_ffi_slice_1(ffi_slice_slice);;
}
finally
{
ffi_slice_pinned.Free();
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_ffi_slice_1b")]
public static extern uint pattern_ffi_slice_1b(SliceMutu32 ffi_slice);
public static uint pattern_ffi_slice_1b(uint[] ffi_slice)
{
var ffi_slice_pinned = GCHandle.Alloc(ffi_slice, GCHandleType.Pinned);
var ffi_slice_slice = new SliceMutu32(ffi_slice_pinned, (ulong) ffi_slice.Length);
try
{
return pattern_ffi_slice_1b(ffi_slice_slice);;
}
finally
{
ffi_slice_pinned.Free();
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_ffi_slice_2")]
public static extern Vec3f32 pattern_ffi_slice_2(SliceVec3f32 ffi_slice, int i);
public static Vec3f32 pattern_ffi_slice_2(Vec3f32[] ffi_slice, int i)
{
var ffi_slice_pinned = GCHandle.Alloc(ffi_slice, GCHandleType.Pinned);
var ffi_slice_slice = new SliceVec3f32(ffi_slice_pinned, (ulong) ffi_slice.Length);
try
{
return pattern_ffi_slice_2(ffi_slice_slice, i);;
}
finally
{
ffi_slice_pinned.Free();
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_ffi_slice_3")]
public static extern void pattern_ffi_slice_3(SliceMutu8 slice, CallbackSliceMut callback);
public static void pattern_ffi_slice_3(byte[] slice, CallbackSliceMut callback)
{
var slice_pinned = GCHandle.Alloc(slice, GCHandleType.Pinned);
var slice_slice = new SliceMutu8(slice_pinned, (ulong) slice.Length);
try
{
pattern_ffi_slice_3(slice_slice, callback);;
}
finally
{
slice_pinned.Free();
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_ffi_slice_4")]
public static extern void pattern_ffi_slice_4(Sliceu8 slice, SliceMutu8 slice2);
public static void pattern_ffi_slice_4(byte[] slice, byte[] slice2)
{
var slice_pinned = GCHandle.Alloc(slice, GCHandleType.Pinned);
var slice_slice = new Sliceu8(slice_pinned, (ulong) slice.Length);
var slice2_pinned = GCHandle.Alloc(slice2, GCHandleType.Pinned);
var slice2_slice = new SliceMutu8(slice2_pinned, (ulong) slice2.Length);
try
{
pattern_ffi_slice_4(slice_slice, slice2_slice);;
}
finally
{
slice_pinned.Free();
slice2_pinned.Free();
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_ffi_slice_5")]
public static extern void pattern_ffi_slice_5(ref Sliceu8 slice, ref SliceMutu8 slice2);
public static void pattern_ffi_slice_5(byte[] slice, byte[] slice2)
{
var slice_pinned = GCHandle.Alloc(slice, GCHandleType.Pinned);
var slice_slice = new Sliceu8(slice_pinned, (ulong) slice.Length);
var slice2_pinned = GCHandle.Alloc(slice2, GCHandleType.Pinned);
var slice2_slice = new SliceMutu8(slice2_pinned, (ulong) slice2.Length);
try
{
pattern_ffi_slice_5(ref slice_slice, ref slice2_slice);;
}
finally
{
slice_pinned.Free();
slice2_pinned.Free();
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_ffi_slice_6")]
public static extern void pattern_ffi_slice_6(ref SliceMutu8 slice, CallbackU8 callback);
public static void pattern_ffi_slice_6(byte[] slice, CallbackU8 callback)
{
var slice_pinned = GCHandle.Alloc(slice, GCHandleType.Pinned);
var slice_slice = new SliceMutu8(slice_pinned, (ulong) slice.Length);
try
{
pattern_ffi_slice_6(ref slice_slice, callback);;
}
finally
{
slice_pinned.Free();
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_ffi_slice_delegate")]
public static extern byte pattern_ffi_slice_delegate(CallbackFFISlice callback);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_ffi_slice_delegate_huge")]
public static extern Vec3f32 pattern_ffi_slice_delegate_huge(CallbackHugeVecSlice callback);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_ffi_option_1")]
public static extern OptionInner pattern_ffi_option_1(OptionInner ffi_slice);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_ffi_option_2")]
public static extern Inner pattern_ffi_option_2(OptionInner ffi_slice);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_ffi_bool")]
public static extern Bool pattern_ffi_bool(Bool ffi_bool);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_ffi_cchar")]
public static extern sbyte pattern_ffi_cchar(sbyte ffi_cchar);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_ffi_cchar_const_pointer")]
public static extern IntPtr pattern_ffi_cchar_const_pointer(IntPtr ffi_cchar);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_ffi_cchar_mut_pointer")]
public static extern IntPtr pattern_ffi_cchar_mut_pointer(IntPtr ffi_cchar);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_api_guard")]
public static extern ulong pattern_api_guard();
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_callback_1")]
public static extern uint pattern_callback_1(MyCallback callback, uint x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_callback_2")]
public static extern MyCallbackVoid pattern_callback_2(MyCallbackVoid callback);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_callback_3")]
public static extern void pattern_callback_3(DelegateCallbackMyCallbackContextual callback, uint x);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "pattern_callback_4")]
public static extern uint pattern_callback_4(MyCallbackNamespaced callback, uint x);
/// Destroys the given instance.
///
/// # Safety
///
/// The passed parameter MUST have been created with the corresponding init function;
/// passing any other value results in undefined behavior.
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_destroy")]
public static extern FFIError simple_service_destroy(ref IntPtr context);
/// Destroys the given instance.
///
/// # Safety
///
/// The passed parameter MUST have been created with the corresponding init function;
/// passing any other value results in undefined behavior.
public static void simple_service_destroy_checked(ref IntPtr context)
{
var rval = simple_service_destroy(ref context);;
if (rval != FFIError.Ok)
{
throw new InteropException<FFIError>(rval);
}
}
/// The constructor must return a `Result<Self, Error>`.
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_new_with")]
public static extern FFIError simple_service_new_with(ref IntPtr context, uint some_value);
/// The constructor must return a `Result<Self, Error>`.
public static void simple_service_new_with_checked(ref IntPtr context, uint some_value)
{
var rval = simple_service_new_with(ref context, some_value);;
if (rval != FFIError.Ok)
{
throw new InteropException<FFIError>(rval);
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_new_without")]
public static extern FFIError simple_service_new_without(ref IntPtr context);
public static void simple_service_new_without_checked(ref IntPtr context)
{
var rval = simple_service_new_without(ref context);;
if (rval != FFIError.Ok)
{
throw new InteropException<FFIError>(rval);
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_new_with_string")]
public static extern FFIError simple_service_new_with_string(ref IntPtr context, string ascii);
public static void simple_service_new_with_string_checked(ref IntPtr context, string ascii)
{
var rval = simple_service_new_with_string(ref context, ascii);;
if (rval != FFIError.Ok)
{
throw new InteropException<FFIError>(rval);
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_new_failing")]
public static extern FFIError simple_service_new_failing(ref IntPtr context, byte some_value);
public static void simple_service_new_failing_checked(ref IntPtr context, byte some_value)
{
var rval = simple_service_new_failing(ref context, some_value);;
if (rval != FFIError.Ok)
{
throw new InteropException<FFIError>(rval);
}
}
/// Methods returning a Result<(), _> are the default and do not
/// need annotations.
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_method_result")]
public static extern FFIError simple_service_method_result(IntPtr context, uint anon1);
/// Methods returning a Result<(), _> are the default and do not
/// need annotations.
public static void simple_service_method_result_checked(IntPtr context, uint anon1)
{
var rval = simple_service_method_result(context, anon1);;
if (rval != FFIError.Ok)
{
throw new InteropException<FFIError>(rval);
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_method_value")]
public static extern uint simple_service_method_value(IntPtr context, uint x);
/// This method should be documented.
///
/// Multiple lines.
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_method_void")]
public static extern void simple_service_method_void(IntPtr context);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_method_mut_self")]
public static extern byte simple_service_method_mut_self(IntPtr context, Sliceu8 slice);
public static byte simple_service_method_mut_self(IntPtr context, byte[] slice)
{
var slice_pinned = GCHandle.Alloc(slice, GCHandleType.Pinned);
var slice_slice = new Sliceu8(slice_pinned, (ulong) slice.Length);
try
{
return simple_service_method_mut_self(context, slice_slice);;
}
finally
{
slice_pinned.Free();
}
}
/// Single line.
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_method_mut_self_void")]
public static extern void simple_service_method_mut_self_void(IntPtr context, SliceBool slice);
/// Single line.
public static void simple_service_method_mut_self_void(IntPtr context, Bool[] slice)
{
var slice_pinned = GCHandle.Alloc(slice, GCHandleType.Pinned);
var slice_slice = new SliceBool(slice_pinned, (ulong) slice.Length);
try
{
simple_service_method_mut_self_void(context, slice_slice);;
}
finally
{
slice_pinned.Free();
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_method_mut_self_ref")]
public static extern byte simple_service_method_mut_self_ref(IntPtr context, ref byte x, out byte y);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_method_mut_self_ref_slice")]
public static extern byte simple_service_method_mut_self_ref_slice(IntPtr context, ref byte x, out byte y, Sliceu8 slice);
public static byte simple_service_method_mut_self_ref_slice(IntPtr context, ref byte x, out byte y, byte[] slice)
{
var slice_pinned = GCHandle.Alloc(slice, GCHandleType.Pinned);
var slice_slice = new Sliceu8(slice_pinned, (ulong) slice.Length);
try
{
return simple_service_method_mut_self_ref_slice(context, ref x, out y, slice_slice);;
}
finally
{
slice_pinned.Free();
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_method_mut_self_ref_slice_limited")]
public static extern byte simple_service_method_mut_self_ref_slice_limited(IntPtr context, ref byte x, out byte y, Sliceu8 slice, Sliceu8 slice2);
public static byte simple_service_method_mut_self_ref_slice_limited(IntPtr context, ref byte x, out byte y, byte[] slice, byte[] slice2)
{
var slice_pinned = GCHandle.Alloc(slice, GCHandleType.Pinned);
var slice_slice = new Sliceu8(slice_pinned, (ulong) slice.Length);
var slice2_pinned = GCHandle.Alloc(slice2, GCHandleType.Pinned);
var slice2_slice = new Sliceu8(slice2_pinned, (ulong) slice2.Length);
try
{
return simple_service_method_mut_self_ref_slice_limited(context, ref x, out y, slice_slice, slice2_slice);;
}
finally
{
slice_pinned.Free();
slice2_pinned.Free();
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_method_mut_self_ffi_error")]
public static extern FFIError simple_service_method_mut_self_ffi_error(IntPtr context, SliceMutu8 slice);
public static void simple_service_method_mut_self_ffi_error(IntPtr context, byte[] slice)
{
var slice_pinned = GCHandle.Alloc(slice, GCHandleType.Pinned);
var slice_slice = new SliceMutu8(slice_pinned, (ulong) slice.Length);
try
{
var rval = simple_service_method_mut_self_ffi_error(context, slice_slice);;
if (rval != FFIError.Ok)
{
throw new InteropException<FFIError>(rval);
}
}
finally
{
slice_pinned.Free();
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_method_mut_self_no_error")]
public static extern FFIError simple_service_method_mut_self_no_error(IntPtr context, SliceMutu8 slice);
public static void simple_service_method_mut_self_no_error(IntPtr context, byte[] slice)
{
var slice_pinned = GCHandle.Alloc(slice, GCHandleType.Pinned);
var slice_slice = new SliceMutu8(slice_pinned, (ulong) slice.Length);
try
{
var rval = simple_service_method_mut_self_no_error(context, slice_slice);;
if (rval != FFIError.Ok)
{
throw new InteropException<FFIError>(rval);
}
}
finally
{
slice_pinned.Free();
}
}
/// Warning, you _must_ discard the returned slice object before calling into this service
/// again, as otherwise undefined behavior might happen.
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_return_slice")]
public static extern Sliceu32 simple_service_return_slice(IntPtr context);
/// Warning, you _must_ discard the returned slice object before calling into this service
/// again, as otherwise undefined behavior might happen.
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_return_slice_mut")]
public static extern SliceMutu32 simple_service_return_slice_mut(IntPtr context);
/// This function has no panic safeguards. If it panics your host app will be in an undefined state.
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_return_string")]
public static extern IntPtr simple_service_return_string(IntPtr context);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_method_void_ffi_error")]
public static extern FFIError simple_service_method_void_ffi_error(IntPtr context);
public static void simple_service_method_void_ffi_error_checked(IntPtr context)
{
var rval = simple_service_method_void_ffi_error(context);;
if (rval != FFIError.Ok)
{
throw new InteropException<FFIError>(rval);
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_method_callback")]
public static extern FFIError simple_service_method_callback(IntPtr context, MyCallback callback);
public static void simple_service_method_callback_checked(IntPtr context, MyCallback callback)
{
var rval = simple_service_method_callback(context, callback);;
if (rval != FFIError.Ok)
{
throw new InteropException<FFIError>(rval);
}
}
/// Destroys the given instance.
///
/// # Safety
///
/// The passed parameter MUST have been created with the corresponding init function;
/// passing any other value results in undefined behavior.
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_lt_destroy")]
public static extern FFIError simple_service_lt_destroy(ref IntPtr context);
/// Destroys the given instance.
///
/// # Safety
///
/// The passed parameter MUST have been created with the corresponding init function;
/// passing any other value results in undefined behavior.
public static void simple_service_lt_destroy_checked(ref IntPtr context)
{
var rval = simple_service_lt_destroy(ref context);;
if (rval != FFIError.Ok)
{
throw new InteropException<FFIError>(rval);
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_lt_new_with")]
public static extern FFIError simple_service_lt_new_with(ref IntPtr context, ref uint some_value);
public static void simple_service_lt_new_with_checked(ref IntPtr context, ref uint some_value)
{
var rval = simple_service_lt_new_with(ref context, ref some_value);;
if (rval != FFIError.Ok)
{
throw new InteropException<FFIError>(rval);
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_lt_method_lt")]
public static extern void simple_service_lt_method_lt(IntPtr context, SliceBool slice);
public static void simple_service_lt_method_lt(IntPtr context, Bool[] slice)
{
var slice_pinned = GCHandle.Alloc(slice, GCHandleType.Pinned);
var slice_slice = new SliceBool(slice_pinned, (ulong) slice.Length);
try
{
simple_service_lt_method_lt(context, slice_slice);;
}
finally
{
slice_pinned.Free();
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_lt_method_lt2")]
public static extern void simple_service_lt_method_lt2(IntPtr context, SliceBool slice);
public static void simple_service_lt_method_lt2(IntPtr context, Bool[] slice)
{
var slice_pinned = GCHandle.Alloc(slice, GCHandleType.Pinned);
var slice_slice = new SliceBool(slice_pinned, (ulong) slice.Length);
try
{
simple_service_lt_method_lt2(context, slice_slice);;
}
finally
{
slice_pinned.Free();
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_lt_return_string_accept_slice")]
public static extern IntPtr simple_service_lt_return_string_accept_slice(IntPtr anon0, Sliceu8 anon1);
public static string simple_service_lt_return_string_accept_slice(IntPtr anon0, byte[] anon1)
{
var anon1_pinned = GCHandle.Alloc(anon1, GCHandleType.Pinned);
var anon1_slice = new Sliceu8(anon1_pinned, (ulong) anon1.Length);
try
{
var s = simple_service_lt_return_string_accept_slice(anon0, anon1_slice);;
return Marshal.PtrToStringAnsi(s);
}
finally
{
anon1_pinned.Free();
}
}
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "simple_service_lt_method_void_ffi_error")]
public static extern FFIError simple_service_lt_method_void_ffi_error(IntPtr context);
public static void simple_service_lt_method_void_ffi_error_checked(IntPtr context)
{
var rval = simple_service_lt_method_void_ffi_error(context);;
if (rval != FFIError.Ok)
{
throw new InteropException<FFIError>(rval);
}
}
}
/// Documented enum.
public enum EnumDocumented
{
/// Variant A.
A = 0,
/// Variant B.
B = 1,
/// Variant B.
C = 2,
}
public enum EnumRenamed
{
X = 0,
}
[Serializable]
[StructLayout(LayoutKind.Sequential, Pack = 2)]
public partial struct Aligned1
{
public byte x;
public ushort y;
}
[Serializable]
[StructLayout(LayoutKind.Sequential, Pack = 64)]
public partial struct Aligned2
{
public byte x;
public ushort y;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public partial struct Array
{
public byte data0;
public byte data1;
public byte data2;
public byte data3;
public byte data4;
public byte data5;
public byte data6;
public byte data7;
public byte data8;
public byte data9;
public byte data10;
public byte data11;
public byte data12;
public byte data13;
public byte data14;
public byte data15;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public partial struct BooleanAlignment
{
public int a;
public short b;
public short c;
public byte d;
public byte e;
public byte f;
public byte g;
public byte h;
public byte i;
public byte j;
public byte k;
public ulong id;
[MarshalAs(UnmanagedType.I1)]
public bool is_valid;
public ulong datum;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public partial struct DelegateCallbackMyCallbackContextual
{
public MyCallbackContextual callback;
public IntPtr context;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public partial struct ExtraTypef32
{
public float x;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public partial struct Genericu32
{
public IntPtr x;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public partial struct Genericu8
{
public IntPtr x;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public partial struct Inner
{
float x;
}
[Serializable]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public partial struct Packed1
{
public byte x;
public ushort y;
}
[Serializable]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public partial struct Packed2
{
public byte x;
public ushort y;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public partial struct Phantomu8
{
public uint x;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public partial struct SomeForeignType
{
public uint x;
}
/// Documented struct.
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public partial struct StructDocumented
{
/// Documented field.
public float x;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public partial struct StructRenamed
{
public EnumRenamed e;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public partial struct Tupled
{
public byte x0;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public partial struct UseAsciiStringPattern
{
public string ascii_string;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public partial struct Vec1
{
public float x;
public float y;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public partial struct Vec2
{
public double x;
public double z;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public partial struct Vec3f32
{
public float x;
public float y;
public float z;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public partial struct Visibility1
{
public byte pblc;
byte prvt;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public partial struct Visibility2
{
public byte pblc1;
public byte pblc2;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public partial struct Weird1u32
{
uint x;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public partial struct Weird2u8
{
byte t;
byte a0;
byte a1;
byte a2;
byte a3;
byte a4;
IntPtr r;
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate byte InteropDelegate_fn_u8_rval_u8(byte x0);
public enum FFIError
{