LCOV - code coverage report
Current view: top level - girepository - gifieldinfo.c (source / functions) Coverage Total Hit
Test: unnamed Lines: 6.5 % 247 16
Test Date: 2024-11-26 05:23:01 Functions: 28.6 % 7 2
Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
       2                 :             :  * GObject introspection: Field implementation
       3                 :             :  *
       4                 :             :  * Copyright (C) 2005 Matthias Clasen
       5                 :             :  * Copyright (C) 2008,2009 Red Hat, Inc.
       6                 :             :  *
       7                 :             :  * SPDX-License-Identifier: LGPL-2.1-or-later
       8                 :             :  *
       9                 :             :  * This library is free software; you can redistribute it and/or
      10                 :             :  * modify it under the terms of the GNU Lesser General Public
      11                 :             :  * License as published by the Free Software Foundation; either
      12                 :             :  * version 2 of the License, or (at your option) any later version.
      13                 :             :  *
      14                 :             :  * This library is distributed in the hope that it will be useful,
      15                 :             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16                 :             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17                 :             :  * Lesser General Public License for more details.
      18                 :             :  *
      19                 :             :  * You should have received a copy of the GNU Lesser General Public
      20                 :             :  * License along with this library; if not, write to the
      21                 :             :  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      22                 :             :  * Boston, MA 02111-1307, USA.
      23                 :             :  */
      24                 :             : 
      25                 :             : #include "config.h"
      26                 :             : 
      27                 :             : #include <glib.h>
      28                 :             : 
      29                 :             : #include <girepository/girepository.h>
      30                 :             : #include "gibaseinfo-private.h"
      31                 :             : #include "girepository-private.h"
      32                 :             : #include "gitypelib-internal.h"
      33                 :             : #include "config.h"
      34                 :             : #include "gifieldinfo.h"
      35                 :             : 
      36                 :             : /**
      37                 :             :  * GIFieldInfo:
      38                 :             :  *
      39                 :             :  * A `GIFieldInfo` struct represents a field of a struct, union, or object.
      40                 :             :  *
      41                 :             :  * The `GIFieldInfo` is fetched by calling
      42                 :             :  * [method@GIRepository.StructInfo.get_field],
      43                 :             :  * [method@GIRepository.UnionInfo.get_field] or
      44                 :             :  * [method@GIRepository.ObjectInfo.get_field].
      45                 :             :  *
      46                 :             :  * A field has a size, type and a struct offset associated and a set of flags,
      47                 :             :  * which are currently `GI_FIELD_IS_READABLE` or `GI_FIELD_IS_WRITABLE`.
      48                 :             :  *
      49                 :             :  * See also: [type@GIRepository.StructInfo], [type@GIRepository.UnionInfo],
      50                 :             :  * [type@GIRepository.ObjectInfo]
      51                 :             :  *
      52                 :             :  * Since: 2.80
      53                 :             :  */
      54                 :             : 
      55                 :             : /**
      56                 :             :  * gi_field_info_get_flags:
      57                 :             :  * @info: a #GIFieldInfo
      58                 :             :  *
      59                 :             :  * Obtain the flags for this `GIFieldInfo`. See
      60                 :             :  * [flags@GIRepository.FieldInfoFlags] for possible flag values.
      61                 :             :  *
      62                 :             :  * Returns: the flags
      63                 :             :  * Since: 2.80
      64                 :             :  */
      65                 :             : GIFieldInfoFlags
      66                 :           0 : gi_field_info_get_flags (GIFieldInfo *info)
      67                 :             : {
      68                 :             :   GIFieldInfoFlags flags;
      69                 :           0 :   GIRealInfo *rinfo = (GIRealInfo *)info;
      70                 :             :   FieldBlob *blob;
      71                 :             : 
      72                 :           0 :   g_return_val_if_fail (info != NULL, 0);
      73                 :           0 :   g_return_val_if_fail (GI_IS_FIELD_INFO (info), 0);
      74                 :             : 
      75                 :           0 :   blob = (FieldBlob *)&rinfo->typelib->data[rinfo->offset];
      76                 :             : 
      77                 :           0 :   flags = 0;
      78                 :             : 
      79                 :           0 :   if (blob->readable)
      80                 :           0 :     flags = flags | GI_FIELD_IS_READABLE;
      81                 :             : 
      82                 :           0 :   if (blob->writable)
      83                 :           0 :     flags = flags | GI_FIELD_IS_WRITABLE;
      84                 :             : 
      85                 :           0 :   return flags;
      86                 :             : }
      87                 :             : 
      88                 :             : /**
      89                 :             :  * gi_field_info_get_size:
      90                 :             :  * @info: a #GIFieldInfo
      91                 :             :  *
      92                 :             :  * Obtain the size of the field member, in bits. This is how
      93                 :             :  * much space you need to allocate to store the field.
      94                 :             :  *
      95                 :             :  * Returns: the field size, in bits
      96                 :             :  * Since: 2.80
      97                 :             :  */
      98                 :             : size_t
      99                 :           0 : gi_field_info_get_size (GIFieldInfo *info)
     100                 :             : {
     101                 :           0 :   GIRealInfo *rinfo = (GIRealInfo *)info;
     102                 :             :   FieldBlob *blob;
     103                 :             : 
     104                 :           0 :   g_return_val_if_fail (info != NULL, 0);
     105                 :           0 :   g_return_val_if_fail (GI_IS_FIELD_INFO (info), 0);
     106                 :             : 
     107                 :           0 :   blob = (FieldBlob *)&rinfo->typelib->data[rinfo->offset];
     108                 :             : 
     109                 :           0 :   return blob->bits;
     110                 :             : }
     111                 :             : 
     112                 :             : /**
     113                 :             :  * gi_field_info_get_offset:
     114                 :             :  * @info: a #GIFieldInfo
     115                 :             :  *
     116                 :             :  * Obtain the offset of the field member, in bytes. This is relative
     117                 :             :  * to the beginning of the struct or union.
     118                 :             :  *
     119                 :             :  * Returns: the field offset, in bytes
     120                 :             :  * Since: 2.80
     121                 :             :  */
     122                 :             : size_t
     123                 :           0 : gi_field_info_get_offset (GIFieldInfo *info)
     124                 :             : {
     125                 :           0 :   GIRealInfo *rinfo = (GIRealInfo *)info;
     126                 :             :   FieldBlob *blob;
     127                 :             : 
     128                 :           0 :   g_return_val_if_fail (info != NULL, 0);
     129                 :           0 :   g_return_val_if_fail (GI_IS_FIELD_INFO (info), 0);
     130                 :             : 
     131                 :           0 :   blob = (FieldBlob *)&rinfo->typelib->data[rinfo->offset];
     132                 :             : 
     133                 :           0 :   return blob->struct_offset;
     134                 :             : }
     135                 :             : 
     136                 :             : /**
     137                 :             :  * gi_field_info_get_type_info:
     138                 :             :  * @info: a #GIFieldInfo
     139                 :             :  *
     140                 :             :  * Obtain the type of a field as a [type@GIRepository.TypeInfo].
     141                 :             :  *
     142                 :             :  * Returns: (transfer full): the [type@GIRepository.TypeInfo]. Free the struct
     143                 :             :  *   by calling [method@GIRepository.BaseInfo.unref] when done.
     144                 :             :  * Since: 2.80
     145                 :             :  */
     146                 :             : GITypeInfo *
     147                 :           2 : gi_field_info_get_type_info (GIFieldInfo *info)
     148                 :             : {
     149                 :           2 :   GIRealInfo *rinfo = (GIRealInfo *)info;
     150                 :           2 :   Header *header = (Header *)rinfo->typelib->data;
     151                 :             :   FieldBlob *blob;
     152                 :             :   GIRealInfo *type_info;
     153                 :             : 
     154                 :           2 :   g_return_val_if_fail (info != NULL, NULL);
     155                 :           2 :   g_return_val_if_fail (GI_IS_FIELD_INFO (info), NULL);
     156                 :             : 
     157                 :           2 :   blob = (FieldBlob *)&rinfo->typelib->data[rinfo->offset];
     158                 :             : 
     159                 :           2 :   if (blob->has_embedded_type)
     160                 :             :     {
     161                 :           1 :       type_info = (GIRealInfo *) gi_base_info_new (GI_INFO_TYPE_TYPE,
     162                 :             :                                                    (GIBaseInfo*)info, rinfo->typelib,
     163                 :           1 :                                                    rinfo->offset + header->field_blob_size);
     164                 :           1 :       type_info->type_is_embedded = TRUE;
     165                 :             :     }
     166                 :             :   else
     167                 :           1 :     return gi_type_info_new ((GIBaseInfo*)info, rinfo->typelib, rinfo->offset + G_STRUCT_OFFSET (FieldBlob, type));
     168                 :             : 
     169                 :           1 :   return (GITypeInfo *) type_info;
     170                 :             : }
     171                 :             : 
     172                 :             : /**
     173                 :             :  * gi_field_info_get_field: (skip)
     174                 :             :  * @field_info: a #GIFieldInfo
     175                 :             :  * @mem: pointer to a block of memory representing a C structure or union
     176                 :             :  * @value: a [type@GIRepository.Argument] into which to store the value retrieved
     177                 :             :  *
     178                 :             :  * Reads a field identified by a `GIFieldInfo` from a C structure or
     179                 :             :  * union.
     180                 :             :  *
     181                 :             :  * This only handles fields of simple C types. It will fail for a field of a
     182                 :             :  * composite type like a nested structure or union even if that is actually
     183                 :             :  * readable.
     184                 :             :  *
     185                 :             :  * Returns: `TRUE` if reading the field succeeded, `FALSE` otherwise
     186                 :             :  * Since: 2.80
     187                 :             :  */
     188                 :             : gboolean
     189                 :           0 : gi_field_info_get_field (GIFieldInfo *field_info,
     190                 :             :                          void        *mem,
     191                 :             :                          GIArgument  *value)
     192                 :             : {
     193                 :             :   size_t offset;
     194                 :             :   GITypeInfo *type_info;
     195                 :           0 :   gboolean result = FALSE;
     196                 :             : 
     197                 :           0 :   g_return_val_if_fail (field_info != NULL, FALSE);
     198                 :           0 :   g_return_val_if_fail (GI_IS_FIELD_INFO (field_info), FALSE);
     199                 :             : 
     200                 :           0 :   if ((gi_field_info_get_flags (field_info) & GI_FIELD_IS_READABLE) == 0)
     201                 :           0 :     return FALSE;
     202                 :             : 
     203                 :           0 :   offset = gi_field_info_get_offset (field_info);
     204                 :           0 :   type_info = gi_field_info_get_type_info (field_info);
     205                 :             : 
     206                 :           0 :   if (gi_type_info_is_pointer (type_info))
     207                 :             :     {
     208                 :           0 :       value->v_pointer = G_STRUCT_MEMBER (void *, mem, offset);
     209                 :           0 :       result = TRUE;
     210                 :             :     }
     211                 :             :   else
     212                 :             :     {
     213                 :           0 :       switch (gi_type_info_get_tag (type_info))
     214                 :             :         {
     215                 :           0 :         case GI_TYPE_TAG_VOID:
     216                 :           0 :           g_warning("Field %s: should not be have void type",
     217                 :             :                     gi_base_info_get_name ((GIBaseInfo *)field_info));
     218                 :           0 :           break;
     219                 :           0 :         case GI_TYPE_TAG_BOOLEAN:
     220                 :           0 :           value->v_boolean = G_STRUCT_MEMBER (gboolean, mem, offset) != FALSE;
     221                 :           0 :           result = TRUE;
     222                 :           0 :           break;
     223                 :           0 :         case GI_TYPE_TAG_INT8:
     224                 :             :         case GI_TYPE_TAG_UINT8:
     225                 :           0 :           value->v_uint8 = G_STRUCT_MEMBER (uint8_t, mem, offset);
     226                 :           0 :           result = TRUE;
     227                 :           0 :           break;
     228                 :           0 :         case GI_TYPE_TAG_INT16:
     229                 :             :         case GI_TYPE_TAG_UINT16:
     230                 :           0 :           value->v_uint16 = G_STRUCT_MEMBER (uint16_t, mem, offset);
     231                 :           0 :           result = TRUE;
     232                 :           0 :           break;
     233                 :           0 :         case GI_TYPE_TAG_INT32:
     234                 :             :         case GI_TYPE_TAG_UINT32:
     235                 :             :         case GI_TYPE_TAG_UNICHAR:
     236                 :           0 :           value->v_uint32 = G_STRUCT_MEMBER (uint32_t, mem, offset);
     237                 :           0 :           result = TRUE;
     238                 :           0 :           break;
     239                 :           0 :         case GI_TYPE_TAG_INT64:
     240                 :             :         case GI_TYPE_TAG_UINT64:
     241                 :           0 :           value->v_uint64 = G_STRUCT_MEMBER (uint64_t, mem, offset);
     242                 :           0 :           result = TRUE;
     243                 :           0 :           break;
     244                 :           0 :         case GI_TYPE_TAG_GTYPE:
     245                 :           0 :           value->v_size = G_STRUCT_MEMBER (size_t, mem, offset);
     246                 :           0 :           result = TRUE;
     247                 :           0 :           break;
     248                 :           0 :         case GI_TYPE_TAG_FLOAT:
     249                 :           0 :           value->v_float = G_STRUCT_MEMBER (float, mem, offset);
     250                 :           0 :           result = TRUE;
     251                 :           0 :           break;
     252                 :           0 :         case GI_TYPE_TAG_DOUBLE:
     253                 :           0 :           value->v_double = G_STRUCT_MEMBER (double, mem, offset);
     254                 :           0 :           result = TRUE;
     255                 :           0 :           break;
     256                 :           0 :         case GI_TYPE_TAG_ARRAY:
     257                 :             :           /* We don't check the array type and that it is fixed-size,
     258                 :             :              we trust gi-compile-repository to do the right thing */
     259                 :           0 :           value->v_pointer = G_STRUCT_MEMBER_P (mem, offset);
     260                 :           0 :           result = TRUE;
     261                 :           0 :           break;
     262                 :           0 :         case GI_TYPE_TAG_UTF8:
     263                 :             :         case GI_TYPE_TAG_FILENAME:
     264                 :             :         case GI_TYPE_TAG_GLIST:
     265                 :             :         case GI_TYPE_TAG_GSLIST:
     266                 :             :         case GI_TYPE_TAG_GHASH:
     267                 :           0 :           g_warning("Field %s: type %s should have is_pointer set",
     268                 :             :                     gi_base_info_get_name ((GIBaseInfo *)field_info),
     269                 :             :                     gi_type_tag_to_string (gi_type_info_get_tag (type_info)));
     270                 :           0 :           break;
     271                 :           0 :         case GI_TYPE_TAG_ERROR:
     272                 :             :           /* Needs to be handled by the language binding directly */
     273                 :           0 :           break;
     274                 :           0 :         case GI_TYPE_TAG_INTERFACE:
     275                 :             :           {
     276                 :           0 :             GIBaseInfo *interface = gi_type_info_get_interface (type_info);
     277                 :           0 :             switch (gi_base_info_get_info_type (interface))
     278                 :             :               {
     279                 :           0 :               case GI_INFO_TYPE_STRUCT:
     280                 :             :               case GI_INFO_TYPE_UNION:
     281                 :             :                 /* Needs to be handled by the language binding directly */
     282                 :           0 :                 break;
     283                 :           0 :               case GI_INFO_TYPE_OBJECT:
     284                 :           0 :                 break;
     285                 :           0 :               case GI_INFO_TYPE_ENUM:
     286                 :             :               case GI_INFO_TYPE_FLAGS:
     287                 :             :                 {
     288                 :             :                   /* FIXME: there's a mismatch here between the value->v_int we use
     289                 :             :                    * here and the int64_t result returned from gi_value_info_get_value().
     290                 :             :                    * But to switch this to int64_t, we'd have to make gi_function_info_invoke()
     291                 :             :                    * translate value->v_int64 to the proper ABI for an enum function
     292                 :             :                    * call parameter, which will usually be int, and then fix up language
     293                 :             :                    * bindings.
     294                 :             :                    */
     295                 :           0 :                   GITypeTag storage_type = gi_enum_info_get_storage_type ((GIEnumInfo *)interface);
     296                 :           0 :                   switch (storage_type)
     297                 :             :                     {
     298                 :           0 :                     case GI_TYPE_TAG_INT8:
     299                 :             :                     case GI_TYPE_TAG_UINT8:
     300                 :           0 :                       value->v_int = (int)G_STRUCT_MEMBER (uint8_t, mem, offset);
     301                 :           0 :                       result = TRUE;
     302                 :           0 :                       break;
     303                 :           0 :                     case GI_TYPE_TAG_INT16:
     304                 :             :                     case GI_TYPE_TAG_UINT16:
     305                 :           0 :                       value->v_int = (int)G_STRUCT_MEMBER (uint16_t, mem, offset);
     306                 :           0 :                       result = TRUE;
     307                 :           0 :                       break;
     308                 :           0 :                     case GI_TYPE_TAG_INT32:
     309                 :             :                     case GI_TYPE_TAG_UINT32:
     310                 :           0 :                       value->v_int = (int)G_STRUCT_MEMBER (uint32_t, mem, offset);
     311                 :           0 :                       result = TRUE;
     312                 :           0 :                       break;
     313                 :           0 :                     case GI_TYPE_TAG_INT64:
     314                 :             :                     case GI_TYPE_TAG_UINT64:
     315                 :           0 :                       value->v_int = (int)G_STRUCT_MEMBER (uint64_t, mem, offset);
     316                 :           0 :                       result = TRUE;
     317                 :           0 :                       break;
     318                 :           0 :                     default:
     319                 :           0 :                       g_warning("Field %s: Unexpected enum storage type %s",
     320                 :             :                                 gi_base_info_get_name ((GIBaseInfo *)field_info),
     321                 :             :                                 gi_type_tag_to_string (storage_type));
     322                 :           0 :                       break;
     323                 :             :                     }
     324                 :           0 :                   break;
     325                 :             :                 }
     326                 :           0 :               case GI_INFO_TYPE_VFUNC:
     327                 :             :               case GI_INFO_TYPE_CALLBACK:
     328                 :           0 :                 g_warning("Field %s: Interface type %d should have is_pointer set",
     329                 :             :                           gi_base_info_get_name ((GIBaseInfo *)field_info),
     330                 :             :                           gi_base_info_get_info_type (interface));
     331                 :           0 :                 break;
     332                 :           0 :               case GI_INFO_TYPE_INVALID:
     333                 :             :               case GI_INFO_TYPE_INTERFACE:
     334                 :             :               case GI_INFO_TYPE_FUNCTION:
     335                 :             :               case GI_INFO_TYPE_CONSTANT:
     336                 :             :               case GI_INFO_TYPE_VALUE:
     337                 :             :               case GI_INFO_TYPE_SIGNAL:
     338                 :             :               case GI_INFO_TYPE_PROPERTY:
     339                 :             :               case GI_INFO_TYPE_FIELD:
     340                 :             :               case GI_INFO_TYPE_ARG:
     341                 :             :               case GI_INFO_TYPE_TYPE:
     342                 :             :               case GI_INFO_TYPE_UNRESOLVED:
     343                 :           0 :                 g_warning("Field %s: Interface type %d not expected",
     344                 :             :                           gi_base_info_get_name ((GIBaseInfo *)field_info),
     345                 :             :                           gi_base_info_get_info_type (interface));
     346                 :           0 :                 break;
     347                 :           0 :               default:
     348                 :           0 :                 break;
     349                 :             :               }
     350                 :             : 
     351                 :           0 :             gi_base_info_unref ((GIBaseInfo *)interface);
     352                 :           0 :             break;
     353                 :             :           }
     354                 :             :           break;
     355                 :           0 :         default:
     356                 :           0 :           break;
     357                 :             :         }
     358                 :             :     }
     359                 :             : 
     360                 :           0 :   gi_base_info_unref ((GIBaseInfo *)type_info);
     361                 :             : 
     362                 :           0 :   return result;
     363                 :             : }
     364                 :             : 
     365                 :             : /**
     366                 :             :  * gi_field_info_set_field: (skip)
     367                 :             :  * @field_info: a #GIFieldInfo
     368                 :             :  * @mem: pointer to a block of memory representing a C structure or union
     369                 :             :  * @value: a [type@GIRepository.Argument] holding the value to store
     370                 :             :  *
     371                 :             :  * Writes a field identified by a `GIFieldInfo` to a C structure or
     372                 :             :  * union.
     373                 :             :  *
     374                 :             :  * This only handles fields of simple C types. It will fail for a field of a
     375                 :             :  * composite type like a nested structure or union even if that is actually
     376                 :             :  * writable. Note also that that it will refuse to write fields where memory
     377                 :             :  * management would by required. A field with a type such as `char *` must be
     378                 :             :  * set with a setter function.
     379                 :             :  *
     380                 :             :  * Returns: `TRUE` if writing the field succeeded, `FALSE` otherwise
     381                 :             :  * Since: 2.80
     382                 :             :  */
     383                 :             : gboolean
     384                 :           0 : gi_field_info_set_field (GIFieldInfo      *field_info,
     385                 :             :                          void             *mem,
     386                 :             :                          const GIArgument *value)
     387                 :             : {
     388                 :             :   size_t offset;
     389                 :             :   GITypeInfo *type_info;
     390                 :           0 :   gboolean result = FALSE;
     391                 :             : 
     392                 :           0 :   g_return_val_if_fail (field_info != NULL, FALSE);
     393                 :           0 :   g_return_val_if_fail (GI_IS_FIELD_INFO (field_info), FALSE);
     394                 :             : 
     395                 :           0 :   if ((gi_field_info_get_flags (field_info) & GI_FIELD_IS_WRITABLE) == 0)
     396                 :           0 :     return FALSE;
     397                 :             : 
     398                 :           0 :   offset = gi_field_info_get_offset (field_info);
     399                 :           0 :   type_info = gi_field_info_get_type_info (field_info);
     400                 :             : 
     401                 :           0 :   if (!gi_type_info_is_pointer (type_info))
     402                 :             :     {
     403                 :           0 :       switch (gi_type_info_get_tag (type_info))
     404                 :             :         {
     405                 :           0 :         case GI_TYPE_TAG_VOID:
     406                 :           0 :           g_warning("Field %s: should not be have void type",
     407                 :             :                     gi_base_info_get_name ((GIBaseInfo *)field_info));
     408                 :           0 :           break;
     409                 :           0 :         case GI_TYPE_TAG_BOOLEAN:
     410                 :           0 :           G_STRUCT_MEMBER (gboolean, mem, offset) = value->v_boolean != FALSE;
     411                 :           0 :           result = TRUE;
     412                 :           0 :           break;
     413                 :           0 :         case GI_TYPE_TAG_INT8:
     414                 :             :         case GI_TYPE_TAG_UINT8:
     415                 :           0 :           G_STRUCT_MEMBER (uint8_t, mem, offset) = value->v_uint8;
     416                 :           0 :           result = TRUE;
     417                 :           0 :           break;
     418                 :           0 :         case GI_TYPE_TAG_INT16:
     419                 :             :         case GI_TYPE_TAG_UINT16:
     420                 :           0 :           G_STRUCT_MEMBER (uint16_t, mem, offset) = value->v_uint16;
     421                 :           0 :           result = TRUE;
     422                 :           0 :           break;
     423                 :           0 :         case GI_TYPE_TAG_INT32:
     424                 :             :         case GI_TYPE_TAG_UINT32:
     425                 :             :         case GI_TYPE_TAG_UNICHAR:
     426                 :           0 :           G_STRUCT_MEMBER (uint32_t, mem, offset) = value->v_uint32;
     427                 :           0 :           result = TRUE;
     428                 :           0 :           break;
     429                 :           0 :         case GI_TYPE_TAG_INT64:
     430                 :             :         case GI_TYPE_TAG_UINT64:
     431                 :           0 :           G_STRUCT_MEMBER (uint64_t, mem, offset) = value->v_uint64;
     432                 :           0 :           result = TRUE;
     433                 :           0 :           break;
     434                 :           0 :         case GI_TYPE_TAG_GTYPE:
     435                 :           0 :           G_STRUCT_MEMBER (size_t, mem, offset) = value->v_size;
     436                 :           0 :           result = TRUE;
     437                 :           0 :           break;
     438                 :           0 :         case GI_TYPE_TAG_FLOAT:
     439                 :           0 :           G_STRUCT_MEMBER (float, mem, offset) = value->v_float;
     440                 :           0 :           result = TRUE;
     441                 :           0 :           break;
     442                 :           0 :         case GI_TYPE_TAG_DOUBLE:
     443                 :           0 :           G_STRUCT_MEMBER (double, mem, offset)= value->v_double;
     444                 :           0 :           result = TRUE;
     445                 :           0 :           break;
     446                 :           0 :         case GI_TYPE_TAG_UTF8:
     447                 :             :         case GI_TYPE_TAG_FILENAME:
     448                 :             :         case GI_TYPE_TAG_ARRAY:
     449                 :             :         case GI_TYPE_TAG_GLIST:
     450                 :             :         case GI_TYPE_TAG_GSLIST:
     451                 :             :         case GI_TYPE_TAG_GHASH:
     452                 :           0 :           g_warning("Field %s: type %s should have is_pointer set",
     453                 :             :                     gi_base_info_get_name ((GIBaseInfo *)field_info),
     454                 :             :                     gi_type_tag_to_string (gi_type_info_get_tag (type_info)));
     455                 :           0 :           break;
     456                 :           0 :         case GI_TYPE_TAG_ERROR:
     457                 :             :           /* Needs to be handled by the language binding directly */
     458                 :           0 :           break;
     459                 :           0 :         case GI_TYPE_TAG_INTERFACE:
     460                 :             :           {
     461                 :           0 :             GIBaseInfo *interface = gi_type_info_get_interface (type_info);
     462                 :           0 :             switch (gi_base_info_get_info_type (interface))
     463                 :             :               {
     464                 :           0 :               case GI_INFO_TYPE_STRUCT:
     465                 :             :               case GI_INFO_TYPE_UNION:
     466                 :             :                 /* Needs to be handled by the language binding directly */
     467                 :           0 :                 break;
     468                 :           0 :               case GI_INFO_TYPE_OBJECT:
     469                 :           0 :                 break;
     470                 :           0 :               case GI_INFO_TYPE_ENUM:
     471                 :             :               case GI_INFO_TYPE_FLAGS:
     472                 :             :                 {
     473                 :             :                   /* See FIXME above
     474                 :             :                    */
     475                 :           0 :                   GITypeTag storage_type = gi_enum_info_get_storage_type ((GIEnumInfo *)interface);
     476                 :           0 :                   switch (storage_type)
     477                 :             :                     {
     478                 :           0 :                     case GI_TYPE_TAG_INT8:
     479                 :             :                     case GI_TYPE_TAG_UINT8:
     480                 :           0 :                       G_STRUCT_MEMBER (uint8_t, mem, offset) = (uint8_t)value->v_int;
     481                 :           0 :                       result = TRUE;
     482                 :           0 :                       break;
     483                 :           0 :                     case GI_TYPE_TAG_INT16:
     484                 :             :                     case GI_TYPE_TAG_UINT16:
     485                 :           0 :                       G_STRUCT_MEMBER (uint16_t, mem, offset) = (uint16_t)value->v_int;
     486                 :           0 :                       result = TRUE;
     487                 :           0 :                       break;
     488                 :           0 :                     case GI_TYPE_TAG_INT32:
     489                 :             :                     case GI_TYPE_TAG_UINT32:
     490                 :           0 :                       G_STRUCT_MEMBER (uint32_t, mem, offset) = (uint32_t)value->v_int;
     491                 :           0 :                       result = TRUE;
     492                 :           0 :                       break;
     493                 :           0 :                     case GI_TYPE_TAG_INT64:
     494                 :             :                     case GI_TYPE_TAG_UINT64:
     495                 :           0 :                       G_STRUCT_MEMBER (uint64_t, mem, offset) = (uint64_t)value->v_int;
     496                 :           0 :                       result = TRUE;
     497                 :           0 :                       break;
     498                 :           0 :                     default:
     499                 :           0 :                       g_warning("Field %s: Unexpected enum storage type %s",
     500                 :             :                                 gi_base_info_get_name ((GIBaseInfo *)field_info),
     501                 :             :                                 gi_type_tag_to_string (storage_type));
     502                 :           0 :                       break;
     503                 :             :                     }
     504                 :           0 :                   break;
     505                 :             :                 }
     506                 :             :                 break;
     507                 :           0 :               case GI_INFO_TYPE_VFUNC:
     508                 :             :               case GI_INFO_TYPE_CALLBACK:
     509                 :           0 :                 g_warning("Field%s: Interface type %d should have is_pointer set",
     510                 :             :                           gi_base_info_get_name ((GIBaseInfo *)field_info),
     511                 :             :                           gi_base_info_get_info_type (interface));
     512                 :           0 :                 break;
     513                 :           0 :               case GI_INFO_TYPE_INVALID:
     514                 :             :               case GI_INFO_TYPE_INTERFACE:
     515                 :             :               case GI_INFO_TYPE_FUNCTION:
     516                 :             :               case GI_INFO_TYPE_CONSTANT:
     517                 :             :               case GI_INFO_TYPE_VALUE:
     518                 :             :               case GI_INFO_TYPE_SIGNAL:
     519                 :             :               case GI_INFO_TYPE_PROPERTY:
     520                 :             :               case GI_INFO_TYPE_FIELD:
     521                 :             :               case GI_INFO_TYPE_ARG:
     522                 :             :               case GI_INFO_TYPE_TYPE:
     523                 :             :               case GI_INFO_TYPE_UNRESOLVED:
     524                 :           0 :                 g_warning("Field %s: Interface type %d not expected",
     525                 :             :                           gi_base_info_get_name ((GIBaseInfo *)field_info),
     526                 :             :                           gi_base_info_get_info_type (interface));
     527                 :           0 :                 break;
     528                 :           0 :               default:
     529                 :           0 :                 break;
     530                 :             :               }
     531                 :             : 
     532                 :           0 :             gi_base_info_unref ((GIBaseInfo *)interface);
     533                 :           0 :             break;
     534                 :             :           }
     535                 :             :           break;
     536                 :           0 :         default:
     537                 :           0 :           break;
     538                 :             :         }
     539                 :             :     } else {
     540                 :           0 :       switch (gi_type_info_get_tag (type_info))
     541                 :             :         {
     542                 :           0 :         case GI_TYPE_TAG_INTERFACE:
     543                 :             :           {
     544                 :           0 :             GIBaseInfo *interface = gi_type_info_get_interface (type_info);
     545                 :           0 :             switch (gi_base_info_get_info_type (interface))
     546                 :             :               {
     547                 :           0 :                 case GI_INFO_TYPE_OBJECT:
     548                 :             :                 case GI_INFO_TYPE_INTERFACE:
     549                 :           0 :                   G_STRUCT_MEMBER (void *, mem, offset) = (void *)value->v_pointer;
     550                 :           0 :                   result = TRUE;
     551                 :           0 :                   break;
     552                 :           0 :                 default:
     553                 :           0 :                   break;
     554                 :             :               }
     555                 :           0 :               gi_base_info_unref ((GIBaseInfo *)interface);
     556                 :             :           }
     557                 :           0 :           break;
     558                 :           0 :         default:
     559                 :           0 :           break;
     560                 :             :         }
     561                 :             :     }
     562                 :             : 
     563                 :           0 :   gi_base_info_unref ((GIBaseInfo *)type_info);
     564                 :             : 
     565                 :           0 :   return result;
     566                 :             : }
     567                 :             : 
     568                 :             : void
     569                 :           4 : gi_field_info_class_init (gpointer g_class,
     570                 :             :                           gpointer class_data)
     571                 :             : {
     572                 :           4 :   GIBaseInfoClass *info_class = g_class;
     573                 :             : 
     574                 :           4 :   info_class->info_type = GI_INFO_TYPE_FIELD;
     575                 :           4 : }
        

Generated by: LCOV version 2.0-1