Branch data Line data Source code
1 : : /* GObject - GLib Type, Object, Parameter and Signal Library
2 : : * Copyright (C) 2000-2001 Red Hat, Inc.
3 : : *
4 : : * SPDX-License-Identifier: LGPL-2.1-or-later
5 : : *
6 : : * This library is free software; you can redistribute it and/or
7 : : * modify it under the terms of the GNU Lesser General Public
8 : : * License as published by the Free Software Foundation; either
9 : : * version 2.1 of the License, or (at your option) any later version.
10 : : *
11 : : * This library is distributed in the hope that it will be useful,
12 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 : : * Lesser General Public License for more details.
15 : : *
16 : : * You should have received a copy of the GNU Lesser General
17 : : * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 : : */
19 : :
20 : : #include "config.h"
21 : :
22 : : #include <string.h>
23 : :
24 : : /* for GValueArray */
25 : : #ifndef GLIB_DISABLE_DEPRECATION_WARNINGS
26 : : #define GLIB_DISABLE_DEPRECATION_WARNINGS
27 : : #endif
28 : :
29 : : #include "gboxed.h"
30 : : #include "gclosure.h"
31 : : #include "gtype-private.h"
32 : : #include "gvalue.h"
33 : : #include "gvaluearray.h"
34 : : #include "gvaluecollector.h"
35 : :
36 : : static inline void /* keep this function in sync with gvalue.c */
37 : 0 : value_meminit (GValue *value,
38 : : GType value_type)
39 : : {
40 : 0 : value->g_type = value_type;
41 : 0 : memset (value->data, 0, sizeof (value->data));
42 : 0 : }
43 : :
44 : : static GValue *
45 : 13 : value_copy (GValue *src_value)
46 : : {
47 : 13 : GValue *dest_value = g_new0 (GValue, 1);
48 : :
49 [ + - ]: 13 : if (G_VALUE_TYPE (src_value))
50 : : {
51 : 13 : g_value_init (dest_value, G_VALUE_TYPE (src_value));
52 : 13 : g_value_copy (src_value, dest_value);
53 : : }
54 : 13 : return dest_value;
55 : : }
56 : :
57 : : static void
58 : 13 : value_free (GValue *value)
59 : : {
60 [ + - ]: 13 : if (G_VALUE_TYPE (value))
61 : 13 : g_value_unset (value);
62 : 13 : g_free (value);
63 : 13 : }
64 : :
65 : : static GPollFD *
66 : 1 : pollfd_copy (GPollFD *src)
67 : : {
68 : 1 : GPollFD *dest = g_new0 (GPollFD, 1);
69 : : /* just a couple of integers */
70 : 1 : memcpy (dest, src, sizeof (GPollFD));
71 : 1 : return dest;
72 : : }
73 : :
74 : : void
75 : 508 : _g_boxed_type_init (void)
76 : : {
77 : 508 : const GTypeInfo info = {
78 : : 0, /* class_size */
79 : : NULL, /* base_init */
80 : : NULL, /* base_destroy */
81 : : NULL, /* class_init */
82 : : NULL, /* class_destroy */
83 : : NULL, /* class_data */
84 : : 0, /* instance_size */
85 : : 0, /* n_preallocs */
86 : : NULL, /* instance_init */
87 : : NULL, /* value_table */
88 : : };
89 : 508 : const GTypeFundamentalInfo finfo = { G_TYPE_FLAG_DERIVABLE, };
90 : : GType type G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
91 : :
92 : : /* G_TYPE_BOXED
93 : : */
94 : 508 : type = g_type_register_fundamental (G_TYPE_BOXED, g_intern_static_string ("GBoxed"), &info, &finfo,
95 : : G_TYPE_FLAG_ABSTRACT | G_TYPE_FLAG_VALUE_ABSTRACT);
96 : 508 : g_assert (type == G_TYPE_BOXED);
97 : 508 : }
98 : :
99 : : static GString *
100 : 1 : gstring_copy (GString *src_gstring)
101 : : {
102 : 1 : return g_string_new_len (src_gstring->str, src_gstring->len);
103 : : }
104 : :
105 : : static void
106 : 1 : gstring_free (GString *gstring)
107 : : {
108 : 1 : g_string_free (gstring, TRUE);
109 : 1 : }
110 : :
111 [ + - + - : 4 : G_DEFINE_BOXED_TYPE (GClosure, g_closure, g_closure_ref, g_closure_unref)
+ - ]
112 [ + + + - : 19 : G_DEFINE_BOXED_TYPE (GValue, g_value, value_copy, value_free)
+ + ]
113 [ + + + - : 1017 : G_DEFINE_BOXED_TYPE (GValueArray, g_value_array, g_value_array_copy, g_value_array_free)
+ + ]
114 [ + - + - : 4 : G_DEFINE_BOXED_TYPE (GDate, g_date, g_date_copy, g_date_free)
+ - ]
115 : : /* the naming is a bit odd, but GString is obviously not G_TYPE_STRING */
116 [ + - + - : 4 : G_DEFINE_BOXED_TYPE (GString, g_gstring, gstring_copy, gstring_free)
+ - ]
117 [ + - + - : 4 : G_DEFINE_BOXED_TYPE (GHashTable, g_hash_table, g_hash_table_ref, g_hash_table_unref)
+ - ]
118 [ + + + - : 7 : G_DEFINE_BOXED_TYPE (GArray, g_array, g_array_ref, g_array_unref)
+ + ]
119 [ + + + - : 7 : G_DEFINE_BOXED_TYPE (GPtrArray, g_ptr_array,g_ptr_array_ref, g_ptr_array_unref)
+ + ]
120 [ + + + - : 240 : G_DEFINE_BOXED_TYPE (GByteArray, g_byte_array, g_byte_array_ref, g_byte_array_unref)
+ + ]
121 [ + + + - : 12 : G_DEFINE_BOXED_TYPE (GBytes, g_bytes, g_bytes_ref, g_bytes_unref)
+ + ]
122 [ + - + - : 4 : G_DEFINE_BOXED_TYPE (GTree, g_tree, g_tree_ref, g_tree_unref)
+ - ]
123 : :
124 [ + - + - : 4 : G_DEFINE_BOXED_TYPE (GRegex, g_regex, g_regex_ref, g_regex_unref)
+ - ]
125 [ + - + - : 4 : G_DEFINE_BOXED_TYPE (GMatchInfo, g_match_info, g_match_info_ref, g_match_info_unref)
+ - ]
126 : :
127 : : #define g_variant_type_get_type g_variant_type_get_gtype
128 [ + + + - : 40 : G_DEFINE_BOXED_TYPE (GVariantType, g_variant_type, g_variant_type_copy, g_variant_type_free)
+ + ]
129 : : #undef g_variant_type_get_type
130 : :
131 [ + - + - : 4 : G_DEFINE_BOXED_TYPE (GVariantBuilder, g_variant_builder, g_variant_builder_ref, g_variant_builder_unref)
+ - ]
132 [ + + + - : 25 : G_DEFINE_BOXED_TYPE (GVariantDict, g_variant_dict, g_variant_dict_ref, g_variant_dict_unref)
+ + ]
133 : :
134 [ + - + - : 248 : G_DEFINE_BOXED_TYPE (GError, g_error, g_error_copy, g_error_free)
+ - ]
135 : :
136 [ + + + - : 9 : G_DEFINE_BOXED_TYPE (GDateTime, g_date_time, g_date_time_ref, g_date_time_unref)
+ + ]
137 [ + - + - : 4 : G_DEFINE_BOXED_TYPE (GTimeZone, g_time_zone, g_time_zone_ref, g_time_zone_unref)
+ - ]
138 [ + - + - : 4 : G_DEFINE_BOXED_TYPE (GKeyFile, g_key_file, g_key_file_ref, g_key_file_unref)
+ - ]
139 [ + - + - : 2 : G_DEFINE_BOXED_TYPE (GMappedFile, g_mapped_file, g_mapped_file_ref, g_mapped_file_unref)
+ - ]
140 [ + - + - : 2 : G_DEFINE_BOXED_TYPE (GBookmarkFile, g_bookmark_file, g_bookmark_file_copy, g_bookmark_file_free)
+ - ]
141 [ + - + - : 2 : G_DEFINE_BOXED_TYPE (GHmac, g_hmac, g_hmac_ref, g_hmac_unref)
+ - ]
142 : :
143 [ + - + - : 4 : G_DEFINE_BOXED_TYPE (GMainLoop, g_main_loop, g_main_loop_ref, g_main_loop_unref)
+ - ]
144 [ + - + - : 4 : G_DEFINE_BOXED_TYPE (GMainContext, g_main_context, g_main_context_ref, g_main_context_unref)
+ - ]
145 [ + - + - : 4 : G_DEFINE_BOXED_TYPE (GSource, g_source, g_source_ref, g_source_unref)
+ - ]
146 [ + - + - : 4 : G_DEFINE_BOXED_TYPE (GPollFD, g_pollfd, pollfd_copy, g_free)
+ - ]
147 [ + - + - : 4 : G_DEFINE_BOXED_TYPE (GMarkupParseContext, g_markup_parse_context, g_markup_parse_context_ref, g_markup_parse_context_unref)
+ - ]
148 : :
149 [ + - + - : 4 : G_DEFINE_BOXED_TYPE (GThread, g_thread, g_thread_ref, g_thread_unref)
+ - ]
150 [ + - + - : 4 : G_DEFINE_BOXED_TYPE (GChecksum, g_checksum, g_checksum_copy, g_checksum_free)
+ - ]
151 [ + - + - : 2 : G_DEFINE_BOXED_TYPE (GUri, g_uri, g_uri_ref, g_uri_unref)
+ - ]
152 : :
153 [ + - + - : 2 : G_DEFINE_BOXED_TYPE (GOptionGroup, g_option_group, g_option_group_ref, g_option_group_unref)
+ - ]
154 [ + - + - : 4 : G_DEFINE_BOXED_TYPE (GPatternSpec, g_pattern_spec, g_pattern_spec_copy, g_pattern_spec_free);
+ - ]
155 : :
156 : : /* This one can't use G_DEFINE_BOXED_TYPE (GStrv, g_strv, g_strdupv, g_strfreev) */
157 : : GType
158 : 355 : g_strv_get_type (void)
159 : : {
160 : : static GType static_g_define_type_id = 0;
161 : :
162 [ + + + - : 355 : if (g_once_init_enter_pointer (&static_g_define_type_id))
+ + ]
163 : : {
164 : : GType g_define_type_id =
165 : 158 : g_boxed_type_register_static (g_intern_static_string ("GStrv"),
166 : : (GBoxedCopyFunc) g_strdupv,
167 : : (GBoxedFreeFunc) g_strfreev);
168 : :
169 : 158 : g_once_init_leave_pointer (&static_g_define_type_id, g_define_type_id);
170 : : }
171 : :
172 : 355 : return static_g_define_type_id;
173 : : }
174 : :
175 : : GType
176 : 0 : g_variant_get_gtype (void)
177 : : {
178 : 0 : return G_TYPE_VARIANT;
179 : : }
180 : :
181 : : static void
182 : 742 : boxed_proxy_value_init (GValue *value)
183 : : {
184 : 742 : value->data[0].v_pointer = NULL;
185 : 742 : }
186 : :
187 : : static void
188 : 1534 : boxed_proxy_value_free (GValue *value)
189 : : {
190 [ + + + + ]: 1534 : if (value->data[0].v_pointer && !(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
191 : 140 : _g_type_boxed_free (G_VALUE_TYPE (value), value->data[0].v_pointer);
192 : 1534 : }
193 : :
194 : : static void
195 : 123 : boxed_proxy_value_copy (const GValue *src_value,
196 : : GValue *dest_value)
197 : : {
198 [ + + ]: 123 : if (src_value->data[0].v_pointer)
199 : 12 : dest_value->data[0].v_pointer = _g_type_boxed_copy (G_VALUE_TYPE (src_value), src_value->data[0].v_pointer);
200 : : else
201 : 111 : dest_value->data[0].v_pointer = src_value->data[0].v_pointer;
202 : 123 : }
203 : :
204 : : static gpointer
205 : 0 : boxed_proxy_value_peek_pointer (const GValue *value)
206 : : {
207 : 0 : return value->data[0].v_pointer;
208 : : }
209 : :
210 : : static gchar*
211 : 852 : boxed_proxy_collect_value (GValue *value,
212 : : guint n_collect_values,
213 : : GTypeCValue *collect_values,
214 : : guint collect_flags)
215 : : {
216 [ + + ]: 852 : if (!collect_values[0].v_pointer)
217 : 395 : value->data[0].v_pointer = NULL;
218 : : else
219 : : {
220 [ + + ]: 457 : if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
221 : : {
222 : 423 : value->data[0].v_pointer = collect_values[0].v_pointer;
223 : 423 : value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
224 : : }
225 : : else
226 : 34 : value->data[0].v_pointer = _g_type_boxed_copy (G_VALUE_TYPE (value), collect_values[0].v_pointer);
227 : : }
228 : :
229 : 852 : return NULL;
230 : : }
231 : :
232 : : static gchar*
233 : 43 : boxed_proxy_lcopy_value (const GValue *value,
234 : : guint n_collect_values,
235 : : GTypeCValue *collect_values,
236 : : guint collect_flags)
237 : : {
238 : 43 : gpointer *boxed_p = collect_values[0].v_pointer;
239 : :
240 : 43 : g_return_val_if_fail (boxed_p != NULL, g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value)));
241 : :
242 [ + + ]: 43 : if (!value->data[0].v_pointer)
243 : 5 : *boxed_p = NULL;
244 [ - + ]: 38 : else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
245 : 0 : *boxed_p = value->data[0].v_pointer;
246 : : else
247 : 38 : *boxed_p = _g_type_boxed_copy (G_VALUE_TYPE (value), value->data[0].v_pointer);
248 : :
249 : 43 : return NULL;
250 : : }
251 : :
252 : : /**
253 : : * g_boxed_type_register_static:
254 : : * @name: Name of the new boxed type.
255 : : * @boxed_copy: Boxed structure copy function.
256 : : * @boxed_free: Boxed structure free function.
257 : : *
258 : : * This function creates a new %G_TYPE_BOXED derived type id for a new
259 : : * boxed type with name @name.
260 : : *
261 : : * Boxed type handling functions have to be provided to copy and free
262 : : * opaque boxed structures of this type.
263 : : *
264 : : * For the general case, it is recommended to use G_DEFINE_BOXED_TYPE()
265 : : * instead of calling g_boxed_type_register_static() directly. The macro
266 : : * will create the appropriate `*_get_type()` function for the boxed type.
267 : : *
268 : : * Returns: New %G_TYPE_BOXED derived type id for @name.
269 : : */
270 : : GType
271 : 1131 : g_boxed_type_register_static (const gchar *name,
272 : : GBoxedCopyFunc boxed_copy,
273 : : GBoxedFreeFunc boxed_free)
274 : : {
275 : : static const GTypeValueTable vtable = {
276 : : boxed_proxy_value_init,
277 : : boxed_proxy_value_free,
278 : : boxed_proxy_value_copy,
279 : : boxed_proxy_value_peek_pointer,
280 : : "p",
281 : : boxed_proxy_collect_value,
282 : : "p",
283 : : boxed_proxy_lcopy_value,
284 : : };
285 : 1131 : GTypeInfo type_info = {
286 : : 0, /* class_size */
287 : : NULL, /* base_init */
288 : : NULL, /* base_finalize */
289 : : NULL, /* class_init */
290 : : NULL, /* class_finalize */
291 : : NULL, /* class_data */
292 : : 0, /* instance_size */
293 : : 0, /* n_preallocs */
294 : : NULL, /* instance_init */
295 : : &vtable, /* value_table */
296 : : };
297 : : GType type;
298 : :
299 : 1131 : g_return_val_if_fail (name != NULL, 0);
300 : 1131 : g_return_val_if_fail (boxed_copy != NULL, 0);
301 : 1131 : g_return_val_if_fail (boxed_free != NULL, 0);
302 : 1131 : g_return_val_if_fail (g_type_from_name (name) == 0, 0);
303 : :
304 : 1131 : type = g_type_register_static (G_TYPE_BOXED, name, &type_info, 0);
305 : :
306 : : /* install proxy functions upon successful registration */
307 [ + - ]: 1131 : if (type)
308 : 1131 : _g_type_boxed_init (type, boxed_copy, boxed_free);
309 : :
310 : 1131 : return type;
311 : : }
312 : :
313 : : /**
314 : : * g_boxed_copy:
315 : : * @boxed_type: The type of @src_boxed.
316 : : * @src_boxed: (not nullable): The boxed structure to be copied.
317 : : *
318 : : * Provide a copy of a boxed structure @src_boxed which is of type @boxed_type.
319 : : *
320 : : * Returns: (transfer full) (not nullable): The newly created copy of the boxed
321 : : * structure.
322 : : */
323 : : gpointer
324 : 787 : g_boxed_copy (GType boxed_type,
325 : : gconstpointer src_boxed)
326 : : {
327 : : GTypeValueTable *value_table;
328 : : gpointer dest_boxed;
329 : :
330 : 787 : g_return_val_if_fail (G_TYPE_IS_BOXED (boxed_type), NULL);
331 : 787 : g_return_val_if_fail (G_TYPE_IS_ABSTRACT (boxed_type) == FALSE, NULL);
332 : 787 : g_return_val_if_fail (src_boxed != NULL, NULL);
333 : :
334 : 787 : value_table = g_type_value_table_peek (boxed_type);
335 : 787 : g_assert (value_table != NULL);
336 : :
337 : : /* check if our proxying implementation is used, we can short-cut here */
338 [ + - ]: 787 : if (value_table->value_copy == boxed_proxy_value_copy)
339 : 787 : dest_boxed = _g_type_boxed_copy (boxed_type, (gpointer) src_boxed);
340 : : else
341 : : {
342 : : GValue src_value, dest_value;
343 : :
344 : : /* we heavily rely on third-party boxed type value vtable
345 : : * implementations to follow normal boxed value storage
346 : : * (data[0].v_pointer is the boxed struct, and
347 : : * data[1].v_uint holds the G_VALUE_NOCOPY_CONTENTS flag,
348 : : * rest zero).
349 : : * but then, we can expect that since we laid out the
350 : : * g_boxed_*() API.
351 : : * data[1].v_uint&G_VALUE_NOCOPY_CONTENTS shouldn't be set
352 : : * after a copy.
353 : : */
354 : : /* equiv. to g_value_set_static_boxed() */
355 : 0 : value_meminit (&src_value, boxed_type);
356 : 0 : src_value.data[0].v_pointer = (gpointer) src_boxed;
357 : 0 : src_value.data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
358 : :
359 : : /* call third-party code copy function, fingers-crossed */
360 : 0 : value_meminit (&dest_value, boxed_type);
361 : 0 : value_table->value_copy (&src_value, &dest_value);
362 : :
363 : : /* double check and grouse if things went wrong */
364 [ # # ]: 0 : if (dest_value.data[1].v_ulong)
365 : 0 : g_warning ("the copy_value() implementation of type '%s' seems to make use of reserved GValue fields",
366 : : g_type_name (boxed_type));
367 : :
368 : 0 : dest_boxed = dest_value.data[0].v_pointer;
369 : : }
370 : :
371 : 787 : return dest_boxed;
372 : : }
373 : :
374 : : /**
375 : : * g_boxed_free:
376 : : * @boxed_type: The type of @boxed.
377 : : * @boxed: (not nullable): The boxed structure to be freed.
378 : : *
379 : : * Free the boxed structure @boxed which is of type @boxed_type.
380 : : */
381 : : void
382 : 441 : g_boxed_free (GType boxed_type,
383 : : gpointer boxed)
384 : : {
385 : : GTypeValueTable *value_table;
386 : :
387 : 441 : g_return_if_fail (G_TYPE_IS_BOXED (boxed_type));
388 : 441 : g_return_if_fail (G_TYPE_IS_ABSTRACT (boxed_type) == FALSE);
389 : 441 : g_return_if_fail (boxed != NULL);
390 : :
391 : 441 : value_table = g_type_value_table_peek (boxed_type);
392 : 441 : g_assert (value_table != NULL);
393 : :
394 : : /* check if our proxying implementation is used, we can short-cut here */
395 [ + - ]: 441 : if (value_table->value_free == boxed_proxy_value_free)
396 : 441 : _g_type_boxed_free (boxed_type, boxed);
397 : : else
398 : : {
399 : : GValue value;
400 : :
401 : : /* see g_boxed_copy() on why we think we can do this */
402 : 0 : value_meminit (&value, boxed_type);
403 : 0 : value.data[0].v_pointer = boxed;
404 : 0 : value_table->value_free (&value);
405 : : }
406 : : }
407 : :
408 : : /**
409 : : * g_value_get_boxed:
410 : : * @value: a valid #GValue of %G_TYPE_BOXED derived type
411 : : *
412 : : * Get the contents of a %G_TYPE_BOXED derived #GValue.
413 : : *
414 : : * Returns: (transfer none) (nullable): boxed contents of @value
415 : : */
416 : : gpointer
417 : 2163 : g_value_get_boxed (const GValue *value)
418 : : {
419 : 2163 : g_return_val_if_fail (G_VALUE_HOLDS_BOXED (value), NULL);
420 : 2163 : g_return_val_if_fail (G_TYPE_IS_VALUE (G_VALUE_TYPE (value)), NULL);
421 : :
422 : 2163 : return value->data[0].v_pointer;
423 : : }
424 : :
425 : : /**
426 : : * g_value_dup_boxed: (skip)
427 : : * @value: a valid #GValue of %G_TYPE_BOXED derived type
428 : : *
429 : : * Get the contents of a %G_TYPE_BOXED derived #GValue. Upon getting,
430 : : * the boxed value is duplicated and needs to be later freed with
431 : : * g_boxed_free(), e.g. like: g_boxed_free (G_VALUE_TYPE (@value),
432 : : * return_value);
433 : : *
434 : : * Returns: (transfer full) (nullable): boxed contents of @value
435 : : */
436 : : gpointer
437 : 579 : g_value_dup_boxed (const GValue *value)
438 : : {
439 : 579 : g_return_val_if_fail (G_VALUE_HOLDS_BOXED (value), NULL);
440 : 579 : g_return_val_if_fail (G_TYPE_IS_VALUE (G_VALUE_TYPE (value)), NULL);
441 : :
442 [ + + ]: 579 : return value->data[0].v_pointer ? g_boxed_copy (G_VALUE_TYPE (value), value->data[0].v_pointer) : NULL;
443 : : }
444 : :
445 : : static inline void
446 : 117 : value_set_boxed_internal (GValue *value,
447 : : gconstpointer boxed,
448 : : gboolean need_copy,
449 : : gboolean need_free)
450 : : {
451 [ + + ]: 117 : if (!boxed)
452 : : {
453 : : /* just resetting to NULL might not be desired, need to
454 : : * have value reinitialized also (for values defaulting
455 : : * to other default value states than a NULL data pointer),
456 : : * g_value_reset() will handle this
457 : : */
458 : 9 : g_value_reset (value);
459 : 9 : return;
460 : : }
461 : :
462 [ - + - - ]: 108 : if (value->data[0].v_pointer && !(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
463 : 0 : g_boxed_free (G_VALUE_TYPE (value), value->data[0].v_pointer);
464 [ + + ]: 108 : value->data[1].v_uint = need_free ? 0 : G_VALUE_NOCOPY_CONTENTS;
465 [ + + ]: 108 : value->data[0].v_pointer = need_copy ? g_boxed_copy (G_VALUE_TYPE (value), boxed) : (gpointer) boxed;
466 : : }
467 : :
468 : : /**
469 : : * g_value_set_boxed:
470 : : * @value: a valid #GValue of %G_TYPE_BOXED derived type
471 : : * @v_boxed: (nullable): boxed value to be set
472 : : *
473 : : * Set the contents of a %G_TYPE_BOXED derived #GValue to @v_boxed.
474 : : */
475 : : void
476 : 46 : g_value_set_boxed (GValue *value,
477 : : gconstpointer boxed)
478 : : {
479 : 46 : g_return_if_fail (G_VALUE_HOLDS_BOXED (value));
480 : 46 : g_return_if_fail (G_TYPE_IS_VALUE (G_VALUE_TYPE (value)));
481 : :
482 : 46 : value_set_boxed_internal (value, boxed, TRUE, TRUE);
483 : : }
484 : :
485 : : /**
486 : : * g_value_set_static_boxed:
487 : : * @value: a valid #GValue of %G_TYPE_BOXED derived type
488 : : * @v_boxed: (nullable): static boxed value to be set
489 : : *
490 : : * Set the contents of a %G_TYPE_BOXED derived #GValue to @v_boxed.
491 : : *
492 : : * The boxed value is assumed to be static, and is thus not duplicated
493 : : * when setting the #GValue.
494 : : */
495 : : void
496 : 2 : g_value_set_static_boxed (GValue *value,
497 : : gconstpointer boxed)
498 : : {
499 : 2 : g_return_if_fail (G_VALUE_HOLDS_BOXED (value));
500 : 2 : g_return_if_fail (G_TYPE_IS_VALUE (G_VALUE_TYPE (value)));
501 : :
502 : 2 : value_set_boxed_internal (value, boxed, FALSE, FALSE);
503 : : }
504 : :
505 : : /**
506 : : * g_value_set_boxed_take_ownership:
507 : : * @value: a valid #GValue of %G_TYPE_BOXED derived type
508 : : * @v_boxed: (nullable): duplicated unowned boxed value to be set
509 : : *
510 : : * This is an internal function introduced mainly for C marshallers.
511 : : *
512 : : * Deprecated: 2.4: Use g_value_take_boxed() instead.
513 : : */
514 : : void
515 : 1 : g_value_set_boxed_take_ownership (GValue *value,
516 : : gconstpointer boxed)
517 : : {
518 : 1 : g_value_take_boxed (value, boxed);
519 : 1 : }
520 : :
521 : : /**
522 : : * g_value_take_boxed:
523 : : * @value: a valid #GValue of %G_TYPE_BOXED derived type
524 : : * @v_boxed: (nullable): duplicated unowned boxed value to be set
525 : : *
526 : : * Sets the contents of a %G_TYPE_BOXED derived #GValue to @v_boxed
527 : : * and takes over the ownership of the caller’s reference to @v_boxed;
528 : : * the caller doesn’t have to unref it any more.
529 : : *
530 : : * Since: 2.4
531 : : */
532 : : void
533 : 69 : g_value_take_boxed (GValue *value,
534 : : gconstpointer boxed)
535 : : {
536 : 69 : g_return_if_fail (G_VALUE_HOLDS_BOXED (value));
537 : 69 : g_return_if_fail (G_TYPE_IS_VALUE (G_VALUE_TYPE (value)));
538 : :
539 : 69 : value_set_boxed_internal (value, boxed, FALSE, TRUE);
540 : : }
|