LCOV - code coverage report
Current view: top level - glib - gtypes.h (source / functions) Coverage Total Hit
Test: unnamed Lines: 100.0 % 12 12
Test Date: 2026-01-13 05:17:23 Functions: 100.0 % 6 6
Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* GLIB - Library of useful routines for C programming
       2                 :             :  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
       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 Public
      17                 :             :  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
      18                 :             :  */
      19                 :             : 
      20                 :             : /*
      21                 :             :  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
      22                 :             :  * file for a list of people on the GLib Team.  See the ChangeLog
      23                 :             :  * files for a list of changes.  These files are distributed with
      24                 :             :  * GLib at ftp://ftp.gtk.org/pub/gtk/.
      25                 :             :  */
      26                 :             : 
      27                 :             : #ifndef __G_TYPES_H__
      28                 :             : #define __G_TYPES_H__
      29                 :             : 
      30                 :             : #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
      31                 :             : #error "Only <glib.h> can be included directly."
      32                 :             : #endif
      33                 :             : 
      34                 :             : #include <glibconfig.h>
      35                 :             : #include <glib/gmacros.h>
      36                 :             : #include <glib/gversionmacros.h>
      37                 :             : 
      38                 :             : /* Must be included after the 3 headers above */
      39                 :             : #include <glib/glib-visibility.h>
      40                 :             : 
      41                 :             : #include <time.h>
      42                 :             : 
      43                 :             : G_BEGIN_DECLS
      44                 :             : 
      45                 :             : /* Provide type definitions for commonly used types.
      46                 :             :  *  These are useful because a "gint8" can be adjusted
      47                 :             :  *  to be 1 byte (8 bits) on all platforms. Similarly and
      48                 :             :  *  more importantly, "gint32" can be adjusted to be
      49                 :             :  *  4 bytes (32 bits) on all platforms.
      50                 :             :  */
      51                 :             : 
      52                 :             : typedef char   gchar;
      53                 :             : typedef short  gshort;
      54                 :             : typedef long   glong;
      55                 :             : typedef int    gint;
      56                 :             : typedef gint   gboolean;
      57                 :             : 
      58                 :             : typedef unsigned char   guchar;
      59                 :             : typedef unsigned short  gushort;
      60                 :             : typedef unsigned long   gulong;
      61                 :             : typedef unsigned int    guint;
      62                 :             : 
      63                 :             : typedef float   gfloat;
      64                 :             : typedef double  gdouble;
      65                 :             : 
      66                 :             : /* Define min and max constants for the fixed size numerical types */
      67                 :             : /**
      68                 :             :  * G_MININT8: (value -128)
      69                 :             :  *
      70                 :             :  * The minimum value which can be held in a #gint8.
      71                 :             :  *
      72                 :             :  * Since: 2.4
      73                 :             :  */
      74                 :             : #define G_MININT8       ((gint8) (-G_MAXINT8 - 1))
      75                 :             : #define G_MAXINT8       ((gint8)  0x7f)
      76                 :             : #define G_MAXUINT8      ((guint8) 0xff)
      77                 :             : 
      78                 :             : /**
      79                 :             :  * G_MININT16: (value -32768)
      80                 :             :  *
      81                 :             :  * The minimum value which can be held in a #gint16.
      82                 :             :  *
      83                 :             :  * Since: 2.4
      84                 :             :  */
      85                 :             : #define G_MININT16      ((gint16) (-G_MAXINT16 - 1))
      86                 :             : #define G_MAXINT16      ((gint16)  0x7fff)
      87                 :             : #define G_MAXUINT16     ((guint16) 0xffff)
      88                 :             : 
      89                 :             : /**
      90                 :             :  * G_MININT32: (value -2147483648)
      91                 :             :  *
      92                 :             :  * The minimum value which can be held in a #gint32.
      93                 :             :  *
      94                 :             :  * Since: 2.4
      95                 :             :  */
      96                 :             : #define G_MININT32      ((gint32) (-G_MAXINT32 - 1))
      97                 :             : #define G_MAXINT32      ((gint32)  0x7fffffff)
      98                 :             : #define G_MAXUINT32     ((guint32) 0xffffffff)
      99                 :             : 
     100                 :             : /**
     101                 :             :  * G_MININT64: (value -9223372036854775808)
     102                 :             :  *
     103                 :             :  * The minimum value which can be held in a #gint64.
     104                 :             :  */
     105                 :             : #define G_MININT64      ((gint64) (-G_MAXINT64 - G_GINT64_CONSTANT(1)))
     106                 :             : #define G_MAXINT64      G_GINT64_CONSTANT(0x7fffffffffffffff)
     107                 :             : #define G_MAXUINT64     G_GUINT64_CONSTANT(0xffffffffffffffff)
     108                 :             : 
     109                 :             : typedef void* gpointer;
     110                 :             : typedef const void *gconstpointer;
     111                 :             : 
     112                 :             : typedef gint            (*GCompareFunc)         (gconstpointer  a,
     113                 :             :                                                  gconstpointer  b);
     114                 :             : typedef gint            (*GCompareDataFunc)     (gconstpointer  a,
     115                 :             :                                                  gconstpointer  b,
     116                 :             :                                                  gpointer       user_data);
     117                 :             : typedef gboolean        (*GEqualFunc)           (gconstpointer  a,
     118                 :             :                                                  gconstpointer  b);
     119                 :             : 
     120                 :             : /**
     121                 :             :  * GEqualFuncFull:
     122                 :             :  * @a: a value
     123                 :             :  * @b: a value to compare with
     124                 :             :  * @user_data: user data provided by the caller
     125                 :             :  *
     126                 :             :  * Specifies the type of a function used to test two values for
     127                 :             :  * equality. The function should return %TRUE if both values are equal
     128                 :             :  * and %FALSE otherwise.
     129                 :             :  *
     130                 :             :  * This is a version of #GEqualFunc which provides a @user_data closure from
     131                 :             :  * the caller.
     132                 :             :  *
     133                 :             :  * Returns: %TRUE if @a = @b; %FALSE otherwise
     134                 :             :  * Since: 2.74
     135                 :             :  */
     136                 :             : typedef gboolean        (*GEqualFuncFull)       (gconstpointer  a,
     137                 :             :                                                  gconstpointer  b,
     138                 :             :                                                  gpointer       user_data);
     139                 :             : 
     140                 :             : typedef void            (*GDestroyNotify)       (gpointer       data);
     141                 :             : typedef void            (*GFunc)                (gpointer       data,
     142                 :             :                                                  gpointer       user_data);
     143                 :             : typedef guint           (*GHashFunc)            (gconstpointer  key);
     144                 :             : typedef void            (*GHFunc)               (gpointer       key,
     145                 :             :                                                  gpointer       value,
     146                 :             :                                                  gpointer       user_data);
     147                 :             : 
     148                 :             : /**
     149                 :             :  * GCopyFunc:
     150                 :             :  * @src: (not nullable): A pointer to the data which should be copied
     151                 :             :  * @data: Additional data
     152                 :             :  *
     153                 :             :  * A function of this signature is used to copy the node data
     154                 :             :  * when doing a deep-copy of a tree.
     155                 :             :  *
     156                 :             :  * Returns: (not nullable): A pointer to the copy
     157                 :             :  *
     158                 :             :  * Since: 2.4
     159                 :             :  */
     160                 :             : typedef gpointer        (*GCopyFunc)            (gconstpointer  src,
     161                 :             :                                                  gpointer       data);
     162                 :             : /**
     163                 :             :  * GFreeFunc:
     164                 :             :  * @data: a data pointer
     165                 :             :  *
     166                 :             :  * Declares a type of function which takes an arbitrary
     167                 :             :  * data pointer argument and has no return value. It is
     168                 :             :  * not currently used in GLib or GTK.
     169                 :             :  */
     170                 :             : typedef void            (*GFreeFunc)            (gpointer       data);
     171                 :             : 
     172                 :             : /**
     173                 :             :  * GTranslateFunc:
     174                 :             :  * @str: the untranslated string
     175                 :             :  * @data: user data specified when installing the function, e.g.
     176                 :             :  *  in g_option_group_set_translate_func()
     177                 :             :  * 
     178                 :             :  * The type of functions which are used to translate user-visible
     179                 :             :  * strings, for <option>--help</option> output.
     180                 :             :  * 
     181                 :             :  * Returns: a translation of the string for the current locale.
     182                 :             :  *  The returned string is owned by GLib and must not be freed.
     183                 :             :  */
     184                 :             : typedef const gchar *   (*GTranslateFunc)       (const gchar   *str,
     185                 :             :                                                  gpointer       data);
     186                 :             : 
     187                 :             : 
     188                 :             : /* Define some mathematical constants that aren't available
     189                 :             :  * symbolically in some strict ISO C implementations.
     190                 :             :  *
     191                 :             :  * Note that the large number of digits used in these definitions
     192                 :             :  * doesn't imply that GLib or current computers in general would be
     193                 :             :  * able to handle floating point numbers with an accuracy like this.
     194                 :             :  * It's mostly an exercise in futility and future proofing. For
     195                 :             :  * extended precision floating point support, look somewhere else
     196                 :             :  * than GLib.
     197                 :             :  */
     198                 :             : #define G_E     2.7182818284590452353602874713526624977572470937000
     199                 :             : #define G_LN2   0.69314718055994530941723212145817656807550013436026
     200                 :             : #define G_LN10  2.3025850929940456840179914546843642076011014886288
     201                 :             : #define G_PI    3.1415926535897932384626433832795028841971693993751
     202                 :             : #define G_PI_2  1.5707963267948966192313216916397514420985846996876
     203                 :             : #define G_PI_4  0.78539816339744830961566084581987572104929234984378
     204                 :             : #define G_SQRT2 1.4142135623730950488016887242096980785696718753769
     205                 :             : 
     206                 :             : /* Portable endian checks and conversions
     207                 :             :  *
     208                 :             :  * glibconfig.h defines G_BYTE_ORDER which expands to one of
     209                 :             :  * the below macros.
     210                 :             :  */
     211                 :             : #define G_LITTLE_ENDIAN 1234
     212                 :             : #define G_BIG_ENDIAN    4321
     213                 :             : #define G_PDP_ENDIAN    3412            /* unused, need specific PDP check */   
     214                 :             : 
     215                 :             : 
     216                 :             : /* Basic bit swapping functions
     217                 :             :  */
     218                 :             : #define GUINT16_SWAP_LE_BE_CONSTANT(val)        ((guint16) ( \
     219                 :             :     (guint16) ((guint16) (val) >> 8) |    \
     220                 :             :     (guint16) ((guint16) (val) << 8)))
     221                 :             : 
     222                 :             : #define GUINT32_SWAP_LE_BE_CONSTANT(val)        ((guint32) ( \
     223                 :             :     (((guint32) (val) & (guint32) 0x000000ffU) << 24) | \
     224                 :             :     (((guint32) (val) & (guint32) 0x0000ff00U) <<  8) | \
     225                 :             :     (((guint32) (val) & (guint32) 0x00ff0000U) >>  8) | \
     226                 :             :     (((guint32) (val) & (guint32) 0xff000000U) >> 24)))
     227                 :             : 
     228                 :             : #define GUINT64_SWAP_LE_BE_CONSTANT(val)        ((guint64) ( \
     229                 :             :       (((guint64) (val) &                                           \
     230                 :             :         (guint64) G_GINT64_CONSTANT (0x00000000000000ffU)) << 56) |       \
     231                 :             :       (((guint64) (val) &                                           \
     232                 :             :         (guint64) G_GINT64_CONSTANT (0x000000000000ff00U)) << 40) |       \
     233                 :             :       (((guint64) (val) &                                           \
     234                 :             :         (guint64) G_GINT64_CONSTANT (0x0000000000ff0000U)) << 24) |       \
     235                 :             :       (((guint64) (val) &                                           \
     236                 :             :         (guint64) G_GINT64_CONSTANT (0x00000000ff000000U)) <<  8) |       \
     237                 :             :       (((guint64) (val) &                                           \
     238                 :             :         (guint64) G_GINT64_CONSTANT (0x000000ff00000000U)) >>  8) |       \
     239                 :             :       (((guint64) (val) &                                           \
     240                 :             :         (guint64) G_GINT64_CONSTANT (0x0000ff0000000000U)) >> 24) |       \
     241                 :             :       (((guint64) (val) &                                           \
     242                 :             :         (guint64) G_GINT64_CONSTANT (0x00ff000000000000U)) >> 40) |       \
     243                 :             :       (((guint64) (val) &                                           \
     244                 :             :         (guint64) G_GINT64_CONSTANT (0xff00000000000000U)) >> 56)))
     245                 :             : 
     246                 :             : /* Arch specific stuff for speed
     247                 :             :  */
     248                 :             : #if defined (__GNUC__) && (__GNUC__ >= 2) && defined (__OPTIMIZE__)
     249                 :             : 
     250                 :             : #  if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
     251                 :             : #    define GUINT32_SWAP_LE_BE(val) ((guint32) __builtin_bswap32 ((guint32) (val)))
     252                 :             : #    define GUINT64_SWAP_LE_BE(val) ((guint64) __builtin_bswap64 ((guint64) (val)))
     253                 :             : #  endif
     254                 :             : 
     255                 :             : #  if defined (__i386__)
     256                 :             : #    define GUINT16_SWAP_LE_BE_IA32(val) \
     257                 :             :        (G_GNUC_EXTENSION                                        \
     258                 :             :         ({ guint16 __v, __x = ((guint16) (val));                \
     259                 :             :            if (__builtin_constant_p (__x))                      \
     260                 :             :              __v = GUINT16_SWAP_LE_BE_CONSTANT (__x);           \
     261                 :             :            else                                                 \
     262                 :             :              __asm__ ("rorw $8, %w0"                          \
     263                 :             :                       : "=r" (__v)                            \
     264                 :             :                       : "0" (__x)                             \
     265                 :             :                       : "cc");                                        \
     266                 :             :             __v; }))
     267                 :             : #    if !defined (__i486__) && !defined (__i586__) \
     268                 :             :         && !defined (__pentium__) && !defined (__i686__) \
     269                 :             :         && !defined (__pentiumpro__) && !defined (__pentium4__)
     270                 :             : #       define GUINT32_SWAP_LE_BE_IA32(val) \
     271                 :             :           (G_GNUC_EXTENSION                                     \
     272                 :             :            ({ guint32 __v, __x = ((guint32) (val));             \
     273                 :             :               if (__builtin_constant_p (__x))                   \
     274                 :             :                 __v = GUINT32_SWAP_LE_BE_CONSTANT (__x);        \
     275                 :             :               else                                              \
     276                 :             :                 __asm__ ("rorw $8, %w0\n\t"                   \
     277                 :             :                          "rorl $16, %0\n\t"                   \
     278                 :             :                          "rorw $8, %w0"                               \
     279                 :             :                          : "=r" (__v)                         \
     280                 :             :                          : "0" (__x)                          \
     281                 :             :                          : "cc");                             \
     282                 :             :               __v; }))
     283                 :             : #    else /* 486 and higher has bswap */
     284                 :             : #       define GUINT32_SWAP_LE_BE_IA32(val) \
     285                 :             :           (G_GNUC_EXTENSION                                     \
     286                 :             :            ({ guint32 __v, __x = ((guint32) (val));             \
     287                 :             :               if (__builtin_constant_p (__x))                   \
     288                 :             :                 __v = GUINT32_SWAP_LE_BE_CONSTANT (__x);        \
     289                 :             :               else                                              \
     290                 :             :                 __asm__ ("bswap %0"                           \
     291                 :             :                          : "=r" (__v)                         \
     292                 :             :                          : "0" (__x));                                \
     293                 :             :               __v; }))
     294                 :             : #    endif /* processor specific 32-bit stuff */
     295                 :             : #    define GUINT64_SWAP_LE_BE_IA32(val) \
     296                 :             :        (G_GNUC_EXTENSION                                                \
     297                 :             :         ({ union { guint64 __ll;                                        \
     298                 :             :                    guint32 __l[2]; } __w, __r;                          \
     299                 :             :            __w.__ll = ((guint64) (val));                                \
     300                 :             :            if (__builtin_constant_p (__w.__ll))                         \
     301                 :             :              __r.__ll = GUINT64_SWAP_LE_BE_CONSTANT (__w.__ll);         \
     302                 :             :            else                                                         \
     303                 :             :              {                                                          \
     304                 :             :                __r.__l[0] = GUINT32_SWAP_LE_BE (__w.__l[1]);            \
     305                 :             :                __r.__l[1] = GUINT32_SWAP_LE_BE (__w.__l[0]);            \
     306                 :             :              }                                                          \
     307                 :             :            __r.__ll; }))
     308                 :             :      /* Possibly just use the constant version and let gcc figure it out? */
     309                 :             : #    define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_IA32 (val))
     310                 :             : #    ifndef GUINT32_SWAP_LE_BE
     311                 :             : #      define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_IA32 (val))
     312                 :             : #    endif
     313                 :             : #    ifndef GUINT64_SWAP_LE_BE
     314                 :             : #      define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_IA32 (val))
     315                 :             : #    endif
     316                 :             : #  elif defined (__ia64__)
     317                 :             : #    define GUINT16_SWAP_LE_BE_IA64(val) \
     318                 :             :        (G_GNUC_EXTENSION                                        \
     319                 :             :         ({ guint16 __v, __x = ((guint16) (val));                \
     320                 :             :            if (__builtin_constant_p (__x))                      \
     321                 :             :              __v = GUINT16_SWAP_LE_BE_CONSTANT (__x);           \
     322                 :             :            else                                                 \
     323                 :             :              __asm__ __volatile__ ("shl %0 = %1, 48 ;;"               \
     324                 :             :                                    "mux1 %0 = %0, @rev ;;"    \
     325                 :             :                                     : "=r" (__v)              \
     326                 :             :                                     : "r" (__x));             \
     327                 :             :             __v; }))
     328                 :             : #    define GUINT32_SWAP_LE_BE_IA64(val) \
     329                 :             :        (G_GNUC_EXTENSION                                        \
     330                 :             :          ({ guint32 __v, __x = ((guint32) (val));               \
     331                 :             :             if (__builtin_constant_p (__x))                     \
     332                 :             :               __v = GUINT32_SWAP_LE_BE_CONSTANT (__x);          \
     333                 :             :             else                                                \
     334                 :             :              __asm__ __volatile__ ("shl %0 = %1, 32 ;;"               \
     335                 :             :                                    "mux1 %0 = %0, @rev ;;"    \
     336                 :             :                                     : "=r" (__v)              \
     337                 :             :                                     : "r" (__x));             \
     338                 :             :             __v; }))
     339                 :             : #    define GUINT64_SWAP_LE_BE_IA64(val) \
     340                 :             :        (G_GNUC_EXTENSION                                        \
     341                 :             :         ({ guint64 __v, __x = ((guint64) (val));                \
     342                 :             :            if (__builtin_constant_p (__x))                      \
     343                 :             :              __v = GUINT64_SWAP_LE_BE_CONSTANT (__x);           \
     344                 :             :            else                                                 \
     345                 :             :              __asm__ __volatile__ ("mux1 %0 = %1, @rev ;;"    \
     346                 :             :                                    : "=r" (__v)                       \
     347                 :             :                                    : "r" (__x));              \
     348                 :             :            __v; }))
     349                 :             : #    define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_IA64 (val))
     350                 :             : #    ifndef GUINT32_SWAP_LE_BE
     351                 :             : #      define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_IA64 (val))
     352                 :             : #    endif
     353                 :             : #    ifndef GUINT64_SWAP_LE_BE
     354                 :             : #      define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_IA64 (val))
     355                 :             : #    endif
     356                 :             : #  elif defined (__x86_64__)
     357                 :             : #    define GUINT32_SWAP_LE_BE_X86_64(val) \
     358                 :             :        (G_GNUC_EXTENSION                                        \
     359                 :             :          ({ guint32 __v, __x = ((guint32) (val));               \
     360                 :             :             if (__builtin_constant_p (__x))                     \
     361                 :             :               __v = GUINT32_SWAP_LE_BE_CONSTANT (__x);          \
     362                 :             :             else                                                \
     363                 :             :              __asm__ ("bswapl %0"                             \
     364                 :             :                       : "=r" (__v)                            \
     365                 :             :                       : "0" (__x));                           \
     366                 :             :             __v; }))
     367                 :             : #    define GUINT64_SWAP_LE_BE_X86_64(val) \
     368                 :             :        (G_GNUC_EXTENSION                                        \
     369                 :             :         ({ guint64 __v, __x = ((guint64) (val));                \
     370                 :             :            if (__builtin_constant_p (__x))                      \
     371                 :             :              __v = GUINT64_SWAP_LE_BE_CONSTANT (__x);           \
     372                 :             :            else                                                 \
     373                 :             :              __asm__ ("bswapq %0"                             \
     374                 :             :                       : "=r" (__v)                            \
     375                 :             :                       : "0" (__x));                           \
     376                 :             :            __v; }))
     377                 :             :      /* gcc seems to figure out optimal code for this on its own */
     378                 :             : #    define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val))
     379                 :             : #    ifndef GUINT32_SWAP_LE_BE
     380                 :             : #      define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_X86_64 (val))
     381                 :             : #    endif
     382                 :             : #    ifndef GUINT64_SWAP_LE_BE
     383                 :             : #      define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_X86_64 (val))
     384                 :             : #    endif
     385                 :             : #  else /* generic gcc */
     386                 :             : #    define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val))
     387                 :             : #    ifndef GUINT32_SWAP_LE_BE
     388                 :             : #      define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val))
     389                 :             : #    endif
     390                 :             : #    ifndef GUINT64_SWAP_LE_BE
     391                 :             : #      define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_CONSTANT (val))
     392                 :             : #    endif
     393                 :             : #  endif
     394                 :             : #else /* generic */
     395                 :             : #  define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val))
     396                 :             : #  define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val))
     397                 :             : #  define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_CONSTANT (val))
     398                 :             : #endif /* generic */
     399                 :             : 
     400                 :             : #define GUINT16_SWAP_LE_PDP(val)        ((guint16) (val))
     401                 :             : #define GUINT16_SWAP_BE_PDP(val)        (GUINT16_SWAP_LE_BE (val))
     402                 :             : #define GUINT32_SWAP_LE_PDP(val)        ((guint32) ( \
     403                 :             :     (((guint32) (val) & (guint32) 0x0000ffffU) << 16) | \
     404                 :             :     (((guint32) (val) & (guint32) 0xffff0000U) >> 16)))
     405                 :             : #define GUINT32_SWAP_BE_PDP(val)        ((guint32) ( \
     406                 :             :     (((guint32) (val) & (guint32) 0x00ff00ffU) << 8) | \
     407                 :             :     (((guint32) (val) & (guint32) 0xff00ff00U) >> 8)))
     408                 :             : 
     409                 :             : /* The G*_TO_?E() macros are defined in glibconfig.h.
     410                 :             :  * The transformation is symmetric, so the FROM just maps to the TO.
     411                 :             :  */
     412                 :             : #define GINT16_FROM_LE(val)     (GINT16_TO_LE (val))
     413                 :             : #define GUINT16_FROM_LE(val)    (GUINT16_TO_LE (val))
     414                 :             : #define GINT16_FROM_BE(val)     (GINT16_TO_BE (val))
     415                 :             : #define GUINT16_FROM_BE(val)    (GUINT16_TO_BE (val))
     416                 :             : #define GINT32_FROM_LE(val)     (GINT32_TO_LE (val))
     417                 :             : #define GUINT32_FROM_LE(val)    (GUINT32_TO_LE (val))
     418                 :             : #define GINT32_FROM_BE(val)     (GINT32_TO_BE (val))
     419                 :             : #define GUINT32_FROM_BE(val)    (GUINT32_TO_BE (val))
     420                 :             : 
     421                 :             : #define GINT64_FROM_LE(val)     (GINT64_TO_LE (val))
     422                 :             : #define GUINT64_FROM_LE(val)    (GUINT64_TO_LE (val))
     423                 :             : #define GINT64_FROM_BE(val)     (GINT64_TO_BE (val))
     424                 :             : #define GUINT64_FROM_BE(val)    (GUINT64_TO_BE (val))
     425                 :             : 
     426                 :             : #define GLONG_FROM_LE(val)      (GLONG_TO_LE (val))
     427                 :             : #define GULONG_FROM_LE(val)     (GULONG_TO_LE (val))
     428                 :             : #define GLONG_FROM_BE(val)      (GLONG_TO_BE (val))
     429                 :             : #define GULONG_FROM_BE(val)     (GULONG_TO_BE (val))
     430                 :             : 
     431                 :             : #define GINT_FROM_LE(val)       (GINT_TO_LE (val))
     432                 :             : #define GUINT_FROM_LE(val)      (GUINT_TO_LE (val))
     433                 :             : #define GINT_FROM_BE(val)       (GINT_TO_BE (val))
     434                 :             : #define GUINT_FROM_BE(val)      (GUINT_TO_BE (val))
     435                 :             : 
     436                 :             : #define GSIZE_FROM_LE(val)      (GSIZE_TO_LE (val))
     437                 :             : #define GSSIZE_FROM_LE(val)     (GSSIZE_TO_LE (val))
     438                 :             : #define GSIZE_FROM_BE(val)      (GSIZE_TO_BE (val))
     439                 :             : #define GSSIZE_FROM_BE(val)     (GSSIZE_TO_BE (val))
     440                 :             : 
     441                 :             : /* Portable versions of host-network order stuff
     442                 :             :  */
     443                 :             : #define g_ntohl(val) (GUINT32_FROM_BE (val))
     444                 :             : #define g_ntohs(val) (GUINT16_FROM_BE (val))
     445                 :             : #define g_htonl(val) (GUINT32_TO_BE (val))
     446                 :             : #define g_htons(val) (GUINT16_TO_BE (val))
     447                 :             : 
     448                 :             : /* Overflow-checked unsigned integer arithmetic
     449                 :             :  */
     450                 :             : #ifndef _GLIB_TEST_OVERFLOW_FALLBACK
     451                 :             : #if defined(HAVE_STDCKDINT_H)
     452                 :             : #define _GLIB_HAVE_STD_OVERFLOW_CHECKS
     453                 :             : /* https://bugzilla.gnome.org/show_bug.cgi?id=769104 */
     454                 :             : #elif __GNUC__ >= 5 && !defined(__INTEL_COMPILER)
     455                 :             : #define _GLIB_HAVE_BUILTIN_OVERFLOW_CHECKS
     456                 :             : #elif g_macro__has_builtin(__builtin_add_overflow)
     457                 :             : #define _GLIB_HAVE_BUILTIN_OVERFLOW_CHECKS
     458                 :             : #elif defined(G_OS_WIN32) && defined(HAVE_INTSAFE_H)
     459                 :             : #define _GLIB_HAVE_INTSAFE_OVERFLOW_CHECKS
     460                 :             : #endif
     461                 :             : #endif
     462                 :             : 
     463                 :             : #ifdef _GLIB_HAVE_STD_OVERFLOW_CHECKS
     464                 :             : 
     465                 :             : #include <stdckdint.h>
     466                 :             : 
     467                 :             : #define g_uint_checked_add(dest, a, b) \
     468                 :             :   (!ckd_add (dest, a, b))
     469                 :             : #define g_uint_checked_mul(dest, a, b) \
     470                 :             :   (!ckd_mul (dest, a, b))
     471                 :             : 
     472                 :             : #define g_uint64_checked_add(dest, a, b) \
     473                 :             :   (!ckd_add (dest, a, b))
     474                 :             : #define g_uint64_checked_mul(dest, a, b) \
     475                 :             :   (!ckd_mul (dest, a, b))
     476                 :             : 
     477                 :             : #define g_size_checked_add(dest, a, b) \
     478                 :             :   (!ckd_add (dest, a, b))
     479                 :             : #define g_size_checked_mul(dest, a, b) \
     480                 :             :   (!ckd_mul (dest, a, b))
     481                 :             : 
     482                 :             : #elif defined(_GLIB_HAVE_BUILTIN_OVERFLOW_CHECKS)
     483                 :             : 
     484                 :             : #define g_uint_checked_add(dest, a, b) \
     485                 :             :     (!__builtin_add_overflow(a, b, dest))
     486                 :             : #define g_uint_checked_mul(dest, a, b) \
     487                 :             :     (!__builtin_mul_overflow(a, b, dest))
     488                 :             : 
     489                 :             : #define g_uint64_checked_add(dest, a, b) \
     490                 :             :     (!__builtin_add_overflow(a, b, dest))
     491                 :             : #define g_uint64_checked_mul(dest, a, b) \
     492                 :             :     (!__builtin_mul_overflow(a, b, dest))
     493                 :             : 
     494                 :             : #define g_size_checked_add(dest, a, b) \
     495                 :             :     (!__builtin_add_overflow(a, b, dest))
     496                 :             : #define g_size_checked_mul(dest, a, b) \
     497                 :             :     (!__builtin_mul_overflow(a, b, dest))
     498                 :             : 
     499                 :             : #elif defined(_GLIB_HAVE_INTSAFE_OVERFLOW_CHECKS)
     500                 :             : 
     501                 :             : #include <intsafe.h>
     502                 :             : 
     503                 :             : #define g_uint_checked_add(dest, a, b) \
     504                 :             :   (!UIntAdd (a, b, dest))
     505                 :             : #define g_uint_checked_mul(dest, a, b) \
     506                 :             :   (!UIntMult (a, b, dest))
     507                 :             : 
     508                 :             : #define g_uint64_checked_add(dest, a, b) \
     509                 :             :   (!ULongLongAdd (a, b, dest))
     510                 :             : #define g_uint64_checked_mul(dest, a, b) \
     511                 :             :   (!ULongLongMult (a, b, dest))
     512                 :             : 
     513                 :             : #define g_size_checked_add(dest, a, b) \
     514                 :             :   (!SizeTAdd (a, b, dest))
     515                 :             : #define g_size_checked_mul(dest, a, b) \
     516                 :             :   (!SizeTMult (a, b, dest))
     517                 :             : 
     518                 :             : #else /* !_GLIB_HAVE_STD_OVERFLOW_CHECKS */
     519                 :             : 
     520                 :             : /* The names of the following inlines are private.  Use the macro
     521                 :             :  * definitions above.
     522                 :             :  */
     523                 :           9 : static inline gboolean _GLIB_CHECKED_ADD_UINT (guint *dest, guint a, guint b) {
     524                 :           9 :   *dest = a + b; return *dest >= a; }
     525                 :           9 : static inline gboolean _GLIB_CHECKED_MUL_UINT (guint *dest, guint a, guint b) {
     526                 :           9 :   *dest = a * b; return !a || *dest / a == b; }
     527                 :           9 : static inline gboolean _GLIB_CHECKED_ADD_UINT64 (guint64 *dest, guint64 a, guint64 b) {
     528                 :           9 :   *dest = a + b; return *dest >= a; }
     529                 :           9 : static inline gboolean _GLIB_CHECKED_MUL_UINT64 (guint64 *dest, guint64 a, guint64 b) {
     530                 :           9 :   *dest = a * b; return !a || *dest / a == b; }
     531                 :           9 : static inline gboolean _GLIB_CHECKED_ADD_SIZE (gsize *dest, gsize a, gsize b) {
     532                 :           9 :   *dest = a + b; return *dest >= a; }
     533                 :           9 : static inline gboolean _GLIB_CHECKED_MUL_SIZE (gsize *dest, gsize a, gsize b) {
     534                 :           9 :   *dest = a * b; return !a || *dest / a == b; }
     535                 :             : 
     536                 :             : #define g_uint_checked_add(dest, a, b) \
     537                 :             :     _GLIB_CHECKED_ADD_UINT(dest, a, b)
     538                 :             : #define g_uint_checked_mul(dest, a, b) \
     539                 :             :     _GLIB_CHECKED_MUL_UINT(dest, a, b)
     540                 :             : 
     541                 :             : #define g_uint64_checked_add(dest, a, b) \
     542                 :             :     _GLIB_CHECKED_ADD_UINT64(dest, a, b)
     543                 :             : #define g_uint64_checked_mul(dest, a, b) \
     544                 :             :     _GLIB_CHECKED_MUL_UINT64(dest, a, b)
     545                 :             : 
     546                 :             : #define g_size_checked_add(dest, a, b) \
     547                 :             :     _GLIB_CHECKED_ADD_SIZE(dest, a, b)
     548                 :             : #define g_size_checked_mul(dest, a, b) \
     549                 :             :     _GLIB_CHECKED_MUL_SIZE(dest, a, b)
     550                 :             : 
     551                 :             : #endif /* !_GLIB_HAVE_STD_OVERFLOW_CHECKS */
     552                 :             : 
     553                 :             : /* IEEE Standard 754 Single Precision Storage Format (gfloat):
     554                 :             :  *
     555                 :             :  *        31 30           23 22            0
     556                 :             :  * +--------+---------------+---------------+
     557                 :             :  * | s 1bit | e[30:23] 8bit | f[22:0] 23bit |
     558                 :             :  * +--------+---------------+---------------+
     559                 :             :  * B0------------------->B1------->B2-->B3-->
     560                 :             :  *
     561                 :             :  * IEEE Standard 754 Double Precision Storage Format (gdouble):
     562                 :             :  *
     563                 :             :  *        63 62            52 51            32   31            0
     564                 :             :  * +--------+----------------+----------------+ +---------------+
     565                 :             :  * | s 1bit | e[62:52] 11bit | f[51:32] 20bit | | f[31:0] 32bit |
     566                 :             :  * +--------+----------------+----------------+ +---------------+
     567                 :             :  * B0--------------->B1---------->B2--->B3---->  B4->B5->B6->B7->
     568                 :             :  */
     569                 :             : /* subtract from biased_exponent to form base2 exponent (normal numbers) */
     570                 :             : typedef union  _GDoubleIEEE754  GDoubleIEEE754;
     571                 :             : typedef union  _GFloatIEEE754   GFloatIEEE754;
     572                 :             : #define G_IEEE754_FLOAT_BIAS    (127)
     573                 :             : #define G_IEEE754_DOUBLE_BIAS   (1023)
     574                 :             : /* multiply with base2 exponent to get base10 exponent (normal numbers) */
     575                 :             : #define G_LOG_2_BASE_10         (0.30102999566398119521)
     576                 :             : #if G_BYTE_ORDER == G_LITTLE_ENDIAN
     577                 :             : union _GFloatIEEE754
     578                 :             : {
     579                 :             :   gfloat v_float;
     580                 :             :   struct {
     581                 :             :     guint mantissa : 23;
     582                 :             :     guint biased_exponent : 8;
     583                 :             :     guint sign : 1;
     584                 :             :   } mpn;
     585                 :             : };
     586                 :             : union _GDoubleIEEE754
     587                 :             : {
     588                 :             :   gdouble v_double;
     589                 :             :   struct {
     590                 :             :     guint mantissa_low : 32;
     591                 :             :     guint mantissa_high : 20;
     592                 :             :     guint biased_exponent : 11;
     593                 :             :     guint sign : 1;
     594                 :             :   } mpn;
     595                 :             : };
     596                 :             : #elif G_BYTE_ORDER == G_BIG_ENDIAN
     597                 :             : union _GFloatIEEE754
     598                 :             : {
     599                 :             :   gfloat v_float;
     600                 :             :   struct {
     601                 :             :     guint sign : 1;
     602                 :             :     guint biased_exponent : 8;
     603                 :             :     guint mantissa : 23;
     604                 :             :   } mpn;
     605                 :             : };
     606                 :             : union _GDoubleIEEE754
     607                 :             : {
     608                 :             :   gdouble v_double;
     609                 :             :   struct {
     610                 :             :     guint sign : 1;
     611                 :             :     guint biased_exponent : 11;
     612                 :             :     guint mantissa_high : 20;
     613                 :             :     guint mantissa_low : 32;
     614                 :             :   } mpn;
     615                 :             : };
     616                 :             : #else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
     617                 :             : #error unknown ENDIAN type
     618                 :             : #endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
     619                 :             : 
     620                 :             : typedef struct _GTimeVal GTimeVal GLIB_DEPRECATED_TYPE_IN_2_62_FOR(GDateTime);
     621                 :             : 
     622                 :             : struct _GTimeVal
     623                 :             : {
     624                 :             :   glong tv_sec;
     625                 :             :   glong tv_usec;
     626                 :             : } GLIB_DEPRECATED_TYPE_IN_2_62_FOR(GDateTime);
     627                 :             : 
     628                 :             : typedef gint grefcount;
     629                 :             : typedef gint gatomicrefcount;  /* should be accessed only using atomics */
     630                 :             : 
     631                 :             : G_END_DECLS
     632                 :             : 
     633                 :             : #endif /* __G_TYPES_H__ */
        

Generated by: LCOV version 2.0-1