LCOV - code coverage report
Current view: top level - glib/gobject - gboxed.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 152 173 87.9 %
Date: 2024-04-23 05:16:05 Functions: 94 97 96.9 %
Branches: 158 260 60.8 %

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

Generated by: LCOV version 1.14