Branch data Line data Source code
1 : : /* GObject - GLib Type, Object, Parameter and Signal Library
2 : : * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc.
3 : : * Copyright © 2010 Christian Persch
4 : : *
5 : : * SPDX-License-Identifier: LGPL-2.1-or-later
6 : : *
7 : : * This library is free software; you can redistribute it and/or
8 : : * modify it under the terms of the GNU Lesser General Public
9 : : * License as published by the Free Software Foundation; either
10 : : * version 2.1 of the License, or (at your option) any later version.
11 : : *
12 : : * This library is distributed in the hope that it will be useful,
13 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 : : * Lesser General Public License for more details.
16 : : *
17 : : * You should have received a copy of the GNU Lesser General
18 : : * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 : : */
20 : :
21 : : /*
22 : : * MT safe
23 : : */
24 : :
25 : : #include "config.h"
26 : :
27 : : #include <string.h>
28 : : #include <stdlib.h> /* qsort() */
29 : :
30 : : #include "gvaluetypes.h"
31 : : #include "gtype-private.h"
32 : : #include "gvaluecollector.h"
33 : : #include "gobject.h"
34 : : #include "gparam.h"
35 : : #include "gboxed.h"
36 : : #include "genums.h"
37 : :
38 : :
39 : : /* --- value functions --- */
40 : : static void
41 : 11648640 : value_init_long0 (GValue *value)
42 : : {
43 : 11648640 : value->data[0].v_long = 0;
44 : 11648640 : }
45 : :
46 : : static void
47 : 570 : value_copy_long0 (const GValue *src_value,
48 : : GValue *dest_value)
49 : : {
50 : 570 : dest_value->data[0].v_long = src_value->data[0].v_long;
51 : 570 : }
52 : :
53 : : static gchar*
54 : 6 : value_lcopy_char (const GValue *value,
55 : : guint n_collect_values,
56 : : GTypeCValue *collect_values,
57 : : guint collect_flags)
58 : : {
59 : 6 : gint8 *int8_p = collect_values[0].v_pointer;
60 : :
61 : 6 : g_return_val_if_fail (int8_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value)));
62 : :
63 : 6 : *int8_p = value->data[0].v_int;
64 : :
65 : 6 : return NULL;
66 : : }
67 : :
68 : : static gchar*
69 : 1761 : value_lcopy_boolean (const GValue *value,
70 : : guint n_collect_values,
71 : : GTypeCValue *collect_values,
72 : : guint collect_flags)
73 : : {
74 : 1761 : gboolean *bool_p = collect_values[0].v_pointer;
75 : :
76 : 1761 : g_return_val_if_fail (bool_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value)));
77 : :
78 : 1761 : *bool_p = value->data[0].v_int;
79 : :
80 : 1761 : return NULL;
81 : : }
82 : :
83 : : static gchar*
84 : 19160929 : value_collect_int (GValue *value,
85 : : guint n_collect_values,
86 : : GTypeCValue *collect_values,
87 : : guint collect_flags)
88 : : {
89 : 19160929 : value->data[0].v_int = collect_values[0].v_int;
90 : :
91 : 19160929 : return NULL;
92 : : }
93 : :
94 : : static gchar*
95 : 11634171 : value_lcopy_int (const GValue *value,
96 : : guint n_collect_values,
97 : : GTypeCValue *collect_values,
98 : : guint collect_flags)
99 : : {
100 : 11634171 : gint *int_p = collect_values[0].v_pointer;
101 : :
102 : 11634171 : g_return_val_if_fail (int_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value)));
103 : :
104 : 11634171 : *int_p = value->data[0].v_int;
105 : :
106 : 11634171 : return NULL;
107 : : }
108 : :
109 : : static gchar*
110 : 1174 : value_collect_long (GValue *value,
111 : : guint n_collect_values,
112 : : GTypeCValue *collect_values,
113 : : guint collect_flags)
114 : : {
115 : 1174 : value->data[0].v_long = collect_values[0].v_long;
116 : :
117 : 1174 : return NULL;
118 : : }
119 : :
120 : : static gchar*
121 : 4 : value_lcopy_long (const GValue *value,
122 : : guint n_collect_values,
123 : : GTypeCValue *collect_values,
124 : : guint collect_flags)
125 : : {
126 : 4 : glong *long_p = collect_values[0].v_pointer;
127 : :
128 : 4 : g_return_val_if_fail (long_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value)));
129 : :
130 : 4 : *long_p = value->data[0].v_long;
131 : :
132 : 4 : return NULL;
133 : : }
134 : :
135 : : static void
136 : 209 : value_init_int64 (GValue *value)
137 : : {
138 : 209 : value->data[0].v_int64 = 0;
139 : 209 : }
140 : :
141 : : static void
142 : 44 : value_copy_int64 (const GValue *src_value,
143 : : GValue *dest_value)
144 : : {
145 : 44 : dest_value->data[0].v_int64 = src_value->data[0].v_int64;
146 : 44 : }
147 : :
148 : : static gchar*
149 : 27 : value_collect_int64 (GValue *value,
150 : : guint n_collect_values,
151 : : GTypeCValue *collect_values,
152 : : guint collect_flags)
153 : : {
154 : 27 : value->data[0].v_int64 = collect_values[0].v_int64;
155 : :
156 : 27 : return NULL;
157 : : }
158 : :
159 : : static gchar*
160 : 11 : value_lcopy_int64 (const GValue *value,
161 : : guint n_collect_values,
162 : : GTypeCValue *collect_values,
163 : : guint collect_flags)
164 : : {
165 : 11 : gint64 *int64_p = collect_values[0].v_pointer;
166 : :
167 : 11 : g_return_val_if_fail (int64_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value)));
168 : :
169 : 11 : *int64_p = value->data[0].v_int64;
170 : :
171 : 11 : return NULL;
172 : : }
173 : :
174 : : static void
175 : 29 : value_init_float (GValue *value)
176 : : {
177 : 29 : value->data[0].v_float = 0.0;
178 : 29 : }
179 : :
180 : : static void
181 : 1 : value_copy_float (const GValue *src_value,
182 : : GValue *dest_value)
183 : : {
184 : 1 : dest_value->data[0].v_float = src_value->data[0].v_float;
185 : 1 : }
186 : :
187 : : static gchar*
188 : 12 : value_collect_float (GValue *value,
189 : : guint n_collect_values,
190 : : GTypeCValue *collect_values,
191 : : guint collect_flags)
192 : : {
193 : 12 : value->data[0].v_float = collect_values[0].v_double;
194 : :
195 : 12 : return NULL;
196 : : }
197 : :
198 : : static gchar*
199 : 1 : value_lcopy_float (const GValue *value,
200 : : guint n_collect_values,
201 : : GTypeCValue *collect_values,
202 : : guint collect_flags)
203 : : {
204 : 1 : gfloat *float_p = collect_values[0].v_pointer;
205 : :
206 : 1 : g_return_val_if_fail (float_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value)));
207 : :
208 : 1 : *float_p = value->data[0].v_float;
209 : :
210 : 1 : return NULL;
211 : : }
212 : :
213 : : static void
214 : 335 : value_init_double (GValue *value)
215 : : {
216 : 335 : value->data[0].v_double = 0.0;
217 : 335 : }
218 : :
219 : : static void
220 : 108 : value_copy_double (const GValue *src_value,
221 : : GValue *dest_value)
222 : : {
223 : 108 : dest_value->data[0].v_double = src_value->data[0].v_double;
224 : 108 : }
225 : :
226 : : static gchar*
227 : 43 : value_collect_double (GValue *value,
228 : : guint n_collect_values,
229 : : GTypeCValue *collect_values,
230 : : guint collect_flags)
231 : : {
232 : 43 : value->data[0].v_double = collect_values[0].v_double;
233 : :
234 : 43 : return NULL;
235 : : }
236 : :
237 : : static gchar*
238 : 9 : value_lcopy_double (const GValue *value,
239 : : guint n_collect_values,
240 : : GTypeCValue *collect_values,
241 : : guint collect_flags)
242 : : {
243 : 9 : gdouble *double_p = collect_values[0].v_pointer;
244 : :
245 : 9 : g_return_val_if_fail (double_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value)));
246 : :
247 : 9 : *double_p = value->data[0].v_double;
248 : :
249 : 9 : return NULL;
250 : : }
251 : :
252 : : static void
253 : 2264193 : value_init_string (GValue *value)
254 : : {
255 : 2264193 : value->data[0].v_pointer = NULL;
256 : 2264193 : }
257 : :
258 : : static void
259 : 2934082 : value_free_string (GValue *value)
260 : : {
261 [ + + ]: 2934082 : if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
262 : 2366012 : g_free (value->data[0].v_pointer);
263 : 2932736 : }
264 : :
265 : : static void
266 : 354 : value_copy_string (const GValue *src_value,
267 : : GValue *dest_value)
268 : : {
269 [ + + ]: 354 : if (src_value->data[1].v_uint & G_VALUE_INTERNED_STRING)
270 : : {
271 : 1 : dest_value->data[0].v_pointer = src_value->data[0].v_pointer;
272 : 1 : dest_value->data[1].v_uint = src_value->data[1].v_uint;
273 : : }
274 : : else
275 : : {
276 : 706 : dest_value->data[0].v_pointer = g_strdup (src_value->data[0].v_pointer);
277 : : /* Don't copy over *any* flags, we're restarting from scratch */
278 : : }
279 : 354 : }
280 : :
281 : : static gchar*
282 : 669390 : value_collect_string (GValue *value,
283 : : guint n_collect_values,
284 : : GTypeCValue *collect_values,
285 : : guint collect_flags)
286 : : {
287 [ + + ]: 669390 : if (!collect_values[0].v_pointer)
288 : 292 : value->data[0].v_pointer = NULL;
289 [ + + ]: 669098 : else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
290 : : {
291 : 568275 : value->data[0].v_pointer = collect_values[0].v_pointer;
292 : 568275 : value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
293 : : }
294 : : else
295 : 201699 : value->data[0].v_pointer = g_strdup (collect_values[0].v_pointer);
296 : :
297 : 669443 : return NULL;
298 : : }
299 : :
300 : : static gchar*
301 : 2263469 : value_lcopy_string (const GValue *value,
302 : : guint n_collect_values,
303 : : GTypeCValue *collect_values,
304 : : guint collect_flags)
305 : : {
306 : 2263469 : gchar **string_p = collect_values[0].v_pointer;
307 : :
308 : 2263469 : g_return_val_if_fail (string_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value)));
309 : :
310 [ + + ]: 2263469 : if (!value->data[0].v_pointer)
311 : 9 : *string_p = NULL;
312 [ - + ]: 2263460 : else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
313 : 0 : *string_p = value->data[0].v_pointer;
314 : : else
315 : 4526984 : *string_p = g_strdup (value->data[0].v_pointer);
316 : :
317 : 2263533 : return NULL;
318 : : }
319 : :
320 : : static void
321 : 539 : value_init_pointer (GValue *value)
322 : : {
323 : 539 : value->data[0].v_pointer = NULL;
324 : 539 : }
325 : :
326 : : static void
327 : 1 : value_copy_pointer (const GValue *src_value,
328 : : GValue *dest_value)
329 : : {
330 : 1 : dest_value->data[0].v_pointer = src_value->data[0].v_pointer;
331 : 1 : }
332 : :
333 : : static gpointer
334 : 0 : value_peek_pointer0 (const GValue *value)
335 : : {
336 : 0 : return value->data[0].v_pointer;
337 : : }
338 : :
339 : : static gchar*
340 : 1117551 : value_collect_pointer (GValue *value,
341 : : guint n_collect_values,
342 : : GTypeCValue *collect_values,
343 : : guint collect_flags)
344 : : {
345 : 1117551 : value->data[0].v_pointer = collect_values[0].v_pointer;
346 : :
347 : 1117551 : return NULL;
348 : : }
349 : :
350 : : static gchar*
351 : 7 : value_lcopy_pointer (const GValue *value,
352 : : guint n_collect_values,
353 : : GTypeCValue *collect_values,
354 : : guint collect_flags)
355 : : {
356 : 7 : gpointer *pointer_p = collect_values[0].v_pointer;
357 : :
358 : 7 : g_return_val_if_fail (pointer_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value)));
359 : :
360 : 7 : *pointer_p = value->data[0].v_pointer;
361 : :
362 : 7 : return NULL;
363 : : }
364 : :
365 : : static void
366 : 922 : value_free_variant (GValue *value)
367 : : {
368 [ + + ]: 922 : if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) &&
369 [ + + ]: 915 : value->data[0].v_pointer)
370 : 417 : g_variant_unref (value->data[0].v_pointer);
371 : 922 : }
372 : :
373 : : static void
374 : 153 : value_copy_variant (const GValue *src_value,
375 : : GValue *dest_value)
376 : : {
377 [ + + ]: 153 : if (src_value->data[0].v_pointer)
378 : 27 : dest_value->data[0].v_pointer = g_variant_ref_sink (src_value->data[0].v_pointer);
379 : : else
380 : 126 : dest_value->data[0].v_pointer = NULL;
381 : 153 : }
382 : :
383 : : static gchar*
384 : 323 : value_collect_variant (GValue *value,
385 : : guint n_collect_values,
386 : : GTypeCValue *collect_values,
387 : : guint collect_flags)
388 : : {
389 [ + + ]: 323 : if (!collect_values[0].v_pointer)
390 : 15 : value->data[0].v_pointer = NULL;
391 : : else
392 : : /* never honour G_VALUE_NOCOPY_CONTENTS for ref-counted types */
393 : 308 : value->data[0].v_pointer = g_variant_ref_sink (collect_values[0].v_pointer);
394 : :
395 : 323 : return NULL;
396 : : }
397 : :
398 : : static gchar*
399 : 27 : value_lcopy_variant (const GValue *value,
400 : : guint n_collect_values,
401 : : GTypeCValue *collect_values,
402 : : guint collect_flags)
403 : : {
404 : 27 : GVariant **variant_p = collect_values[0].v_pointer;
405 : :
406 : 27 : g_return_val_if_fail (variant_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value)));
407 : :
408 [ + + ]: 27 : if (!value->data[0].v_pointer)
409 : 1 : *variant_p = NULL;
410 [ - + ]: 26 : else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
411 : 0 : *variant_p = value->data[0].v_pointer;
412 : : else
413 : 26 : *variant_p = g_variant_ref_sink (value->data[0].v_pointer);
414 : :
415 : 27 : return NULL;
416 : : }
417 : :
418 : : /* --- type initialization --- */
419 : : void
420 : 508 : _g_value_types_init (void)
421 : : {
422 : 508 : GTypeInfo info = {
423 : : 0, /* class_size */
424 : : NULL, /* base_init */
425 : : NULL, /* base_destroy */
426 : : NULL, /* class_init */
427 : : NULL, /* class_destroy */
428 : : NULL, /* class_data */
429 : : 0, /* instance_size */
430 : : 0, /* n_preallocs */
431 : : NULL, /* instance_init */
432 : : NULL, /* value_table */
433 : : };
434 : 508 : const GTypeFundamentalInfo finfo = { G_TYPE_FLAG_DERIVABLE, };
435 : : GType type G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
436 : :
437 : : /* G_TYPE_CHAR / G_TYPE_UCHAR
438 : : */
439 : : {
440 : : static const GTypeValueTable value_table = {
441 : : value_init_long0, /* value_init */
442 : : NULL, /* value_free */
443 : : value_copy_long0, /* value_copy */
444 : : NULL, /* value_peek_pointer */
445 : : "i", /* collect_format */
446 : : value_collect_int, /* collect_value */
447 : : "p", /* lcopy_format */
448 : : value_lcopy_char, /* lcopy_value */
449 : : };
450 : 508 : info.value_table = &value_table;
451 : 508 : type = g_type_register_fundamental (G_TYPE_CHAR, g_intern_static_string ("gchar"), &info, &finfo, 0);
452 : 508 : g_assert (type == G_TYPE_CHAR);
453 : 508 : type = g_type_register_fundamental (G_TYPE_UCHAR, g_intern_static_string ("guchar"), &info, &finfo, 0);
454 : 508 : g_assert (type == G_TYPE_UCHAR);
455 : : }
456 : :
457 : : /* G_TYPE_BOOLEAN
458 : : */
459 : : {
460 : : static const GTypeValueTable value_table = {
461 : : value_init_long0, /* value_init */
462 : : NULL, /* value_free */
463 : : value_copy_long0, /* value_copy */
464 : : NULL, /* value_peek_pointer */
465 : : "i", /* collect_format */
466 : : value_collect_int, /* collect_value */
467 : : "p", /* lcopy_format */
468 : : value_lcopy_boolean, /* lcopy_value */
469 : : };
470 : 508 : info.value_table = &value_table;
471 : 508 : type = g_type_register_fundamental (G_TYPE_BOOLEAN, g_intern_static_string ("gboolean"), &info, &finfo, 0);
472 : 508 : g_assert (type == G_TYPE_BOOLEAN);
473 : : }
474 : :
475 : : /* G_TYPE_INT / G_TYPE_UINT
476 : : */
477 : : {
478 : : static const GTypeValueTable value_table = {
479 : : value_init_long0, /* value_init */
480 : : NULL, /* value_free */
481 : : value_copy_long0, /* value_copy */
482 : : NULL, /* value_peek_pointer */
483 : : "i", /* collect_format */
484 : : value_collect_int, /* collect_value */
485 : : "p", /* lcopy_format */
486 : : value_lcopy_int, /* lcopy_value */
487 : : };
488 : 508 : info.value_table = &value_table;
489 : 508 : type = g_type_register_fundamental (G_TYPE_INT, g_intern_static_string ("gint"), &info, &finfo, 0);
490 : 508 : g_assert (type == G_TYPE_INT);
491 : 508 : type = g_type_register_fundamental (G_TYPE_UINT, g_intern_static_string ("guint"), &info, &finfo, 0);
492 : 508 : g_assert (type == G_TYPE_UINT);
493 : : }
494 : :
495 : : /* G_TYPE_LONG / G_TYPE_ULONG
496 : : */
497 : : {
498 : : static const GTypeValueTable value_table = {
499 : : value_init_long0, /* value_init */
500 : : NULL, /* value_free */
501 : : value_copy_long0, /* value_copy */
502 : : NULL, /* value_peek_pointer */
503 : : "l", /* collect_format */
504 : : value_collect_long, /* collect_value */
505 : : "p", /* lcopy_format */
506 : : value_lcopy_long, /* lcopy_value */
507 : : };
508 : 508 : info.value_table = &value_table;
509 : 508 : type = g_type_register_fundamental (G_TYPE_LONG, g_intern_static_string ("glong"), &info, &finfo, 0);
510 : 508 : g_assert (type == G_TYPE_LONG);
511 : 508 : type = g_type_register_fundamental (G_TYPE_ULONG, g_intern_static_string ("gulong"), &info, &finfo, 0);
512 : 508 : g_assert (type == G_TYPE_ULONG);
513 : : }
514 : :
515 : : /* G_TYPE_INT64 / G_TYPE_UINT64
516 : : */
517 : : {
518 : : static const GTypeValueTable value_table = {
519 : : value_init_int64, /* value_init */
520 : : NULL, /* value_free */
521 : : value_copy_int64, /* value_copy */
522 : : NULL, /* value_peek_pointer */
523 : : "q", /* collect_format */
524 : : value_collect_int64, /* collect_value */
525 : : "p", /* lcopy_format */
526 : : value_lcopy_int64, /* lcopy_value */
527 : : };
528 : 508 : info.value_table = &value_table;
529 : 508 : type = g_type_register_fundamental (G_TYPE_INT64, g_intern_static_string ("gint64"), &info, &finfo, 0);
530 : 508 : g_assert (type == G_TYPE_INT64);
531 : 508 : type = g_type_register_fundamental (G_TYPE_UINT64, g_intern_static_string ("guint64"), &info, &finfo, 0);
532 : 508 : g_assert (type == G_TYPE_UINT64);
533 : : }
534 : :
535 : : /* G_TYPE_FLOAT
536 : : */
537 : : {
538 : : static const GTypeValueTable value_table = {
539 : : value_init_float, /* value_init */
540 : : NULL, /* value_free */
541 : : value_copy_float, /* value_copy */
542 : : NULL, /* value_peek_pointer */
543 : : "d", /* collect_format */
544 : : value_collect_float, /* collect_value */
545 : : "p", /* lcopy_format */
546 : : value_lcopy_float, /* lcopy_value */
547 : : };
548 : 508 : info.value_table = &value_table;
549 : 508 : type = g_type_register_fundamental (G_TYPE_FLOAT, g_intern_static_string ("gfloat"), &info, &finfo, 0);
550 : 508 : g_assert (type == G_TYPE_FLOAT);
551 : : }
552 : :
553 : : /* G_TYPE_DOUBLE
554 : : */
555 : : {
556 : : static const GTypeValueTable value_table = {
557 : : value_init_double, /* value_init */
558 : : NULL, /* value_free */
559 : : value_copy_double, /* value_copy */
560 : : NULL, /* value_peek_pointer */
561 : : "d", /* collect_format */
562 : : value_collect_double, /* collect_value */
563 : : "p", /* lcopy_format */
564 : : value_lcopy_double, /* lcopy_value */
565 : : };
566 : 508 : info.value_table = &value_table;
567 : 508 : type = g_type_register_fundamental (G_TYPE_DOUBLE, g_intern_static_string ("gdouble"), &info, &finfo, 0);
568 : 508 : g_assert (type == G_TYPE_DOUBLE);
569 : : }
570 : :
571 : : /* G_TYPE_STRING
572 : : */
573 : : {
574 : : static const GTypeValueTable value_table = {
575 : : value_init_string, /* value_init */
576 : : value_free_string, /* value_free */
577 : : value_copy_string, /* value_copy */
578 : : value_peek_pointer0, /* value_peek_pointer */
579 : : "p", /* collect_format */
580 : : value_collect_string, /* collect_value */
581 : : "p", /* lcopy_format */
582 : : value_lcopy_string, /* lcopy_value */
583 : : };
584 : 508 : info.value_table = &value_table;
585 : 508 : type = g_type_register_fundamental (G_TYPE_STRING, g_intern_static_string ("gchararray"), &info, &finfo, 0);
586 : 508 : g_assert (type == G_TYPE_STRING);
587 : : }
588 : :
589 : : /* G_TYPE_POINTER
590 : : */
591 : : {
592 : : static const GTypeValueTable value_table = {
593 : : value_init_pointer, /* value_init */
594 : : NULL, /* value_free */
595 : : value_copy_pointer, /* value_copy */
596 : : value_peek_pointer0, /* value_peek_pointer */
597 : : "p", /* collect_format */
598 : : value_collect_pointer, /* collect_value */
599 : : "p", /* lcopy_format */
600 : : value_lcopy_pointer, /* lcopy_value */
601 : : };
602 : 508 : info.value_table = &value_table;
603 : 508 : type = g_type_register_fundamental (G_TYPE_POINTER, g_intern_static_string ("gpointer"), &info, &finfo, 0);
604 : 508 : g_assert (type == G_TYPE_POINTER);
605 : : }
606 : :
607 : : /* G_TYPE_VARIANT
608 : : */
609 : : {
610 : : static const GTypeValueTable value_table = {
611 : : value_init_pointer, /* value_init */
612 : : value_free_variant, /* value_free */
613 : : value_copy_variant, /* value_copy */
614 : : value_peek_pointer0, /* value_peek_pointer */
615 : : "p", /* collect_format */
616 : : value_collect_variant, /* collect_value */
617 : : "p", /* lcopy_format */
618 : : value_lcopy_variant, /* lcopy_value */
619 : : };
620 : 508 : info.value_table = &value_table;
621 : 508 : type = g_type_register_fundamental (G_TYPE_VARIANT, g_intern_static_string ("GVariant"), &info, &finfo, 0);
622 : 508 : g_assert (type == G_TYPE_VARIANT);
623 : : }
624 : 508 : }
625 : :
626 : :
627 : : /* --- GValue functions --- */
628 : : /**
629 : : * g_value_set_char:
630 : : * @value: a valid #GValue of type %G_TYPE_CHAR
631 : : * @v_char: character value to be set
632 : : *
633 : : * Set the contents of a %G_TYPE_CHAR #GValue to @v_char.
634 : : * Deprecated: 2.32: This function's input type is broken, see g_value_set_schar()
635 : : */
636 : : void
637 : 11 : g_value_set_char (GValue *value,
638 : : gchar v_char)
639 : : {
640 : 11 : g_return_if_fail (G_VALUE_HOLDS_CHAR (value));
641 : :
642 : 11 : value->data[0].v_int = v_char;
643 : : }
644 : :
645 : : /**
646 : : * g_value_get_char:
647 : : * @value: a valid #GValue of type %G_TYPE_CHAR
648 : : *
649 : : * Do not use this function; it is broken on platforms where the %char
650 : : * type is unsigned, such as ARM and PowerPC. See g_value_get_schar().
651 : : *
652 : : * Get the contents of a %G_TYPE_CHAR #GValue.
653 : : *
654 : : * Returns: character contents of @value
655 : : * Deprecated: 2.32: This function's return type is broken, see g_value_get_schar()
656 : : */
657 : : gchar
658 : 15 : g_value_get_char (const GValue *value)
659 : : {
660 : 15 : g_return_val_if_fail (G_VALUE_HOLDS_CHAR (value), 0);
661 : :
662 : 15 : return value->data[0].v_int;
663 : : }
664 : :
665 : : /**
666 : : * g_value_set_schar:
667 : : * @value: a valid #GValue of type %G_TYPE_CHAR
668 : : * @v_char: signed 8 bit integer to be set
669 : : *
670 : : * Set the contents of a %G_TYPE_CHAR #GValue to @v_char.
671 : : *
672 : : * Since: 2.32
673 : : */
674 : : void
675 : 10 : g_value_set_schar (GValue *value,
676 : : gint8 v_char)
677 : : {
678 : 10 : g_return_if_fail (G_VALUE_HOLDS_CHAR (value));
679 : :
680 : 10 : value->data[0].v_int = v_char;
681 : : }
682 : :
683 : : /**
684 : : * g_value_get_schar:
685 : : * @value: a valid #GValue of type %G_TYPE_CHAR
686 : : *
687 : : * Get the contents of a %G_TYPE_CHAR #GValue.
688 : : *
689 : : * Returns: signed 8 bit integer contents of @value
690 : : * Since: 2.32
691 : : */
692 : : gint8
693 : 41 : g_value_get_schar (const GValue *value)
694 : : {
695 : 41 : g_return_val_if_fail (G_VALUE_HOLDS_CHAR (value), 0);
696 : :
697 : 41 : return value->data[0].v_int;
698 : : }
699 : :
700 : : /**
701 : : * g_value_set_uchar:
702 : : * @value: a valid #GValue of type %G_TYPE_UCHAR
703 : : * @v_uchar: unsigned character value to be set
704 : : *
705 : : * Set the contents of a %G_TYPE_UCHAR #GValue to @v_uchar.
706 : : */
707 : : void
708 : 10 : g_value_set_uchar (GValue *value,
709 : : guchar v_uchar)
710 : : {
711 : 10 : g_return_if_fail (G_VALUE_HOLDS_UCHAR (value));
712 : :
713 : 10 : value->data[0].v_uint = v_uchar;
714 : : }
715 : :
716 : : /**
717 : : * g_value_get_uchar:
718 : : * @value: a valid #GValue of type %G_TYPE_UCHAR
719 : : *
720 : : * Get the contents of a %G_TYPE_UCHAR #GValue.
721 : : *
722 : : * Returns: unsigned character contents of @value
723 : : */
724 : : guchar
725 : 114 : g_value_get_uchar (const GValue *value)
726 : : {
727 : 114 : g_return_val_if_fail (G_VALUE_HOLDS_UCHAR (value), 0);
728 : :
729 : 114 : return value->data[0].v_uint;
730 : : }
731 : :
732 : : /**
733 : : * g_value_set_boolean:
734 : : * @value: a valid #GValue of type %G_TYPE_BOOLEAN
735 : : * @v_boolean: boolean value to be set
736 : : *
737 : : * Set the contents of a %G_TYPE_BOOLEAN #GValue to @v_boolean.
738 : : */
739 : : void
740 : 11134 : g_value_set_boolean (GValue *value,
741 : : gboolean v_boolean)
742 : : {
743 : 11134 : g_return_if_fail (G_VALUE_HOLDS_BOOLEAN (value));
744 : :
745 : 11134 : value->data[0].v_int = v_boolean != FALSE;
746 : : }
747 : :
748 : : /**
749 : : * g_value_get_boolean:
750 : : * @value: a valid #GValue of type %G_TYPE_BOOLEAN
751 : : *
752 : : * Get the contents of a %G_TYPE_BOOLEAN #GValue.
753 : : *
754 : : * Returns: boolean contents of @value
755 : : */
756 : : gboolean
757 : 120397 : g_value_get_boolean (const GValue *value)
758 : : {
759 : 120397 : g_return_val_if_fail (G_VALUE_HOLDS_BOOLEAN (value), 0);
760 : :
761 : 120397 : return value->data[0].v_int;
762 : : }
763 : :
764 : : /**
765 : : * g_value_set_int:
766 : : * @value: a valid #GValue of type %G_TYPE_INT
767 : : * @v_int: integer value to be set
768 : : *
769 : : * Set the contents of a %G_TYPE_INT #GValue to @v_int.
770 : : */
771 : : void
772 : 11654693 : g_value_set_int (GValue *value,
773 : : gint v_int)
774 : : {
775 : 11654693 : g_return_if_fail (G_VALUE_HOLDS_INT (value));
776 : :
777 : 11654693 : value->data[0].v_int = v_int;
778 : : }
779 : :
780 : : /**
781 : : * g_value_get_int:
782 : : * @value: a valid #GValue of type %G_TYPE_INT
783 : : *
784 : : * Get the contents of a %G_TYPE_INT #GValue.
785 : : *
786 : : * Returns: integer contents of @value
787 : : */
788 : : gint
789 : 18551393 : g_value_get_int (const GValue *value)
790 : : {
791 : 18551393 : g_return_val_if_fail (G_VALUE_HOLDS_INT (value), 0);
792 : :
793 : 18551393 : return value->data[0].v_int;
794 : : }
795 : :
796 : : /**
797 : : * g_value_set_uint:
798 : : * @value: a valid #GValue of type %G_TYPE_UINT
799 : : * @v_uint: unsigned integer value to be set
800 : : *
801 : : * Set the contents of a %G_TYPE_UINT #GValue to @v_uint.
802 : : */
803 : : void
804 : 996 : g_value_set_uint (GValue *value,
805 : : guint v_uint)
806 : : {
807 : 996 : g_return_if_fail (G_VALUE_HOLDS_UINT (value));
808 : :
809 : 996 : value->data[0].v_uint = v_uint;
810 : : }
811 : :
812 : : /**
813 : : * g_value_get_uint:
814 : : * @value: a valid #GValue of type %G_TYPE_UINT
815 : : *
816 : : * Get the contents of a %G_TYPE_UINT #GValue.
817 : : *
818 : : * Returns: unsigned integer contents of @value
819 : : */
820 : : guint
821 : 1676237 : g_value_get_uint (const GValue *value)
822 : : {
823 : 1676237 : g_return_val_if_fail (G_VALUE_HOLDS_UINT (value), 0);
824 : :
825 : 1676237 : return value->data[0].v_uint;
826 : : }
827 : :
828 : : /**
829 : : * g_value_set_long:
830 : : * @value: a valid #GValue of type %G_TYPE_LONG
831 : : * @v_long: long integer value to be set
832 : : *
833 : : * Set the contents of a %G_TYPE_LONG #GValue to @v_long.
834 : : */
835 : : void
836 : 20 : g_value_set_long (GValue *value,
837 : : glong v_long)
838 : : {
839 : 20 : g_return_if_fail (G_VALUE_HOLDS_LONG (value));
840 : :
841 : 20 : value->data[0].v_long = v_long;
842 : : }
843 : :
844 : : /**
845 : : * g_value_get_long:
846 : : * @value: a valid #GValue of type %G_TYPE_LONG
847 : : *
848 : : * Get the contents of a %G_TYPE_LONG #GValue.
849 : : *
850 : : * Returns: long integer contents of @value
851 : : */
852 : : glong
853 : 31 : g_value_get_long (const GValue *value)
854 : : {
855 : 31 : g_return_val_if_fail (G_VALUE_HOLDS_LONG (value), 0);
856 : :
857 : 31 : return value->data[0].v_long;
858 : : }
859 : :
860 : : /**
861 : : * g_value_set_ulong:
862 : : * @value: a valid #GValue of type %G_TYPE_ULONG
863 : : * @v_ulong: unsigned long integer value to be set
864 : : *
865 : : * Set the contents of a %G_TYPE_ULONG #GValue to @v_ulong.
866 : : */
867 : : void
868 : 25 : g_value_set_ulong (GValue *value,
869 : : gulong v_ulong)
870 : : {
871 : 25 : g_return_if_fail (G_VALUE_HOLDS_ULONG (value));
872 : :
873 : 25 : value->data[0].v_ulong = v_ulong;
874 : : }
875 : :
876 : : /**
877 : : * g_value_get_ulong:
878 : : * @value: a valid #GValue of type %G_TYPE_ULONG
879 : : *
880 : : * Get the contents of a %G_TYPE_ULONG #GValue.
881 : : *
882 : : * Returns: unsigned long integer contents of @value
883 : : */
884 : : gulong
885 : 1187 : g_value_get_ulong (const GValue *value)
886 : : {
887 : 1187 : g_return_val_if_fail (G_VALUE_HOLDS_ULONG (value), 0);
888 : :
889 : 1187 : return value->data[0].v_ulong;
890 : : }
891 : :
892 : : /**
893 : : * g_value_get_int64:
894 : : * @value: a valid #GValue of type %G_TYPE_INT64
895 : : *
896 : : * Get the contents of a %G_TYPE_INT64 #GValue.
897 : : *
898 : : * Returns: 64bit integer contents of @value
899 : : */
900 : : void
901 : 30 : g_value_set_int64 (GValue *value,
902 : : gint64 v_int64)
903 : : {
904 : 30 : g_return_if_fail (G_VALUE_HOLDS_INT64 (value));
905 : :
906 : 30 : value->data[0].v_int64 = v_int64;
907 : : }
908 : :
909 : : /**
910 : : * g_value_set_int64:
911 : : * @value: a valid #GValue of type %G_TYPE_INT64
912 : : * @v_int64: 64bit integer value to be set
913 : : *
914 : : * Set the contents of a %G_TYPE_INT64 #GValue to @v_int64.
915 : : */
916 : : gint64
917 : 59 : g_value_get_int64 (const GValue *value)
918 : : {
919 : 59 : g_return_val_if_fail (G_VALUE_HOLDS_INT64 (value), 0);
920 : :
921 : 59 : return value->data[0].v_int64;
922 : : }
923 : :
924 : : /**
925 : : * g_value_set_uint64:
926 : : * @value: a valid #GValue of type %G_TYPE_UINT64
927 : : * @v_uint64: unsigned 64bit integer value to be set
928 : : *
929 : : * Set the contents of a %G_TYPE_UINT64 #GValue to @v_uint64.
930 : : */
931 : : void
932 : 35 : g_value_set_uint64 (GValue *value,
933 : : guint64 v_uint64)
934 : : {
935 : 35 : g_return_if_fail (G_VALUE_HOLDS_UINT64 (value));
936 : :
937 : 35 : value->data[0].v_uint64 = v_uint64;
938 : : }
939 : :
940 : : /**
941 : : * g_value_get_uint64:
942 : : * @value: a valid #GValue of type %G_TYPE_UINT64
943 : : *
944 : : * Get the contents of a %G_TYPE_UINT64 #GValue.
945 : : *
946 : : * Returns: unsigned 64bit integer contents of @value
947 : : */
948 : : guint64
949 : 64 : g_value_get_uint64 (const GValue *value)
950 : : {
951 : 64 : g_return_val_if_fail (G_VALUE_HOLDS_UINT64 (value), 0);
952 : :
953 : 64 : return value->data[0].v_uint64;
954 : : }
955 : :
956 : : /**
957 : : * g_value_set_float:
958 : : * @value: a valid #GValue of type %G_TYPE_FLOAT
959 : : * @v_float: float value to be set
960 : : *
961 : : * Set the contents of a %G_TYPE_FLOAT #GValue to @v_float.
962 : : */
963 : : void
964 : 18 : g_value_set_float (GValue *value,
965 : : gfloat v_float)
966 : : {
967 : 18 : g_return_if_fail (G_VALUE_HOLDS_FLOAT (value));
968 : :
969 : 18 : value->data[0].v_float = v_float;
970 : : }
971 : :
972 : : /**
973 : : * g_value_get_float:
974 : : * @value: a valid #GValue of type %G_TYPE_FLOAT
975 : : *
976 : : * Get the contents of a %G_TYPE_FLOAT #GValue.
977 : : *
978 : : * Returns: float contents of @value
979 : : */
980 : : gfloat
981 : 30 : g_value_get_float (const GValue *value)
982 : : {
983 : 30 : g_return_val_if_fail (G_VALUE_HOLDS_FLOAT (value), 0);
984 : :
985 : 30 : return value->data[0].v_float;
986 : : }
987 : :
988 : : /**
989 : : * g_value_set_double:
990 : : * @value: a valid #GValue of type %G_TYPE_DOUBLE
991 : : * @v_double: double value to be set
992 : : *
993 : : * Set the contents of a %G_TYPE_DOUBLE #GValue to @v_double.
994 : : */
995 : : void
996 : 96 : g_value_set_double (GValue *value,
997 : : gdouble v_double)
998 : : {
999 : 96 : g_return_if_fail (G_VALUE_HOLDS_DOUBLE (value));
1000 : :
1001 : 96 : value->data[0].v_double = v_double;
1002 : : }
1003 : :
1004 : : /**
1005 : : * g_value_get_double:
1006 : : * @value: a valid #GValue of type %G_TYPE_DOUBLE
1007 : : *
1008 : : * Get the contents of a %G_TYPE_DOUBLE #GValue.
1009 : : *
1010 : : * Returns: double contents of @value
1011 : : */
1012 : : gdouble
1013 : 193 : g_value_get_double (const GValue *value)
1014 : : {
1015 : 193 : g_return_val_if_fail (G_VALUE_HOLDS_DOUBLE (value), 0);
1016 : :
1017 : 193 : return value->data[0].v_double;
1018 : : }
1019 : :
1020 : : /**
1021 : : * g_value_set_string:
1022 : : * @value: a valid #GValue of type %G_TYPE_STRING
1023 : : * @v_string: (nullable): caller-owned string to be duplicated for the #GValue
1024 : : *
1025 : : * Set the contents of a %G_TYPE_STRING #GValue to a copy of @v_string.
1026 : : */
1027 : : void
1028 : 709 : g_value_set_string (GValue *value,
1029 : : const gchar *v_string)
1030 : : {
1031 : : gchar *new_val;
1032 : :
1033 : 709 : g_return_if_fail (G_VALUE_HOLDS_STRING (value));
1034 : :
1035 : 709 : new_val = g_strdup (v_string);
1036 : :
1037 [ + + ]: 709 : if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)
1038 : 1 : value->data[1].v_uint = 0;
1039 : : else
1040 : 708 : g_free (value->data[0].v_pointer);
1041 : :
1042 : 709 : value->data[0].v_pointer = new_val;
1043 : : }
1044 : :
1045 : : /**
1046 : : * g_value_set_static_string:
1047 : : * @value: a valid #GValue of type %G_TYPE_STRING
1048 : : * @v_string: (nullable): static string to be set
1049 : : *
1050 : : * Set the contents of a %G_TYPE_STRING #GValue to @v_string.
1051 : : * The string is assumed to be static, and is thus not duplicated
1052 : : * when setting the #GValue.
1053 : : *
1054 : : * If the the string is a canonical string, using g_value_set_interned_string()
1055 : : * is more appropriate.
1056 : : */
1057 : : void
1058 : 7 : g_value_set_static_string (GValue *value,
1059 : : const gchar *v_string)
1060 : : {
1061 : 7 : g_return_if_fail (G_VALUE_HOLDS_STRING (value));
1062 : :
1063 [ + + ]: 7 : if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
1064 : 6 : g_free (value->data[0].v_pointer);
1065 : 7 : value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
1066 : 7 : value->data[0].v_pointer = (gchar*) v_string;
1067 : : }
1068 : :
1069 : : /**
1070 : : * g_value_set_interned_string:
1071 : : * @value: a valid #GValue of type %G_TYPE_STRING
1072 : : * @v_string: (nullable): static string to be set
1073 : : *
1074 : : * Set the contents of a %G_TYPE_STRING #GValue to @v_string. The string is
1075 : : * assumed to be static and interned (canonical, for example from
1076 : : * g_intern_string()), and is thus not duplicated when setting the #GValue.
1077 : : *
1078 : : * Since: 2.66
1079 : : */
1080 : : void
1081 : 4 : g_value_set_interned_string (GValue *value,
1082 : : const gchar *v_string)
1083 : : {
1084 : 4 : g_return_if_fail (G_VALUE_HOLDS_STRING (value));
1085 : :
1086 [ + + ]: 4 : if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
1087 : 3 : g_free (value->data[0].v_pointer);
1088 : 4 : value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS | G_VALUE_INTERNED_STRING;
1089 : 4 : value->data[0].v_pointer = (gchar *) v_string;
1090 : : }
1091 : :
1092 : : /**
1093 : : * g_value_set_string_take_ownership:
1094 : : * @value: a valid #GValue of type %G_TYPE_STRING
1095 : : * @v_string: (nullable): duplicated unowned string to be set
1096 : : *
1097 : : * This is an internal function introduced mainly for C marshallers.
1098 : : *
1099 : : * Deprecated: 2.4: Use g_value_take_string() instead.
1100 : : */
1101 : : void
1102 : 0 : g_value_set_string_take_ownership (GValue *value,
1103 : : gchar *v_string)
1104 : : {
1105 : 0 : g_value_take_string (value, v_string);
1106 : 0 : }
1107 : :
1108 : : /**
1109 : : * g_value_take_string:
1110 : : * @value: a valid #GValue of type %G_TYPE_STRING
1111 : : * @v_string: (nullable) (transfer full): string to take ownership of
1112 : : *
1113 : : * Sets the contents of a %G_TYPE_STRING #GValue to @v_string.
1114 : : *
1115 : : * Since: 2.4
1116 : : */
1117 : : void
1118 : 2262889 : g_value_take_string (GValue *value,
1119 : : gchar *v_string)
1120 : : {
1121 : 2262889 : g_return_if_fail (G_VALUE_HOLDS_STRING (value));
1122 : :
1123 [ + + ]: 2262889 : if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)
1124 : 1 : value->data[1].v_uint = 0;
1125 : : else
1126 : 2262888 : g_free (value->data[0].v_pointer);
1127 : 2262955 : value->data[0].v_pointer = v_string;
1128 : : }
1129 : :
1130 : : /**
1131 : : * g_value_get_string:
1132 : : * @value: a valid #GValue of type %G_TYPE_STRING
1133 : : *
1134 : : * Get the contents of a %G_TYPE_STRING #GValue.
1135 : : *
1136 : : * Returns: (nullable) (transfer none): string content of @value
1137 : : */
1138 : : const gchar*
1139 : 104202 : g_value_get_string (const GValue *value)
1140 : : {
1141 : 104202 : g_return_val_if_fail (G_VALUE_HOLDS_STRING (value), NULL);
1142 : :
1143 : 104202 : return value->data[0].v_pointer;
1144 : : }
1145 : :
1146 : : /**
1147 : : * g_value_dup_string:
1148 : : * @value: a valid #GValue of type %G_TYPE_STRING
1149 : : *
1150 : : * Get a copy the contents of a %G_TYPE_STRING #GValue.
1151 : : *
1152 : : * Returns: (nullable) (transfer full): a newly allocated copy of the string content of @value
1153 : : */
1154 : : gchar*
1155 : 568640 : g_value_dup_string (const GValue *value)
1156 : : {
1157 : 568640 : g_return_val_if_fail (G_VALUE_HOLDS_STRING (value), NULL);
1158 : :
1159 : 1137280 : return g_strdup (value->data[0].v_pointer);
1160 : : }
1161 : :
1162 : : /**
1163 : : * g_value_steal_string:
1164 : : * @value: a valid #GValue of type %G_TYPE_STRING
1165 : : *
1166 : : * Steal ownership on contents of a %G_TYPE_STRING #GValue.
1167 : : * As a result of this operation the value's contents will be reset to %NULL.
1168 : : *
1169 : : * The purpose of this call is to provide a way to avoid an extra copy
1170 : : * when some object have been serialized into string through #GValue API.
1171 : : *
1172 : : * NOTE: for safety and compatibility purposes, if #GValue contains
1173 : : * static string, or an interned one, this function will return a copy
1174 : : * of the string. Otherwise the transfer notation would be ambiguous.
1175 : : *
1176 : : * Returns: (nullable) (transfer full): string content of @value;
1177 : : * Should be freed with g_free() when no longer needed.
1178 : : *
1179 : : * Since: 2.80
1180 : : */
1181 : : gchar*
1182 : 3 : g_value_steal_string (GValue *value)
1183 : : {
1184 : : gchar *ret;
1185 : :
1186 : 3 : g_return_val_if_fail (G_VALUE_HOLDS_STRING (value), NULL);
1187 : :
1188 : 3 : ret = value->data[0].v_pointer;
1189 : 3 : value->data[0].v_pointer = NULL;
1190 : :
1191 [ + + ]: 3 : if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)
1192 : 1 : return g_strdup (ret);
1193 : :
1194 : 2 : return ret;
1195 : : }
1196 : :
1197 : : /**
1198 : : * g_value_set_pointer:
1199 : : * @value: a valid #GValue of %G_TYPE_POINTER
1200 : : * @v_pointer: pointer value to be set
1201 : : *
1202 : : * Set the contents of a pointer #GValue to @v_pointer.
1203 : : */
1204 : : void
1205 : 8 : g_value_set_pointer (GValue *value,
1206 : : gpointer v_pointer)
1207 : : {
1208 : 8 : g_return_if_fail (G_VALUE_HOLDS_POINTER (value));
1209 : :
1210 : 8 : value->data[0].v_pointer = v_pointer;
1211 : : }
1212 : :
1213 : : /**
1214 : : * g_value_get_pointer:
1215 : : * @value: a valid #GValue of %G_TYPE_POINTER
1216 : : *
1217 : : * Get the contents of a pointer #GValue.
1218 : : *
1219 : : * Returns: (transfer none): pointer contents of @value
1220 : : */
1221 : : gpointer
1222 : 1674180 : g_value_get_pointer (const GValue *value)
1223 : : {
1224 : 1674180 : g_return_val_if_fail (G_VALUE_HOLDS_POINTER (value), NULL);
1225 : :
1226 : 1674180 : return value->data[0].v_pointer;
1227 : : }
1228 : :
1229 [ + + + - : 1102 : G_DEFINE_POINTER_TYPE (GType, g_gtype)
+ + ]
1230 : :
1231 : : /**
1232 : : * g_value_set_gtype:
1233 : : * @value: a valid #GValue of type %G_TYPE_GTYPE
1234 : : * @v_gtype: #GType to be set
1235 : : *
1236 : : * Set the contents of a %G_TYPE_GTYPE #GValue to @v_gtype.
1237 : : *
1238 : : * Since: 2.12
1239 : : */
1240 : : void
1241 : 9 : g_value_set_gtype (GValue *value,
1242 : : GType v_gtype)
1243 : : {
1244 : 9 : g_return_if_fail (G_VALUE_HOLDS_GTYPE (value));
1245 : :
1246 : 9 : value->data[0].v_pointer = GTYPE_TO_POINTER (v_gtype);
1247 : :
1248 : : }
1249 : :
1250 : : /**
1251 : : * g_value_get_gtype:
1252 : : * @value: a valid #GValue of type %G_TYPE_GTYPE
1253 : : *
1254 : : * Get the contents of a %G_TYPE_GTYPE #GValue.
1255 : : *
1256 : : * Since: 2.12
1257 : : *
1258 : : * Returns: the #GType stored in @value
1259 : : */
1260 : : GType
1261 : 71 : g_value_get_gtype (const GValue *value)
1262 : : {
1263 : 71 : g_return_val_if_fail (G_VALUE_HOLDS_GTYPE (value), 0);
1264 : :
1265 : 71 : return GPOINTER_TO_TYPE (value->data[0].v_pointer);
1266 : : }
1267 : :
1268 : : /**
1269 : : * g_value_set_variant:
1270 : : * @value: a valid #GValue of type %G_TYPE_VARIANT
1271 : : * @variant: (nullable): a #GVariant, or %NULL
1272 : : *
1273 : : * Set the contents of a variant #GValue to @variant.
1274 : : * If the variant is floating, it is consumed.
1275 : : *
1276 : : * Since: 2.26
1277 : : */
1278 : : void
1279 : 95 : g_value_set_variant (GValue *value,
1280 : : GVariant *variant)
1281 : : {
1282 : : GVariant *old_variant;
1283 : :
1284 : 95 : g_return_if_fail (G_VALUE_HOLDS_VARIANT (value));
1285 : :
1286 : 95 : old_variant = value->data[0].v_pointer;
1287 : :
1288 [ + + ]: 95 : if (variant)
1289 : 90 : value->data[0].v_pointer = g_variant_ref_sink (variant);
1290 : : else
1291 : 5 : value->data[0].v_pointer = NULL;
1292 : :
1293 [ - + ]: 95 : if (old_variant)
1294 : 0 : g_variant_unref (old_variant);
1295 : : }
1296 : :
1297 : : /**
1298 : : * g_value_take_variant:
1299 : : * @value: a valid #GValue of type %G_TYPE_VARIANT
1300 : : * @variant: (nullable) (transfer full): a #GVariant, or %NULL
1301 : : *
1302 : : * Set the contents of a variant #GValue to @variant, and takes over
1303 : : * the ownership of the caller's reference to @variant;
1304 : : * the caller doesn't have to unref it any more (i.e. the reference
1305 : : * count of the variant is not increased).
1306 : : *
1307 : : * If @variant was floating then its floating reference is converted to
1308 : : * a hard reference.
1309 : : *
1310 : : * If you want the #GValue to hold its own reference to @variant, use
1311 : : * g_value_set_variant() instead.
1312 : : *
1313 : : * This is an internal function introduced mainly for C marshallers.
1314 : : *
1315 : : * Since: 2.26
1316 : : */
1317 : : void
1318 : 9 : g_value_take_variant (GValue *value,
1319 : : GVariant *variant)
1320 : : {
1321 : : GVariant *old_variant;
1322 : :
1323 : 9 : g_return_if_fail (G_VALUE_HOLDS_VARIANT (value));
1324 : :
1325 : 9 : old_variant = value->data[0].v_pointer;
1326 : :
1327 [ + + ]: 9 : if (variant)
1328 : 7 : value->data[0].v_pointer = g_variant_take_ref (variant);
1329 : : else
1330 : 2 : value->data[0].v_pointer = NULL;
1331 : :
1332 [ - + ]: 9 : if (old_variant)
1333 : 0 : g_variant_unref (old_variant);
1334 : : }
1335 : :
1336 : : /**
1337 : : * g_value_get_variant:
1338 : : * @value: a valid #GValue of type %G_TYPE_VARIANT
1339 : : *
1340 : : * Get the contents of a variant #GValue.
1341 : : *
1342 : : * Returns: (transfer none) (nullable): variant contents of @value (may be %NULL)
1343 : : *
1344 : : * Since: 2.26
1345 : : */
1346 : : GVariant*
1347 : 357 : g_value_get_variant (const GValue *value)
1348 : : {
1349 : 357 : g_return_val_if_fail (G_VALUE_HOLDS_VARIANT (value), NULL);
1350 : :
1351 : 357 : return value->data[0].v_pointer;
1352 : : }
1353 : :
1354 : : /**
1355 : : * g_value_dup_variant:
1356 : : * @value: a valid #GValue of type %G_TYPE_VARIANT
1357 : : *
1358 : : * Get the contents of a variant #GValue, increasing its refcount. The returned
1359 : : * #GVariant is never floating.
1360 : : *
1361 : : * Returns: (transfer full) (nullable): variant contents of @value (may be %NULL);
1362 : : * should be unreffed using g_variant_unref() when no longer needed
1363 : : *
1364 : : * Since: 2.26
1365 : : */
1366 : : GVariant*
1367 : 291 : g_value_dup_variant (const GValue *value)
1368 : : {
1369 : : GVariant *variant;
1370 : :
1371 : 291 : g_return_val_if_fail (G_VALUE_HOLDS_VARIANT (value), NULL);
1372 : :
1373 : 291 : variant = value->data[0].v_pointer;
1374 [ + + ]: 291 : if (variant)
1375 : 68 : g_variant_ref_sink (variant);
1376 : :
1377 : 291 : return variant;
1378 : : }
1379 : :
1380 : : /**
1381 : : * g_strdup_value_contents:
1382 : : * @value: #GValue which contents are to be described.
1383 : : *
1384 : : * Return a newly allocated string, which describes the contents of a
1385 : : * #GValue. The main purpose of this function is to describe #GValue
1386 : : * contents for debugging output, the way in which the contents are
1387 : : * described may change between different GLib versions.
1388 : : *
1389 : : * Returns: Newly allocated string.
1390 : : */
1391 : : gchar*
1392 : 0 : g_strdup_value_contents (const GValue *value)
1393 : : {
1394 : : const gchar *src;
1395 : : gchar *contents;
1396 : :
1397 : 0 : g_return_val_if_fail (G_IS_VALUE (value), NULL);
1398 : :
1399 [ # # # # : 0 : if (G_VALUE_HOLDS_STRING (value))
# # ]
1400 : : {
1401 : 0 : src = g_value_get_string (value);
1402 : :
1403 [ # # ]: 0 : if (!src)
1404 : 0 : contents = g_strdup ("NULL");
1405 : : else
1406 : : {
1407 : 0 : gchar *s = g_strescape (src, NULL);
1408 : :
1409 : 0 : contents = g_strdup_printf ("\"%s\"", s);
1410 : 0 : g_free (s);
1411 : : }
1412 : : }
1413 [ # # ]: 0 : else if (g_value_type_transformable (G_VALUE_TYPE (value), G_TYPE_STRING))
1414 : : {
1415 : 0 : GValue tmp_value = G_VALUE_INIT;
1416 : : gchar *s;
1417 : :
1418 : 0 : g_value_init (&tmp_value, G_TYPE_STRING);
1419 : 0 : g_value_transform (value, &tmp_value);
1420 : 0 : s = g_strescape (g_value_get_string (&tmp_value), NULL);
1421 : 0 : g_value_unset (&tmp_value);
1422 [ # # # # : 0 : if (G_VALUE_HOLDS_ENUM (value) || G_VALUE_HOLDS_FLAGS (value))
# # # # #
# # # ]
1423 : 0 : contents = g_strdup_printf ("((%s) %s)",
1424 : : g_type_name (G_VALUE_TYPE (value)),
1425 : : s);
1426 : : else
1427 [ # # ]: 0 : contents = g_strdup (s ? s : "NULL");
1428 : 0 : g_free (s);
1429 : : }
1430 [ # # ]: 0 : else if (g_value_fits_pointer (value))
1431 : : {
1432 : 0 : gpointer p = g_value_peek_pointer (value);
1433 : :
1434 [ # # ]: 0 : if (!p)
1435 : 0 : contents = g_strdup ("NULL");
1436 [ # # # # : 0 : else if (G_VALUE_HOLDS_OBJECT (value))
# # ]
1437 : 0 : contents = g_strdup_printf ("((%s*) %p)", G_OBJECT_TYPE_NAME (p), p);
1438 [ # # # # : 0 : else if (G_VALUE_HOLDS_PARAM (value))
# # ]
1439 : 0 : contents = g_strdup_printf ("((%s*) %p)", G_PARAM_SPEC_TYPE_NAME (p), p);
1440 [ # # # # : 0 : else if (G_VALUE_HOLDS (value, G_TYPE_STRV))
# # ]
1441 : : {
1442 : 0 : GStrv strv = g_value_get_boxed (value);
1443 : 0 : GString *tmp = g_string_new ("[");
1444 : :
1445 [ # # ]: 0 : while (*strv != NULL)
1446 : : {
1447 : 0 : gchar *escaped = g_strescape (*strv, NULL);
1448 : :
1449 : 0 : g_string_append_printf (tmp, "\"%s\"", escaped);
1450 : 0 : g_free (escaped);
1451 : :
1452 [ # # ]: 0 : if (*++strv != NULL)
1453 [ # # ]: 0 : g_string_append (tmp, ", ");
1454 : : }
1455 : :
1456 [ # # ]: 0 : g_string_append (tmp, "]");
1457 : 0 : contents = g_string_free (tmp, FALSE);
1458 : : }
1459 [ # # # # : 0 : else if (G_VALUE_HOLDS_BOXED (value))
# # ]
1460 : 0 : contents = g_strdup_printf ("((%s*) %p)", g_type_name (G_VALUE_TYPE (value)), p);
1461 [ # # # # : 0 : else if (G_VALUE_HOLDS_POINTER (value))
# # ]
1462 : 0 : contents = g_strdup_printf ("((gpointer) %p)", p);
1463 : : else
1464 : 0 : contents = g_strdup ("???");
1465 : : }
1466 : : else
1467 : 0 : contents = g_strdup ("???");
1468 : :
1469 : 0 : return contents;
1470 : : }
1471 : :
1472 : : /**
1473 : : * g_pointer_type_register_static:
1474 : : * @name: the name of the new pointer type.
1475 : : *
1476 : : * Creates a new %G_TYPE_POINTER derived type id for a new
1477 : : * pointer type with name @name.
1478 : : *
1479 : : * Returns: a new %G_TYPE_POINTER derived type id for @name.
1480 : : */
1481 : : GType
1482 : 509 : g_pointer_type_register_static (const gchar *name)
1483 : : {
1484 : 509 : const GTypeInfo type_info = {
1485 : : 0, /* class_size */
1486 : : NULL, /* base_init */
1487 : : NULL, /* base_finalize */
1488 : : NULL, /* class_init */
1489 : : NULL, /* class_finalize */
1490 : : NULL, /* class_data */
1491 : : 0, /* instance_size */
1492 : : 0, /* n_preallocs */
1493 : : NULL, /* instance_init */
1494 : : NULL /* value_table */
1495 : : };
1496 : : GType type;
1497 : :
1498 : 509 : g_return_val_if_fail (name != NULL, 0);
1499 : 509 : g_return_val_if_fail (g_type_from_name (name) == 0, 0);
1500 : :
1501 : 509 : type = g_type_register_static (G_TYPE_POINTER, name, &type_info, 0);
1502 : :
1503 : 509 : return type;
1504 : : }
|