-
Notifications
You must be signed in to change notification settings - Fork 8
/
glib.replacements
1062 lines (985 loc) · 35.6 KB
/
glib.replacements
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
convert c: #define NULL ((void *)0)
to c: #define NULL 0
convert c: #define TRUE (!FALSE)
to c: #define TRUE 1
convert c:
#define G_STATIC_ASSERT(expr) \
typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __LINE__)[(expr) ? 1 : -1] G_GNUC_UNUSED
to fb:
#define G_STATIC_ASSERT(expr) #assert expr
convert c: #define G_STRLOC __FILE__ ":" G_STRINGIFY (__LINE__)
to fb: #define G_STRLOC __FILE__ ":" G_STRINGIFY(__LINE__)
convert c: #define _G_NEW(struct_type, n_structs, func) ((struct_type *) g_##func##_n((n_structs), sizeof(struct_type)))
to fb: #define _G_NEW(struct_type, n_structs, func) cptr(struct_type ptr, g_##func##_n((n_structs), sizeof(struct_type)))
convert c: #define _G_RENEW(struct_type, mem, n_structs, func) ((struct_type *) g_##func##_n(mem, (n_structs), sizeof(struct_type)))
to fb: #define _G_RENEW(struct_type, mem, n_structs, func) cptr(struct_type ptr, g_##func##_n(mem, (n_structs), sizeof(struct_type)))
convert c:
#define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name) \
static char *dll_name; \
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { \
wchar_t wcbfr[1000]; \
char *tem; \
switch (fdwReason) { \
case DLL_PROCESS_ATTACH: \
GetModuleFileNameW((HMODULE)hinstDLL, wcbfr, G_N_ELEMENTS(wcbfr)); \
tem = g_utf16_to_utf8(wcbfr, -1, NULL, NULL, NULL); \
dll_name = g_path_get_basename(tem); \
g_free(tem); \
break; \
} \
return TRUE; \
}
to fb:
#macro G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name)
dim shared dll_name as zstring ptr
function DllMain stdcall alias "DllMain"(byval hinstDLL as HINSTANCE, byval fdwReason as DWORD, byval lpvReserved as LPVOID) as BOOL
dim wcbfr as wstring * 1000
dim tem as zstring ptr
select case fdwReason
case DLL_PROCESS_ATTACH
GetModuleFileNameW(cast(HMODULE, hinstDLL), wcbfr, 1000)
tem = g_utf16_to_utf8(wcbfr, -1, NULL, NULL, NULL)
dll_name = g_path_get_basename(tem)
g_free(tem)
end select
return CTRUE
end function
#endmacro
convert c: #define g_error(...) do { g_log(G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, __VA_ARGS__); for (;;) ; } while (0)
to c: #define g_error(...) do { g_log(G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, __VA_ARGS__); } while (0)
convert c: #define g_slice_dup(type, mem) (1 ? (type*) g_slice_copy(sizeof(type), (mem)) : ((void) ((type*) 0 == (mem)), (type*) 0))
to c: #define g_slice_dup(type, mem) ((type*) g_slice_copy(sizeof(type), (mem)))
convert c: #define g_slice_free(type, mem) do { if (1) g_slice_free1(sizeof(type), (mem)); else (void) ((type*) 0 == (mem)); } while (0)
to c: #define g_slice_free(type, mem) do { g_slice_free1(sizeof(type), (mem)); } while (0)
convert c: #define g_slice_free_chain(type, mem_chain, next) do { if (1) g_slice_free_chain_with_offset(sizeof(type), (mem_chain), G_STRUCT_OFFSET(type, next)); else (void) ((type*) 0 == (mem_chain)); } while (0)
to c: #define g_slice_free_chain(type, mem_chain, next) do { g_slice_free_chain_with_offset(sizeof(type), (mem_chain), G_STRUCT_OFFSET(type, next)); } while (0)
convert c:
#define g_assert_cmpstr(s1, cmp, s2) \
do { \
const char *__s1 = (s1), *__s2 = (s2); \
if (g_strcmp0(__s1, __s2) cmp 0) \
; \
else \
g_assertion_message_cmpstr(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, #s1 " " #cmp " " #s2, __s1, #cmp, __s2); \
} while (0)
to fb:
#macro g_assert_cmpstr(s1, cmp, s2)
scope
dim as const zstring ptr __s1 = (s1), __s2 = (s2)
if g_strcmp0(__s1, __s2) cmp 0 then
else
g_assertion_message_cmpstr(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, #s1 " " #cmp " " #s2, __s1, #cmp, __s2)
end if
end scope
#endmacro
convert c:
#define g_assert_cmpint(n1, cmp, n2) \
do { \
gint64 __n1 = (n1), __n2 = (n2); \
if (__n1 cmp __n2) \
; \
else \
g_assertion_message_cmpnum(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'i'); \
} while (0)
to fb:
#macro g_assert_cmpint(n1, cmp, n2)
scope
dim as gint64 __n1 = (n1), __n2 = (n2)
if __n1 cmp __n2 then
else
g_assertion_message_cmpnum(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'i')
end if
end scope
#endmacro
convert c:
#define g_assert_cmpuint(n1, cmp, n2) \
do { \
guint64 __n1 = (n1), __n2 = (n2); \
if (__n1 cmp __n2) \
; \
else \
g_assertion_message_cmpnum(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'i'); \
} while (0)
to fb:
#macro g_assert_cmpuint(n1, cmp, n2)
scope
dim as guint64 __n1 = (n1), __n2 = (n2)
if __n1 cmp __n2
else
g_assertion_message_cmpnum(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'i')
end if
end scope
#endmacro
convert c:
#define g_assert_cmphex(n1, cmp, n2) \
do { \
guint64 __n1 = (n1), __n2 = (n2); \
if (__n1 cmp __n2) \
; \
else \
g_assertion_message_cmpnum(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'x'); \
} while (0)
to fb:
#macro g_assert_cmphex(n1, cmp, n2)
scope
dim as guint64 __n1 = (n1), __n2 = (n2)
if __n1 cmp __n2 then
else
g_assertion_message_cmpnum(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'x')
end if
end scope
#endmacro
# This one uses "long double", but I think it can be translated to just "double" just fine
convert c:
#define g_assert_cmpfloat(n1, cmp, n2) \
do { \
long double __n1 = (n1), __n2 = (n2); \
if (__n1 cmp __n2) \
; \
else \
g_assertion_message_cmpnum(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'f'); \
} while (0)
to fb:
#macro g_assert_cmpfloat(n1, cmp, n2)
scope
dim as double __n1 = (n1), __n2 = (n2)
if __n1 cmp __n2 then
else
g_assertion_message_cmpnum(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'f')
end if
end scope
#endmacro
convert c:
#define g_test_add(testpath, Fixture, tdata, fsetup, ftest, fteardown) \
do { \
void (*add_vtable)( \
const char*, \
gsize, \
gconstpointer, \
void (*)(Fixture*, gconstpointer), \
void (*)(Fixture*, gconstpointer), \
void (*)(Fixture*, gconstpointer) \
) = (void (*)( \
const gchar *, \
gsize, \
gconstpointer, \
void (*)(Fixture*, gconstpointer), \
void (*)(Fixture*, gconstpointer), \
void (*)(Fixture*, gconstpointer) \
)) g_test_add_vtable; \
add_vtable(testpath, sizeof (Fixture), tdata, fsetup, ftest, fteardown); \
} while (0)
to c:
#define g_test_add(testpath, Fixture, tdata, fsetup, ftest, fteardown) \
do { \
void (*add_vtable)( \
const char*, \
gsize, \
gconstpointer, \
void (*)(Fixture*, gconstpointer), \
void (*)(Fixture*, gconstpointer), \
void (*)(Fixture*, gconstpointer) \
) = (void (*)( \
const gchar *, \
gsize, \
gconstpointer, \
void (*)(Fixture*, gconstpointer), \
void (*)(Fixture*, gconstpointer), \
void (*)(Fixture*, gconstpointer) \
)) &g_test_add_vtable; \
add_vtable(testpath, sizeof (Fixture), tdata, fsetup, ftest, fteardown); \
} while (0)
convert c: #define GLIB_SYSDEF_POLLIN =1
to fb: #define GLIB_SYSDEF_POLLIN =1
convert c: #define GLIB_SYSDEF_POLLOUT =4
to fb: #define GLIB_SYSDEF_POLLOUT =4
convert c: #define GLIB_SYSDEF_POLLPRI =2
to fb: #define GLIB_SYSDEF_POLLPRI =2
convert c: #define GLIB_SYSDEF_POLLHUP =16
to fb: #define GLIB_SYSDEF_POLLHUP =16
convert c: #define GLIB_SYSDEF_POLLERR =8
to fb: #define GLIB_SYSDEF_POLLERR =8
convert c: #define GLIB_SYSDEF_POLLNVAL =32
to fb: #define GLIB_SYSDEF_POLLNVAL =32
convert c: #define G_DEFINE_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED(TN, t_n, T_P, 0, {})
to fb: #define G_DEFINE_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED(TN, t_n, T_P, 0, )
convert c:
#define G_DEFINE_TYPE_WITH_CODE(TN, t_n, T_P, _C_) \
_G_DEFINE_TYPE_EXTENDED_BEGIN(TN, t_n, T_P, 0) \
{ \
_C_; \
} \
_G_DEFINE_TYPE_EXTENDED_END()
to fb:
#macro G_DEFINE_TYPE_WITH_CODE(TN, t_n, T_P, _C_)
_G_DEFINE_TYPE_EXTENDED_BEGIN(TN, t_n, T_P, 0)
scope
_C_
end scope
_G_DEFINE_TYPE_EXTENDED_END()
#endmacro
convert c: #define G_DEFINE_ABSTRACT_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED(TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT, {})
to fb: #define G_DEFINE_ABSTRACT_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED(TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT, )
convert c:
#define G_DEFINE_ABSTRACT_TYPE_WITH_CODE(TN, t_n, T_P, _C_) \
_G_DEFINE_TYPE_EXTENDED_BEGIN(TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT) \
{ \
_C_; \
} \
_G_DEFINE_TYPE_EXTENDED_END()
to fb:
#macro G_DEFINE_ABSTRACT_TYPE_WITH_CODE(TN, t_n, T_P, _C_)
_G_DEFINE_TYPE_EXTENDED_BEGIN(TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT)
scope
_C_
end scope
_G_DEFINE_TYPE_EXTENDED_END()
#endmacro
convert c:
#define G_DEFINE_TYPE_EXTENDED(TN, t_n, T_P, _f_, _C_) \
_G_DEFINE_TYPE_EXTENDED_BEGIN(TN, t_n, T_P, _f_) \
{ \
_C_; \
} \
_G_DEFINE_TYPE_EXTENDED_END()
to fb:
#macro G_DEFINE_TYPE_EXTENDED(TN, t_n, T_P, _f_, _C_)
_G_DEFINE_TYPE_EXTENDED_BEGIN(TN, t_n, T_P, _f_)
scope
_C_
end scope
_G_DEFINE_TYPE_EXTENDED_END()
#endmacro
convert c: #define G_DEFINE_INTERFACE(TN, t_n, T_P) G_DEFINE_INTERFACE_WITH_CODE(TN, t_n, T_P, ;)
to fb: #define G_DEFINE_INTERFACE(TN, t_n, T_P) G_DEFINE_INTERFACE_WITH_CODE(TN, t_n, T_P, )
convert c:
#define G_DEFINE_INTERFACE_WITH_CODE(TN, t_n, T_P, _C_) \
_G_DEFINE_INTERFACE_EXTENDED_BEGIN(TN, t_n, T_P) \
{ \
_C_; \
} \
_G_DEFINE_INTERFACE_EXTENDED_END()
to fb:
#macro G_DEFINE_INTERFACE_WITH_CODE(TN, t_n, T_P, _C_)
_G_DEFINE_INTERFACE_EXTENDED_BEGIN(TN, t_n, T_P)
scope
_C_
end scope
_G_DEFINE_INTERFACE_EXTENDED_END()
#endmacro
convert c:
#define G_ADD_PRIVATE(TypeName) \
{ \
TypeName##_private_offset = g_type_add_instance_private(g_define_type_id, sizeof (TypeName##Private)); \
}
to fb:
#macro G_ADD_PRIVATE(TypeName)
scope
TypeName##_private_offset = g_type_add_instance_private(g_define_type_id, sizeof(TypeName##Private))
end scope
#endmacro
convert c:
#define _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \
static void type_name##_class_intern_init(gpointer klass) { \
type_name##_parent_class = g_type_class_peek_parent(klass); \
if (TypeName##_private_offset != 0) \
g_type_class_adjust_private_offset(klass, &TypeName##_private_offset); \
type_name##_class_init((TypeName##Class*) klass); \
}
to fb:
#macro _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name)
extern "C"
private sub type_name##_class_intern_init(byval klass as gpointer)
type_name##_parent_class = g_type_class_peek_parent(klass)
if TypeName##_private_offset <> 0 then
g_type_class_adjust_private_offset(klass, @TypeName##_private_offset)
end if
type_name##_class_init(cptr(TypeName##Class ptr, klass))
end sub
end extern
#endmacro
convert c:
#define _G_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \
static void type_name##_init(TypeName *self); \
static void type_name##_class_init(TypeName##Class *klass); \
static gpointer type_name##_parent_class = NULL; \
static gint TypeName##_private_offset; \
_G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \
G_GNUC_UNUSED static inline gpointer type_name##_get_instance_private(const TypeName *self) { \
return (G_STRUCT_MEMBER_P(self, TypeName##_private_offset)); \
} \
GType type_name##_get_type(void) { \
static volatile gsize g_define_type_id__volatile = 0; \
if (g_once_init_enter(&g_define_type_id__volatile)) { \
GType g_define_type_id = g_type_register_static_simple( \
TYPE_PARENT, \
g_intern_static_string(#TypeName), \
sizeof(TypeName##Class), \
(GClassInitFunc)type_name##_class_intern_init, \
sizeof(TypeName), \
(GInstanceInitFunc)type_name##_init, \
(GTypeFlags)flags \
); \
{
to fb:
#macro _G_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags)
extern "C"
declare sub type_name##_init(byval self as TypeName ptr)
declare sub type_name##_class_init(byval klass as TypeName##Class ptr)
dim shared as gpointer type_name##_parent_class = NULL
dim shared as gint TypeName##_private_offset
_G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name)
private function type_name##_get_instance_private(byval self as const TypeName ptr) as gpointer
return G_STRUCT_MEMBER_P(self, TypeName##_private_offset)
end function
function type_name##_get_type() as GType
static as gsize g_define_type_id__volatile = 0
if g_once_init_enter(@g_define_type_id__volatile) then
var g_define_type_id = g_type_register_static_simple( _
TYPE_PARENT, _
g_intern_static_string(#TypeName), _
sizeof(TypeName##Class), _
cast(GClassInitFunc, @type_name##_class_intern_init), _
sizeof(TypeName), _
cast(GInstanceInitFunc, @type_name##_init), _
cast(GTypeFlags, flags) _
)
scope
#endmacro
convert c:
#define _G_DEFINE_TYPE_EXTENDED_END() \
} \
g_once_init_leave(&g_define_type_id__volatile, g_define_type_id); \
} \
return g_define_type_id__volatile; \
}
to fb:
#macro _G_DEFINE_TYPE_EXTENDED_END()
end scope
g_once_init_leave(@g_define_type_id__volatile, g_define_type_id)
end if
return g_define_type_id__volatile
end function
end extern
#endmacro
convert c:
#define _G_DEFINE_INTERFACE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PREREQ) \
static void type_name##_default_init(TypeName##Interface *klass); \
GType type_name##_get_type(void) { \
static volatile gsize g_define_type_id__volatile = 0; \
if (g_once_init_enter(&g_define_type_id__volatile)) { \
GType g_define_type_id = g_type_register_static_simple( \
G_TYPE_INTERFACE, \
g_intern_static_string(#TypeName), \
sizeof(TypeName##Interface), \
(GClassInitFunc)type_name##_default_init, \
0, \
(GInstanceInitFunc)NULL, \
(GTypeFlags)0 \
); \
if (TYPE_PREREQ) \
g_type_interface_add_prerequisite(g_define_type_id, TYPE_PREREQ); \
{
to fb:
#macro _G_DEFINE_INTERFACE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PREREQ)
extern "C"
declare sub type_name##_default_init(byval klass as TypeName##Interface ptr)
function type_name##_get_type() as GType
static as gsize g_define_type_id__volatile = 0
if g_once_init_enter(@g_define_type_id__volatile) then
var g_define_type_id = g_type_register_static_simple( _
G_TYPE_INTERFACE, _
g_intern_static_string(#TypeName), _
sizeof(TypeName##Interface), _
cast(GClassInitFunc, @type_name##_default_init), _
0, _
cast(GInstanceInitFunc, NULL), _
cast(GTypeFlags, 0) _
)
if TYPE_PREREQ then
g_type_interface_add_prerequisite(g_define_type_id, TYPE_PREREQ)
end if
scope
#endmacro
convert c:
#define _G_DEFINE_INTERFACE_EXTENDED_END() \
} \
g_once_init_leave(&g_define_type_id__volatile, g_define_type_id); \
} \
return g_define_type_id__volatile; \
}
to fb:
#macro _G_DEFINE_INTERFACE_EXTENDED_END()
end scope
g_once_init_leave(@g_define_type_id__volatile, g_define_type_id)
end if
return g_define_type_id__volatile
end function
end extern
#endmacro
convert c: #define G_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func) G_DEFINE_BOXED_TYPE_WITH_CODE(TypeName, type_name, copy_func, free_func, {})
to fb: #define G_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func) G_DEFINE_BOXED_TYPE_WITH_CODE(TypeName, type_name, copy_func, free_func, )
convert c:
#define G_DEFINE_BOXED_TYPE_WITH_CODE(TypeName, type_name, copy_func, free_func, _C_) \
_G_DEFINE_BOXED_TYPE_BEGIN(TypeName, type_name, copy_func, free_func) \
{ \
_C_; \
} \
_G_DEFINE_TYPE_EXTENDED_END()
to fb:
#macro G_DEFINE_BOXED_TYPE_WITH_CODE(TypeName, type_name, copy_func, free_func, _C_)
_G_DEFINE_BOXED_TYPE_BEGIN(TypeName, type_name, copy_func, free_func)
scope
_C_
end scope
_G_DEFINE_TYPE_EXTENDED_END()
#endmacro
# The "union { ... } __attribute__((__transparent_union__))" parameters require special attention -
# they could be translated as a parameter corresponding to the last union member (the one using the function pointer typedef).
# This would also make _g_register_boxed's signature match that of its initializer expression.
# But even better than that, we can just solve out _g_register_boxed completely, so the signature never has to be specified.
convert c:
#define _G_DEFINE_BOXED_TYPE_BEGIN(TypeName, type_name, copy_func, free_func) \
GType type_name##_get_type(void) { \
static volatile gsize g_define_type_id__volatile = 0; \
if (g_once_init_enter(&g_define_type_id__volatile)) { \
GType (*_g_register_boxed)( \
const gchar *, \
union { \
TypeName *(*do_copy_type)(TypeName *); \
TypeName *(*do_const_copy_type)(const TypeName *); \
GBoxedCopyFunc do_copy_boxed; \
} __attribute__((__transparent_union__)), \
union { \
void (*do_free_type)(TypeName *); \
GBoxedFreeFunc do_free_boxed; \
} __attribute__((__transparent_union__)) \
) = g_boxed_type_register_static; \
GType g_define_type_id = _g_register_boxed( \
g_intern_static_string(#TypeName), \
copy_func, \
free_func \
); \
{
to fb:
#macro _G_DEFINE_BOXED_TYPE_BEGIN(TypeName, type_name, copy_func, free_func)
extern "C"
function type_name##_get_type() as GType
static as gsize g_define_type_id__volatile = 0
if g_once_init_enter(@g_define_type_id__volatile) then
var g_define_type_id = g_boxed_type_register_static( _
g_intern_static_string(#TypeName), _
cast(GBoxedCopyFunc, copy_func), _
cast(GBoxedFreeFunc, free_func) _
)
scope
#endmacro
convert c: #define G_DEFINE_POINTER_TYPE(TypeName, type_name) G_DEFINE_POINTER_TYPE_WITH_CODE(TypeName, type_name, {})
to fb: #define G_DEFINE_POINTER_TYPE(TypeName, type_name) G_DEFINE_POINTER_TYPE_WITH_CODE(TypeName, type_name, )
convert c:
#define G_DEFINE_POINTER_TYPE_WITH_CODE(TypeName, type_name, _C_) \
_G_DEFINE_POINTER_TYPE_BEGIN(TypeName, type_name) \
{ \
_C_; \
} \
_G_DEFINE_TYPE_EXTENDED_END()
to fb:
#macro G_DEFINE_POINTER_TYPE_WITH_CODE(TypeName, type_name, _C_)
_G_DEFINE_POINTER_TYPE_BEGIN(TypeName, type_name)
scope
_C_
end scope
_G_DEFINE_TYPE_EXTENDED_END()
#endmacro
convert c:
#define _G_DEFINE_POINTER_TYPE_BEGIN(TypeName, type_name) \
GType type_name##_get_type(void) { \
static volatile gsize g_define_type_id__volatile = 0; \
if (g_once_init_enter(&g_define_type_id__volatile)) { \
GType g_define_type_id = g_pointer_type_register_static(g_intern_static_string(#TypeName)); \
{
to fb:
#macro _G_DEFINE_POINTER_TYPE_BEGIN(TypeName, type_name)
extern "C"
function type_name##_get_type() as GType
static as gsize g_define_type_id__volatile = 0
if g_once_init_enter(@g_define_type_id__volatile) then
var g_define_type_id = g_pointer_type_register_static(g_intern_static_string(#TypeName))
scope
#endmacro
convert c:
#define _G_TYPE_CIT(ip, gt) \
(G_GNUC_EXTENSION ({ \
GTypeInstance *__inst = (GTypeInstance*) ip; \
GType __t = gt; \
gboolean __r; \
if (!__inst) \
__r = FALSE; \
else if (__inst->g_class && __inst->g_class->g_type == __t) \
__r = TRUE; \
else \
__r = g_type_check_instance_is_a(__inst, __t); \
__r; \
}))
to fb:
#define _G_TYPE_CIT(ip, gt) _
iif(cptr(GTypeInstance ptr, ip) = 0, _
FALSE, _
iif(cptr(GTypeInstance ptr, ip)->g_class andalso cptr(GTypeInstance ptr, ip)->g_class->g_type = gt, _
CTRUE, _
g_type_check_instance_is_a(cptr(GTypeInstance ptr, ip), gt)))
convert c:
#define _G_TYPE_CCT(cp, gt) \
(G_GNUC_EXTENSION ({ \
GTypeClass *__class = (GTypeClass*) cp; \
GType __t = gt; \
gboolean __r; \
if (!__class) \
__r = FALSE; \
else if (__class->g_type == __t) \
__r = TRUE; \
else \
__r = g_type_check_class_is_a(__class, __t); \
__r; \
}))
to fb:
#define _G_TYPE_CCT(cp, gt) _
iif(cptr(GTypeClass ptr, cp) = 0, _
FALSE, _
iif(cptr(GTypeClass ptr, cp)->g_type = gt, _
CTRUE, _
g_type_check_class_is_a(cptr(GTypeClass ptr, cp), gt)))
convert c:
#define _G_TYPE_CVH(vl, gt) \
(G_GNUC_EXTENSION ({ \
GValue *__val = (GValue*) vl; \
GType __t = gt; \
gboolean __r; \
if (!__val) \
__r = FALSE; \
else if (__val->g_type == __t) \
__r = TRUE; \
else \
__r = g_type_check_value_holds(__val, __t); \
__r; \
}))
to fb:
#define _G_TYPE_CVH(vl, gt) _
iif(cptr(GValue ptr, vl) = 0 _
FALSE, _
iif(cptr(GValue ptr, vl)->g_type = gt, _
CTRUE, _
g_type_check_value_holds(cptr(GValue ptr, vl), gt)))
convert c: #define G_DEFINE_DYNAMIC_TYPE(TN, t_n, T_P) G_DEFINE_DYNAMIC_TYPE_EXTENDED(TN, t_n, T_P, 0, {})
to fb: #define G_DEFINE_DYNAMIC_TYPE(TN, t_n, T_P) G_DEFINE_DYNAMIC_TYPE_EXTENDED(TN, t_n, T_P, 0, )
convert c:
#define G_DEFINE_DYNAMIC_TYPE_EXTENDED(TypeName, type_name, TYPE_PARENT, flags, CODE) \
static void type_name##_init(TypeName *self); \
static void type_name##_class_init(TypeName##Class *klass); \
static void type_name##_class_finalize(TypeName##Class *klass); \
static gpointer type_name##_parent_class = NULL; \
static GType type_name##_type_id = 0; \
static gint TypeName##_private_offset; \
_G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \
static inline gpointer type_name##_get_instance_private(TypeName *self) { \
return (G_STRUCT_MEMBER_P(self, TypeName##_private_offset)); \
} \
GType type_name##_get_type (void) { \
return type_name##_type_id; \
} \
static void type_name##_register_type(GTypeModule *type_module) { \
GType g_define_type_id G_GNUC_UNUSED; \
const GTypeInfo g_define_type_info = { \
sizeof(TypeName##Class), \
(GBaseInitFunc)NULL, \
(GBaseFinalizeFunc)NULL, \
(GClassInitFunc)type_name##_class_intern_init, \
(GClassFinalizeFunc)type_name##_class_finalize, \
NULL, \
sizeof(TypeName), \
0, \
(GInstanceInitFunc)type_name##_init, \
NULL \
}; \
type_name##_type_id = g_type_module_register_type( \
type_module, \
TYPE_PARENT, \
#TypeName, \
&g_define_type_info, \
(GTypeFlags)flags \
); \
g_define_type_id = type_name##_type_id; \
{ \
CODE; \
} \
}
to fb:
#macro G_DEFINE_DYNAMIC_TYPE_EXTENDED(TypeName, type_name, TYPE_PARENT, flags, CODE)
extern "C"
declare sub type_name##_init(byval self as TypeName ptr)
declare sub type_name##_class_init(byval klass as TypeName##Class ptr)
declare sub type_name##_class_finalize(byval klass as TypeName##Class ptr)
dim shared as gpointer type_name##_parent_class = NULL
dim shared as GType type_name##_type_id = 0
dim shared as gint TypeName##_private_offset
_G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name)
private function type_name##_get_instance_private(byval self as TypeName ptr) as gpointer
return G_STRUCT_MEMBER_P(self, TypeName##_private_offset)
end function
function type_name##_get_type() as GType
return type_name##_type_id
end function
private sub type_name##_register_type(byval type_module as GTypeModule ptr)
dim as GType g_define_type_id
dim as const GTypeInfo g_define_type_info = ( _
sizeof(TypeName##Class), _
cast(GBaseInitFunc, NULL), _
cast(GBaseFinalizeFunc, NULL), _
cast(GClassInitFunc, @type_name##_class_intern_init), _
cast(GClassFinalizeFunc, @type_name##_class_finalize), _
NULL, _
sizeof(TypeName), _
0, _
cast(GInstanceInitFunc, @type_name##_init), _
NULL
)
type_name##_type_id = g_type_module_register_type( _
type_module, _
TYPE_PARENT, _
#TypeName, _
@g_define_type_info, _
cast(GTypeFlags, flags) _
)
g_define_type_id = type_name##_type_id
scope
CODE
end scope
end sub
end extern
#endmacro
convert c:
#define G_ADD_PRIVATE_DYNAMIC(TypeName) \
{ \
TypeName##_private_offset = sizeof(TypeName##Private); \
}
to fb:
#macro G_ADD_PRIVATE_DYNAMIC(TypeName)
scope
TypeName##_private_offset = sizeof(TypeName##Private)
end scope
#endmacro
convert c: #define G_N_ELEMENTS(arr) (sizeof(arr) / sizeof((arr)[0]))
to fb: #define G_N_ELEMENTS(arr) (ubound(arr) - lbound(array) + 1)
convert c:
#define g_warn_if_fail(expr)
do {
if G_LIKELY(expr)
;
else
g_warn_message(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, #expr);
} while (0)
to c:
#define g_warn_if_fail(expr)
do {
if (G_LIKELY(expr))
;
else
g_warn_message(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, #expr);
} while (0)
convert c:
#define g_return_if_fail(expr)
do {
if G_LIKELY(expr) {
} else {
g_return_if_fail_warning(G_LOG_DOMAIN, G_STRFUNC, #expr);
return;
}
;
} while (0)
to c:
#define g_return_if_fail(expr)
do {
if (G_LIKELY(expr)) {
} else {
g_return_if_fail_warning(G_LOG_DOMAIN, G_STRFUNC, #expr);
return;
}
;
} while (0)
convert c:
#define g_return_val_if_fail(expr, val)
do {
if G_LIKELY(expr) {
} else {
g_return_if_fail_warning(G_LOG_DOMAIN, G_STRFUNC, #expr);
return (val);
}
;
} while (0)
to c:
#define g_return_val_if_fail(expr, val)
do {
if (G_LIKELY(expr)) {
} else {
g_return_if_fail_warning(G_LOG_DOMAIN, G_STRFUNC, #expr);
return (val);
}
;
} while (0)
convert c:
#define g_assert_true(expr)
do {
if G_LIKELY(expr)
;
else
g_assertion_message(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, "'" #expr "' should be TRUE");
} while (0)
to c:
#define g_assert_true(expr)
do {
if (G_LIKELY(expr))
;
else
g_assertion_message(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, "'" #expr "' should be TRUE");
} while (0)
convert c:
#define g_assert_false(expr)
do {
if G_LIKELY(!(expr))
;
else
g_assertion_message(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, "'" #expr "' should be FALSE");
} while (0)
to c:
#define g_assert_false(expr)
do {
if (G_LIKELY(!(expr)))
;
else
g_assertion_message(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, "'" #expr "' should be FALSE");
} while (0)
convert c:
#define g_assert_null(expr)
do {
if G_LIKELY((expr) == NULL)
;
else
g_assertion_message(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, "'" #expr "' should be NULL");
} while (0)
to c:
#define g_assert_null(expr)
do {
if (G_LIKELY((expr) == NULL))
;
else
g_assertion_message(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, "'" #expr "' should be NULL");
} while (0)
convert c:
#define g_assert_nonnull(expr)
do {
if G_LIKELY((expr) != NULL)
;
else
g_assertion_message(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, "'" #expr "' should not be NULL");
} while (0)
to c:
#define g_assert_nonnull(expr)
do {
if (G_LIKELY((expr) != NULL))
;
else
g_assertion_message(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, "'" #expr "' should not be NULL");
} while (0)
convert c:
#define g_assert(expr)
do {
if G_LIKELY(expr)
;
else
g_assertion_message_expr(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, #expr);
} while (0)
to c:
#define g_assert(expr)
do {
if (G_LIKELY(expr))
;
else
g_assertion_message_expr(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, #expr);
} while (0)
convert c:
#define _GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName)
typedef ModuleObjName *_GLIB_AUTOPTR_TYPENAME(ModuleObjName);
static inline void _GLIB_AUTOPTR_FUNC_NAME(ModuleObjName)(ModuleObjName **_ptr) {
_GLIB_AUTOPTR_FUNC_NAME(ParentName)((ParentName **) _ptr);
}
to fb:
#macro _GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName)
extern "C"
type _GLIB_AUTOPTR_TYPENAME(ModuleObjName) as ModuleObjName ptr
private sub _GLIB_AUTOPTR_FUNC_NAME(ModuleObjName)(byval _ptr as ModuleObjName ptr ptr)
_GLIB_AUTOPTR_FUNC_NAME(ParentName)(cptr(ParentName ptr ptr, _ptr))
end sub
end extern
#endmacro
convert c:
#define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func)
typedef TypeName *_GLIB_AUTOPTR_TYPENAME(TypeName);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static inline void _GLIB_AUTOPTR_FUNC_NAME(TypeName)(TypeName **_ptr) {
if (*_ptr)
(func)(*_ptr);
}
G_GNUC_END_IGNORE_DEPRECATIONS
to fb:
#macro G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func)
extern "C"
type _GLIB_AUTOPTR_TYPENAME(TypeName) as TypeName ptr
private sub _GLIB_AUTOPTR_FUNC_NAME(TypeName)(byval _ptr as TypeName ptr ptr)
if *_ptr then
func(*_ptr)
end if
end sub
end extern
#endmacro
convert c:
#define G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TypeName, func)
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static inline void _GLIB_AUTO_FUNC_NAME(TypeName)(TypeName *_ptr) {
(func)(_ptr);
}
G_GNUC_END_IGNORE_DEPRECATIONS
to fb:
#macro G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TypeName, func)
extern "C"
private sub _GLIB_AUTO_FUNC_NAME(TypeName)(byval _ptr as TypeName ptr)
func(_ptr)
end sub
end extern
#endmacro
convert c:
#define G_DEFINE_AUTO_CLEANUP_FREE_FUNC(TypeName, func, none)
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static inline void _GLIB_AUTO_FUNC_NAME(TypeName)(TypeName *_ptr) {
if (*_ptr != none)
(func)(*_ptr);
}
G_GNUC_END_IGNORE_DEPRECATIONS
to fb:
#macro G_DEFINE_AUTO_CLEANUP_FREE_FUNC(TypeName, func, none)
extern "C"
private sub _GLIB_AUTO_FUNC_NAME(TypeName)(byval _ptr as TypeName ptr)
if *_ptr <> none
func(*_ptr)
end if
end sub
end extern
#endmacro
convert c:
#define G_DECLARE_FINAL_TYPE(ModuleObjName, module_obj_name, MODULE, OBJ_NAME, ParentName)
GType module_obj_name##_get_type(void);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
typedef struct _##ModuleObjName ModuleObjName;
typedef struct {
ParentName##Class parent_class;
} ModuleObjName##Class;
_GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName)
static inline ModuleObjName *MODULE##_##OBJ_NAME(gconstpointer ptr) {
return G_TYPE_CHECK_INSTANCE_CAST(ptr, module_obj_name##_get_type(), ModuleObjName);
}
static inline gboolean MODULE##_IS_##OBJ_NAME(gconstpointer ptr) {
return G_TYPE_CHECK_INSTANCE_TYPE(ptr, module_obj_name##_get_type());
}
G_GNUC_END_IGNORE_DEPRECATIONS
to fb:
#macro G_DECLARE_FINAL_TYPE(ModuleObjName, module_obj_name, MODULE, OBJ_NAME, ParentName)
extern "C"
declare function module_obj_name##_get_type() as GType
type ModuleObjName as _##ModuleObjName
type ModuleObjName##Class
parent_class as ParentName##Class
end type
_GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName)
#define MODULE##_##OBJ_NAME(ptr_) cptr(ModuleObjName ptr, G_TYPE_CHECK_INSTANCE_CAST(ptr_, module_obj_name##_get_type(), ModuleObjName))
#define MODULE##_IS_##OBJ_NAME(ptr_) cast(gboolean, G_TYPE_CHECK_INSTANCE_TYPE(ptr_, module_obj_name##_get_type()))
end extern
#endmacro
convert c:
#define G_DECLARE_DERIVABLE_TYPE(ModuleObjName, module_obj_name, MODULE, OBJ_NAME, ParentName)
GType module_obj_name##_get_type(void);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
typedef struct _##ModuleObjName ModuleObjName;
typedef struct _##ModuleObjName##Class ModuleObjName##Class;
struct _##ModuleObjName {
ParentName parent_instance;
};
_GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName)
static inline ModuleObjName *MODULE##_##OBJ_NAME(gconstpointer ptr) {
return G_TYPE_CHECK_INSTANCE_CAST(ptr, module_obj_name##_get_type(), ModuleObjName);
}
static inline ModuleObjName##Class *MODULE##_##OBJ_NAME##_CLASS(gconstpointer ptr) {
return G_TYPE_CHECK_CLASS_CAST(ptr, module_obj_name##_get_type(), ModuleObjName##Class);
}
static inline gboolean MODULE##_IS_##OBJ_NAME(gconstpointer ptr) {
return G_TYPE_CHECK_INSTANCE_TYPE(ptr, module_obj_name##_get_type());
}
static inline gboolean MODULE##_IS_##OBJ_NAME##_CLASS(gconstpointer ptr) {