re83.html 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <title>&lt;GVariant&gt;: </title>
  6. <meta name="generator" content="DocBook XSL Stylesheets V1.79.2">
  7. <link rel="home" href="index.html" title="">
  8. <link rel="up" href="ch01.html" title="GLib">
  9. <link rel="prev" href="re82.html" title="&lt;%GLibUserDirectory&gt;">
  10. <link rel="next" href="re84.html" title="&lt;GVariantBuilder&gt;">
  11. <meta name="generator" content="GTK-Doc V1.33.1 (XML mode)">
  12. <link rel="stylesheet" href="style.css" type="text/css">
  13. </head>
  14. <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
  15. <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
  16. <td width="100%" align="left" class="shortcuts"></td>
  17. <td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
  18. <td><img src="up-insensitive.png" width="16" height="16" border="0"></td>
  19. <td><a accesskey="p" href="re82.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
  20. <td><a accesskey="n" href="re84.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
  21. </tr></table>
  22. <div class="refentry">
  23. <a name="id-1.1.84"></a><div class="titlepage"></div>
  24. <div class="refnamediv">
  25. <h2>&lt;GVariant&gt;</h2>
  26. <p>&lt;GVariant&gt;</p>
  27. </div>
  28. <div class="refsect1">
  29. <a name="id-1.1.84.2"></a><h2>Description</h2>
  30. <p><span class="type">GVariant</span> is a variant datatype; it can contain one or more values
  31. along with information about the type of the values.
  32. </p>
  33. <p>A <span class="type">GVariant</span> may contain simple types, like an integer, or a boolean value;
  34. or complex types, like an array of two strings, or a dictionary of key
  35. value pairs. A <span class="type">GVariant</span> is also immutable: once it's been created neither
  36. its type nor its content can be modified further.
  37. </p>
  38. <p>GVariant is useful whenever data needs to be serialized, for example when
  39. sending method parameters in DBus, or when saving settings using GSettings.
  40. </p>
  41. <p>When creating a new <span class="type">GVariant</span>, you pass the data you want to store in it
  42. along with a string representing the type of data you wish to pass to it.
  43. </p>
  44. <p>For instance, if you want to create a <span class="type">GVariant</span> holding an integer value you
  45. can use:
  46. </p>
  47. <div class="informalexample"><pre class="programlisting">
  48. GVariant *v = g_variant_new ("u", 40);
  49. </pre></div>
  50. <p>The string "u" in the first argument tells <span class="type">GVariant</span> that the data passed to
  51. the constructor (40) is going to be an unsigned integer.
  52. </p>
  53. <p>More advanced examples of <span class="type">GVariant</span> in use can be found in documentation for
  54. [GVariant format strings][gvariant-format-strings-pointers].
  55. </p>
  56. <p>The range of possible values is determined by the type.
  57. </p>
  58. <p>The type system used by <span class="type">GVariant</span> is <span class="type">GVariantType</span>.
  59. </p>
  60. <p><span class="type">GVariant</span> instances always have a type and a value (which are given
  61. at construction time). The type and value of a <span class="type">GVariant</span> instance
  62. can never change other than by the <span class="type">GVariant</span> itself being
  63. destroyed. A <span class="type">GVariant</span> cannot contain a pointer.
  64. </p>
  65. <p><span class="type">GVariant</span> is reference counted using <code class="function">g_variant_ref()</code> and
  66. <code class="function">g_variant_unref()</code>. <span class="type">GVariant</span> also has floating reference counts --
  67. see <code class="function">g_variant_ref_sink()</code>.
  68. </p>
  69. <p><span class="type">GVariant</span> is completely threadsafe. A <span class="type">GVariant</span> instance can be
  70. concurrently accessed in any way from any number of threads without
  71. problems.
  72. </p>
  73. <p><span class="type">GVariant</span> is heavily optimised for dealing with data in serialised
  74. form. It works particularly well with data located in memory-mapped
  75. files. It can perform nearly all deserialisation operations in a
  76. small constant time, usually touching only a single memory page.
  77. Serialised <span class="type">GVariant</span> data can also be sent over the network.
  78. </p>
  79. <p><span class="type">GVariant</span> is largely compatible with D-Bus. Almost all types of
  80. <span class="type">GVariant</span> instances can be sent over D-Bus. See <span class="type">GVariantType</span> for
  81. exceptions. (However, <span class="type">GVariant</span>'s serialisation format is not the same
  82. as the serialisation format of a D-Bus message body: use <span class="type">GDBusMessage</span>,
  83. in the gio library, for those.)
  84. </p>
  85. <p>For space-efficiency, the <span class="type">GVariant</span> serialisation format does not
  86. automatically include the variant's length, type or endianness,
  87. which must either be implied from context (such as knowledge that a
  88. particular file format always contains a little-endian
  89. <code class="constant">G_VARIANT_TYPE_VARIANT</code> which occupies the whole length of the file)
  90. or supplied out-of-band (for instance, a length, type and/or endianness
  91. indicator could be placed at the beginning of a file, network message
  92. or network stream).
  93. </p>
  94. <p>A <span class="type">GVariant</span>'s size is limited mainly by any lower level operating
  95. system constraints, such as the number of bits in <span class="type">gsize</span>. For
  96. example, it is reasonable to have a 2GB file mapped into memory
  97. with <span class="type">GMappedFile</span>, and call <code class="function">g_variant_new_from_data()</code> on it.
  98. </p>
  99. <p>For convenience to C programmers, <span class="type">GVariant</span> features powerful
  100. varargs-based value construction and destruction. This feature is
  101. designed to be embedded in other libraries.
  102. </p>
  103. <p>There is a Python-inspired text language for describing <span class="type">GVariant</span>
  104. values. <span class="type">GVariant</span> includes a printer for this language and a parser
  105. with type inferencing.
  106. </p>
  107. <div class="refsect2">
  108. <a name="id-1.1.84.2.21"></a><h3>Memory Use</h3>
  109. <p><span class="type">GVariant</span> tries to be quite efficient with respect to memory use.
  110. This section gives a rough idea of how much memory is used by the
  111. current implementation. The information here is subject to change
  112. in the future.
  113. </p>
  114. <p>The memory allocated by <span class="type">GVariant</span> can be grouped into 4 broad
  115. purposes: memory for serialised data, memory for the type
  116. information cache, buffer management memory and memory for the
  117. <span class="type">GVariant</span> structure itself.
  118. </p>
  119. </div>
  120. <div class="refsect2">
  121. <a name="id-1.1.84.2.22"></a><h3>Serialised Data Memory</h3>
  122. <p>This is the memory that is used for storing GVariant data in
  123. serialised form. This is what would be sent over the network or
  124. what would end up on disk, not counting any indicator of the
  125. endianness, or of the length or type of the top-level variant.
  126. </p>
  127. <p>The amount of memory required to store a boolean is 1 byte. 16,
  128. 32 and 64 bit integers and double precision floating point numbers
  129. use their "natural" size. Strings (including object path and
  130. signature strings) are stored with a nul terminator, and as such
  131. use the length of the string plus 1 byte.
  132. </p>
  133. <p>Maybe types use no space at all to represent the null value and
  134. use the same amount of space (sometimes plus one byte) as the
  135. equivalent non-maybe-typed value to represent the non-null case.
  136. </p>
  137. <p>Arrays use the amount of space required to store each of their
  138. members, concatenated. Additionally, if the items stored in an
  139. array are not of a fixed-size (ie: strings, other arrays, etc)
  140. then an additional framing offset is stored for each item. The
  141. size of this offset is either 1, 2 or 4 bytes depending on the
  142. overall size of the container. Additionally, extra padding bytes
  143. are added as required for alignment of child values.
  144. </p>
  145. <p>Tuples (including dictionary entries) use the amount of space
  146. required to store each of their members, concatenated, plus one
  147. framing offset (as per arrays) for each non-fixed-sized item in
  148. the tuple, except for the last one. Additionally, extra padding
  149. bytes are added as required for alignment of child values.
  150. </p>
  151. <p>Variants use the same amount of space as the item inside of the
  152. variant, plus 1 byte, plus the length of the type string for the
  153. item inside the variant.
  154. </p>
  155. <p>As an example, consider a dictionary mapping strings to variants.
  156. In the case that the dictionary is empty, 0 bytes are required for
  157. the serialisation.
  158. </p>
  159. <p>If we add an item "width" that maps to the int32 value of 500 then
  160. we will use 4 byte to store the int32 (so 6 for the variant
  161. containing it) and 6 bytes for the string. The variant must be
  162. aligned to 8 after the 6 bytes of the string, so that's 2 extra
  163. bytes. 6 (string) + 2 (padding) + 6 (variant) is 14 bytes used
  164. for the dictionary entry. An additional 1 byte is added to the
  165. array as a framing offset making a total of 15 bytes.
  166. </p>
  167. <p>If we add another entry, "title" that maps to a nullable string
  168. that happens to have a value of null, then we use 0 bytes for the
  169. null value (and 3 bytes for the variant to contain it along with
  170. its type string) plus 6 bytes for the string. Again, we need 2
  171. padding bytes. That makes a total of 6 + 2 + 3 = 11 bytes.
  172. </p>
  173. <p>We now require extra padding between the two items in the array.
  174. After the 14 bytes of the first item, that's 2 bytes required.
  175. We now require 2 framing offsets for an extra two
  176. bytes. 14 + 2 + 11 + 2 = 29 bytes to encode the entire two-item
  177. dictionary.
  178. </p>
  179. </div>
  180. <div class="refsect2">
  181. <a name="id-1.1.84.2.23"></a><h3>Type Information Cache</h3>
  182. <p>For each GVariant type that currently exists in the program a type
  183. information structure is kept in the type information cache. The
  184. type information structure is required for rapid deserialisation.
  185. </p>
  186. <p>Continuing with the above example, if a <span class="type">GVariant</span> exists with the
  187. type "a{sv}" then a type information struct will exist for
  188. "a{sv}", "{sv}", "s", and "v". Multiple uses of the same type
  189. will share the same type information. Additionally, all
  190. single-digit types are stored in read-only static memory and do
  191. not contribute to the writable memory footprint of a program using
  192. <span class="type">GVariant</span>.
  193. </p>
  194. <p>Aside from the type information structures stored in read-only
  195. memory, there are two forms of type information. One is used for
  196. container types where there is a single element type: arrays and
  197. maybe types. The other is used for container types where there
  198. are multiple element types: tuples and dictionary entries.
  199. </p>
  200. <p>Array type info structures are 6 * sizeof (void *), plus the
  201. memory required to store the type string itself. This means that
  202. on 32-bit systems, the cache entry for "a{sv}" would require 30
  203. bytes of memory (plus malloc overhead).
  204. </p>
  205. <p>Tuple type info structures are 6 * sizeof (void *), plus 4 *
  206. sizeof (void *) for each item in the tuple, plus the memory
  207. required to store the type string itself. A 2-item tuple, for
  208. example, would have a type information structure that consumed
  209. writable memory in the size of 14 * sizeof (void *) (plus type
  210. string) This means that on 32-bit systems, the cache entry for
  211. "{sv}" would require 61 bytes of memory (plus malloc overhead).
  212. </p>
  213. <p>This means that in total, for our "a{sv}" example, 91 bytes of
  214. type information would be allocated.
  215. </p>
  216. <p>The type information cache, additionally, uses a <span class="type">GHashTable</span> to
  217. store and look up the cached items and stores a pointer to this
  218. hash table in static storage. The hash table is freed when there
  219. are zero items in the type cache.
  220. </p>
  221. <p>Although these sizes may seem large it is important to remember
  222. that a program will probably only have a very small number of
  223. different types of values in it and that only one type information
  224. structure is required for many different values of the same type.
  225. </p>
  226. </div>
  227. <div class="refsect2">
  228. <a name="id-1.1.84.2.24"></a><h3>Buffer Management Memory</h3>
  229. <p><span class="type">GVariant</span> uses an internal buffer management structure to deal
  230. with the various different possible sources of serialised data
  231. that it uses. The buffer is responsible for ensuring that the
  232. correct call is made when the data is no longer in use by
  233. <span class="type">GVariant</span>. This may involve a <code class="function">g_free()</code> or a <code class="function">g_slice_free()</code> or
  234. even <code class="function">g_mapped_file_unref()</code>.
  235. </p>
  236. <p>One buffer management structure is used for each chunk of
  237. serialised data. The size of the buffer management structure
  238. is 4 * (void *). On 32-bit systems, that's 16 bytes.
  239. </p>
  240. </div>
  241. <div class="refsect2">
  242. <a name="id-1.1.84.2.25"></a><h3>GVariant structure</h3>
  243. <p>The size of a <span class="type">GVariant</span> structure is 6 * (void *). On 32-bit
  244. systems, that's 24 bytes.
  245. </p>
  246. <p><span class="type">GVariant</span> structures only exist if they are explicitly created
  247. with API calls. For example, if a <span class="type">GVariant</span> is constructed out of
  248. serialised data for the example given above (with the dictionary)
  249. then although there are 9 individual values that comprise the
  250. entire dictionary (two keys, two values, two variants containing
  251. the values, two dictionary entries, plus the dictionary itself),
  252. only 1 <span class="type">GVariant</span> instance exists -- the one referring to the
  253. dictionary.
  254. </p>
  255. <p>If calls are made to start accessing the other values then
  256. <span class="type">GVariant</span> instances will exist for those values only for as long
  257. as they are in use (ie: until you call <code class="function">g_variant_unref()</code>). The
  258. type information is shared. The serialised data and the buffer
  259. management structure for that serialised data is shared by the
  260. child.
  261. </p>
  262. </div>
  263. <div class="refsect2">
  264. <a name="id-1.1.84.2.26"></a><h3>Summary</h3>
  265. <p>To put the entire example together, for our dictionary mapping
  266. strings to variants (with two entries, as given above), we are
  267. using 91 bytes of memory for type information, 29 bytes of memory
  268. for the serialised data, 16 bytes for buffer management and 24
  269. bytes for the <span class="type">GVariant</span> instance, or a total of 160 bytes, plus
  270. malloc overhead. If we were to use <code class="function">g_variant_get_child_value()</code> to
  271. access the two dictionary entries, we would use an additional 48
  272. bytes. If we were to have other dictionaries of the same type, we
  273. would use more memory for the serialised data and buffer
  274. management for those dictionaries, but the type information would
  275. be shared.</p>
  276. </div>
  277. </div>
  278. <div class="refsect1">
  279. <a name="id-1.1.84.3"></a><h2>Functions</h2>
  280. <div class="refsect2">
  281. <a name="id-1.1.84.3.2"></a><h3>byteswap</h3>
  282. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:byteswap self))
  283. </pre></div>
  284. <p>Performs a byteswapping operation on the contents of <em class="parameter"><code>value</code></em>. The
  285. result is that all multi-byte numeric data contained in <em class="parameter"><code>value</code></em> is
  286. byteswapped. That includes 16, 32, and 64bit signed and unsigned
  287. integers as well as file handles and double precision floating point
  288. values.
  289. </p>
  290. <p>This function is an identity mapping on any value that does not
  291. contain multi-byte numeric data. That include strings, booleans,
  292. bytes and containers containing only these things (recursively).
  293. </p>
  294. <p>The returned value is always in normal form and is marked as trusted.</p>
  295. <div class="refsect3">
  296. <a name="id-1.1.84.3.2.6"></a><h4>Parameters</h4>
  297. <div class="informaltable"><table><tr>
  298. <td class="parameter_name"><p>value</p></td>
  299. <td class="parameter_description">
  300. <p>a <span class="type">GVariant</span></p>
  301. <p>Passed as <code class="code">self</code></p>
  302. </td>
  303. </tr></table></div>
  304. </div>
  305. </div>
  306. <div class="refsect2">
  307. <a name="id-1.1.84.3.3"></a><h3>check-format-string?</h3>
  308. <div class="informalexample"><pre class="programlisting">(define-values
  309. (%return)
  310. (variant:check-format-string? self format-string copy-only))
  311. </pre></div>
  312. <p>Checks if calling <code class="function">g_variant_get()</code> with <em class="parameter"><code>format_string</code></em> on <em class="parameter"><code>value</code></em> would
  313. be valid from a type-compatibility standpoint. <em class="parameter"><code>format_string</code></em> is
  314. assumed to be a valid format string (from a syntactic standpoint).
  315. </p>
  316. <p>If <em class="parameter"><code>copy_only</code></em> is <code class="constant">TRUE</code> then this function additionally checks that it
  317. would be safe to call <code class="function">g_variant_unref()</code> on <em class="parameter"><code>value</code></em> immediately after
  318. the call to <code class="function">g_variant_get()</code> without invalidating the result. This is
  319. only possible if deep copies are made (ie: there are no pointers to
  320. the data inside of the soon-to-be-freed <span class="type">GVariant</span> instance). If this
  321. check fails then a <code class="function">g_critical()</code> is printed and <code class="constant">FALSE</code> is returned.
  322. </p>
  323. <p>This function is meant to be used by functions that wish to provide
  324. varargs accessors to <span class="type">GVariant</span> values of uncertain values (eg:
  325. <code class="function">g_variant_lookup()</code> or <code class="function">g_menu_model_get_item_attribute()</code>).</p>
  326. <div class="refsect3">
  327. <a name="id-1.1.84.3.3.6"></a><h4>Parameters</h4>
  328. <div class="informaltable"><table>
  329. <tr>
  330. <td class="parameter_name"><p>value</p></td>
  331. <td class="parameter_description">
  332. <p>a <span class="type">GVariant</span></p>
  333. <p>Passed as <code class="code">self</code></p>
  334. </td>
  335. </tr>
  336. <tr>
  337. <td class="parameter_name"><p>format_string</p></td>
  338. <td class="parameter_description">
  339. <p>a valid <span class="type">GVariant</span> format string</p>
  340. <p>Passed as <code class="code">format-string</code></p>
  341. </td>
  342. </tr>
  343. <tr>
  344. <td class="parameter_name"><p>copy_only</p></td>
  345. <td class="parameter_description">
  346. <p><code class="constant">TRUE</code> to ensure the format string makes deep copies</p>
  347. <p>Passed as <code class="code">copy-only</code></p>
  348. </td>
  349. </tr>
  350. </table></div>
  351. </div>
  352. </div>
  353. <div class="refsect2">
  354. <a name="id-1.1.84.3.4"></a><h3>classify</h3>
  355. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:classify self))
  356. </pre></div>
  357. <p>Classifies <em class="parameter"><code>value</code></em> according to its top-level type.</p>
  358. <div class="refsect3">
  359. <a name="id-1.1.84.3.4.4"></a><h4>Parameters</h4>
  360. <div class="informaltable"><table><tr>
  361. <td class="parameter_name"><p>value</p></td>
  362. <td class="parameter_description">
  363. <p>a <span class="type">GVariant</span></p>
  364. <p>Passed as <code class="code">self</code></p>
  365. </td>
  366. </tr></table></div>
  367. </div>
  368. </div>
  369. <div class="refsect2">
  370. <a name="id-1.1.84.3.5"></a><h3>compare</h3>
  371. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:compare self two))
  372. </pre></div>
  373. <p>Compares <em class="parameter"><code>one</code></em> and <em class="parameter"><code>two</code></em>.
  374. </p>
  375. <p>The types of <em class="parameter"><code>one</code></em> and <em class="parameter"><code>two</code></em> are <span class="type">gconstpointer</span> only to allow use of
  376. this function with <span class="type">GTree</span>, <span class="type">GPtrArray</span>, etc. They must each be a
  377. <span class="type">GVariant</span>.
  378. </p>
  379. <p>Comparison is only defined for basic types (ie: booleans, numbers,
  380. strings). For booleans, <code class="constant">FALSE</code> is less than <code class="constant">TRUE</code>. Numbers are
  381. ordered in the usual way. Strings are in ASCII lexographical order.
  382. </p>
  383. <p>It is a programmer error to attempt to compare container values or
  384. two values that have types that are not exactly equal. For example,
  385. you cannot compare a 32-bit signed integer with a 32-bit unsigned
  386. integer. Also note that this function is not particularly
  387. well-behaved when it comes to comparison of doubles; in particular,
  388. the handling of incomparable values (ie: NaN) is undefined.
  389. </p>
  390. <p>If you only require an equality comparison, <code class="function">g_variant_equal()</code> is more
  391. general.</p>
  392. <div class="refsect3">
  393. <a name="id-1.1.84.3.5.8"></a><h4>Parameters</h4>
  394. <div class="informaltable"><table>
  395. <tr>
  396. <td class="parameter_name"><p>one</p></td>
  397. <td class="parameter_description">
  398. <p>a basic-typed <span class="type">GVariant</span> instance</p>
  399. <p>Passed as <code class="code">self</code></p>
  400. </td>
  401. </tr>
  402. <tr>
  403. <td class="parameter_name"><p>two</p></td>
  404. <td class="parameter_description">
  405. <p>a <span class="type">GVariant</span> instance of the same type</p>
  406. <p>Passed as <code class="code">two</code></p>
  407. </td>
  408. </tr>
  409. </table></div>
  410. </div>
  411. </div>
  412. <div class="refsect2">
  413. <a name="id-1.1.84.3.6"></a><h3>dup-bytestring</h3>
  414. <div class="informalexample"><pre class="programlisting">(define-values (%return length) (variant:dup-bytestring self))
  415. </pre></div>
  416. <p>Similar to <code class="function">g_variant_get_bytestring()</code> except that instead of
  417. returning a constant string, the string is duplicated.
  418. </p>
  419. <p>The return value must be freed using <code class="function">g_free()</code>.</p>
  420. <div class="refsect3">
  421. <a name="id-1.1.84.3.6.5"></a><h4>Parameters</h4>
  422. <div class="informaltable"><table>
  423. <tr>
  424. <td class="parameter_name"><p>value</p></td>
  425. <td class="parameter_description">
  426. <p>an array-of-bytes <span class="type">GVariant</span> instance</p>
  427. <p>Passed as <code class="code">self</code></p>
  428. </td>
  429. </tr>
  430. <tr>
  431. <td class="parameter_name"><p>length</p></td>
  432. <td class="parameter_description">
  433. <p>a pointer to a <span class="type">gsize</span>, to store
  434. the length (not including the nul terminator)</p>
  435. <p>Inferred from <code class="code">%return</code></p>
  436. </td>
  437. </tr>
  438. </table></div>
  439. </div>
  440. </div>
  441. <div class="refsect2">
  442. <a name="id-1.1.84.3.7"></a><h3>dup-bytestring-array</h3>
  443. <div class="informalexample"><pre class="programlisting">(define-values (%return length) (variant:dup-bytestring-array self))
  444. </pre></div>
  445. <p>Gets the contents of an array of array of bytes <span class="type">GVariant</span>. This call
  446. makes a deep copy; the return result should be released with
  447. <code class="function">g_strfreev()</code>.
  448. </p>
  449. <p>If <em class="parameter"><code>length</code></em> is non-<code class="constant">NULL</code> then the number of elements in the result is
  450. stored there. In any case, the resulting array will be
  451. <code class="constant">NULL</code>-terminated.
  452. </p>
  453. <p>For an empty array, <em class="parameter"><code>length</code></em> will be set to 0 and a pointer to a
  454. <code class="constant">NULL</code> pointer will be returned.</p>
  455. <div class="refsect3">
  456. <a name="id-1.1.84.3.7.6"></a><h4>Parameters</h4>
  457. <div class="informaltable"><table>
  458. <tr>
  459. <td class="parameter_name"><p>value</p></td>
  460. <td class="parameter_description">
  461. <p>an array of array of bytes <span class="type">GVariant</span> ('aay')</p>
  462. <p>Passed as <code class="code">self</code></p>
  463. </td>
  464. </tr>
  465. <tr>
  466. <td class="parameter_name"><p>length</p></td>
  467. <td class="parameter_description">
  468. <p>the length of the result, or <code class="constant">NULL</code></p>
  469. <p>Inferred from <code class="code">%return</code></p>
  470. </td>
  471. </tr>
  472. </table></div>
  473. </div>
  474. </div>
  475. <div class="refsect2">
  476. <a name="id-1.1.84.3.8"></a><h3>dup-objv</h3>
  477. <div class="informalexample"><pre class="programlisting">(define-values (%return length) (variant:dup-objv self))
  478. </pre></div>
  479. <p>Gets the contents of an array of object paths <span class="type">GVariant</span>. This call
  480. makes a deep copy; the return result should be released with
  481. <code class="function">g_strfreev()</code>.
  482. </p>
  483. <p>If <em class="parameter"><code>length</code></em> is non-<code class="constant">NULL</code> then the number of elements in the result
  484. is stored there. In any case, the resulting array will be
  485. <code class="constant">NULL</code>-terminated.
  486. </p>
  487. <p>For an empty array, <em class="parameter"><code>length</code></em> will be set to 0 and a pointer to a
  488. <code class="constant">NULL</code> pointer will be returned.</p>
  489. <div class="refsect3">
  490. <a name="id-1.1.84.3.8.6"></a><h4>Parameters</h4>
  491. <div class="informaltable"><table>
  492. <tr>
  493. <td class="parameter_name"><p>value</p></td>
  494. <td class="parameter_description">
  495. <p>an array of object paths <span class="type">GVariant</span></p>
  496. <p>Passed as <code class="code">self</code></p>
  497. </td>
  498. </tr>
  499. <tr>
  500. <td class="parameter_name"><p>length</p></td>
  501. <td class="parameter_description">
  502. <p>the length of the result, or <code class="constant">NULL</code></p>
  503. <p>Inferred from <code class="code">%return</code></p>
  504. </td>
  505. </tr>
  506. </table></div>
  507. </div>
  508. </div>
  509. <div class="refsect2">
  510. <a name="id-1.1.84.3.9"></a><h3>dup-string</h3>
  511. <div class="informalexample"><pre class="programlisting">(define-values (%return length) (variant:dup-string self))
  512. </pre></div>
  513. <p>Similar to <code class="function">g_variant_get_string()</code> except that instead of returning
  514. a constant string, the string is duplicated.
  515. </p>
  516. <p>The string will always be UTF-8 encoded.
  517. </p>
  518. <p>The return value must be freed using <code class="function">g_free()</code>.</p>
  519. <div class="refsect3">
  520. <a name="id-1.1.84.3.9.6"></a><h4>Parameters</h4>
  521. <div class="informaltable"><table>
  522. <tr>
  523. <td class="parameter_name"><p>value</p></td>
  524. <td class="parameter_description">
  525. <p>a string <span class="type">GVariant</span> instance</p>
  526. <p>Passed as <code class="code">self</code></p>
  527. </td>
  528. </tr>
  529. <tr>
  530. <td class="parameter_name"><p>length</p></td>
  531. <td class="parameter_description">
  532. <p>a pointer to a <span class="type">gsize</span>, to store the length</p>
  533. <p>Passed as <code class="code">length</code></p>
  534. </td>
  535. </tr>
  536. </table></div>
  537. </div>
  538. </div>
  539. <div class="refsect2">
  540. <a name="id-1.1.84.3.10"></a><h3>dup-strv</h3>
  541. <div class="informalexample"><pre class="programlisting">(define-values (%return length) (variant:dup-strv self))
  542. </pre></div>
  543. <p>Gets the contents of an array of strings <span class="type">GVariant</span>. This call
  544. makes a deep copy; the return result should be released with
  545. <code class="function">g_strfreev()</code>.
  546. </p>
  547. <p>If <em class="parameter"><code>length</code></em> is non-<code class="constant">NULL</code> then the number of elements in the result
  548. is stored there. In any case, the resulting array will be
  549. <code class="constant">NULL</code>-terminated.
  550. </p>
  551. <p>For an empty array, <em class="parameter"><code>length</code></em> will be set to 0 and a pointer to a
  552. <code class="constant">NULL</code> pointer will be returned.</p>
  553. <div class="refsect3">
  554. <a name="id-1.1.84.3.10.6"></a><h4>Parameters</h4>
  555. <div class="informaltable"><table>
  556. <tr>
  557. <td class="parameter_name"><p>value</p></td>
  558. <td class="parameter_description">
  559. <p>an array of strings <span class="type">GVariant</span></p>
  560. <p>Passed as <code class="code">self</code></p>
  561. </td>
  562. </tr>
  563. <tr>
  564. <td class="parameter_name"><p>length</p></td>
  565. <td class="parameter_description">
  566. <p>the length of the result, or <code class="constant">NULL</code></p>
  567. <p>Inferred from <code class="code">%return</code></p>
  568. </td>
  569. </tr>
  570. </table></div>
  571. </div>
  572. </div>
  573. <div class="refsect2">
  574. <a name="id-1.1.84.3.11"></a><h3>equal?</h3>
  575. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:equal? self two))
  576. </pre></div>
  577. <p>Checks if <em class="parameter"><code>one</code></em> and <em class="parameter"><code>two</code></em> have the same type and value.
  578. </p>
  579. <p>The types of <em class="parameter"><code>one</code></em> and <em class="parameter"><code>two</code></em> are <span class="type">gconstpointer</span> only to allow use of
  580. this function with <span class="type">GHashTable</span>. They must each be a <span class="type">GVariant</span>.</p>
  581. <div class="refsect3">
  582. <a name="id-1.1.84.3.11.5"></a><h4>Parameters</h4>
  583. <div class="informaltable"><table>
  584. <tr>
  585. <td class="parameter_name"><p>one</p></td>
  586. <td class="parameter_description">
  587. <p>a <span class="type">GVariant</span> instance</p>
  588. <p>Passed as <code class="code">self</code></p>
  589. </td>
  590. </tr>
  591. <tr>
  592. <td class="parameter_name"><p>two</p></td>
  593. <td class="parameter_description">
  594. <p>a <span class="type">GVariant</span> instance</p>
  595. <p>Passed as <code class="code">two</code></p>
  596. </td>
  597. </tr>
  598. </table></div>
  599. </div>
  600. </div>
  601. <div class="refsect2">
  602. <a name="id-1.1.84.3.12"></a><h3>get-boolean?</h3>
  603. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-boolean? self))
  604. </pre></div>
  605. <p>Returns the boolean value of <em class="parameter"><code>value</code></em>.
  606. </p>
  607. <p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type
  608. other than <code class="constant">G_VARIANT_TYPE_BOOLEAN</code>.</p>
  609. <div class="refsect3">
  610. <a name="id-1.1.84.3.12.5"></a><h4>Parameters</h4>
  611. <div class="informaltable"><table><tr>
  612. <td class="parameter_name"><p>value</p></td>
  613. <td class="parameter_description">
  614. <p>a boolean <span class="type">GVariant</span> instance</p>
  615. <p>Passed as <code class="code">self</code></p>
  616. </td>
  617. </tr></table></div>
  618. </div>
  619. </div>
  620. <div class="refsect2">
  621. <a name="id-1.1.84.3.13"></a><h3>get-byte</h3>
  622. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-byte self))
  623. </pre></div>
  624. <p>Returns the byte value of <em class="parameter"><code>value</code></em>.
  625. </p>
  626. <p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type
  627. other than <code class="constant">G_VARIANT_TYPE_BYTE</code>.</p>
  628. <div class="refsect3">
  629. <a name="id-1.1.84.3.13.5"></a><h4>Parameters</h4>
  630. <div class="informaltable"><table><tr>
  631. <td class="parameter_name"><p>value</p></td>
  632. <td class="parameter_description">
  633. <p>a byte <span class="type">GVariant</span> instance</p>
  634. <p>Passed as <code class="code">self</code></p>
  635. </td>
  636. </tr></table></div>
  637. </div>
  638. </div>
  639. <div class="refsect2">
  640. <a name="id-1.1.84.3.14"></a><h3>get-bytestring</h3>
  641. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-bytestring self))
  642. </pre></div>
  643. <p>Returns the string value of a <span class="type">GVariant</span> instance with an
  644. array-of-bytes type. The string has no particular encoding.
  645. </p>
  646. <p>If the array does not end with a nul terminator character, the empty
  647. string is returned. For this reason, you can always trust that a
  648. non-<code class="constant">NULL</code> nul-terminated string will be returned by this function.
  649. </p>
  650. <p>If the array contains a nul terminator character somewhere other than
  651. the last byte then the returned string is the string, up to the first
  652. such nul character.
  653. </p>
  654. <p><code class="function">g_variant_get_fixed_array()</code> should be used instead if the array contains
  655. arbitrary data that could not be nul-terminated or could contain nul bytes.
  656. </p>
  657. <p>It is an error to call this function with a <em class="parameter"><code>value</code></em> that is not an
  658. array of bytes.
  659. </p>
  660. <p>The return value remains valid as long as <em class="parameter"><code>value</code></em> exists.</p>
  661. <div class="refsect3">
  662. <a name="id-1.1.84.3.14.9"></a><h4>Parameters</h4>
  663. <div class="informaltable"><table><tr>
  664. <td class="parameter_name"><p>value</p></td>
  665. <td class="parameter_description">
  666. <p>an array-of-bytes <span class="type">GVariant</span> instance</p>
  667. <p>Passed as <code class="code">self</code></p>
  668. </td>
  669. </tr></table></div>
  670. </div>
  671. </div>
  672. <div class="refsect2">
  673. <a name="id-1.1.84.3.15"></a><h3>get-bytestring-array</h3>
  674. <div class="informalexample"><pre class="programlisting">(define-values (%return length) (variant:get-bytestring-array self))
  675. </pre></div>
  676. <p>Gets the contents of an array of array of bytes <span class="type">GVariant</span>. This call
  677. makes a shallow copy; the return result should be released with
  678. <code class="function">g_free()</code>, but the individual strings must not be modified.
  679. </p>
  680. <p>If <em class="parameter"><code>length</code></em> is non-<code class="constant">NULL</code> then the number of elements in the result is
  681. stored there. In any case, the resulting array will be
  682. <code class="constant">NULL</code>-terminated.
  683. </p>
  684. <p>For an empty array, <em class="parameter"><code>length</code></em> will be set to 0 and a pointer to a
  685. <code class="constant">NULL</code> pointer will be returned.</p>
  686. <div class="refsect3">
  687. <a name="id-1.1.84.3.15.6"></a><h4>Parameters</h4>
  688. <div class="informaltable"><table>
  689. <tr>
  690. <td class="parameter_name"><p>value</p></td>
  691. <td class="parameter_description">
  692. <p>an array of array of bytes <span class="type">GVariant</span> ('aay')</p>
  693. <p>Passed as <code class="code">self</code></p>
  694. </td>
  695. </tr>
  696. <tr>
  697. <td class="parameter_name"><p>length</p></td>
  698. <td class="parameter_description">
  699. <p>the length of the result, or <code class="constant">NULL</code></p>
  700. <p>Inferred from <code class="code">%return</code></p>
  701. </td>
  702. </tr>
  703. </table></div>
  704. </div>
  705. </div>
  706. <div class="refsect2">
  707. <a name="id-1.1.84.3.16"></a><h3>get-child-value</h3>
  708. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-child-value self index-))
  709. </pre></div>
  710. <p>Reads a child item out of a container <span class="type">GVariant</span> instance. This
  711. includes variants, maybes, arrays, tuples and dictionary
  712. entries. It is an error to call this function on any other type of
  713. <span class="type">GVariant</span>.
  714. </p>
  715. <p>It is an error if <em class="parameter"><code>index_</code></em> is greater than the number of child items
  716. in the container. See <code class="function">g_variant_n_children()</code>.
  717. </p>
  718. <p>The returned value is never floating. You should free it with
  719. <code class="function">g_variant_unref()</code> when you're done with it.
  720. </p>
  721. <p>Note that values borrowed from the returned child are not guaranteed to
  722. still be valid after the child is freed even if you still hold a reference
  723. to <em class="parameter"><code>value</code></em>, if <em class="parameter"><code>value</code></em> has not been serialised at the time this function is
  724. called. To avoid this, you can serialize <em class="parameter"><code>value</code></em> by calling
  725. <code class="function">g_variant_get_data()</code> and optionally ignoring the return value.
  726. </p>
  727. <p>There may be implementation specific restrictions on deeply nested values,
  728. which would result in the unit tuple being returned as the child value,
  729. instead of further nested children. <span class="type">GVariant</span> is guaranteed to handle
  730. nesting up to at least 64 levels.
  731. </p>
  732. <p>This function is O(1).</p>
  733. <div class="refsect3">
  734. <a name="id-1.1.84.3.16.9"></a><h4>Parameters</h4>
  735. <div class="informaltable"><table>
  736. <tr>
  737. <td class="parameter_name"><p>value</p></td>
  738. <td class="parameter_description">
  739. <p>a container <span class="type">GVariant</span></p>
  740. <p>Passed as <code class="code">self</code></p>
  741. </td>
  742. </tr>
  743. <tr>
  744. <td class="parameter_name"><p>index_</p></td>
  745. <td class="parameter_description">
  746. <p>the index of the child to fetch</p>
  747. <p>Passed as <code class="code">index-</code></p>
  748. </td>
  749. </tr>
  750. </table></div>
  751. </div>
  752. </div>
  753. <div class="refsect2">
  754. <a name="id-1.1.84.3.17"></a><h3>get-data</h3>
  755. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-data self))
  756. </pre></div>
  757. <p>Returns a pointer to the serialised form of a <span class="type">GVariant</span> instance.
  758. The returned data may not be in fully-normalised form if read from an
  759. untrusted source. The returned data must not be freed; it remains
  760. valid for as long as <em class="parameter"><code>value</code></em> exists.
  761. </p>
  762. <p>If <em class="parameter"><code>value</code></em> is a fixed-sized value that was deserialised from a
  763. corrupted serialised container then <code class="constant">NULL</code> may be returned. In this
  764. case, the proper thing to do is typically to use the appropriate
  765. number of nul bytes in place of <em class="parameter"><code>value</code></em>. If <em class="parameter"><code>value</code></em> is not fixed-sized
  766. then <code class="constant">NULL</code> is never returned.
  767. </p>
  768. <p>In the case that <em class="parameter"><code>value</code></em> is already in serialised form, this function
  769. is O(1). If the value is not already in serialised form,
  770. serialisation occurs implicitly and is approximately O(n) in the size
  771. of the result.
  772. </p>
  773. <p>To deserialise the data returned by this function, in addition to the
  774. serialised data, you must know the type of the <span class="type">GVariant</span>, and (if the
  775. machine might be different) the endianness of the machine that stored
  776. it. As a result, file formats or network messages that incorporate
  777. serialised <span class="type">GVariants</span> must include this information either
  778. implicitly (for instance "the file always contains a
  779. <code class="constant">G_VARIANT_TYPE_VARIANT</code> and it is always in little-endian order") or
  780. explicitly (by storing the type and/or endianness in addition to the
  781. serialised data).</p>
  782. <div class="refsect3">
  783. <a name="id-1.1.84.3.17.7"></a><h4>Parameters</h4>
  784. <div class="informaltable"><table><tr>
  785. <td class="parameter_name"><p>value</p></td>
  786. <td class="parameter_description">
  787. <p>a <span class="type">GVariant</span> instance</p>
  788. <p>Passed as <code class="code">self</code></p>
  789. </td>
  790. </tr></table></div>
  791. </div>
  792. </div>
  793. <div class="refsect2">
  794. <a name="id-1.1.84.3.18"></a><h3>get-data-as-bytes</h3>
  795. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-data-as-bytes self))
  796. </pre></div>
  797. <p>Returns a pointer to the serialised form of a <span class="type">GVariant</span> instance.
  798. The semantics of this function are exactly the same as
  799. <code class="function">g_variant_get_data()</code>, except that the returned <span class="type">GBytes</span> holds
  800. a reference to the variant data.</p>
  801. <div class="refsect3">
  802. <a name="id-1.1.84.3.18.4"></a><h4>Parameters</h4>
  803. <div class="informaltable"><table><tr>
  804. <td class="parameter_name"><p>value</p></td>
  805. <td class="parameter_description">
  806. <p>a <span class="type">GVariant</span></p>
  807. <p>Passed as <code class="code">self</code></p>
  808. </td>
  809. </tr></table></div>
  810. </div>
  811. </div>
  812. <div class="refsect2">
  813. <a name="id-1.1.84.3.19"></a><h3>get-double</h3>
  814. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-double self))
  815. </pre></div>
  816. <p>Returns the double precision floating point value of <em class="parameter"><code>value</code></em>.
  817. </p>
  818. <p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type
  819. other than <code class="constant">G_VARIANT_TYPE_DOUBLE</code>.</p>
  820. <div class="refsect3">
  821. <a name="id-1.1.84.3.19.5"></a><h4>Parameters</h4>
  822. <div class="informaltable"><table><tr>
  823. <td class="parameter_name"><p>value</p></td>
  824. <td class="parameter_description">
  825. <p>a double <span class="type">GVariant</span> instance</p>
  826. <p>Passed as <code class="code">self</code></p>
  827. </td>
  828. </tr></table></div>
  829. </div>
  830. </div>
  831. <div class="refsect2">
  832. <a name="id-1.1.84.3.20"></a><h3>get-handle</h3>
  833. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-handle self))
  834. </pre></div>
  835. <p>Returns the 32-bit signed integer value of <em class="parameter"><code>value</code></em>.
  836. </p>
  837. <p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type other
  838. than <code class="constant">G_VARIANT_TYPE_HANDLE</code>.
  839. </p>
  840. <p>By convention, handles are indexes into an array of file descriptors
  841. that are sent alongside a D-Bus message. If you're not interacting
  842. with D-Bus, you probably don't need them.</p>
  843. <div class="refsect3">
  844. <a name="id-1.1.84.3.20.6"></a><h4>Parameters</h4>
  845. <div class="informaltable"><table><tr>
  846. <td class="parameter_name"><p>value</p></td>
  847. <td class="parameter_description">
  848. <p>a handle <span class="type">GVariant</span> instance</p>
  849. <p>Passed as <code class="code">self</code></p>
  850. </td>
  851. </tr></table></div>
  852. </div>
  853. </div>
  854. <div class="refsect2">
  855. <a name="id-1.1.84.3.21"></a><h3>get-int16</h3>
  856. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-int16 self))
  857. </pre></div>
  858. <p>Returns the 16-bit signed integer value of <em class="parameter"><code>value</code></em>.
  859. </p>
  860. <p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type
  861. other than <code class="constant">G_VARIANT_TYPE_INT16</code>.</p>
  862. <div class="refsect3">
  863. <a name="id-1.1.84.3.21.5"></a><h4>Parameters</h4>
  864. <div class="informaltable"><table><tr>
  865. <td class="parameter_name"><p>value</p></td>
  866. <td class="parameter_description">
  867. <p>an int16 <span class="type">GVariant</span> instance</p>
  868. <p>Passed as <code class="code">self</code></p>
  869. </td>
  870. </tr></table></div>
  871. </div>
  872. </div>
  873. <div class="refsect2">
  874. <a name="id-1.1.84.3.22"></a><h3>get-int32</h3>
  875. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-int32 self))
  876. </pre></div>
  877. <p>Returns the 32-bit signed integer value of <em class="parameter"><code>value</code></em>.
  878. </p>
  879. <p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type
  880. other than <code class="constant">G_VARIANT_TYPE_INT32</code>.</p>
  881. <div class="refsect3">
  882. <a name="id-1.1.84.3.22.5"></a><h4>Parameters</h4>
  883. <div class="informaltable"><table><tr>
  884. <td class="parameter_name"><p>value</p></td>
  885. <td class="parameter_description">
  886. <p>an int32 <span class="type">GVariant</span> instance</p>
  887. <p>Passed as <code class="code">self</code></p>
  888. </td>
  889. </tr></table></div>
  890. </div>
  891. </div>
  892. <div class="refsect2">
  893. <a name="id-1.1.84.3.23"></a><h3>get-int64</h3>
  894. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-int64 self))
  895. </pre></div>
  896. <p>Returns the 64-bit signed integer value of <em class="parameter"><code>value</code></em>.
  897. </p>
  898. <p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type
  899. other than <code class="constant">G_VARIANT_TYPE_INT64</code>.</p>
  900. <div class="refsect3">
  901. <a name="id-1.1.84.3.23.5"></a><h4>Parameters</h4>
  902. <div class="informaltable"><table><tr>
  903. <td class="parameter_name"><p>value</p></td>
  904. <td class="parameter_description">
  905. <p>an int64 <span class="type">GVariant</span> instance</p>
  906. <p>Passed as <code class="code">self</code></p>
  907. </td>
  908. </tr></table></div>
  909. </div>
  910. </div>
  911. <div class="refsect2">
  912. <a name="id-1.1.84.3.24"></a><h3>get-maybe</h3>
  913. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-maybe self))
  914. </pre></div>
  915. <p>Given a maybe-typed <span class="type">GVariant</span> instance, extract its value. If the
  916. value is Nothing, then this function returns <code class="constant">NULL</code>.</p>
  917. <div class="refsect3">
  918. <a name="id-1.1.84.3.24.4"></a><h4>Parameters</h4>
  919. <div class="informaltable"><table><tr>
  920. <td class="parameter_name"><p>value</p></td>
  921. <td class="parameter_description">
  922. <p>a maybe-typed value</p>
  923. <p>Passed as <code class="code">self</code></p>
  924. </td>
  925. </tr></table></div>
  926. </div>
  927. </div>
  928. <div class="refsect2">
  929. <a name="id-1.1.84.3.25"></a><h3>get-normal-form</h3>
  930. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-normal-form self))
  931. </pre></div>
  932. <p>Gets a <span class="type">GVariant</span> instance that has the same value as <em class="parameter"><code>value</code></em> and is
  933. trusted to be in normal form.
  934. </p>
  935. <p>If <em class="parameter"><code>value</code></em> is already trusted to be in normal form then a new
  936. reference to <em class="parameter"><code>value</code></em> is returned.
  937. </p>
  938. <p>If <em class="parameter"><code>value</code></em> is not already trusted, then it is scanned to check if it
  939. is in normal form. If it is found to be in normal form then it is
  940. marked as trusted and a new reference to it is returned.
  941. </p>
  942. <p>If <em class="parameter"><code>value</code></em> is found not to be in normal form then a new trusted
  943. <span class="type">GVariant</span> is created with the same value as <em class="parameter"><code>value</code></em>.
  944. </p>
  945. <p>It makes sense to call this function if you've received <span class="type">GVariant</span>
  946. data from untrusted sources and you want to ensure your serialised
  947. output is definitely in normal form.
  948. </p>
  949. <p>If <em class="parameter"><code>value</code></em> is already in normal form, a new reference will be returned
  950. (which will be floating if <em class="parameter"><code>value</code></em> is floating). If it is not in normal form,
  951. the newly created <span class="type">GVariant</span> will be returned with a single non-floating
  952. reference. Typically, <code class="function">g_variant_take_ref()</code> should be called on the return
  953. value from this function to guarantee ownership of a single non-floating
  954. reference to it.</p>
  955. <div class="refsect3">
  956. <a name="id-1.1.84.3.25.9"></a><h4>Parameters</h4>
  957. <div class="informaltable"><table><tr>
  958. <td class="parameter_name"><p>value</p></td>
  959. <td class="parameter_description">
  960. <p>a <span class="type">GVariant</span></p>
  961. <p>Passed as <code class="code">self</code></p>
  962. </td>
  963. </tr></table></div>
  964. </div>
  965. </div>
  966. <div class="refsect2">
  967. <a name="id-1.1.84.3.26"></a><h3>get-objv</h3>
  968. <div class="informalexample"><pre class="programlisting">(define-values (%return length) (variant:get-objv self))
  969. </pre></div>
  970. <p>Gets the contents of an array of object paths <span class="type">GVariant</span>. This call
  971. makes a shallow copy; the return result should be released with
  972. <code class="function">g_free()</code>, but the individual strings must not be modified.
  973. </p>
  974. <p>If <em class="parameter"><code>length</code></em> is non-<code class="constant">NULL</code> then the number of elements in the result
  975. is stored there. In any case, the resulting array will be
  976. <code class="constant">NULL</code>-terminated.
  977. </p>
  978. <p>For an empty array, <em class="parameter"><code>length</code></em> will be set to 0 and a pointer to a
  979. <code class="constant">NULL</code> pointer will be returned.</p>
  980. <div class="refsect3">
  981. <a name="id-1.1.84.3.26.6"></a><h4>Parameters</h4>
  982. <div class="informaltable"><table>
  983. <tr>
  984. <td class="parameter_name"><p>value</p></td>
  985. <td class="parameter_description">
  986. <p>an array of object paths <span class="type">GVariant</span></p>
  987. <p>Passed as <code class="code">self</code></p>
  988. </td>
  989. </tr>
  990. <tr>
  991. <td class="parameter_name"><p>length</p></td>
  992. <td class="parameter_description">
  993. <p>the length of the result, or <code class="constant">NULL</code></p>
  994. <p>Inferred from <code class="code">%return</code></p>
  995. </td>
  996. </tr>
  997. </table></div>
  998. </div>
  999. </div>
  1000. <div class="refsect2">
  1001. <a name="id-1.1.84.3.27"></a><h3>get-size</h3>
  1002. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-size self))
  1003. </pre></div>
  1004. <p>Determines the number of bytes that would be required to store <em class="parameter"><code>value</code></em>
  1005. with <code class="function">g_variant_store()</code>.
  1006. </p>
  1007. <p>If <em class="parameter"><code>value</code></em> has a fixed-sized type then this function always returned
  1008. that fixed size.
  1009. </p>
  1010. <p>In the case that <em class="parameter"><code>value</code></em> is already in serialised form or the size has
  1011. already been calculated (ie: this function has been called before)
  1012. then this function is O(1). Otherwise, the size is calculated, an
  1013. operation which is approximately O(n) in the number of values
  1014. involved.</p>
  1015. <div class="refsect3">
  1016. <a name="id-1.1.84.3.27.6"></a><h4>Parameters</h4>
  1017. <div class="informaltable"><table><tr>
  1018. <td class="parameter_name"><p>value</p></td>
  1019. <td class="parameter_description">
  1020. <p>a <span class="type">GVariant</span> instance</p>
  1021. <p>Passed as <code class="code">self</code></p>
  1022. </td>
  1023. </tr></table></div>
  1024. </div>
  1025. </div>
  1026. <div class="refsect2">
  1027. <a name="id-1.1.84.3.28"></a><h3>get-string</h3>
  1028. <div class="informalexample"><pre class="programlisting">(define-values (%return length) (variant:get-string self))
  1029. </pre></div>
  1030. <p>Returns the string value of a <span class="type">GVariant</span> instance with a string
  1031. type. This includes the types <code class="constant">G_VARIANT_TYPE_STRING</code>,
  1032. <code class="constant">G_VARIANT_TYPE_OBJECT_PATH</code> and <code class="constant">G_VARIANT_TYPE_SIGNATURE</code>.
  1033. </p>
  1034. <p>The string will always be UTF-8 encoded, will never be <code class="constant">NULL</code>, and will never
  1035. contain nul bytes.
  1036. </p>
  1037. <p>If <em class="parameter"><code>length</code></em> is non-<code class="constant">NULL</code> then the length of the string (in bytes) is
  1038. returned there. For trusted values, this information is already
  1039. known. Untrusted values will be validated and, if valid, a <code class="function">strlen()</code> will be
  1040. performed. If invalid, a default value will be returned — for
  1041. <code class="constant">G_VARIANT_TYPE_OBJECT_PATH</code>, this is <code class="code">"/"</code>, and for other types it is the
  1042. empty string.
  1043. </p>
  1044. <p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type
  1045. other than those three.
  1046. </p>
  1047. <p>The return value remains valid as long as <em class="parameter"><code>value</code></em> exists.</p>
  1048. <div class="refsect3">
  1049. <a name="id-1.1.84.3.28.8"></a><h4>Parameters</h4>
  1050. <div class="informaltable"><table>
  1051. <tr>
  1052. <td class="parameter_name"><p>value</p></td>
  1053. <td class="parameter_description">
  1054. <p>a string <span class="type">GVariant</span> instance</p>
  1055. <p>Passed as <code class="code">self</code></p>
  1056. </td>
  1057. </tr>
  1058. <tr>
  1059. <td class="parameter_name"><p>length</p></td>
  1060. <td class="parameter_description">
  1061. <p>a pointer to a <span class="type">gsize</span>,
  1062. to store the length</p>
  1063. <p>Passed as <code class="code">length</code></p>
  1064. </td>
  1065. </tr>
  1066. </table></div>
  1067. </div>
  1068. </div>
  1069. <div class="refsect2">
  1070. <a name="id-1.1.84.3.29"></a><h3>get-strv</h3>
  1071. <div class="informalexample"><pre class="programlisting">(define-values (%return length) (variant:get-strv self))
  1072. </pre></div>
  1073. <p>Gets the contents of an array of strings <span class="type">GVariant</span>. This call
  1074. makes a shallow copy; the return result should be released with
  1075. <code class="function">g_free()</code>, but the individual strings must not be modified.
  1076. </p>
  1077. <p>If <em class="parameter"><code>length</code></em> is non-<code class="constant">NULL</code> then the number of elements in the result
  1078. is stored there. In any case, the resulting array will be
  1079. <code class="constant">NULL</code>-terminated.
  1080. </p>
  1081. <p>For an empty array, <em class="parameter"><code>length</code></em> will be set to 0 and a pointer to a
  1082. <code class="constant">NULL</code> pointer will be returned.</p>
  1083. <div class="refsect3">
  1084. <a name="id-1.1.84.3.29.6"></a><h4>Parameters</h4>
  1085. <div class="informaltable"><table>
  1086. <tr>
  1087. <td class="parameter_name"><p>value</p></td>
  1088. <td class="parameter_description">
  1089. <p>an array of strings <span class="type">GVariant</span></p>
  1090. <p>Passed as <code class="code">self</code></p>
  1091. </td>
  1092. </tr>
  1093. <tr>
  1094. <td class="parameter_name"><p>length</p></td>
  1095. <td class="parameter_description">
  1096. <p>the length of the result, or <code class="constant">NULL</code></p>
  1097. <p>Inferred from <code class="code">%return</code></p>
  1098. </td>
  1099. </tr>
  1100. </table></div>
  1101. </div>
  1102. </div>
  1103. <div class="refsect2">
  1104. <a name="id-1.1.84.3.30"></a><h3>get-type</h3>
  1105. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-type self))
  1106. </pre></div>
  1107. <p>Determines the type of <em class="parameter"><code>value</code></em>.
  1108. </p>
  1109. <p>The return value is valid for the lifetime of <em class="parameter"><code>value</code></em> and must not
  1110. be freed.</p>
  1111. <div class="refsect3">
  1112. <a name="id-1.1.84.3.30.5"></a><h4>Parameters</h4>
  1113. <div class="informaltable"><table><tr>
  1114. <td class="parameter_name"><p>value</p></td>
  1115. <td class="parameter_description">
  1116. <p>a <span class="type">GVariant</span></p>
  1117. <p>Passed as <code class="code">self</code></p>
  1118. </td>
  1119. </tr></table></div>
  1120. </div>
  1121. </div>
  1122. <div class="refsect2">
  1123. <a name="id-1.1.84.3.31"></a><h3>get-type-string</h3>
  1124. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-type-string self))
  1125. </pre></div>
  1126. <p>Returns the type string of <em class="parameter"><code>value</code></em>. Unlike the result of calling
  1127. <code class="function">g_variant_type_peek_string()</code>, this string is nul-terminated. This
  1128. string belongs to <span class="type">GVariant</span> and must not be freed.</p>
  1129. <div class="refsect3">
  1130. <a name="id-1.1.84.3.31.4"></a><h4>Parameters</h4>
  1131. <div class="informaltable"><table><tr>
  1132. <td class="parameter_name"><p>value</p></td>
  1133. <td class="parameter_description">
  1134. <p>a <span class="type">GVariant</span></p>
  1135. <p>Passed as <code class="code">self</code></p>
  1136. </td>
  1137. </tr></table></div>
  1138. </div>
  1139. </div>
  1140. <div class="refsect2">
  1141. <a name="id-1.1.84.3.32"></a><h3>get-uint16</h3>
  1142. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-uint16 self))
  1143. </pre></div>
  1144. <p>Returns the 16-bit unsigned integer value of <em class="parameter"><code>value</code></em>.
  1145. </p>
  1146. <p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type
  1147. other than <code class="constant">G_VARIANT_TYPE_UINT16</code>.</p>
  1148. <div class="refsect3">
  1149. <a name="id-1.1.84.3.32.5"></a><h4>Parameters</h4>
  1150. <div class="informaltable"><table><tr>
  1151. <td class="parameter_name"><p>value</p></td>
  1152. <td class="parameter_description">
  1153. <p>a uint16 <span class="type">GVariant</span> instance</p>
  1154. <p>Passed as <code class="code">self</code></p>
  1155. </td>
  1156. </tr></table></div>
  1157. </div>
  1158. </div>
  1159. <div class="refsect2">
  1160. <a name="id-1.1.84.3.33"></a><h3>get-uint32</h3>
  1161. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-uint32 self))
  1162. </pre></div>
  1163. <p>Returns the 32-bit unsigned integer value of <em class="parameter"><code>value</code></em>.
  1164. </p>
  1165. <p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type
  1166. other than <code class="constant">G_VARIANT_TYPE_UINT32</code>.</p>
  1167. <div class="refsect3">
  1168. <a name="id-1.1.84.3.33.5"></a><h4>Parameters</h4>
  1169. <div class="informaltable"><table><tr>
  1170. <td class="parameter_name"><p>value</p></td>
  1171. <td class="parameter_description">
  1172. <p>a uint32 <span class="type">GVariant</span> instance</p>
  1173. <p>Passed as <code class="code">self</code></p>
  1174. </td>
  1175. </tr></table></div>
  1176. </div>
  1177. </div>
  1178. <div class="refsect2">
  1179. <a name="id-1.1.84.3.34"></a><h3>get-uint64</h3>
  1180. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-uint64 self))
  1181. </pre></div>
  1182. <p>Returns the 64-bit unsigned integer value of <em class="parameter"><code>value</code></em>.
  1183. </p>
  1184. <p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type
  1185. other than <code class="constant">G_VARIANT_TYPE_UINT64</code>.</p>
  1186. <div class="refsect3">
  1187. <a name="id-1.1.84.3.34.5"></a><h4>Parameters</h4>
  1188. <div class="informaltable"><table><tr>
  1189. <td class="parameter_name"><p>value</p></td>
  1190. <td class="parameter_description">
  1191. <p>a uint64 <span class="type">GVariant</span> instance</p>
  1192. <p>Passed as <code class="code">self</code></p>
  1193. </td>
  1194. </tr></table></div>
  1195. </div>
  1196. </div>
  1197. <div class="refsect2">
  1198. <a name="id-1.1.84.3.35"></a><h3>get-variant</h3>
  1199. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-variant self))
  1200. </pre></div>
  1201. <p>Unboxes <em class="parameter"><code>value</code></em>. The result is the <span class="type">GVariant</span> instance that was
  1202. contained in <em class="parameter"><code>value</code></em>.</p>
  1203. <div class="refsect3">
  1204. <a name="id-1.1.84.3.35.4"></a><h4>Parameters</h4>
  1205. <div class="informaltable"><table><tr>
  1206. <td class="parameter_name"><p>value</p></td>
  1207. <td class="parameter_description">
  1208. <p>a variant <span class="type">GVariant</span> instance</p>
  1209. <p>Passed as <code class="code">self</code></p>
  1210. </td>
  1211. </tr></table></div>
  1212. </div>
  1213. </div>
  1214. <div class="refsect2">
  1215. <a name="id-1.1.84.3.36"></a><h3>hash</h3>
  1216. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:hash self))
  1217. </pre></div>
  1218. <p>Generates a hash value for a <span class="type">GVariant</span> instance.
  1219. </p>
  1220. <p>The output of this function is guaranteed to be the same for a given
  1221. value only per-process. It may change between different processor
  1222. architectures or even different versions of GLib. Do not use this
  1223. function as a basis for building protocols or file formats.
  1224. </p>
  1225. <p>The type of <em class="parameter"><code>value</code></em> is <span class="type">gconstpointer</span> only to allow use of this
  1226. function with <span class="type">GHashTable</span>. <em class="parameter"><code>value</code></em> must be a <span class="type">GVariant</span>.</p>
  1227. <div class="refsect3">
  1228. <a name="id-1.1.84.3.36.6"></a><h4>Parameters</h4>
  1229. <div class="informaltable"><table><tr>
  1230. <td class="parameter_name"><p>value</p></td>
  1231. <td class="parameter_description">
  1232. <p>a basic <span class="type">GVariant</span> value as a <span class="type">gconstpointer</span></p>
  1233. <p>Passed as <code class="code">self</code></p>
  1234. </td>
  1235. </tr></table></div>
  1236. </div>
  1237. </div>
  1238. <div class="refsect2">
  1239. <a name="id-1.1.84.3.37"></a><h3>is-container?</h3>
  1240. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:is-container? self))
  1241. </pre></div>
  1242. <p>Checks if <em class="parameter"><code>value</code></em> is a container.</p>
  1243. <div class="refsect3">
  1244. <a name="id-1.1.84.3.37.4"></a><h4>Parameters</h4>
  1245. <div class="informaltable"><table><tr>
  1246. <td class="parameter_name"><p>value</p></td>
  1247. <td class="parameter_description">
  1248. <p>a <span class="type">GVariant</span> instance</p>
  1249. <p>Passed as <code class="code">self</code></p>
  1250. </td>
  1251. </tr></table></div>
  1252. </div>
  1253. </div>
  1254. <div class="refsect2">
  1255. <a name="id-1.1.84.3.38"></a><h3>is-floating?</h3>
  1256. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:is-floating? self))
  1257. </pre></div>
  1258. <p>Checks whether <em class="parameter"><code>value</code></em> has a floating reference count.
  1259. </p>
  1260. <p>This function should only ever be used to assert that a given variant
  1261. is or is not floating, or for debug purposes. To acquire a reference
  1262. to a variant that might be floating, always use <code class="function">g_variant_ref_sink()</code>
  1263. or <code class="function">g_variant_take_ref()</code>.
  1264. </p>
  1265. <p>See <code class="function">g_variant_ref_sink()</code> for more information about floating reference
  1266. counts.</p>
  1267. <div class="refsect3">
  1268. <a name="id-1.1.84.3.38.6"></a><h4>Parameters</h4>
  1269. <div class="informaltable"><table><tr>
  1270. <td class="parameter_name"><p>value</p></td>
  1271. <td class="parameter_description">
  1272. <p>a <span class="type">GVariant</span></p>
  1273. <p>Passed as <code class="code">self</code></p>
  1274. </td>
  1275. </tr></table></div>
  1276. </div>
  1277. </div>
  1278. <div class="refsect2">
  1279. <a name="id-1.1.84.3.39"></a><h3>is-normal-form?</h3>
  1280. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:is-normal-form? self))
  1281. </pre></div>
  1282. <p>Checks if <em class="parameter"><code>value</code></em> is in normal form.
  1283. </p>
  1284. <p>The main reason to do this is to detect if a given chunk of
  1285. serialised data is in normal form: load the data into a <span class="type">GVariant</span>
  1286. using <code class="function">g_variant_new_from_data()</code> and then use this function to
  1287. check.
  1288. </p>
  1289. <p>If <em class="parameter"><code>value</code></em> is found to be in normal form then it will be marked as
  1290. being trusted. If the value was already marked as being trusted then
  1291. this function will immediately return <code class="constant">TRUE</code>.
  1292. </p>
  1293. <p>There may be implementation specific restrictions on deeply nested values.
  1294. GVariant is guaranteed to handle nesting up to at least 64 levels.</p>
  1295. <div class="refsect3">
  1296. <a name="id-1.1.84.3.39.7"></a><h4>Parameters</h4>
  1297. <div class="informaltable"><table><tr>
  1298. <td class="parameter_name"><p>value</p></td>
  1299. <td class="parameter_description">
  1300. <p>a <span class="type">GVariant</span> instance</p>
  1301. <p>Passed as <code class="code">self</code></p>
  1302. </td>
  1303. </tr></table></div>
  1304. </div>
  1305. </div>
  1306. <div class="refsect2">
  1307. <a name="id-1.1.84.3.40"></a><h3>is-of-type?</h3>
  1308. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:is-of-type? self type))
  1309. </pre></div>
  1310. <p>Checks if a value has a type matching the provided type.</p>
  1311. <div class="refsect3">
  1312. <a name="id-1.1.84.3.40.4"></a><h4>Parameters</h4>
  1313. <div class="informaltable"><table>
  1314. <tr>
  1315. <td class="parameter_name"><p>value</p></td>
  1316. <td class="parameter_description">
  1317. <p>a <span class="type">GVariant</span> instance</p>
  1318. <p>Passed as <code class="code">self</code></p>
  1319. </td>
  1320. </tr>
  1321. <tr>
  1322. <td class="parameter_name"><p>type</p></td>
  1323. <td class="parameter_description">
  1324. <p>a <span class="type">GVariantType</span></p>
  1325. <p>Passed as <code class="code">type</code></p>
  1326. </td>
  1327. </tr>
  1328. </table></div>
  1329. </div>
  1330. </div>
  1331. <div class="refsect2">
  1332. <a name="id-1.1.84.3.41"></a><h3>lookup-value</h3>
  1333. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:lookup-value self key expected-type))
  1334. </pre></div>
  1335. <p>Looks up a value in a dictionary <span class="type">GVariant</span>.
  1336. </p>
  1337. <p>This function works with dictionaries of the type a{s*} (and equally
  1338. well with type a{o*}, but we only further discuss the string case
  1339. for sake of clarity).
  1340. </p>
  1341. <p>In the event that <em class="parameter"><code>dictionary</code></em> has the type a{sv}, the <em class="parameter"><code>expected_type</code></em>
  1342. string specifies what type of value is expected to be inside of the
  1343. variant. If the value inside the variant has a different type then
  1344. <code class="constant">NULL</code> is returned. In the event that <em class="parameter"><code>dictionary</code></em> has a value type other
  1345. than v then <em class="parameter"><code>expected_type</code></em> must directly match the value type and it is
  1346. used to unpack the value directly or an error occurs.
  1347. </p>
  1348. <p>In either case, if <em class="parameter"><code>key</code></em> is not found in <em class="parameter"><code>dictionary</code></em>, <code class="constant">NULL</code> is returned.
  1349. </p>
  1350. <p>If the key is found and the value has the correct type, it is
  1351. returned. If <em class="parameter"><code>expected_type</code></em> was specified then any non-<code class="constant">NULL</code> return
  1352. value will have this type.
  1353. </p>
  1354. <p>This function is currently implemented with a linear scan. If you
  1355. plan to do many lookups then <span class="type">GVariantDict</span> may be more efficient.</p>
  1356. <div class="refsect3">
  1357. <a name="id-1.1.84.3.41.9"></a><h4>Parameters</h4>
  1358. <div class="informaltable"><table>
  1359. <tr>
  1360. <td class="parameter_name"><p>dictionary</p></td>
  1361. <td class="parameter_description">
  1362. <p>a dictionary <span class="type">GVariant</span></p>
  1363. <p>Passed as <code class="code">self</code></p>
  1364. </td>
  1365. </tr>
  1366. <tr>
  1367. <td class="parameter_name"><p>key</p></td>
  1368. <td class="parameter_description">
  1369. <p>the key to look up in the dictionary</p>
  1370. <p>Passed as <code class="code">key</code></p>
  1371. </td>
  1372. </tr>
  1373. <tr>
  1374. <td class="parameter_name"><p>expected_type</p></td>
  1375. <td class="parameter_description">
  1376. <p>a <span class="type">GVariantType</span>, or <code class="constant">NULL</code></p>
  1377. <p>Passed as <code class="code">expected-type</code></p>
  1378. </td>
  1379. </tr>
  1380. </table></div>
  1381. </div>
  1382. </div>
  1383. <div class="refsect2">
  1384. <a name="id-1.1.84.3.42"></a><h3>n-children</h3>
  1385. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:n-children self))
  1386. </pre></div>
  1387. <p>Determines the number of children in a container <span class="type">GVariant</span> instance.
  1388. This includes variants, maybes, arrays, tuples and dictionary
  1389. entries. It is an error to call this function on any other type of
  1390. <span class="type">GVariant</span>.
  1391. </p>
  1392. <p>For variants, the return value is always 1. For values with maybe
  1393. types, it is always zero or one. For arrays, it is the length of the
  1394. array. For tuples it is the number of tuple items (which depends
  1395. only on the type). For dictionary entries, it is always 2
  1396. </p>
  1397. <p>This function is O(1).</p>
  1398. <div class="refsect3">
  1399. <a name="id-1.1.84.3.42.6"></a><h4>Parameters</h4>
  1400. <div class="informaltable"><table><tr>
  1401. <td class="parameter_name"><p>value</p></td>
  1402. <td class="parameter_description">
  1403. <p>a container <span class="type">GVariant</span></p>
  1404. <p>Passed as <code class="code">self</code></p>
  1405. </td>
  1406. </tr></table></div>
  1407. </div>
  1408. </div>
  1409. <div class="refsect2">
  1410. <a name="id-1.1.84.3.43"></a><h3>print</h3>
  1411. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:print self type-annotate))
  1412. </pre></div>
  1413. <p>Pretty-prints <em class="parameter"><code>value</code></em> in the format understood by <code class="function">g_variant_parse()</code>.
  1414. </p>
  1415. <p>The format is described [here][gvariant-text].
  1416. </p>
  1417. <p>If <em class="parameter"><code>type_annotate</code></em> is <code class="constant">TRUE</code>, then type information is included in
  1418. the output.</p>
  1419. <div class="refsect3">
  1420. <a name="id-1.1.84.3.43.6"></a><h4>Parameters</h4>
  1421. <div class="informaltable"><table>
  1422. <tr>
  1423. <td class="parameter_name"><p>value</p></td>
  1424. <td class="parameter_description">
  1425. <p>a <span class="type">GVariant</span></p>
  1426. <p>Passed as <code class="code">self</code></p>
  1427. </td>
  1428. </tr>
  1429. <tr>
  1430. <td class="parameter_name"><p>type_annotate</p></td>
  1431. <td class="parameter_description">
  1432. <p><code class="constant">TRUE</code> if type information should be included in
  1433. the output</p>
  1434. <p>Passed as <code class="code">type-annotate</code></p>
  1435. </td>
  1436. </tr>
  1437. </table></div>
  1438. </div>
  1439. </div>
  1440. <div class="refsect2">
  1441. <a name="id-1.1.84.3.44"></a><h3>ref</h3>
  1442. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:ref self))
  1443. </pre></div>
  1444. <p>Increases the reference count of <em class="parameter"><code>value</code></em>.</p>
  1445. <div class="refsect3">
  1446. <a name="id-1.1.84.3.44.4"></a><h4>Parameters</h4>
  1447. <div class="informaltable"><table><tr>
  1448. <td class="parameter_name"><p>value</p></td>
  1449. <td class="parameter_description">
  1450. <p>a <span class="type">GVariant</span></p>
  1451. <p>Passed as <code class="code">self</code></p>
  1452. </td>
  1453. </tr></table></div>
  1454. </div>
  1455. </div>
  1456. <div class="refsect2">
  1457. <a name="id-1.1.84.3.45"></a><h3>ref-sink</h3>
  1458. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:ref-sink self))
  1459. </pre></div>
  1460. <p><span class="type">GVariant</span> uses a floating reference count system. All functions with
  1461. names starting with <code class="code">g_variant_new_</code> return floating
  1462. references.
  1463. </p>
  1464. <p>Calling <code class="function">g_variant_ref_sink()</code> on a <span class="type">GVariant</span> with a floating reference
  1465. will convert the floating reference into a full reference. Calling
  1466. <code class="function">g_variant_ref_sink()</code> on a non-floating <span class="type">GVariant</span> results in an
  1467. additional normal reference being added.
  1468. </p>
  1469. <p>In other words, if the <em class="parameter"><code>value</code></em> is floating, then this call "assumes
  1470. ownership" of the floating reference, converting it to a normal
  1471. reference. If the <em class="parameter"><code>value</code></em> is not floating, then this call adds a
  1472. new normal reference increasing the reference count by one.
  1473. </p>
  1474. <p>All calls that result in a <span class="type">GVariant</span> instance being inserted into a
  1475. container will call <code class="function">g_variant_ref_sink()</code> on the instance. This means
  1476. that if the value was just created (and has only its floating
  1477. reference) then the container will assume sole ownership of the value
  1478. at that point and the caller will not need to unreference it. This
  1479. makes certain common styles of programming much easier while still
  1480. maintaining normal refcounting semantics in situations where values
  1481. are not floating.</p>
  1482. <div class="refsect3">
  1483. <a name="id-1.1.84.3.45.7"></a><h4>Parameters</h4>
  1484. <div class="informaltable"><table><tr>
  1485. <td class="parameter_name"><p>value</p></td>
  1486. <td class="parameter_description">
  1487. <p>a <span class="type">GVariant</span></p>
  1488. <p>Passed as <code class="code">self</code></p>
  1489. </td>
  1490. </tr></table></div>
  1491. </div>
  1492. </div>
  1493. <div class="refsect2">
  1494. <a name="id-1.1.84.3.46"></a><h3>store</h3>
  1495. <div class="informalexample"><pre class="programlisting">(define-values () (variant:store self data))
  1496. </pre></div>
  1497. <p>Stores the serialised form of <em class="parameter"><code>value</code></em> at <em class="parameter"><code>data</code></em>. <em class="parameter"><code>data</code></em> should be
  1498. large enough. See <code class="function">g_variant_get_size()</code>.
  1499. </p>
  1500. <p>The stored data is in machine native byte order but may not be in
  1501. fully-normalised form if read from an untrusted source. See
  1502. <code class="function">g_variant_get_normal_form()</code> for a solution.
  1503. </p>
  1504. <p>As with <code class="function">g_variant_get_data()</code>, to be able to deserialise the
  1505. serialised variant successfully, its type and (if the destination
  1506. machine might be different) its endianness must also be available.
  1507. </p>
  1508. <p>This function is approximately O(n) in the size of <em class="parameter"><code>data</code></em>.</p>
  1509. <div class="refsect3">
  1510. <a name="id-1.1.84.3.46.7"></a><h4>Parameters</h4>
  1511. <div class="informaltable"><table>
  1512. <tr>
  1513. <td class="parameter_name"><p>value</p></td>
  1514. <td class="parameter_description">
  1515. <p>the <span class="type">GVariant</span> to store</p>
  1516. <p>Passed as <code class="code">self</code></p>
  1517. </td>
  1518. </tr>
  1519. <tr>
  1520. <td class="parameter_name"><p>data</p></td>
  1521. <td class="parameter_description">
  1522. <p>the location to store the serialised data at</p>
  1523. <p>Passed as <code class="code">data</code></p>
  1524. </td>
  1525. </tr>
  1526. </table></div>
  1527. </div>
  1528. </div>
  1529. <div class="refsect2">
  1530. <a name="id-1.1.84.3.47"></a><h3>take-ref</h3>
  1531. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:take-ref self))
  1532. </pre></div>
  1533. <p>If <em class="parameter"><code>value</code></em> is floating, sink it. Otherwise, do nothing.
  1534. </p>
  1535. <p>Typically you want to use <code class="function">g_variant_ref_sink()</code> in order to
  1536. automatically do the correct thing with respect to floating or
  1537. non-floating references, but there is one specific scenario where
  1538. this function is helpful.
  1539. </p>
  1540. <p>The situation where this function is helpful is when creating an API
  1541. that allows the user to provide a callback function that returns a
  1542. <span class="type">GVariant</span>. We certainly want to allow the user the flexibility to
  1543. return a non-floating reference from this callback (for the case
  1544. where the value that is being returned already exists).
  1545. </p>
  1546. <p>At the same time, the style of the <span class="type">GVariant</span> API makes it likely that
  1547. for newly-created <span class="type">GVariant</span> instances, the user can be saved some
  1548. typing if they are allowed to return a <span class="type">GVariant</span> with a floating
  1549. reference.
  1550. </p>
  1551. <p>Using this function on the return value of the user's callback allows
  1552. the user to do whichever is more convenient for them. The caller
  1553. will always receives exactly one full reference to the value: either
  1554. the one that was returned in the first place, or a floating reference
  1555. that has been converted to a full reference.
  1556. </p>
  1557. <p>This function has an odd interaction when combined with
  1558. <code class="function">g_variant_ref_sink()</code> running at the same time in another thread on
  1559. the same <span class="type">GVariant</span> instance. If <code class="function">g_variant_ref_sink()</code> runs first then
  1560. the result will be that the floating reference is converted to a hard
  1561. reference. If <code class="function">g_variant_take_ref()</code> runs first then the result will
  1562. be that the floating reference is converted to a hard reference and
  1563. an additional reference on top of that one is added. It is best to
  1564. avoid this situation.</p>
  1565. <div class="refsect3">
  1566. <a name="id-1.1.84.3.47.9"></a><h4>Parameters</h4>
  1567. <div class="informaltable"><table><tr>
  1568. <td class="parameter_name"><p>value</p></td>
  1569. <td class="parameter_description">
  1570. <p>a <span class="type">GVariant</span></p>
  1571. <p>Passed as <code class="code">self</code></p>
  1572. </td>
  1573. </tr></table></div>
  1574. </div>
  1575. </div>
  1576. <div class="refsect2">
  1577. <a name="id-1.1.84.3.48"></a><h3>unref</h3>
  1578. <div class="informalexample"><pre class="programlisting">(define-values () (variant:unref self))
  1579. </pre></div>
  1580. <p>Decreases the reference count of <em class="parameter"><code>value</code></em>. When its reference count
  1581. drops to 0, the memory used by the variant is freed.</p>
  1582. <div class="refsect3">
  1583. <a name="id-1.1.84.3.48.4"></a><h4>Parameters</h4>
  1584. <div class="informaltable"><table><tr>
  1585. <td class="parameter_name"><p>value</p></td>
  1586. <td class="parameter_description">
  1587. <p>a <span class="type">GVariant</span></p>
  1588. <p>Passed as <code class="code">self</code></p>
  1589. </td>
  1590. </tr></table></div>
  1591. </div>
  1592. </div>
  1593. <div class="refsect2">
  1594. <a name="id-1.1.84.3.49"></a><h3>variant:new-variant</h3>
  1595. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-variant value))
  1596. </pre></div>
  1597. <p>Undocumented</p>
  1598. <div class="refsect3">
  1599. <a name="id-1.1.84.3.49.4"></a><h4>Parameters</h4>
  1600. <div class="informaltable"><table><tr>
  1601. <td class="parameter_name"><p>value</p></td>
  1602. <td class="parameter_description">
  1603. <p></p>
  1604. <p>Passed as <code class="code">value</code></p>
  1605. </td>
  1606. </tr></table></div>
  1607. </div>
  1608. </div>
  1609. <div class="refsect2">
  1610. <a name="id-1.1.84.3.50"></a><h3>variant:new-uint64</h3>
  1611. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-uint64 value))
  1612. </pre></div>
  1613. <p>Undocumented</p>
  1614. <div class="refsect3">
  1615. <a name="id-1.1.84.3.50.4"></a><h4>Parameters</h4>
  1616. <div class="informaltable"><table><tr>
  1617. <td class="parameter_name"><p>value</p></td>
  1618. <td class="parameter_description">
  1619. <p></p>
  1620. <p>Passed as <code class="code">value</code></p>
  1621. </td>
  1622. </tr></table></div>
  1623. </div>
  1624. </div>
  1625. <div class="refsect2">
  1626. <a name="id-1.1.84.3.51"></a><h3>variant:new-uint32</h3>
  1627. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-uint32 value))
  1628. </pre></div>
  1629. <p>Undocumented</p>
  1630. <div class="refsect3">
  1631. <a name="id-1.1.84.3.51.4"></a><h4>Parameters</h4>
  1632. <div class="informaltable"><table><tr>
  1633. <td class="parameter_name"><p>value</p></td>
  1634. <td class="parameter_description">
  1635. <p></p>
  1636. <p>Passed as <code class="code">value</code></p>
  1637. </td>
  1638. </tr></table></div>
  1639. </div>
  1640. </div>
  1641. <div class="refsect2">
  1642. <a name="id-1.1.84.3.52"></a><h3>variant:new-uint16</h3>
  1643. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-uint16 value))
  1644. </pre></div>
  1645. <p>Undocumented</p>
  1646. <div class="refsect3">
  1647. <a name="id-1.1.84.3.52.4"></a><h4>Parameters</h4>
  1648. <div class="informaltable"><table><tr>
  1649. <td class="parameter_name"><p>value</p></td>
  1650. <td class="parameter_description">
  1651. <p></p>
  1652. <p>Passed as <code class="code">value</code></p>
  1653. </td>
  1654. </tr></table></div>
  1655. </div>
  1656. </div>
  1657. <div class="refsect2">
  1658. <a name="id-1.1.84.3.53"></a><h3>variant:new-tuple</h3>
  1659. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-tuple children))
  1660. </pre></div>
  1661. <p>Undocumented</p>
  1662. <div class="refsect3">
  1663. <a name="id-1.1.84.3.53.4"></a><h4>Parameters</h4>
  1664. <div class="informaltable"><table>
  1665. <tr>
  1666. <td class="parameter_name"><p>children</p></td>
  1667. <td class="parameter_description">
  1668. <p></p>
  1669. <p>Passed as <code class="code">children</code></p>
  1670. </td>
  1671. </tr>
  1672. <tr>
  1673. <td class="parameter_name"><p>n_children</p></td>
  1674. <td class="parameter_description">
  1675. <p></p>
  1676. <p>Inferred from <code class="code">children</code></p>
  1677. </td>
  1678. </tr>
  1679. </table></div>
  1680. </div>
  1681. </div>
  1682. <div class="refsect2">
  1683. <a name="id-1.1.84.3.54"></a><h3>variant:new-strv</h3>
  1684. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-strv strv))
  1685. </pre></div>
  1686. <p>Undocumented</p>
  1687. <div class="refsect3">
  1688. <a name="id-1.1.84.3.54.4"></a><h4>Parameters</h4>
  1689. <div class="informaltable"><table>
  1690. <tr>
  1691. <td class="parameter_name"><p>strv</p></td>
  1692. <td class="parameter_description">
  1693. <p></p>
  1694. <p>Passed as <code class="code">strv</code></p>
  1695. </td>
  1696. </tr>
  1697. <tr>
  1698. <td class="parameter_name"><p>length</p></td>
  1699. <td class="parameter_description">
  1700. <p></p>
  1701. <p>Inferred from <code class="code">strv</code></p>
  1702. </td>
  1703. </tr>
  1704. </table></div>
  1705. </div>
  1706. </div>
  1707. <div class="refsect2">
  1708. <a name="id-1.1.84.3.55"></a><h3>variant:new-string</h3>
  1709. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-string string))
  1710. </pre></div>
  1711. <p>Undocumented</p>
  1712. <div class="refsect3">
  1713. <a name="id-1.1.84.3.55.4"></a><h4>Parameters</h4>
  1714. <div class="informaltable"><table><tr>
  1715. <td class="parameter_name"><p>string</p></td>
  1716. <td class="parameter_description">
  1717. <p></p>
  1718. <p>Passed as <code class="code">string</code></p>
  1719. </td>
  1720. </tr></table></div>
  1721. </div>
  1722. </div>
  1723. <div class="refsect2">
  1724. <a name="id-1.1.84.3.56"></a><h3>variant:new-signature</h3>
  1725. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-signature signature))
  1726. </pre></div>
  1727. <p>Undocumented</p>
  1728. <div class="refsect3">
  1729. <a name="id-1.1.84.3.56.4"></a><h4>Parameters</h4>
  1730. <div class="informaltable"><table><tr>
  1731. <td class="parameter_name"><p>signature</p></td>
  1732. <td class="parameter_description">
  1733. <p></p>
  1734. <p>Passed as <code class="code">signature</code></p>
  1735. </td>
  1736. </tr></table></div>
  1737. </div>
  1738. </div>
  1739. <div class="refsect2">
  1740. <a name="id-1.1.84.3.57"></a><h3>variant:new-objv</h3>
  1741. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-objv strv))
  1742. </pre></div>
  1743. <p>Undocumented</p>
  1744. <div class="refsect3">
  1745. <a name="id-1.1.84.3.57.4"></a><h4>Parameters</h4>
  1746. <div class="informaltable"><table>
  1747. <tr>
  1748. <td class="parameter_name"><p>strv</p></td>
  1749. <td class="parameter_description">
  1750. <p></p>
  1751. <p>Passed as <code class="code">strv</code></p>
  1752. </td>
  1753. </tr>
  1754. <tr>
  1755. <td class="parameter_name"><p>length</p></td>
  1756. <td class="parameter_description">
  1757. <p></p>
  1758. <p>Inferred from <code class="code">strv</code></p>
  1759. </td>
  1760. </tr>
  1761. </table></div>
  1762. </div>
  1763. </div>
  1764. <div class="refsect2">
  1765. <a name="id-1.1.84.3.58"></a><h3>variant:new-object-path</h3>
  1766. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-object-path object-path))
  1767. </pre></div>
  1768. <p>Undocumented</p>
  1769. <div class="refsect3">
  1770. <a name="id-1.1.84.3.58.4"></a><h4>Parameters</h4>
  1771. <div class="informaltable"><table><tr>
  1772. <td class="parameter_name"><p>object_path</p></td>
  1773. <td class="parameter_description">
  1774. <p></p>
  1775. <p>Passed as <code class="code">object-path</code></p>
  1776. </td>
  1777. </tr></table></div>
  1778. </div>
  1779. </div>
  1780. <div class="refsect2">
  1781. <a name="id-1.1.84.3.59"></a><h3>variant:new-maybe</h3>
  1782. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-maybe child-type child))
  1783. </pre></div>
  1784. <p>Undocumented</p>
  1785. <div class="refsect3">
  1786. <a name="id-1.1.84.3.59.4"></a><h4>Parameters</h4>
  1787. <div class="informaltable"><table>
  1788. <tr>
  1789. <td class="parameter_name"><p>child_type</p></td>
  1790. <td class="parameter_description">
  1791. <p></p>
  1792. <p>Passed as <code class="code">child-type</code></p>
  1793. </td>
  1794. </tr>
  1795. <tr>
  1796. <td class="parameter_name"><p>child</p></td>
  1797. <td class="parameter_description">
  1798. <p></p>
  1799. <p>Passed as <code class="code">child</code></p>
  1800. </td>
  1801. </tr>
  1802. </table></div>
  1803. </div>
  1804. </div>
  1805. <div class="refsect2">
  1806. <a name="id-1.1.84.3.60"></a><h3>variant:new-int64</h3>
  1807. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-int64 value))
  1808. </pre></div>
  1809. <p>Undocumented</p>
  1810. <div class="refsect3">
  1811. <a name="id-1.1.84.3.60.4"></a><h4>Parameters</h4>
  1812. <div class="informaltable"><table><tr>
  1813. <td class="parameter_name"><p>value</p></td>
  1814. <td class="parameter_description">
  1815. <p></p>
  1816. <p>Passed as <code class="code">value</code></p>
  1817. </td>
  1818. </tr></table></div>
  1819. </div>
  1820. </div>
  1821. <div class="refsect2">
  1822. <a name="id-1.1.84.3.61"></a><h3>variant:new-int32</h3>
  1823. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-int32 value))
  1824. </pre></div>
  1825. <p>Undocumented</p>
  1826. <div class="refsect3">
  1827. <a name="id-1.1.84.3.61.4"></a><h4>Parameters</h4>
  1828. <div class="informaltable"><table><tr>
  1829. <td class="parameter_name"><p>value</p></td>
  1830. <td class="parameter_description">
  1831. <p></p>
  1832. <p>Passed as <code class="code">value</code></p>
  1833. </td>
  1834. </tr></table></div>
  1835. </div>
  1836. </div>
  1837. <div class="refsect2">
  1838. <a name="id-1.1.84.3.62"></a><h3>variant:new-int16</h3>
  1839. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-int16 value))
  1840. </pre></div>
  1841. <p>Undocumented</p>
  1842. <div class="refsect3">
  1843. <a name="id-1.1.84.3.62.4"></a><h4>Parameters</h4>
  1844. <div class="informaltable"><table><tr>
  1845. <td class="parameter_name"><p>value</p></td>
  1846. <td class="parameter_description">
  1847. <p></p>
  1848. <p>Passed as <code class="code">value</code></p>
  1849. </td>
  1850. </tr></table></div>
  1851. </div>
  1852. </div>
  1853. <div class="refsect2">
  1854. <a name="id-1.1.84.3.63"></a><h3>variant:new-handle</h3>
  1855. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-handle value))
  1856. </pre></div>
  1857. <p>Undocumented</p>
  1858. <div class="refsect3">
  1859. <a name="id-1.1.84.3.63.4"></a><h4>Parameters</h4>
  1860. <div class="informaltable"><table><tr>
  1861. <td class="parameter_name"><p>value</p></td>
  1862. <td class="parameter_description">
  1863. <p></p>
  1864. <p>Passed as <code class="code">value</code></p>
  1865. </td>
  1866. </tr></table></div>
  1867. </div>
  1868. </div>
  1869. <div class="refsect2">
  1870. <a name="id-1.1.84.3.64"></a><h3>variant:new-from-data</h3>
  1871. <div class="informalexample"><pre class="programlisting">(define-values
  1872. (%return)
  1873. (variant:new-from-data type data trusted notify user-data))
  1874. </pre></div>
  1875. <p>Undocumented</p>
  1876. <div class="refsect3">
  1877. <a name="id-1.1.84.3.64.4"></a><h4>Parameters</h4>
  1878. <div class="informaltable"><table>
  1879. <tr>
  1880. <td class="parameter_name"><p>type</p></td>
  1881. <td class="parameter_description">
  1882. <p></p>
  1883. <p>Passed as <code class="code">type</code></p>
  1884. </td>
  1885. </tr>
  1886. <tr>
  1887. <td class="parameter_name"><p>data</p></td>
  1888. <td class="parameter_description">
  1889. <p></p>
  1890. <p>Passed as <code class="code">data</code></p>
  1891. </td>
  1892. </tr>
  1893. <tr>
  1894. <td class="parameter_name"><p>size</p></td>
  1895. <td class="parameter_description">
  1896. <p></p>
  1897. <p>Inferred from <code class="code">data</code></p>
  1898. </td>
  1899. </tr>
  1900. <tr>
  1901. <td class="parameter_name"><p>trusted</p></td>
  1902. <td class="parameter_description">
  1903. <p></p>
  1904. <p>Passed as <code class="code">trusted</code></p>
  1905. </td>
  1906. </tr>
  1907. <tr>
  1908. <td class="parameter_name"><p>notify</p></td>
  1909. <td class="parameter_description">
  1910. <p></p>
  1911. <p>Passed as <code class="code">notify</code></p>
  1912. </td>
  1913. </tr>
  1914. <tr>
  1915. <td class="parameter_name"><p>user_data</p></td>
  1916. <td class="parameter_description">
  1917. <p></p>
  1918. <p>Passed as <code class="code">user-data</code></p>
  1919. </td>
  1920. </tr>
  1921. </table></div>
  1922. </div>
  1923. </div>
  1924. <div class="refsect2">
  1925. <a name="id-1.1.84.3.65"></a><h3>variant:new-from-bytes</h3>
  1926. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-from-bytes type bytes trusted))
  1927. </pre></div>
  1928. <p>Undocumented</p>
  1929. <div class="refsect3">
  1930. <a name="id-1.1.84.3.65.4"></a><h4>Parameters</h4>
  1931. <div class="informaltable"><table>
  1932. <tr>
  1933. <td class="parameter_name"><p>type</p></td>
  1934. <td class="parameter_description">
  1935. <p></p>
  1936. <p>Passed as <code class="code">type</code></p>
  1937. </td>
  1938. </tr>
  1939. <tr>
  1940. <td class="parameter_name"><p>bytes</p></td>
  1941. <td class="parameter_description">
  1942. <p></p>
  1943. <p>Passed as <code class="code">bytes</code></p>
  1944. </td>
  1945. </tr>
  1946. <tr>
  1947. <td class="parameter_name"><p>trusted</p></td>
  1948. <td class="parameter_description">
  1949. <p></p>
  1950. <p>Passed as <code class="code">trusted</code></p>
  1951. </td>
  1952. </tr>
  1953. </table></div>
  1954. </div>
  1955. </div>
  1956. <div class="refsect2">
  1957. <a name="id-1.1.84.3.66"></a><h3>variant:new-fixed-array</h3>
  1958. <div class="informalexample"><pre class="programlisting">(define-values
  1959. (%return)
  1960. (variant:new-fixed-array element-type elements n-elements element-size))
  1961. </pre></div>
  1962. <p>Undocumented</p>
  1963. <div class="refsect3">
  1964. <a name="id-1.1.84.3.66.4"></a><h4>Parameters</h4>
  1965. <div class="informaltable"><table>
  1966. <tr>
  1967. <td class="parameter_name"><p>element_type</p></td>
  1968. <td class="parameter_description">
  1969. <p></p>
  1970. <p>Passed as <code class="code">element-type</code></p>
  1971. </td>
  1972. </tr>
  1973. <tr>
  1974. <td class="parameter_name"><p>elements</p></td>
  1975. <td class="parameter_description">
  1976. <p></p>
  1977. <p>Passed as <code class="code">elements</code></p>
  1978. </td>
  1979. </tr>
  1980. <tr>
  1981. <td class="parameter_name"><p>n_elements</p></td>
  1982. <td class="parameter_description">
  1983. <p></p>
  1984. <p>Passed as <code class="code">n-elements</code></p>
  1985. </td>
  1986. </tr>
  1987. <tr>
  1988. <td class="parameter_name"><p>element_size</p></td>
  1989. <td class="parameter_description">
  1990. <p></p>
  1991. <p>Passed as <code class="code">element-size</code></p>
  1992. </td>
  1993. </tr>
  1994. </table></div>
  1995. </div>
  1996. </div>
  1997. <div class="refsect2">
  1998. <a name="id-1.1.84.3.67"></a><h3>variant:new-double</h3>
  1999. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-double value))
  2000. </pre></div>
  2001. <p>Undocumented</p>
  2002. <div class="refsect3">
  2003. <a name="id-1.1.84.3.67.4"></a><h4>Parameters</h4>
  2004. <div class="informaltable"><table><tr>
  2005. <td class="parameter_name"><p>value</p></td>
  2006. <td class="parameter_description">
  2007. <p></p>
  2008. <p>Passed as <code class="code">value</code></p>
  2009. </td>
  2010. </tr></table></div>
  2011. </div>
  2012. </div>
  2013. <div class="refsect2">
  2014. <a name="id-1.1.84.3.68"></a><h3>variant:new-dict-entry</h3>
  2015. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-dict-entry key value))
  2016. </pre></div>
  2017. <p>Undocumented</p>
  2018. <div class="refsect3">
  2019. <a name="id-1.1.84.3.68.4"></a><h4>Parameters</h4>
  2020. <div class="informaltable"><table>
  2021. <tr>
  2022. <td class="parameter_name"><p>key</p></td>
  2023. <td class="parameter_description">
  2024. <p></p>
  2025. <p>Passed as <code class="code">key</code></p>
  2026. </td>
  2027. </tr>
  2028. <tr>
  2029. <td class="parameter_name"><p>value</p></td>
  2030. <td class="parameter_description">
  2031. <p></p>
  2032. <p>Passed as <code class="code">value</code></p>
  2033. </td>
  2034. </tr>
  2035. </table></div>
  2036. </div>
  2037. </div>
  2038. <div class="refsect2">
  2039. <a name="id-1.1.84.3.69"></a><h3>variant:new-bytestring-array</h3>
  2040. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-bytestring-array strv))
  2041. </pre></div>
  2042. <p>Undocumented</p>
  2043. <div class="refsect3">
  2044. <a name="id-1.1.84.3.69.4"></a><h4>Parameters</h4>
  2045. <div class="informaltable"><table>
  2046. <tr>
  2047. <td class="parameter_name"><p>strv</p></td>
  2048. <td class="parameter_description">
  2049. <p></p>
  2050. <p>Passed as <code class="code">strv</code></p>
  2051. </td>
  2052. </tr>
  2053. <tr>
  2054. <td class="parameter_name"><p>length</p></td>
  2055. <td class="parameter_description">
  2056. <p></p>
  2057. <p>Inferred from <code class="code">strv</code></p>
  2058. </td>
  2059. </tr>
  2060. </table></div>
  2061. </div>
  2062. </div>
  2063. <div class="refsect2">
  2064. <a name="id-1.1.84.3.70"></a><h3>variant:new-bytestring</h3>
  2065. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-bytestring string))
  2066. </pre></div>
  2067. <p>Undocumented</p>
  2068. <div class="refsect3">
  2069. <a name="id-1.1.84.3.70.4"></a><h4>Parameters</h4>
  2070. <div class="informaltable"><table><tr>
  2071. <td class="parameter_name"><p>string</p></td>
  2072. <td class="parameter_description">
  2073. <p></p>
  2074. <p>Passed as <code class="code">string</code></p>
  2075. </td>
  2076. </tr></table></div>
  2077. </div>
  2078. </div>
  2079. <div class="refsect2">
  2080. <a name="id-1.1.84.3.71"></a><h3>variant:new-byte</h3>
  2081. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-byte value))
  2082. </pre></div>
  2083. <p>Undocumented</p>
  2084. <div class="refsect3">
  2085. <a name="id-1.1.84.3.71.4"></a><h4>Parameters</h4>
  2086. <div class="informaltable"><table><tr>
  2087. <td class="parameter_name"><p>value</p></td>
  2088. <td class="parameter_description">
  2089. <p></p>
  2090. <p>Passed as <code class="code">value</code></p>
  2091. </td>
  2092. </tr></table></div>
  2093. </div>
  2094. </div>
  2095. <div class="refsect2">
  2096. <a name="id-1.1.84.3.72"></a><h3>variant:new-boolean</h3>
  2097. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-boolean value))
  2098. </pre></div>
  2099. <p>Undocumented</p>
  2100. <div class="refsect3">
  2101. <a name="id-1.1.84.3.72.4"></a><h4>Parameters</h4>
  2102. <div class="informaltable"><table><tr>
  2103. <td class="parameter_name"><p>value</p></td>
  2104. <td class="parameter_description">
  2105. <p></p>
  2106. <p>Passed as <code class="code">value</code></p>
  2107. </td>
  2108. </tr></table></div>
  2109. </div>
  2110. </div>
  2111. <div class="refsect2">
  2112. <a name="id-1.1.84.3.73"></a><h3>variant:new-array</h3>
  2113. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-array child-type children))
  2114. </pre></div>
  2115. <p>Undocumented</p>
  2116. <div class="refsect3">
  2117. <a name="id-1.1.84.3.73.4"></a><h4>Parameters</h4>
  2118. <div class="informaltable"><table>
  2119. <tr>
  2120. <td class="parameter_name"><p>child_type</p></td>
  2121. <td class="parameter_description">
  2122. <p></p>
  2123. <p>Passed as <code class="code">child-type</code></p>
  2124. </td>
  2125. </tr>
  2126. <tr>
  2127. <td class="parameter_name"><p>children</p></td>
  2128. <td class="parameter_description">
  2129. <p></p>
  2130. <p>Passed as <code class="code">children</code></p>
  2131. </td>
  2132. </tr>
  2133. <tr>
  2134. <td class="parameter_name"><p>n_children</p></td>
  2135. <td class="parameter_description">
  2136. <p></p>
  2137. <p>Inferred from <code class="code">children</code></p>
  2138. </td>
  2139. </tr>
  2140. </table></div>
  2141. </div>
  2142. </div>
  2143. <div class="refsect2">
  2144. <a name="id-1.1.84.3.74"></a><h3>variant:is-object-path?</h3>
  2145. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:is-object-path? string))
  2146. </pre></div>
  2147. <p>Determines if a given string is a valid D-Bus object path. You
  2148. should ensure that a string is a valid D-Bus object path before
  2149. passing it to <code class="function">g_variant_new_object_path()</code>.
  2150. </p>
  2151. <p>A valid object path starts with <code class="code">/</code> followed by zero or more
  2152. sequences of characters separated by <code class="code">/</code> characters. Each sequence
  2153. must contain only the characters <code class="code">[A-Z][a-z][0-9]_</code>. No sequence
  2154. (including the one following the final <code class="code">/</code> character) may be empty.</p>
  2155. <div class="refsect3">
  2156. <a name="id-1.1.84.3.74.5"></a><h4>Parameters</h4>
  2157. <div class="informaltable"><table><tr>
  2158. <td class="parameter_name"><p>string</p></td>
  2159. <td class="parameter_description">
  2160. <p>a normal C nul-terminated string</p>
  2161. <p>Passed as <code class="code">string</code></p>
  2162. </td>
  2163. </tr></table></div>
  2164. </div>
  2165. </div>
  2166. <div class="refsect2">
  2167. <a name="id-1.1.84.3.75"></a><h3>variant:is-signature?</h3>
  2168. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:is-signature? string))
  2169. </pre></div>
  2170. <p>Determines if a given string is a valid D-Bus type signature. You
  2171. should ensure that a string is a valid D-Bus type signature before
  2172. passing it to <code class="function">g_variant_new_signature()</code>.
  2173. </p>
  2174. <p>D-Bus type signatures consist of zero or more definite <span class="type">GVariantType</span>
  2175. strings in sequence.</p>
  2176. <div class="refsect3">
  2177. <a name="id-1.1.84.3.75.5"></a><h4>Parameters</h4>
  2178. <div class="informaltable"><table><tr>
  2179. <td class="parameter_name"><p>string</p></td>
  2180. <td class="parameter_description">
  2181. <p>a normal C nul-terminated string</p>
  2182. <p>Passed as <code class="code">string</code></p>
  2183. </td>
  2184. </tr></table></div>
  2185. </div>
  2186. </div>
  2187. <div class="refsect2">
  2188. <a name="id-1.1.84.3.76"></a><h3>variant:parse</h3>
  2189. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:parse type text limit endptr))
  2190. </pre></div>
  2191. <p>Parses a <span class="type">GVariant</span> from a text representation.
  2192. </p>
  2193. <p>A single <span class="type">GVariant</span> is parsed from the content of <em class="parameter"><code>text</code></em>.
  2194. </p>
  2195. <p>The format is described [here][gvariant-text].
  2196. </p>
  2197. <p>The memory at <em class="parameter"><code>limit</code></em> will never be accessed and the parser behaves as
  2198. if the character at <em class="parameter"><code>limit</code></em> is the nul terminator. This has the
  2199. effect of bounding <em class="parameter"><code>text</code></em>.
  2200. </p>
  2201. <p>If <em class="parameter"><code>endptr</code></em> is non-<code class="constant">NULL</code> then <em class="parameter"><code>text</code></em> is permitted to contain data
  2202. following the value that this function parses and <em class="parameter"><code>endptr</code></em> will be
  2203. updated to point to the first character past the end of the text
  2204. parsed by this function. If <em class="parameter"><code>endptr</code></em> is <code class="constant">NULL</code> and there is extra data
  2205. then an error is returned.
  2206. </p>
  2207. <p>If <em class="parameter"><code>type</code></em> is non-<code class="constant">NULL</code> then the value will be parsed to have that
  2208. type. This may result in additional parse errors (in the case that
  2209. the parsed value doesn't fit the type) but may also result in fewer
  2210. errors (in the case that the type would have been ambiguous, such as
  2211. with empty arrays).
  2212. </p>
  2213. <p>In the event that the parsing is successful, the resulting <span class="type">GVariant</span>
  2214. is returned. It is never floating, and must be freed with
  2215. <code class="function">g_variant_unref()</code>.
  2216. </p>
  2217. <p>In case of any error, <code class="constant">NULL</code> will be returned. If <em class="parameter"><code>error</code></em> is non-<code class="constant">NULL</code>
  2218. then it will be set to reflect the error that occurred.
  2219. </p>
  2220. <p>Officially, the language understood by the parser is "any string
  2221. produced by <code class="function">g_variant_print()</code>".
  2222. </p>
  2223. <p>There may be implementation specific restrictions on deeply nested values,
  2224. which would result in a <code class="constant">G_VARIANT_PARSE_ERROR_RECURSION</code> error. <span class="type">GVariant</span> is
  2225. guaranteed to handle nesting up to at least 64 levels.</p>
  2226. <div class="refsect3">
  2227. <a name="id-1.1.84.3.76.13"></a><h4>Parameters</h4>
  2228. <div class="informaltable"><table>
  2229. <tr>
  2230. <td class="parameter_name"><p>type</p></td>
  2231. <td class="parameter_description">
  2232. <p>a <span class="type">GVariantType</span>, or <code class="constant">NULL</code></p>
  2233. <p>Passed as <code class="code">type</code></p>
  2234. </td>
  2235. </tr>
  2236. <tr>
  2237. <td class="parameter_name"><p>text</p></td>
  2238. <td class="parameter_description">
  2239. <p>a string containing a GVariant in text form</p>
  2240. <p>Passed as <code class="code">text</code></p>
  2241. </td>
  2242. </tr>
  2243. <tr>
  2244. <td class="parameter_name"><p>limit</p></td>
  2245. <td class="parameter_description">
  2246. <p>a pointer to the end of <em class="parameter"><code>text</code></em>, or <code class="constant">NULL</code></p>
  2247. <p>Passed as <code class="code">limit</code></p>
  2248. </td>
  2249. </tr>
  2250. <tr>
  2251. <td class="parameter_name"><p>endptr</p></td>
  2252. <td class="parameter_description">
  2253. <p>a location to store the end pointer, or <code class="constant">NULL</code></p>
  2254. <p>Passed as <code class="code">endptr</code></p>
  2255. </td>
  2256. </tr>
  2257. </table></div>
  2258. </div>
  2259. </div>
  2260. <div class="refsect2">
  2261. <a name="id-1.1.84.3.77"></a><h3>variant:parse-error-print-context</h3>
  2262. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:parse-error-print-context error source-str))
  2263. </pre></div>
  2264. <p>Pretty-prints a message showing the context of a <span class="type">GVariant</span> parse
  2265. error within the string for which parsing was attempted.
  2266. </p>
  2267. <p>The resulting string is suitable for output to the console or other
  2268. monospace media where newlines are treated in the usual way.
  2269. </p>
  2270. <p>The message will typically look something like one of the following:
  2271. </p>
  2272. <div class="informalexample"><pre class="programlisting">
  2273. unterminated string constant:
  2274. (1, 2, 3, 'abc
  2275. ^^^^
  2276. </pre></div>
  2277. <p>or
  2278. </p>
  2279. <div class="informalexample"><pre class="programlisting">
  2280. unable to find a common type:
  2281. [1, 2, 3, 'str']
  2282. ^ ^^^^^
  2283. </pre></div>
  2284. <p>The format of the message may change in a future version.
  2285. </p>
  2286. <p><em class="parameter"><code>error</code></em> must have come from a failed attempt to <code class="function">g_variant_parse()</code> and
  2287. <em class="parameter"><code>source_str</code></em> must be exactly the same string that caused the error.
  2288. If <em class="parameter"><code>source_str</code></em> was not nul-terminated when you passed it to
  2289. <code class="function">g_variant_parse()</code> then you must add nul termination before using this
  2290. function.</p>
  2291. <div class="refsect3">
  2292. <a name="id-1.1.84.3.77.11"></a><h4>Parameters</h4>
  2293. <div class="informaltable"><table>
  2294. <tr>
  2295. <td class="parameter_name"><p>error</p></td>
  2296. <td class="parameter_description">
  2297. <p>a <span class="type">GError</span> from the <span class="type">GVariantParseError</span> domain</p>
  2298. <p>Passed as <code class="code">error</code></p>
  2299. </td>
  2300. </tr>
  2301. <tr>
  2302. <td class="parameter_name"><p>source_str</p></td>
  2303. <td class="parameter_description">
  2304. <p>the string that was given to the parser</p>
  2305. <p>Passed as <code class="code">source-str</code></p>
  2306. </td>
  2307. </tr>
  2308. </table></div>
  2309. </div>
  2310. </div>
  2311. <div class="refsect2">
  2312. <a name="id-1.1.84.3.78"></a><h3>variant:parse-error-quark</h3>
  2313. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:parse-error-quark))
  2314. </pre></div>
  2315. <p>Undocumented</p>
  2316. </div>
  2317. <div class="refsect2">
  2318. <a name="id-1.1.84.3.79"></a><h3>variant:parser-get-error-quark</h3>
  2319. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:parser-get-error-quark))
  2320. </pre></div>
  2321. <p>Same as <code class="function">g_variant_error_quark()</code>.</p>
  2322. </div>
  2323. </div>
  2324. </div>
  2325. <div class="footer">
  2326. <hr>Generated by GTK-Doc V1.33.1</div>
  2327. </body>
  2328. </html>