LCOV - code coverage report
Current view: top level - gobject - gboxed.c (source / functions) Coverage Total Hit
Test: unnamed Lines: 87.7 % 171 150
Test Date: 2025-12-09 05:20:19 Functions: 96.9 % 96 93
Branches: - 0 0

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

Generated by: LCOV version 2.0-1