1. 30 Jul, 2018 2 commits
  2. 18 Jul, 2018 1 commit
  3. 17 Jul, 2018 2 commits
  4. 16 Jul, 2018 5 commits
  5. 11 Jul, 2018 2 commits
  6. 10 Jul, 2018 1 commit
    • Philip Withnall's avatar
      gatomic: Tweak __atomic_load*() calls to work with -Wbad-function-cast · 194df27f
      Philip Withnall authored
      When compiling third-party projects with -Wbad-function-cast, the inline
      g_atomic_pointer_get() implementation which uses C11 __atomic_load*()
      calls on GCC was causing compilation errors like:
      
         error: cast from function call of type ‘long unsigned int’ to non-matching type ‘void *’
      
      While we don’t want to compile all of GLib with -Wbad-function-cast, we
      should support its headers being included in projects which do enable
      that warning.
      
      It doesn’t seem to be possible to cast away the warning (e.g. by casting
      the function’s result through (void)), so we have to assign to an
      intermediate integer of the right size first.
      
      The same has to be done for the bool return value from
      __sync_bool_compare_and_swap(). In that case, casting from bool to
      gboolean raises a -Wbad-function-cast warning, since gboolean is
      secretly int.
      
      The atomic tests have been modified to enable -Wbad-function-cast to
      catch regressions of this in futur...
      194df27f
  7. 09 Jul, 2018 9 commits
    • Richard Hughes's avatar
      Add a g_ref_string_new_len() to allow creating from non-NUL byte arrays · dad58d73
      Richard Hughes authored
      A lot of GLib APIs provide a string length and explicitly say that the strings
      are not NUL terminated. For instance, parsing XML using GMarkupParser or
      reading packed binary strings from mmapped data files.
      dad58d73
    • Philip Withnall's avatar
      glib: Don’t use time(NULL) to get current time · 92e05928
      Philip Withnall authored
      Use either g_get_real_time() or g_date_time_new_now_local(). This means
      we don’t need to worry about time_t being 32b in future (the year 2038
      problem), and it makes the need for error handling a bit more explicit.
      Improve the error handling in several cases.
      
      Based on a patch by Niels De Graef
      (!142
      
      ).
      
      Signed-off-by: Philip Withnall's avatarPhilip Withnall <withnall@endlessm.com>
      
      #1402
      92e05928
    • Emmanuele Bassi's avatar
      Increase coverage of atomic refcounted data · 0d00667d
      Emmanuele Bassi authored
      We are not testing the API directly, and this leads to holes in the code
      coverage.
      0d00667d
    • Emmanuele Bassi's avatar
      Increase coverage for GRefString · 37687941
      Emmanuele Bassi authored
      We still have some holes in the code coverage of the GRefString test
      suite.
      37687941
    • Emmanuele Bassi's avatar
      Add length accessor for GRefString · 32ecb86f
      Emmanuele Bassi authored
      Since we store the size of the allocation in the underlying ArcBox, we
      can get a constant time getter for the length of the string.
      32ecb86f
    • Emmanuele Bassi's avatar
      Add size accessor to RcBox and ArcBox · 43b7a8f1
      Emmanuele Bassi authored
      It may be useful to know how big a reference counted allocation is
      outside of internal checks.
      43b7a8f1
    • Emmanuele Bassi's avatar
      Add reference counted strings · 00a723f5
      Emmanuele Bassi authored
      The last part of the reference counting saga.
      
      Now that we have:
      
       - reference counter types
       - reference counted allocations
      
      we can finally add reference counted strings using reference counted
      allocations to avoid creating a new String type, and reimplementing
      every single string-based API.
      00a723f5
    • Emmanuele Bassi's avatar
      Make g_rc_box_dup()/g_arc_box_dup() more generic · 8990c3c4
      Emmanuele Bassi authored
      It's more useful to have a dup() function that copies any blob of memory
      into a reference counted allocation, than to have a dup() that only
      copies a reference counted allocation.
      8990c3c4
    • Emmanuele Bassi's avatar
      Add refcounted data · c5d2417d
      Emmanuele Bassi authored
      It is useful to provide a "reference counted allocation" API that can
      add reference counting semantics to any memory allocation. This allows
      turning data structures that usually are placed on the stack into memory
      that can be placed on the heap without:
      
       - adding a public reference count field
       - implementing copy/free semantics
      
      This mechanism is similar to Rust's Rc<Box<T>> combination of traits,
      and uses a Valgrind-friendly overallocation mechanism to store the
      reference count into a private data segment, like we do with GObject's
      private instance data.
      c5d2417d
  8. 06 Jul, 2018 1 commit
  9. 29 Jun, 2018 2 commits
  10. 22 Jun, 2018 1 commit
  11. 21 Jun, 2018 2 commits
    • Daniel Drake's avatar
      gspawn: Optimize with posix_spawn codepath · 61f54591
      Daniel Drake authored
      When the amount of free memory on the system is somewhat low, gnome-shell
      will sometimes fail to launch apps, reporting the error:
        fork(): Cannot allocate memory
      
      fork() is failing here because while cloning the process virtual address
      space, Linux worries that the thread being forked may end up COWing the
      entire address space of the parent process (gnome-shell, which is
      memory-hungry), and there is not enough free memory to permit that to
      happen.
      
      In this case we are simply calling fork() in order to quickly call exec(),
      which will throw away the entirity of the duplicated VM, so we should
      look for ways to avoid the overcommit check.
      
      The well known solution to this is to use clone(CLONE_VM) or vfork(), which
      completely avoids creating a new memory address space for the child.
      However, that comes with a bunch of caveats and complications:
      
        https://gist.github.com/nicowilliams/a8a07b0fc75df05f684c23c18d7db234
        https://ewontfix.com/7/
      
      In 2016, glibc's posix_spawn() was rewritten to use this approach
      while also resolving the concerns.
      https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=9ff72da471a509a8c19791efe469f47fa6977410
      
      I experimented with a similar approach in glib, but it was not practical
      because glibc has several items of important internal knowledge (such as
      knowing which signals should be given special treatment because they are
      NPTL implementation details) that are not cleanly exposed elsewhere.
      
      Instead, this patch adapts the gspawn code to use posix_spawn() where
      possible, which will reap the benefits of that implementation.
      The posix_spawn API is more limited than the gspawn API though,
      partly due to natural limitations of using CLONE_VM, so the posix_spawn
      path is added as a separate codepath which is only executed when the
      conditions are right. Callers such as gnome-shell will have to be modified
      to meet these conditions, such as not having a child_setup function.
      
      In addition to allowing for the gnome-shell "Cannot allocate memory"
      failure to be avoided, this should result in a general speedup in this
      area, because fork()'s behaviour of cloning the entire VM space
      has a cost which is now avoided. posix_spawn() has also recently
      been optimized on OpenSolaris as the most performant way to spawn
      a child process.
      61f54591
    • Daniel Drake's avatar
      gspawn: Add g_spawn_async_with_fds variant · 3524de16
      Daniel Drake authored
      Add a new process spawning function variant which allows the caller
      to pass specific file descriptors for stdin, stdout and stderr.
      It is otherwise identical to g_spawn_async_with_pipes.
      
      Allow the same fd to be passed in multiple parameters. To make this
      workable, the child process logic that closes the fd after the first time
      it has been dup2'ed needed tweaking; we now just set those fds to be
      closed upon exec using the CLOEXEC flag. Add a test for this case.
      
      This will be used by gnome-shell to avoid performing equivalent
      dup2 actions in a child_setup function. Dropping use of child_setup will
      enable use of an upcoming optimized process spawning codepath.
      3524de16
  12. 14 Jun, 2018 2 commits
  13. 12 Jun, 2018 1 commit
  14. 11 Jun, 2018 2 commits
    • LRN's avatar
      Force binary mode for stdout in printf tests · ce1e32ec
      LRN authored
      This allows test calls to produce output with \n
      line separators on Windows, instead of \r\n.
      Reduces the number of ifdefs, since all checks
      can be done against one template on all platforms.
      ce1e32ec
    • Emmanuele Bassi's avatar
      Add tests for refcount types · 09e2247d
      Emmanuele Bassi authored
      Test that the API behaves as expected, especially when we get to
      saturation.
      
      Additionally, check that both the function and the macro versions of the
      API behave identically.
      09e2247d
  15. 10 Jun, 2018 1 commit
    • Emmanuele Bassi's avatar
      Classify the tests · 16d1a3d2
      Emmanuele Bassi authored
      Meson has the ability to classify tests according to "suites", a list of
      tags. This is especially useful when we want to run specific sets of
      tests — e.g. only GLib's tests — instead of the whole test suite. It
      also allows us to classify special tests, like "slow" ones, so that we
      can only run them when needed.
      16d1a3d2
  16. 08 Jun, 2018 1 commit
  17. 04 Jun, 2018 1 commit
  18. 29 May, 2018 1 commit
    • Emmanuele Bassi's avatar
      Add fuzzy floating point comparison macro · 0b4c2eef
      Emmanuele Bassi authored
      Add a test macro that allows comparing two floating point values for
      equality within a certain tolerance.
      
      This macro has been independently reimplemented by various projects:
      
       * Clutter
       * Graphene
       * colord
      
      #914
      0b4c2eef
  19. 27 May, 2018 1 commit
  20. 26 May, 2018 1 commit
  21. 25 May, 2018 1 commit
    • Jan Alexander Steffens's avatar
      macros: Double-cast func for g_autolist to avoid warning · c7d11d34
      Jan Alexander Steffens authored
      For g_autolist and g_autoslist, the cleanup func was cast to
      GDestroyNotify before being passed to g_(s)list_free_full. This cast
      provokes GCC 8 to emit a warning if the return type is not void:
      
          …/gmacros.h:462:99: warning: cast between incompatible function types
          from … to 'void (*)(void *)' [-Wcast-function-type]
      
      Cast to 'void (*)(void)' first, which suppresses the warning as
      recommended by the GCC documentation. g_autoptr remains untouched.
      
      Fixes #1382
      c7d11d34