~ubuntu-branches/ubuntu/vivid/glib2.0/vivid-proposed

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
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GLib Reference Manual: GVariant Format Strings</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="index.html" title="GLib Reference Manual">
<link rel="up" href="glib-data-types.html" title="GLib Data Types">
<link rel="prev" href="glib-GVariant.html" title="GVariant">
<link rel="next" href="gvariant-text.html" title="GVariant Text Format">
<meta name="generator" content="GTK-Doc V1.21 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
<td width="100%" align="left" class="shortcuts"></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><a accesskey="u" href="glib-data-types.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="glib-GVariant.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="gvariant-text.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="refentry">
<a name="gvariant-format-strings"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle">GVariant Format Strings</span></h2>
<p>GVariant Format Strings — varargs conversion of GVariants</p>
</td>
<td class="gallery_image" valign="top" align="right"></td>
</tr></table></div>
<div class="refsect1">
<a name="id-1.6.20.3"></a><h2>Variable Argument Conversions</h2>
<p>
   This page attempts to document how to perform variable argument
   conversions with GVariant.
  </p>
<p>
   Conversions occur according to format strings.  A format string is a two-way mapping between a single
   <a class="link" href="glib-GVariant.html#GVariant" title="GVariant">GVariant</a> value and one or more C values.
  </p>
<p>
   A conversion from C values into a <a class="link" href="glib-GVariant.html#GVariant" title="GVariant">GVariant</a> value is made using the
   <a class="link" href="glib-GVariant.html#g-variant-new" title="g_variant_new ()"><code class="function">g_variant_new()</code></a> function.  A conversion from a
   <a class="link" href="glib-GVariant.html#GVariant" title="GVariant">GVariant</a> into C values is made using the
   <a class="link" href="glib-GVariant.html#g-variant-get" title="g_variant_get ()"><code class="function">g_variant_get()</code></a> function.
  </p>
</div>
<div class="refsect1">
<a name="id-1.6.20.4"></a><h2>Syntax</h2>
<p>
   This section exhaustively describes all possibilities for GVariant format strings.  There are no valid forms of
   format strings other than those described here.  Please note that the format string syntax is likely to expand in the
   future.
  </p>
<p>
   Valid format strings have one of the following forms:
  </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p>any type string</p></li>
<li class="listitem"><p>
     a type string prefixed with a '<code class="literal">@</code>'
    </p></li>
<li class="listitem"><p>
     '<code class="literal">&amp;s</code>' '<code class="literal">&amp;o</code>', '<code class="literal">&amp;g</code>', '<code class="literal">^as</code>',
     '<code class="literal">^a&amp;s</code>', '<code class="literal">^ao</code>', '<code class="literal">^a&amp;o</code>','<code class="literal">^ay</code>',
     '<code class="literal">^&amp;ay</code>', '<code class="literal">^aay</code>' or '<code class="literal">^a&amp;ay</code>'.
    </p></li>
<li class="listitem"><p>
     any format string, prefixed with an '<code class="literal">m</code>'
    </p></li>
<li class="listitem"><p>
     a sequence of zero or more format strings, concatenated and enclosed in parentheses
    </p></li>
<li class="listitem"><p>
     an opening brace, followed by two format strings, followed by a closing brace (subject to the constraint that the
     first format string correspond to a type valid for use as the key type of a dictionary)
    </p></li>
</ul></div>
</div>
<div class="refsect1">
<a name="id-1.6.20.5"></a><h2>Symbols</h2>
<p>
    The following table describes the rough meaning of symbols that may appear inside a GVariant format string.  Each
    symbol is described in detail in its own section, including usage examples.
  </p>
<div class="informaltable"><table border="1">
<colgroup>
<col class="col_0">
<col class="col_1">
</colgroup>
<tbody>
<tr>
<td>
       <p>
        <span class="strong"><strong>Symbol</strong></span>
       </p>
      </td>
<td>
       <p>
         <span class="strong"><strong>Meaning</strong></span>
       </p>
      </td>
</tr>
<tr>
<td>
       <p>
        <span class="strong"><strong>
         <code class="literal">b</code>, <code class="literal">y</code>, <code class="literal">n</code>, <code class="literal">q</code>, <code class="literal">i</code>,
         <code class="literal">u</code>, <code class="literal">x</code>, <code class="literal">t</code>, <code class="literal">h</code>, <code class="literal">d</code>
        </strong></span>
       </p>
      </td>
<td>
       <p>
        Used for building or deconstructing boolean, byte and numeric types.  See
        <a href="gvariant-format-strings.html#gvariant-format-strings-numeric-types">Numeric Types</a> below.
       </p>
      </td>
</tr>
<tr>
<td>
       <p>
        <span class="strong"><strong>
         <code class="literal">s</code>, <code class="literal">o</code>, <code class="literal">g</code>
        </strong></span>
       </p>
      </td>
<td>
       <p>
        Used for building or deconstructing string types.  See
        <a href="gvariant-format-strings.html#gvariant-format-strings-strings">Strings</a> below.
       </p>
      </td>
</tr>
<tr>
<td>
       <p>
        <span class="strong"><strong><code class="literal">v</code></strong></span>
       </p>
      </td>
<td>
       <p>
        Used for building or deconstructing variant types.  See
        <a href="gvariant-format-strings.html#gvariant-format-strings-variants">Variants</a> below.
       </p>
      </td>
</tr>
<tr>
<td>
       <p>
        <span class="strong"><strong>
         <code class="literal">a</code>
        </strong></span>
       </p>
      </td>
<td>
       <p>
        Used for building or deconstructing arrays.  See
        <a href="gvariant-format-strings.html#gvariant-format-strings-arrays">Arrays</a> below.
       </p>
      </td>
</tr>
<tr>
<td>
       <p>
        <span class="strong"><strong>
         <code class="literal">m</code>
        </strong></span>
       </p>
      </td>
<td>
       <p>
         Used for building or deconstructing maybe types.  See
         <a href="gvariant-format-strings.html#gvariant-format-strings-maybe-types">Maybe Types</a> below.
       </p>
      </td>
</tr>
<tr>
<td>
       <p>
        <span class="strong"><strong>
         <code class="literal">()</code>
        </strong></span>
       </p>
      </td>
<td>
       <p>
         Used for building or deconstructing tuples.  See
         <a href="gvariant-format-strings.html#gvariant-format-strings-tuples">Tuples</a> below.
       </p>
      </td>
</tr>
<tr>
<td>
       <p>
        <span class="strong"><strong>
         <code class="literal">{}</code>
        </strong></span>
       </p>
      </td>
<td>
       <p>
        Used for building or deconstructing dictionary entries. See
        <a href="gvariant-format-strings.html#gvariant-format-strings-dictionaries">Dictionaries</a> below.
       </p>
      </td>
</tr>
<tr>
<td>
       <p>
        <span class="strong"><strong>
         <code class="literal">@</code>
        </strong></span>
       </p>
      </td>
<td>
       <p>
        Used as a prefix for a GVariant type string (not a prefix for a format string, so <code class="literal">@as</code> is
        a valid format string but <code class="literal">@^as</code> is not).  Denotes that a pointer to a
        <a class="link" href="glib-GVariant.html#GVariant" title="GVariant">GVariant</a> should be used in place of the normal C type or types.  For
        <a class="link" href="glib-GVariant.html#g-variant-new" title="g_variant_new ()"><code class="function">g_variant_new()</code></a> this means that you must pass a
        non-<a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> <code class="code">(<a class="link" href="glib-GVariant.html#GVariant" title="GVariant">GVariant</a>
        *)</code>; if it is a floating reference, ownership will be taken, as
        if by using <a class="link" href="glib-GVariant.html#g-variant-ref-sink" title="g_variant_ref_sink ()"><code class="function">g_variant_ref_sink()</code></a>.
        For <a class="link" href="glib-GVariant.html#g-variant-get" title="g_variant_get ()"><code class="function">g_variant_get()</code></a> this means that you
        must pass a pointer to a <code class="code">(<a class="link" href="glib-GVariant.html#GVariant" title="GVariant">GVariant</a> *)</code> for the value to be returned
        by reference or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> to ignore the value.  See
        <a href="gvariant-format-strings.html#gvariant-format-strings-gvariant"><code class="code">GVariant *</code></a> below.
       </p>
      </td>
</tr>
<tr>
<td>
       <p>
        <span class="strong"><strong>
         <code class="literal">*</code>, <code class="literal">?</code>, <code class="literal">r</code>
        </strong></span>
       </p>
      </td>
<td>
       <p>
        Exactly equivalent to <code class="literal">@*</code>, <code class="literal">@?</code> and <code class="literal">@r</code>.  Provided only for
        completeness so that all GVariant type strings can be used also as format strings.  See <a href="gvariant-format-strings.html#gvariant-format-strings-gvariant"><code class="code">GVariant *</code></a> below.
       </p>
      </td>
</tr>
<tr>
<td>
       <p>
        <span class="strong"><strong><code class="literal">&amp;</code></strong></span>
       </p>
      </td>
<td>
       <p>
        Used as a prefix for a GVariant type string (not a prefix for a format string, so <code class="literal">&amp;s</code> is
        a valid format string but <code class="literal">&amp;@s</code> is not).
        Denotes that a C pointer to serialised data
        should be used in place of the normal C type.  See
        <a href="gvariant-format-strings.html#gvariant-format-strings-pointers">Pointers</a> below.
       </p>
      </td>
</tr>
<tr>
<td>
       <p>
        <span class="strong"><strong><code class="literal">^</code></strong></span>
       </p>
      </td>
<td>
       <p>
        Used as a prefix on some specific types of format strings.  See
        <a href="gvariant-format-strings.html#gvariant-format-strings-convenience">Convenience Conversions</a> below.
       </p>
      </td>
</tr>
</tbody>
</table></div>
<div class="refsect2">
<a name="gvariant-format-strings-numeric-types"></a><h3>Numeric Types</h3>
<p>
    <span class="strong"><strong>
     Characters: <code class="literal">b</code>, <code class="literal">y</code>, <code class="literal">n</code>, <code class="literal">q</code>,
     <code class="literal">i</code>, <code class="literal">u</code>, <code class="literal">x</code>, <code class="literal">t</code>, <code class="literal">h</code>,
     <code class="literal">d</code>
    </strong></span>
   </p>
<p>
    Variable argument conversions from numeric types work in the most obvious way possible.  Upon encountering one of
    these characters, <a class="link" href="glib-GVariant.html#g-variant-new" title="g_variant_new ()"><code class="function">g_variant_new()</code></a> takes the equivalent C
    type as an argument.  <a class="link" href="glib-GVariant.html#g-variant-get" title="g_variant_get ()"><code class="function">g_variant_get()</code></a> takes a pointer to
    the equivalent C type (or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> to ignore the value).
   </p>
<p>
    The equivalent C types are as follows:
   </p>
<div class="informaltable"><table border="1">
<colgroup>
<col class="col_0">
<col class="col_1">
</colgroup>
<tbody>
<tr>
<td>
        <p>
          <span class="strong"><strong>Character</strong></span>
        </p>
       </td>
<td>
        <p>
          <span class="strong"><strong>Equivalent C type</strong></span>
        </p>
       </td>
</tr>
<tr>
<td>
        <p>
         <span class="strong"><strong>
          <code class="literal">b</code>
         </strong></span>
        </p>
       </td>
<td>
        <p>
         <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="type">gboolean</span></a>
        </p>
       </td>
</tr>
<tr>
<td>
        <p>
         <span class="strong"><strong>
          <code class="literal">y</code>
         </strong></span>
        </p>
       </td>
<td>
        <p>
         <a class="link" href="glib-Basic-Types.html#guchar" title="guchar"><span class="type">guchar</span></a>
        </p>
       </td>
</tr>
<tr>
<td>
        <p>
         <span class="strong"><strong>
          <code class="literal">n</code>
         </strong></span>
        </p>
       </td>
<td>
        <p>
         <a class="link" href="glib-Basic-Types.html#gint16" title="gint16"><span class="type">gint16</span></a>
        </p>
       </td>
</tr>
<tr>
<td>
        <p>
         <span class="strong"><strong>
          <code class="literal">q</code>
         </strong></span>
        </p>
       </td>
<td>
        <p>
         <a class="link" href="glib-Basic-Types.html#guint16" title="guint16"><span class="type">guint16</span></a>
        </p>
       </td>
</tr>
<tr>
<td>
        <p>
         <span class="strong"><strong>
          <code class="literal">i</code>
         </strong></span>
        </p>
       </td>
<td>
        <p>
         <a class="link" href="glib-Basic-Types.html#gint32" title="gint32"><span class="type">gint32</span></a>
        </p>
       </td>
</tr>
<tr>
<td>
        <p>
         <span class="strong"><strong>
          <code class="literal">u</code>
         </strong></span>
        </p>
       </td>
<td>
        <p>
         <a class="link" href="glib-Basic-Types.html#guint32" title="guint32"><span class="type">guint32</span></a>
        </p>
       </td>
</tr>
<tr>
<td>
        <p>
         <span class="strong"><strong>
          <code class="literal">x</code>
         </strong></span>
        </p>
       </td>
<td>
        <p>
         <a class="link" href="glib-Basic-Types.html#gint64" title="gint64"><span class="type">gint64</span></a>
        </p>
       </td>
</tr>
<tr>
<td>
        <p>
         <span class="strong"><strong>
          <code class="literal">t</code>
         </strong></span>
        </p>
       </td>
<td>
        <p>
         <a class="link" href="glib-Basic-Types.html#guint64" title="guint64"><span class="type">guint64</span></a>
        </p>
       </td>
</tr>
<tr>
<td>
        <p>
         <span class="strong"><strong>
          <code class="literal">h</code>
         </strong></span>
        </p>
       </td>
<td>
        <p>
         <a class="link" href="glib-Basic-Types.html#gint32" title="gint32"><span class="type">gint32</span></a>
        </p>
       </td>
</tr>
<tr>
<td>
        <p>
         <span class="strong"><strong>
          <code class="literal">d</code>
         </strong></span>
        </p>
       </td>
<td>
        <p>
         <a class="link" href="glib-Basic-Types.html#gdouble" title="gdouble"><span class="type">gdouble</span></a>
        </p>
       </td>
</tr>
</tbody>
</table></div>
<a name="gvariant-varargs"></a><p>
    Note that in C, small integer types in variable argument lists are promoted up to <a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">int</span></a> or <a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="type">unsigned int</span></a> as appropriate, and
    read back accordingly.  <a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">int</span></a> is 32 bits on every platform on which GLib is
    currently supported.  This means that you can use C expressions of type <a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">int</span></a>
    with <a class="link" href="glib-GVariant.html#g-variant-new" title="g_variant_new ()"><code class="function">g_variant_new()</code></a> and format characters
    '<code class="literal">b</code>', '<code class="literal">y</code>', '<code class="literal">n</code>', '<code class="literal">q</code>',
    '<code class="literal">i</code>', '<code class="literal">u</code>' and '<code class="literal">h</code>'.  Specifically, you can use integer
    literals with these characters.
   </p>
<p>
    When using the '<code class="literal">x</code>' and '<code class="literal">t</code>' characters, you must ensure that the value that you
    provide is 64 bit.  This means that you should use a cast or make use of the
    <a class="link" href="glib-Basic-Types.html#G-GINT64-CONSTANT:CAPS" title="G_GINT64_CONSTANT()"><code class="literal">G_GINT64_CONSTANT</code></a> or
    <a class="link" href="glib-Basic-Types.html#G-GUINT64-CONSTANT:CAPS" title="G_GUINT64_CONSTANT()"><code class="literal">G_GUINT64_CONSTANT</code></a> macros.
   </p>
<p>
    No type promotion occurs when using <a class="link" href="glib-GVariant.html#g-variant-get" title="g_variant_get ()"><code class="function">g_variant_get()</code></a> since
    it operates with pointers.  The pointers must always point to a memory region of exactly the correct size.
   </p>
<div class="refsect3">
<a name="id-1.6.20.5.4.10"></a><h4>Examples</h4>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18</pre></td>
        <td class="listing_code"><pre class="programlisting">GVariant <span class="gtkdoc opt">*</span>value1<span class="gtkdoc opt">, *</span>value2<span class="gtkdoc opt">, *</span>value3<span class="gtkdoc opt">, *</span>value4<span class="gtkdoc opt">;</span>

value1 <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-new">g_variant_new</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;y&quot;</span><span class="gtkdoc opt">,</span> <span class="number">200</span><span class="gtkdoc opt">);</span>
value2 <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-new">g_variant_new</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;b&quot;</span><span class="gtkdoc opt">,</span> TRUE<span class="gtkdoc opt">);</span>
value3 <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-new">g_variant_new</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;d&quot;</span><span class="gtkdoc opt">,</span> <span class="number">37.5</span><span class="gtkdoc opt">):</span>
value4 <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-new">g_variant_new</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;x&quot;</span><span class="gtkdoc opt">,</span> <span class="function"><a href="glib-Basic-Types.html#G-GINT64-CONSTANT:CAPS">G_GINT64_CONSTANT</a></span> <span class="gtkdoc opt">(</span><span class="number">998877665544332211</span><span class="gtkdoc opt">));</span>

<span class="gtkdoc opt">{</span>
  gdouble floating<span class="gtkdoc opt">;</span>
  gboolean truth<span class="gtkdoc opt">;</span>
  gint64 bignum<span class="gtkdoc opt">;</span>


  <span class="function"><a href="glib-GVariant.html#g-variant-get">g_variant_get</a></span> <span class="gtkdoc opt">(</span>value1<span class="gtkdoc opt">,</span> <span class="string">&quot;y&quot;</span><span class="gtkdoc opt">,</span> NULL<span class="gtkdoc opt">);</span>      <span class="comment">/* ignore the value. */</span>
  <span class="function"><a href="glib-GVariant.html#g-variant-get">g_variant_get</a></span> <span class="gtkdoc opt">(</span>value2<span class="gtkdoc opt">,</span> <span class="string">&quot;b&quot;</span><span class="gtkdoc opt">, &amp;</span>truth<span class="gtkdoc opt">);</span>
  <span class="function"><a href="glib-GVariant.html#g-variant-get">g_variant_get</a></span> <span class="gtkdoc opt">(</span>value3<span class="gtkdoc opt">,</span> <span class="string">&quot;d&quot;</span><span class="gtkdoc opt">, &amp;</span>floating<span class="gtkdoc opt">);</span>
  <span class="function"><a href="glib-GVariant.html#g-variant-get">g_variant_get</a></span> <span class="gtkdoc opt">(</span>value4<span class="gtkdoc opt">,</span> <span class="string">&quot;x&quot;</span><span class="gtkdoc opt">, &amp;</span>bignum<span class="gtkdoc opt">);</span>
<span class="gtkdoc opt">}</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

</div>
</div>
<hr>
<div class="refsect2">
<a name="gvariant-format-strings-strings"></a><h3>Strings</h3>
<p>
    <span class="strong"><strong>
     Characters: <code class="literal">s</code>, <code class="literal">o</code>, <code class="literal">g</code>
    </strong></span>
   </p>
<p>
    String conversions occur to and from standard nul-terminated C strings.  Upon encountering an
    '<code class="literal">s</code>', '<code class="literal">o</code>' or '<code class="literal">g</code>' in a format string,
    <a class="link" href="glib-GVariant.html#g-variant-new" title="g_variant_new ()"><code class="function">g_variant_new()</code></a> takes a <code class="code">(const
    <a class="link" href="glib-Basic-Types.html#gchar" title="gchar">gchar</a> *)</code> and makes a copy of it.
    <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> is not a valid string.  If the '<code class="literal">o</code>' or
    '<code class="literal">g</code>' characters are used, care must be taken to ensure that the passed string is a valid DBus
    object path or DBus type signature, respectively.
   </p>
<p>
    Upon encounting '<code class="literal">s</code>', '<code class="literal">o</code>' or '<code class="literal">g</code>', <a class="link" href="glib-GVariant.html#g-variant-get" title="g_variant_get ()"><code class="function">g_variant_get()</code></a> takes a pointer to a
    <code class="code">(<a class="link" href="glib-Basic-Types.html#gchar" title="gchar">gchar</a> *)</code> (ie: <code class="code">(<a class="link" href="glib-Basic-Types.html#gchar" title="gchar">gchar</a> **)</code>) and
    sets it to a newly-allocated copy of the string.  It is appropriate to free this copy using
    <a class="link" href="glib-Memory-Allocation.html#g-free" title="g_free ()"><code class="function">g_free()</code></a>.
    <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> may also be passed to indicate that the value of the
    string should be ignored (in which case no copy is made).
   </p>
<div class="refsect3">
<a name="id-1.6.20.5.5.5"></a><h4>Examples</h4>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17</pre></td>
        <td class="listing_code"><pre class="programlisting">GVariant <span class="gtkdoc opt">*</span>value1<span class="gtkdoc opt">, *</span>value2<span class="gtkdoc opt">, *</span>value3<span class="gtkdoc opt">;</span>

value1 <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-new">g_variant_new</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;s&quot;</span><span class="gtkdoc opt">,</span> <span class="string">&quot;hello world!&quot;</span><span class="gtkdoc opt">);</span>
value2 <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-new">g_variant_new</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;o&quot;</span><span class="gtkdoc opt">,</span> <span class="string">&quot;/must/be/a/valid/path&quot;</span><span class="gtkdoc opt">);</span>
value3 <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-new">g_variant_new</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;g&quot;</span><span class="gtkdoc opt">,</span> <span class="string">&quot;iias&quot;</span><span class="gtkdoc opt">);</span>

<span class="gtkdoc ppc">#if 0</span>
  <span class="function"><a href="glib-GVariant.html#g-variant-new">g_variant_new</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;s&quot;</span><span class="gtkdoc opt">,</span> NULL<span class="gtkdoc opt">);</span>      <span class="comment">/* not valid: NULL is not a string. */</span>
<span class="gtkdoc ppc">#endif</span>

<span class="gtkdoc opt">{</span>
  gchar <span class="gtkdoc opt">*</span>result<span class="gtkdoc opt">;</span>

  <span class="function"><a href="glib-GVariant.html#g-variant-get">g_variant_get</a></span> <span class="gtkdoc opt">(</span>value1<span class="gtkdoc opt">,</span> <span class="string">&quot;s&quot;</span><span class="gtkdoc opt">, &amp;</span>result<span class="gtkdoc opt">);</span>
  <span class="function"><a href="glib-Warnings-and-Assertions.html#g-print">g_print</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;It was '%s'</span><span class="gtkdoc esc">\n</span><span class="string">&quot;</span><span class="gtkdoc opt">,</span> result<span class="gtkdoc opt">);</span>
  <span class="function"><a href="glib-Memory-Allocation.html#g-free">g_free</a></span> <span class="gtkdoc opt">(</span>result<span class="gtkdoc opt">);</span>
<span class="gtkdoc opt">}</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

</div>
</div>
<hr>
<div class="refsect2">
<a name="gvariant-format-strings-variants"></a><h3>Variants</h3>
<p>
    <span class="strong"><strong>
     Characters: <code class="literal">v</code>
    </strong></span>
   </p>
<p>
    Upon encountering a '<code class="literal">v</code>',
    <a class="link" href="glib-GVariant.html#g-variant-new" title="g_variant_new ()"><code class="function">g_variant_new()</code></a> takes a <code class="code">(<a class="link" href="glib-GVariant.html#GVariant" title="GVariant">GVariant</a> *)</code>.  The value of the
    <a class="link" href="glib-GVariant.html#GVariant" title="GVariant"><span class="type">GVariant</span></a> is used as the contents of the variant value.
   </p>
<p>
    Upon encountering a '<code class="literal">v</code>', <a class="link" href="glib-GVariant.html#g-variant-get" title="g_variant_get ()"><code class="function">g_variant_get()</code></a> takes a pointer to a
    <code class="code">(<a class="link" href="glib-GVariant.html#GVariant" title="GVariant">GVariant</a> *)</code> (ie: <code class="code">(<a class="link" href="glib-GVariant.html#GVariant" title="GVariant">GVariant</a> **)
    </code>).  It is set to a new reference to a <a class="link" href="glib-GVariant.html#GVariant" title="GVariant"><span class="type">GVariant</span></a> instance
    containing the contents of the variant value.  It is appropriate to free this reference using
    <a class="link" href="glib-GVariant.html#g-variant-unref" title="g_variant_unref ()"><code class="function">g_variant_unref()</code></a>.
    <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> may also be passed to indicate that the value should be
    ignored (in which case no new reference is created).
   </p>
<div class="refsect3">
<a name="id-1.6.20.5.6.5"></a><h4>Examples</h4>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9</pre></td>
        <td class="listing_code"><pre class="programlisting">GVariant <span class="gtkdoc opt">*</span>x<span class="gtkdoc opt">, *</span>y<span class="gtkdoc opt">;</span>

<span class="comment">/* the following two lines are equivalent: */</span>
x <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-new">g_variant_new</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;v&quot;</span><span class="gtkdoc opt">,</span> y<span class="gtkdoc opt">);</span>
x <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-new-variant">g_variant_new_variant</a></span> <span class="gtkdoc opt">(</span>y<span class="gtkdoc opt">);</span>

<span class="comment">/* as are these: */</span>
<span class="function"><a href="glib-GVariant.html#g-variant-get">g_variant_get</a></span> <span class="gtkdoc opt">(</span>x<span class="gtkdoc opt">,</span> <span class="string">&quot;v&quot;</span><span class="gtkdoc opt">, &amp;</span>y<span class="gtkdoc opt">);</span>
y <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-get-variant">g_variant_get_variant</a></span> <span class="gtkdoc opt">(</span>x<span class="gtkdoc opt">);</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

</div>
</div>
<hr>
<div class="refsect2">
<a name="gvariant-format-strings-arrays"></a><h3>Arrays</h3>
<p>
    <span class="strong"><strong>
     Characters: <code class="literal">a</code>
    </strong></span>
   </p>
<p>
    Upon encountering an '<code class="literal">a</code>' character followed by a type string,
    <a class="link" href="glib-GVariant.html#g-variant-new" title="g_variant_new ()"><code class="function">g_variant_new()</code></a> will take a
    <code class="code">(<a class="link" href="glib-GVariant.html#GVariantBuilder" title="struct GVariantBuilder">GVariantBuilder</a> *)</code> that has been created as an array builder
    for an array of the type given in the type string.  The builder will have
    <a class="link" href="glib-GVariant.html#g-variant-builder-end" title="g_variant_builder_end ()"><code class="function">g_variant_builder_end()</code></a> called on it and the
    result will be used as the value.  As a special exception, if the given type string is a definite type, then
    <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> may be given to mean an empty array of that type.
   </p>
<p>
    Upon encountering an '<code class="literal">a</code>' character followed by a type string,
    <a class="link" href="glib-GVariant.html#g-variant-get" title="g_variant_get ()"><code class="function">g_variant_get()</code></a> will take a pointer to a
    <code class="code">(<a class="link" href="glib-GVariant.html#GVariantIter" title="struct GVariantIter">GVariantIter</a> *)</code> (ie:
    <code class="code">(<a class="link" href="glib-GVariant.html#GVariantIter" title="struct GVariantIter">GVariantIter</a> **)</code>).
    A new heap-allocated iterator is created and returned, initialised for iterating over the elements of the array.
    This iterator should be freed when you are done with it, using
    <a class="link" href="glib-GVariant.html#g-variant-iter-free" title="g_variant_iter_free ()"><code class="function">g_variant_iter_free()</code></a>.
    <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> may also be given to indicate that the value of the array
    should be ignored.
   </p>
<div class="refsect3">
<a name="id-1.6.20.5.7.5"></a><h4>Examples</h4>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22</pre></td>
        <td class="listing_code"><pre class="programlisting">GVariantBuilder <span class="gtkdoc opt">*</span>builder<span class="gtkdoc opt">;</span>
GVariant <span class="gtkdoc opt">*</span>value<span class="gtkdoc opt">;</span>

builder <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-builder-new">g_variant_builder_new</a></span> <span class="gtkdoc opt">(</span><span class="function"><a href="glib-GVariantType.html#G-VARIANT-TYPE:CAPS">G_VARIANT_TYPE</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;as&quot;</span><span class="gtkdoc opt">));</span>
<span class="function"><a href="glib-GVariant.html#g-variant-builder-add">g_variant_builder_add</a></span> <span class="gtkdoc opt">(</span>builder<span class="gtkdoc opt">,</span> <span class="string">&quot;s&quot;</span><span class="gtkdoc opt">,</span> <span class="string">&quot;when&quot;</span><span class="gtkdoc opt">);</span>
<span class="function"><a href="glib-GVariant.html#g-variant-builder-add">g_variant_builder_add</a></span> <span class="gtkdoc opt">(</span>builder<span class="gtkdoc opt">,</span> <span class="string">&quot;s&quot;</span><span class="gtkdoc opt">,</span> <span class="string">&quot;in&quot;</span><span class="gtkdoc opt">);</span>
<span class="function"><a href="glib-GVariant.html#g-variant-builder-add">g_variant_builder_add</a></span> <span class="gtkdoc opt">(</span>builder<span class="gtkdoc opt">,</span> <span class="string">&quot;s&quot;</span><span class="gtkdoc opt">,</span> <span class="string">&quot;the&quot;</span><span class="gtkdoc opt">);</span>
<span class="function"><a href="glib-GVariant.html#g-variant-builder-add">g_variant_builder_add</a></span> <span class="gtkdoc opt">(</span>builder<span class="gtkdoc opt">,</span> <span class="string">&quot;s&quot;</span><span class="gtkdoc opt">,</span> <span class="string">&quot;course&quot;</span><span class="gtkdoc opt">);</span>
value <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-new">g_variant_new</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;as&quot;</span><span class="gtkdoc opt">,</span> builder<span class="gtkdoc opt">);</span>
<span class="function"><a href="glib-GVariant.html#g-variant-builder-unref">g_variant_builder_unref</a></span> <span class="gtkdoc opt">(</span>builder<span class="gtkdoc opt">);</span>

<span class="gtkdoc opt">{</span>
  GVariantIter <span class="gtkdoc opt">*</span>iter<span class="gtkdoc opt">;</span>
  gchar <span class="gtkdoc opt">*</span>str<span class="gtkdoc opt">;</span>

  <span class="function"><a href="glib-GVariant.html#g-variant-get">g_variant_get</a></span> <span class="gtkdoc opt">(</span>value<span class="gtkdoc opt">,</span> <span class="string">&quot;as&quot;</span><span class="gtkdoc opt">, &amp;</span>iter<span class="gtkdoc opt">);</span>
  <span class="keyword">while</span> <span class="gtkdoc opt">(</span><span class="function"><a href="glib-GVariant.html#g-variant-iter-loop">g_variant_iter_loop</a></span> <span class="gtkdoc opt">(</span>iter<span class="gtkdoc opt">,</span> <span class="string">&quot;s&quot;</span><span class="gtkdoc opt">, &amp;</span>str<span class="gtkdoc opt">))</span>
    <span class="function"><a href="glib-Warnings-and-Assertions.html#g-print">g_print</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;%s</span><span class="gtkdoc esc">\n</span><span class="string">&quot;</span><span class="gtkdoc opt">,</span> str<span class="gtkdoc opt">);</span>
  <span class="function"><a href="glib-GVariant.html#g-variant-iter-free">g_variant_iter_free</a></span> <span class="gtkdoc opt">(</span>iter<span class="gtkdoc opt">);</span>
<span class="gtkdoc opt">}</span>

<span class="function"><a href="glib-GVariant.html#g-variant-unref">g_variant_unref</a></span> <span class="gtkdoc opt">(</span>value<span class="gtkdoc opt">);</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

</div>
</div>
<hr>
<div class="refsect2">
<a name="gvariant-format-strings-maybe-types"></a><h3>Maybe Types</h3>
<p>
    <span class="strong"><strong>
     Characters: <code class="literal">m</code>
    </strong></span>
   </p>
<p>
    Maybe types are handled in two separate ways depending on the format string that follows the
    '<code class="literal">m</code>'.  The method that is used currently depends entirely on the character immediately following the
    '<code class="literal">m</code>'.
   </p>
<p>
    The first way is used with format strings starting with '<code class="literal">a</code>', '<code class="literal">s</code>',
    '<code class="literal">o</code>', '<code class="literal">g</code>', '<code class="literal">v</code>', '<code class="literal">@</code>',
    '<code class="literal">*</code>', '<code class="literal">?</code>', '<code class="literal">r</code>', '<code class="literal">&amp;</code>', or
    '<code class="literal">^</code>'.  In all of these cases, for non-maybe types,
    <a class="link" href="glib-GVariant.html#g-variant-new" title="g_variant_new ()"><code class="function">g_variant_new()</code></a> takes a pointer to a
    non-<a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> value and
    <a class="link" href="glib-GVariant.html#g-variant-get" title="g_variant_get ()"><code class="function">g_variant_get()</code></a> returns (by reference) a
    non-<a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> pointer.  When any of these format strings are
    prefixed with an '<code class="literal">m</code>', the type of arguments that are collected does not change in any way, but
    <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> becomes a permissable value, to indicate the Nothing case.
   </p>
<p>
    Note that the "special exception" introduced in the array section for constructing empty arrays is ignored
    here.  Using a <code class="literal">NULL</code> pointer with the format string '<code class="literal">mas</code>' constructs
    the Nothing value -- not an empty array.
   </p>
<p>
    The second way is used with all other format strings.  For
    <a class="link" href="glib-GVariant.html#g-variant-new" title="g_variant_new ()"><code class="function">g_variant_new()</code></a> an additional
    <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="type">gboolean</span></a> argument is collected and for
    <a class="link" href="glib-GVariant.html#g-variant-get" title="g_variant_get ()"><code class="function">g_variant_get()</code></a> an additional
    <code class="code">(<a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean">gboolean</a> *)</code>.  Following this argument, the arguments that are normally
    collected for the equivalent non-maybe type will be collected.
   </p>
<p>
    If <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a> is given to
    <a class="link" href="glib-GVariant.html#g-variant-new" title="g_variant_new ()"><code class="function">g_variant_new()</code></a> then the Nothing value is constructed and
    the collected arguments are ignored.  Otherwise (if <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> was
    given), the arguments are used in the normal way to create the Just value.
   </p>
<p>
    If <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> is given to
    <a class="link" href="glib-GVariant.html#g-variant-get" title="g_variant_get ()"><code class="function">g_variant_get()</code></a> then the value is ignored.  If a
    non-<a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> pointer is given then it is used to return by reference
    whether the value was Just.  In the case that the value was Just, the
    <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="type">gboolean</span></a> will be set to
    <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> and the value will be stored in the arguments in the usual
    way.  In the case that the value was Nothing, the <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="type">gboolean</span></a> will be set to
    <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a> and the arguments will be collected in the normal way
    but have their values set to binary zero.
   </p>
<div class="refsect3">
<a name="id-1.6.20.5.8.9"></a><h4>Examples</h4>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>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</pre></td>
        <td class="listing_code"><pre class="programlisting">GVariant <span class="gtkdoc opt">*</span>value1<span class="gtkdoc opt">, *</span>value2<span class="gtkdoc opt">, *</span>value3<span class="gtkdoc opt">, *</span>value4<span class="gtkdoc opt">, *</span>value5<span class="gtkdoc opt">, *</span>value6<span class="gtkdoc opt">;</span>
value1 <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-new">g_variant_new</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;ms&quot;</span><span class="gtkdoc opt">,</span> <span class="string">&quot;Hello world&quot;</span><span class="gtkdoc opt">);</span>
value2 <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-new">g_variant_new</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;ms&quot;</span><span class="gtkdoc opt">,</span> NULL<span class="gtkdoc opt">);</span>
value3 <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-new">g_variant_new</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;(m(ii)s)&quot;</span><span class="gtkdoc opt">,</span> TRUE<span class="gtkdoc opt">,</span> <span class="number">123</span><span class="gtkdoc opt">,</span> <span class="number">456</span><span class="gtkdoc opt">,</span> <span class="string">&quot;Done&quot;</span><span class="gtkdoc opt">);</span>
value4 <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-new">g_variant_new</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;(m(ii)s)&quot;</span><span class="gtkdoc opt">,</span> FALSE<span class="gtkdoc opt">, -</span><span class="number">1</span><span class="gtkdoc opt">, -</span><span class="number">1</span><span class="gtkdoc opt">,</span> <span class="string">&quot;Done&quot;</span><span class="gtkdoc opt">);</span>          <span class="comment">/* both '-1' are ignored. */</span>
value5 <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-new">g_variant_new</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;(m&#64;(ii)s)&quot;</span><span class="gtkdoc opt">,</span> NULL<span class="gtkdoc opt">,</span> <span class="string">&quot;Done&quot;</span><span class="gtkdoc opt">);</span>

<span class="gtkdoc opt">{</span>
  GVariant <span class="gtkdoc opt">*</span>contents<span class="gtkdoc opt">;</span>
  <span class="gtkdoc kwb">const</span> gchar <span class="gtkdoc opt">*</span>cstr<span class="gtkdoc opt">;</span>
  gboolean just<span class="gtkdoc opt">;</span>
  gint32 x<span class="gtkdoc opt">,</span> y<span class="gtkdoc opt">;</span>
  gchar <span class="gtkdoc opt">*</span>str<span class="gtkdoc opt">;</span>

  <span class="function"><a href="glib-GVariant.html#g-variant-get">g_variant_get</a></span> <span class="gtkdoc opt">(</span>value1<span class="gtkdoc opt">,</span> <span class="string">&quot;ms&quot;</span><span class="gtkdoc opt">, &amp;</span>str<span class="gtkdoc opt">);</span>
  <span class="keyword">if</span> <span class="gtkdoc opt">(</span>str <span class="gtkdoc opt">!=</span> NULL<span class="gtkdoc opt">)</span>
    <span class="function"><a href="glib-Warnings-and-Assertions.html#g-print">g_print</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;str: %s</span><span class="gtkdoc esc">\n</span><span class="string">&quot;</span><span class="gtkdoc opt">,</span> str<span class="gtkdoc opt">);</span>
  <span class="keyword">else</span>
    <span class="function"><a href="glib-Warnings-and-Assertions.html#g-print">g_print</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;it was null</span><span class="gtkdoc esc">\n</span><span class="string">&quot;</span><span class="gtkdoc opt">);</span>
  <span class="function"><a href="glib-Memory-Allocation.html#g-free">g_free</a></span> <span class="gtkdoc opt">(</span>str<span class="gtkdoc opt">);</span>


  <span class="function"><a href="glib-GVariant.html#g-variant-get">g_variant_get</a></span> <span class="gtkdoc opt">(</span>value2<span class="gtkdoc opt">,</span> <span class="string">&quot;m&amp;s&quot;</span><span class="gtkdoc opt">, &amp;</span>cstr<span class="gtkdoc opt">);</span>
  <span class="keyword">if</span> <span class="gtkdoc opt">(</span>cstr <span class="gtkdoc opt">!=</span> NULL<span class="gtkdoc opt">)</span>
    <span class="function"><a href="glib-Warnings-and-Assertions.html#g-print">g_print</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;str: %s</span><span class="gtkdoc esc">\n</span><span class="string">&quot;</span><span class="gtkdoc opt">,</span> cstr<span class="gtkdoc opt">);</span>
  <span class="keyword">else</span>
    <span class="function"><a href="glib-Warnings-and-Assertions.html#g-print">g_print</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;it was null</span><span class="gtkdoc esc">\n</span><span class="string">&quot;</span><span class="gtkdoc opt">);</span>
  <span class="comment">/* don't free 'cstr' */</span>


  <span class="comment">/* NULL passed for the gboolean *, but two 'gint32 *' still collected */</span>
  <span class="function"><a href="glib-GVariant.html#g-variant-get">g_variant_get</a></span> <span class="gtkdoc opt">(</span>value3<span class="gtkdoc opt">,</span> <span class="string">&quot;(m(ii)s)&quot;</span><span class="gtkdoc opt">,</span> NULL<span class="gtkdoc opt">,</span> NULL<span class="gtkdoc opt">,</span> NULL<span class="gtkdoc opt">, &amp;</span>str<span class="gtkdoc opt">);</span>
  <span class="function"><a href="glib-Warnings-and-Assertions.html#g-print">g_print</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;string is %s</span><span class="gtkdoc esc">\n</span><span class="string">&quot;</span><span class="gtkdoc opt">,</span> str<span class="gtkdoc opt">);</span>
  <span class="function"><a href="glib-Memory-Allocation.html#g-free">g_free</a></span> <span class="gtkdoc opt">(</span>str<span class="gtkdoc opt">);</span>

  <span class="comment">/* note: &amp;s used, so g_free() not needed */</span>
  <span class="function"><a href="glib-GVariant.html#g-variant-get">g_variant_get</a></span> <span class="gtkdoc opt">(</span>value4<span class="gtkdoc opt">,</span> <span class="string">&quot;(m(ii)&amp;s)&quot;</span><span class="gtkdoc opt">, &amp;</span>just<span class="gtkdoc opt">, &amp;</span>x<span class="gtkdoc opt">, &amp;</span>y<span class="gtkdoc opt">, &amp;</span>cstr<span class="gtkdoc opt">);</span>
  <span class="keyword">if</span> <span class="gtkdoc opt">(</span>just<span class="gtkdoc opt">)</span>
    <span class="function"><a href="glib-Warnings-and-Assertions.html#g-print">g_print</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;it was (%d, %d)</span><span class="gtkdoc esc">\n</span><span class="string">&quot;</span><span class="gtkdoc opt">,</span> x<span class="gtkdoc opt">,</span> y<span class="gtkdoc opt">);</span>
  <span class="keyword">else</span>
    <span class="function"><a href="glib-Warnings-and-Assertions.html#g-print">g_print</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;it was null</span><span class="gtkdoc esc">\n</span><span class="string">&quot;</span><span class="gtkdoc opt">);</span>
  <span class="function"><a href="glib-Warnings-and-Assertions.html#g-print">g_print</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;string is %s</span><span class="gtkdoc esc">\n</span><span class="string">&quot;</span><span class="gtkdoc opt">,</span> cstr<span class="gtkdoc opt">);</span>
  <span class="comment">/* don't free 'cstr' */</span>


  <span class="function"><a href="glib-GVariant.html#g-variant-get">g_variant_get</a></span> <span class="gtkdoc opt">(</span>value5<span class="gtkdoc opt">,</span> <span class="string">&quot;(m*s)&quot;</span><span class="gtkdoc opt">, &amp;</span>contents<span class="gtkdoc opt">,</span> NULL<span class="gtkdoc opt">);</span> <span class="comment">/* ignore the string. */</span>
  <span class="keyword">if</span> <span class="gtkdoc opt">(</span>contents <span class="gtkdoc opt">!=</span> NULL<span class="gtkdoc opt">)</span>
    <span class="gtkdoc opt">{</span>
      <span class="function"><a href="glib-GVariant.html#g-variant-get">g_variant_get</a></span> <span class="gtkdoc opt">(</span>contents<span class="gtkdoc opt">,</span> <span class="string">&quot;(ii)&quot;</span><span class="gtkdoc opt">, &amp;</span>x<span class="gtkdoc opt">, &amp;</span>y<span class="gtkdoc opt">);</span>
      <span class="function"><a href="glib-Warnings-and-Assertions.html#g-print">g_print</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;it was (%d, %d)</span><span class="gtkdoc esc">\n</span><span class="string">&quot;</span><span class="gtkdoc opt">,</span> x<span class="gtkdoc opt">,</span> y<span class="gtkdoc opt">);</span>
      <span class="function"><a href="glib-GVariant.html#g-variant-unref">g_variant_unref</a></span> <span class="gtkdoc opt">(</span>contents<span class="gtkdoc opt">);</span>
    <span class="gtkdoc opt">}</span>
  <span class="keyword">else</span>
    <span class="function"><a href="glib-Warnings-and-Assertions.html#g-print">g_print</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;it was null</span><span class="gtkdoc esc">\n</span><span class="string">&quot;</span><span class="gtkdoc opt">);</span>
<span class="gtkdoc opt">}</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

</div>
</div>
<hr>
<div class="refsect2">
<a name="gvariant-format-strings-tuples"></a><h3>Tuples</h3>
<p>
    <span class="strong"><strong>
     Characters: <code class="code">()</code>
    </strong></span>
   </p>
<p>
    Tuples are handled by handling each item in the tuple, in sequence.  Each item is handled in the usual way.
   </p>
<div class="refsect3">
<a name="id-1.6.20.5.9.4"></a><h4>Examples</h4>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15</pre></td>
        <td class="listing_code"><pre class="programlisting">GVariant <span class="gtkdoc opt">*</span>value1<span class="gtkdoc opt">, *</span>value2<span class="gtkdoc opt">;</span>

value1 <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-new">g_variant_new</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;(s(ii))&quot;</span><span class="gtkdoc opt">,</span> <span class="string">&quot;Hello&quot;</span><span class="gtkdoc opt">,</span> <span class="number">55</span><span class="gtkdoc opt">,</span> <span class="number">77</span><span class="gtkdoc opt">);</span>
value2 <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-new">g_variant_new</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;()&quot;</span><span class="gtkdoc opt">);</span>

<span class="gtkdoc opt">{</span>
  gchar <span class="gtkdoc opt">*</span>string<span class="gtkdoc opt">;</span>
  gint x<span class="gtkdoc opt">,</span> y<span class="gtkdoc opt">;</span>

  <span class="function"><a href="glib-GVariant.html#g-variant-get">g_variant_get</a></span> <span class="gtkdoc opt">(</span>value1<span class="gtkdoc opt">,</span> <span class="string">&quot;(s(ii))&quot;</span><span class="gtkdoc opt">, &amp;</span>string<span class="gtkdoc opt">, &amp;</span>x<span class="gtkdoc opt">, &amp;</span>y<span class="gtkdoc opt">);</span>
  <span class="function"><a href="glib-Warnings-and-Assertions.html#g-print">g_print</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;%s, %d, %d</span><span class="gtkdoc esc">\n</span><span class="string">&quot;</span><span class="gtkdoc opt">,</span> string<span class="gtkdoc opt">,</span> x<span class="gtkdoc opt">,</span> y<span class="gtkdoc opt">);</span>
  <span class="function"><a href="glib-Memory-Allocation.html#g-free">g_free</a></span> <span class="gtkdoc opt">(</span>string<span class="gtkdoc opt">);</span>

  <span class="function"><a href="glib-GVariant.html#g-variant-get">g_variant_get</a></span> <span class="gtkdoc opt">(</span>value2<span class="gtkdoc opt">,</span> <span class="string">&quot;()&quot;</span><span class="gtkdoc opt">);</span>   <span class="comment">/* do nothing... */</span>
<span class="gtkdoc opt">}</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

</div>
</div>
<hr>
<div class="refsect2">
<a name="gvariant-format-strings-dictionaries"></a><h3>Dictionaries</h3>
<p>
    <span class="strong"><strong>
     Characters: <code class="code">{}</code>
    </strong></span>
   </p>
<p>
    Dictionary entries are handled by handling first the key, then the value.  Each is handled in the usual way.
   </p>
<div class="refsect3">
<a name="id-1.6.20.5.10.4"></a><h4>Examples</h4>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7</pre></td>
        <td class="listing_code"><pre class="programlisting">GVariantBuilder <span class="gtkdoc opt">*</span>b<span class="gtkdoc opt">;</span>
GVariant <span class="gtkdoc opt">*</span>dict<span class="gtkdoc opt">;</span>

b <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-builder-new">g_variant_builder_new</a></span> <span class="gtkdoc opt">(</span><span class="function"><a href="glib-GVariantType.html#G-VARIANT-TYPE:CAPS">G_VARIANT_TYPE</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;a{sv}&quot;</span><span class="gtkdoc opt">));</span>
<span class="function"><a href="glib-GVariant.html#g-variant-builder-add">g_variant_builder_add</a></span> <span class="gtkdoc opt">(</span>b<span class="gtkdoc opt">,</span> <span class="string">&quot;{sv}&quot;</span><span class="gtkdoc opt">,</span> <span class="string">&quot;name&quot;</span><span class="gtkdoc opt">,</span> <span class="function"><a href="glib-GVariant.html#g-variant-new-string">g_variant_new_string</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;foo&quot;</span><span class="gtkdoc opt">));</span>
<span class="function"><a href="glib-GVariant.html#g-variant-builder-add">g_variant_builder_add</a></span> <span class="gtkdoc opt">(</span>b<span class="gtkdoc opt">,</span> <span class="string">&quot;{sv}&quot;</span><span class="gtkdoc opt">,</span> <span class="string">&quot;timeout&quot;</span><span class="gtkdoc opt">,</span> <span class="function"><a href="glib-GVariant.html#g-variant-new-int32">g_variant_new_int32</a></span> <span class="gtkdoc opt">(</span><span class="number">10</span><span class="gtkdoc opt">));</span>
dict <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-builder-end">g_variant_builder_end</a></span> <span class="gtkdoc opt">(</span>b<span class="gtkdoc opt">);</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

</div>
</div>
<hr>
<div class="refsect2">
<a name="gvariant-format-strings-gvariant"></a><h3>GVariant *</h3>
<p>
    <span class="strong"><strong>
     Characters: <code class="literal">@</code>, <code class="literal">*</code>, <code class="literal">?</code>, <code class="literal">r</code>
    </strong></span>

   </p>
<p>
    Upon encountering a '<code class="literal">@</code>' in front of a type string,
    <a class="link" href="glib-GVariant.html#g-variant-new" title="g_variant_new ()"><code class="function">g_variant_new()</code></a> takes a
    non-<a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> pointer to a
    <a class="link" href="glib-GVariant.html#GVariant" title="GVariant"><span class="type">GVariant</span></a> and uses its value directly instead of collecting arguments to
    create the value.  The provided <a class="link" href="glib-GVariant.html#GVariant" title="GVariant"><span class="type">GVariant</span></a> must have a type that matches the
    type string following the '<code class="literal">@</code>'.  '<code class="literal">*</code>' is
    the same as '<code class="literal">@*</code>' (ie: take a <a class="link" href="glib-GVariant.html#GVariant" title="GVariant"><span class="type">GVariant</span></a> of any type).
    '<code class="literal">?</code>' is the same as '<code class="literal">@?</code>' (ie: take a
    <a class="link" href="glib-GVariant.html#GVariant" title="GVariant"><span class="type">GVariant</span></a> of any basic type).  '<code class="literal">r</code>' is the same as
    '<code class="literal">@r</code>' (ie: take a <a class="link" href="glib-GVariant.html#GVariant" title="GVariant"><span class="type">GVariant</span></a> of any tuple type).
   </p>
<p>
    Upon encountering a '<code class="literal">@</code>' in front of a type string,
    <a class="link" href="glib-GVariant.html#g-variant-get" title="g_variant_get ()"><code class="function">g_variant_get()</code></a>
    takes a pointer to a <code class="code">(<a class="link" href="glib-GVariant.html#GVariant" title="GVariant">GVariant</a> *)</code> (ie: a
    <code class="code">(<a class="link" href="glib-GVariant.html#GVariant" title="GVariant">GVariant</a> **)</code>) and sets it to a new reference to a
    <a class="link" href="glib-GVariant.html#GVariant" title="GVariant"><span class="type">GVariant</span></a> containing the value (instead of deconstructing the value into
    C types in the usual way).  <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> can be given to ignore the
    value.  '<code class="literal">*</code>', '<code class="literal">?</code>' and '<code class="literal">r</code>' are handled in a way analogous to
    what is stated above.
   </p>
<p>
    You can always use '<code class="literal">*</code>' as an alternative to '<code class="literal">?</code>', '<code class="literal">r</code>' or any
    use of '<code class="literal">@</code>'.  Using the other characters where possible is recommended, however, due to the
    improvements in type safety and code self-documentation.
   </p>
<div class="refsect3">
<a name="id-1.6.20.5.11.6"></a><h4>Examples</h4>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23</pre></td>
        <td class="listing_code"><pre class="programlisting">GVariant <span class="gtkdoc opt">*</span>value1<span class="gtkdoc opt">, *</span>value2<span class="gtkdoc opt">;</span>

value1 <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-new">g_variant_new</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;(i&#64;ii)&quot;</span><span class="gtkdoc opt">,</span> <span class="number">44</span><span class="gtkdoc opt">,</span> <span class="function"><a href="glib-GVariant.html#g-variant-new-int32">g_variant_new_int32</a></span> <span class="gtkdoc opt">(</span><span class="number">55</span><span class="gtkdoc opt">),</span> <span class="number">66</span><span class="gtkdoc opt">);</span>

<span class="comment">/* note: consumes floating reference count on 'value1' */</span>
value2 <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-new">g_variant_new</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;(&#64;(iii)*)&quot;</span><span class="gtkdoc opt">,</span> value1<span class="gtkdoc opt">,</span> <span class="function"><a href="glib-GVariant.html#g-variant-new-string">g_variant_new_string</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;foo&quot;</span><span class="gtkdoc opt">));</span>

<span class="gtkdoc opt">{</span>
  <span class="gtkdoc kwb">const</span> gchar <span class="gtkdoc opt">*</span>string<span class="gtkdoc opt">;</span>
  GVariant <span class="gtkdoc opt">*</span>tmp<span class="gtkdoc opt">;</span>
  gsize length<span class="gtkdoc opt">;</span>
  gint x<span class="gtkdoc opt">,</span> y<span class="gtkdoc opt">,</span> z<span class="gtkdoc opt">;</span>

  <span class="function"><a href="glib-GVariant.html#g-variant-get">g_variant_get</a></span> <span class="gtkdoc opt">(</span>value2<span class="gtkdoc opt">,</span> <span class="string">&quot;((iii)*)&quot;</span><span class="gtkdoc opt">, &amp;</span>x<span class="gtkdoc opt">, &amp;</span>y<span class="gtkdoc opt">, &amp;</span>z<span class="gtkdoc opt">, &amp;</span>tmp<span class="gtkdoc opt">);</span>
  string <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-get-string">g_variant_get_string</a></span> <span class="gtkdoc opt">(</span>tmp<span class="gtkdoc opt">, &amp;</span>length<span class="gtkdoc opt">);</span>
  <span class="function"><a href="glib-Warnings-and-Assertions.html#g-print">g_print</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;it is %d %d %d %s (length=%d)</span><span class="gtkdoc esc">\n</span><span class="string">&quot;</span><span class="gtkdoc opt">,</span> x<span class="gtkdoc opt">,</span> y<span class="gtkdoc opt">,</span> z<span class="gtkdoc opt">,</span> string<span class="gtkdoc opt">, (</span><span class="gtkdoc kwb">int</span><span class="gtkdoc opt">)</span> length<span class="gtkdoc opt">);</span>
  <span class="function"><a href="glib-GVariant.html#g-variant-unref">g_variant_unref</a></span> <span class="gtkdoc opt">(</span>tmp<span class="gtkdoc opt">);</span>

  <span class="comment">/* quick way to skip all the values in a tuple */</span>
  <span class="function"><a href="glib-GVariant.html#g-variant-get">g_variant_get</a></span> <span class="gtkdoc opt">(</span>value2<span class="gtkdoc opt">,</span> <span class="string">&quot;(rs)&quot;</span><span class="gtkdoc opt">,</span> NULL<span class="gtkdoc opt">, &amp;</span>string<span class="gtkdoc opt">);</span> <span class="comment">/* or &quot;(&#64;(iii)s)&quot; */</span>
  <span class="function"><a href="glib-Warnings-and-Assertions.html#g-print">g_print</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;i only got the string: %s</span><span class="gtkdoc esc">\n</span><span class="string">&quot;</span><span class="gtkdoc opt">,</span> string<span class="gtkdoc opt">);</span>
  <span class="function"><a href="glib-Memory-Allocation.html#g-free">g_free</a></span> <span class="gtkdoc opt">(</span>string<span class="gtkdoc opt">);</span>
<span class="gtkdoc opt">}</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

</div>
</div>
<hr>
<div class="refsect2">
<a name="gvariant-format-strings-pointers"></a><h3>Pointers</h3>
<p>
    <span class="strong"><strong>
     Characters: <code class="code">&amp;</code>
    </strong></span>
   </p>
<p>
    The '<code class="code">&amp;</code>' character is used to indicate that serialised data should be directly exchanged via a
    pointer.
   </p>
<p>
    Currently, the only use for this character is when it is applied to a string (ie: '<code class="literal">&amp;s</code>',
    '<code class="literal">&amp;o</code>' or '<code class="code">&amp;g</code>').  For
    <a class="link" href="glib-GVariant.html#g-variant-new" title="g_variant_new ()"><code class="function">g_variant_new()</code></a> this has absolutely no effect.  The string
    is collected and duplicated normally.  For <a class="link" href="glib-GVariant.html#g-variant-get" title="g_variant_get ()"><code class="function">g_variant_get()</code></a>
    it means that instead of creating a newly allocated copy of the string, a pointer to the serialised data is
    returned.  This pointer should not be freed.  Validity checks are performed to ensure that the string data will
    always be properly nul-terminated.
   </p>
<div class="refsect3">
<a name="id-1.6.20.5.12.5"></a><h4>Examples</h4>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="gtkdoc opt">{</span>
  <span class="gtkdoc kwb">const</span> gchar <span class="gtkdoc opt">*</span>str<span class="gtkdoc opt">;</span>
  GVariant <span class="gtkdoc opt">*</span>value<span class="gtkdoc opt">;</span>

  value <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-new">g_variant_new</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;&amp;s&quot;</span><span class="gtkdoc opt">,</span> <span class="string">&quot;hello world&quot;</span><span class="gtkdoc opt">);</span>
  str <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-GVariant.html#g-variant-get">g_variant_get</a></span> <span class="gtkdoc opt">(</span>value<span class="gtkdoc opt">,</span> <span class="string">&quot;&amp;s&quot;</span><span class="gtkdoc opt">, &amp;</span>str<span class="gtkdoc opt">);</span>
  <span class="function"><a href="glib-Warnings-and-Assertions.html#g-print">g_print</a></span> <span class="gtkdoc opt">(</span><span class="string">&quot;string is: %s</span><span class="gtkdoc esc">\n</span><span class="string">&quot;</span><span class="gtkdoc opt">,</span> str<span class="gtkdoc opt">);</span>
  <span class="comment">/* no need to free str */</span>
<span class="gtkdoc opt">}</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

</div>
</div>
<hr>
<div class="refsect2">
<a name="gvariant-format-strings-convenience"></a><h3>Convenience Conversions</h3>
<p>
    <span class="strong"><strong>
     Characters: <code class="literal">^</code>
    </strong></span>
   </p>
<p>
    The '<code class="literal">^</code>' character currently supports conversion to and from bytestrings or to and from arrays
    of strings or bytestrings.  It has a number of forms.
   </p>
<p>
    In all forms, when used with <a class="link" href="glib-GVariant.html#g-variant-new" title="g_variant_new ()"><code class="function">g_variant_new()</code></a> one
    pointer value is collected from the variable arguments and passed to a function (as given in the table below).
    The result of that function is used as the value for this position.  When used with
    <a class="link" href="glib-GVariant.html#g-variant-get" title="g_variant_get ()"><code class="function">g_variant_get()</code></a> one pointer value is produced by using
    the function (given in the table) and returned by reference.
   </p>
<div class="informaltable"><table border="1">
<colgroup>
<col class="col_0">
<col class="col_1">
</colgroup>
<tbody>
<tr>
<td>
        <p>
         <span class="strong"><strong>Conversion</strong></span>
        </p>
       </td>
<td>
        <p>
          <span class="strong"><strong>
            Used with <a class="link" href="glib-GVariant.html#g-variant-new" title="g_variant_new ()"><code class="function">g_variant_new()</code></a>
          </strong></span>
        </p>
       </td>
<td>
        <p>
          <span class="strong"><strong>
            Used with <a class="link" href="glib-GVariant.html#g-variant-get" title="g_variant_get ()"><code class="function">g_variant_get()</code></a>
          </strong></span>
        </p>
       </td>
</tr>
<tr>
<td>
        <p>
         <span class="strong"><strong>
          <code class="literal">^as</code>
         </strong></span>
        </p>
       </td>
<td rowspan="2">
        <p>
         equivalent to <a class="link" href="glib-GVariant.html#g-variant-new-strv" title="g_variant_new_strv ()"><code class="function">g_variant_new_strv()</code></a>
        </p>
       </td>
<td>
        <p>
         equivalent to <a class="link" href="glib-GVariant.html#g-variant-dup-strv" title="g_variant_dup_strv ()"><code class="function">g_variant_dup_strv()</code></a>
        </p>
       </td>
</tr>
<tr>
<td>
        <p>
         <span class="strong"><strong>
          <code class="literal">^a&amp;s</code>
         </strong></span>
        </p>
       </td>
<td>
        <p>
         equivalent to <a class="link" href="glib-GVariant.html#g-variant-get-strv" title="g_variant_get_strv ()"><code class="function">g_variant_get_strv()</code></a>
        </p>
       </td>
</tr>
<tr>
<td>
        <p>
         <span class="strong"><strong>
          <code class="literal">^ao</code>
         </strong></span>
        </p>
       </td>
<td rowspan="2">
        <p>
         equivalent to <a class="link" href="glib-GVariant.html#g-variant-new-objv" title="g_variant_new_objv ()"><code class="function">g_variant_new_objv()</code></a>
        </p>
       </td>
<td>
        <p>
         equivalent to <a class="link" href="glib-GVariant.html#g-variant-dup-objv" title="g_variant_dup_objv ()"><code class="function">g_variant_dup_objv()</code></a>
        </p>
       </td>
</tr>
<tr>
<td>
        <p>
         <span class="strong"><strong>
          <code class="literal">^a&amp;o</code>
         </strong></span>
        </p>
       </td>
<td>
        <p>
         equivalent to <a class="link" href="glib-GVariant.html#g-variant-get-objv" title="g_variant_get_objv ()"><code class="function">g_variant_get_objv()</code></a>
        </p>
       </td>
</tr>
<tr>
<td>
        <p>
         <span class="strong"><strong>
          <code class="literal">^ay</code>
         </strong></span>
        </p>
       </td>
<td rowspan="2">
        <p>
         equivalent to <a class="link" href="glib-GVariant.html#g-variant-new-bytestring" title="g_variant_new_bytestring ()"><code class="function">g_variant_new_bytestring()</code></a>
        </p>
       </td>
<td>
        <p>
         equivalent to <a class="link" href="glib-GVariant.html#g-variant-dup-bytestring" title="g_variant_dup_bytestring ()"><code class="function">g_variant_dup_bytestring()</code></a>
        </p>
       </td>
</tr>
<tr>
<td>
        <p>
         <span class="strong"><strong>
          <code class="literal">^&amp;ay</code>
         </strong></span>
        </p>
       </td>
<td>
        <p>
         equivalent to <a class="link" href="glib-GVariant.html#g-variant-get-bytestring" title="g_variant_get_bytestring ()"><code class="function">g_variant_get_bytestring()</code></a>
        </p>
       </td>
</tr>
<tr>
<td>
        <p>
         <span class="strong"><strong>
          <code class="literal">^aay</code>
         </strong></span>
        </p>
       </td>
<td rowspan="2">
        <p>
         equivalent to <a class="link" href="glib-GVariant.html#g-variant-new-bytestring-array" title="g_variant_new_bytestring_array ()"><code class="function">g_variant_new_bytestring_array()</code></a>
        </p>
       </td>
<td>
        <p>
         equivalent to <a class="link" href="glib-GVariant.html#g-variant-dup-bytestring-array" title="g_variant_dup_bytestring_array ()"><code class="function">g_variant_dup_bytestring_array()</code></a>
        </p>
       </td>
</tr>
<tr>
<td>
        <p>
         <span class="strong"><strong>
          <code class="literal">^a&amp;ay</code>
         </strong></span>
        </p>
       </td>
<td>
        <p>
         equivalent to <a class="link" href="glib-GVariant.html#g-variant-get-bytestring-array" title="g_variant_get_bytestring_array ()"><code class="function">g_variant_get_bytestring_array()</code></a>
        </p>
       </td>
</tr>
</tbody>
</table></div>
</div>
</div>
</div>
<div class="footer">
<hr>
          Generated by GTK-Doc V1.21</div>
</body>
</html>