Skip to content
  • Allison Karlitskaya's avatar
    GLib: add bounds-checked unsigned int arithmetic · d0219f25
    Allison Karlitskaya authored
    Add some helpers for builds-checked unsigned integer arithmetic to GLib.
    These will be based on compiler intrinsics where they are available,
    falling back to standard manual checks otherwise.
    
    The fallback case needs to be implemented as a function (which we do
    inline) because we cannot rely on statement expressions.  We also
    implement the intrinsics case as an inline in order to avoid people
    accidentally writing non-portable code which depends on static
    evaluation of the builtin.
    
    For now there is only support for addition and multiplication for guint,
    guint64 and gsize.  It may make sense to add support for subtraction or
    for the signed equivalents of those types in the future if we find a use
    for that.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=503096
    d0219f25