Commit Graph

7386 Commits

Author SHA1 Message Date
Egor Bychin
a3f81a2ef5 gkeyfile: Remove unreachable code 2021-10-15 14:15:43 +03:00
Egor Bychin
e9adcd8f7f gbacktrace: Fix fcntl command arguments not being checked 2021-10-15 14:15:43 +03:00
Gleb Popov
709226d6f2 Do not try to access errno after calling getpwnam_r. 2021-09-28 10:36:42 +00:00
liuyangming
2b8682191c fix uninitial variable 2021-09-27 18:35:37 +08:00
Emmanuel Fleury
f304df34c7 Coerce type cast to void* because it causes compiler warnings
glib/gtestutils.c:4261:11: warning: incompatible pointer types passing 'gpointer *' (aka 'void **') to parameter of type 'GSList **' (aka 'struct _GSList **')
  while (!g_atomic_pointer_compare_and_exchange (test_filename_free_list, node->next, node));
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
glib/gatomic.h:215:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
    __atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
                                           ^~~~~~~~~~~~~~
2021-09-23 22:09:07 +02:00
Michael Catanzaro
969a26378b Merge branch 'fix_pw_name_segfault' into 'main'
gutils: Avoid segfault in g_get_user_database_entry

See merge request GNOME/glib!2244
2021-09-22 12:46:00 +00:00
Jamie Bainbridge
bb40105fe9 gutils: Avoid segfault in g_get_user_database_entry
g_get_user_database_entry() capitalises the first letter of pw_name
with g_ascii_toupper (pw->pw_name[0]).

However, the manpage for getpwnam() and getpwuid() says the result of
those calls "may point to a static area". GLib is then trying to edit
static memory which belongs to a shared library, so segfaults.

The reentrant variants of the above calls are supposed to fill the user
buffer supplied to them, however Michael Catanzaro also found a bug in
systemd where the data is not copied to the user buffer and still points
to static memory, resulting in the same sort of segfault. See:
https://github.com/systemd/systemd/issues/20679

Solve both these cases in GLib by copying pw_name off to a temporary
variable, set uppercase on that variable, and use the variable to join
into the desired string. Free the variable after it is no longer needed.

Signed-off-by: Jamie Bainbridge <jamie.bainbridge@gmail.com>
2021-09-22 11:40:45 +10:00
Emmanuele Bassi
6fcad9d288 Merge branch 'open-2.71' into 'main'
Add version macros for GLib 2.72 and bump version to 2.71.0

See merge request GNOME/glib!2249
2021-09-21 13:36:42 +00:00
Philip Withnall
bbd1350beb Merge branch '#0434_GSequenceSlowsDown_counter' into 'main'
gsequence: make treap priorities more random to avoid worst-case scenarios

Closes #2468

See merge request GNOME/glib!2236
2021-09-21 10:40:48 +00:00
Matthias Clasen
ab895d91d5 Update to Unicode 14 2021-09-21 09:41:29 +00:00
Matthias Clasen
7fc7c57b6f GString: Bump minimum size
GString starts out at a size of 2, which is just
not useful. Bump the minimum size to 64 to cut
down on the number of tiny reallocations we do.
2021-09-18 20:16:57 -04:00
Philip Withnall
94b74c761d gversionmacros: Add version macros for GLib 2.72
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-09-17 11:35:21 +01:00
Alexandr Miloslavskiy
59e5612339 gsequence: make treap priorities more random to avoid worst-case scenarios
Previously, priority was not randomly generated and was instead derived
from `GSequenceNode*` pointer value.

As a result, when a `GSequence` was freed and another was created, the
nodes were returned to memory allocator in such order that allocating
them again caused various performance problems in treap.

To my understanding, the problem develops like this :
1) Initially, memory allocator makes some nodes
2) For each node, priority is derived from pointer alone.
   Due to the hash function, initially the priorities are reasonably
   randomly distributed.
3) `GSequence` moves inserted nodes around to satisfy treap property.
   The priority for node must be >= than priorities of its children
4) When `GSequence` is freed, it frees nodes in a new order.
   It finds root node and then recursively frees left/right children.
   Due to (3), hashes of freed nodes become partially ordered.
   Note that this doesn't depend on choice of hash function.
5) Memory allocator will typically add freed chunks to free list.
   This means that it will reallocate nodes in same or inverse order.
6) This results in order of hashes being more and more non-random.
7) This order happens to be increasingly anti-optimal.
   That is, `GSequence` needs more `node_rotate` to maintain treap.
   This also causes the tree to become more and more unbalanced.
   The problem becomes worse with each iteration.

The solution is to use additional noise to maintain reasonable
randomness. This prevents "poisoning" the memory allocator.

On top of that, this patch somehow decreases average tree's height,
which is good because it speeds up various operations. I can't quite
explain why the height decreases with new code, probably the properties
of old hash function didn't quite match the needs of treap?

My averaged results for tree height with different sequence lengths:
  Items | before|         after |
--------+-------+---------------+
      2 |  2,69 |  2,67 -00,74% |
      4 |  3,71 |  3,80 +02,43% |
      8 |  5,30 |  5,34 +00,75% |
     16 |  7,45 |  7,22 -03,09% |
     32 | 10,05 |  9,38 -06,67% |
     64 | 12,97 | 11,72 -09,64% |
    128 | 16,01 | 14,20 -11,31% |
    256 | 19,11 | 16,77 -12,24% |
    512 | 22,03 | 19,39 -11,98% |
   1024 | 25,29 | 22,03 -12,89% |
   2048 | 28,43 | 24,82 -12,70% |
   4096 | 31,11 | 27,52 -11,54% |
   8192 | 34,31 | 30,30 -11,69% |
  16384 | 37,40 | 32,81 -12,27% |
  32768 | 40,40 | 35,84 -11,29% |
  65536 | 43,00 | 38,24 -11,07% |
 131072 | 45,50 | 40,83 -10,26% |
 262144 | 48,40 | 43,00 -11,16% |
 524288 | 52,40 | 46,80 -10,69% |

The memory cost of the patch is zero on 64-bit, because the new field
uses the alignment hole between two other fields.

Note: priorities can sometimes have collisions. This is fine, because
treap allows equal priorities, but these will gradually decrease
performance. The hash function that was used previously has just one
collision on 0xbfff7fff in 32-bit space, but such pointer will not
occur because `g_slice_alloc()` always aligns to sizeof(void*).
However, in 64-bit space the old hash function had collisions anyway,
because it only uses lower 32 bits of pointer.

Closes #2468
2021-09-09 23:34:16 +03:00
Evan Miller
508352339a Fix false deprecation warnings on old GCC/MSVC
Closes #2472
2021-09-07 11:21:20 +01:00
Philip Withnall
0eadf651fb tests: Rewrite thread-pool test for freeing queued items
The previous test was racy: it assumed that not all queued thread pool
jobs would start to be executed before `g_thread_pool_free()` was
called, whereas actually on some systems (particularly BSD ones), they
would all start (or even finish) being executed, and hence the free
function might never be called.

Rewrite the test to:
 • Synchronise the test function and worker thread functions more
   closely.
 • Not bother about ordering the shared and exclusive variants of the
   test differently. That seems to be a hangover from another test
   above.
 • Limit the number of worker threads to 1, rather than 2, since this
   makes the test easier to control.

This has been tested with `--repeat 10000` on Linux, and it succeeds all
of those runs whereas previously it failed quite reliably.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2456
2021-08-19 14:25:24 +01:00
Philip Withnall
b402f66c07 gthreadpool: Remove a dummy item from the queue before freeing
Now that `g_thread_pool_new_full()` can be used to set a user-provided
free function for queue elements, ensure that the internal dummy item
used to wake up the worker threads is removed from the queue before it’s
called.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2456
2021-08-19 14:25:24 +01:00
Simon McVittie
052e335500 tests: Make use of g_test_fail_message()
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-19 09:49:11 +01:00
Simon McVittie
a076dbcb68 gtestutils: Allow failing a test with a printf-style message
This allows a pattern like

    g_test_message ("cannot reticulate splines: %s", error->message);
    g_test_fail ();

to be replaced by the simpler

    g_test_fail_printf ("cannot reticulate splines: %s", error->message);

with the secondary benefit of making the message available to TAP
consumers as part of the "not ok" message.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-19 09:49:11 +01:00
Simon McVittie
182d9995ca gtestutils: Allow skipping tests with a printf-style message
Forming the g_test_skip() message from printf-style arguments seems
common enough to deserve a convenience function.

g_test_incomplete() is mechanically almost equivalent to g_test_skip()
(the semantics are different but the implementation is very similar),
so give it a similar mechanism for symmetry.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-19 09:41:08 +01:00
Sebastian Dröge
336c747e59 Merge branch 'string-ctors' into 'main'
Annotate the GString constructors

See merge request GNOME/glib!2226
2021-08-17 07:10:54 +00:00
Avinash Sonawane
31f793b71a Docs: Mention that G_VA_COPY() must be followed by va_end() 2021-08-16 20:05:59 +00:00
Emmanuele Bassi
d5b6c55cfe Annotate the GString constructors
Otherwise the introspection scanner won't recognise them as
constructors, because the GString get_type function has a different
symbol prefix.

See: https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/399
2021-08-16 20:58:53 +01:00
Simon McVittie
b006403c4e tests: Fix error handling when testing gtestutils
We had two compensating bugs here. We didn't correctly clear the
error indicator after testing a test-case that calls g_test_fail(),
which meant we were leaving the error set to exit status 1 when
falling through to the next test; and then we didn't check the exit
status of the next test, but instead assumed that g_spawn_sync()
would fail (it does not).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-05 12:09:53 +01:00
Philip Withnall
709df8eeb4 Merge branch 'docgen-fixes' into 'main'
Adapt documentation to gi-docgen

See merge request GNOME/glib!2206
2021-08-03 13:53:38 +00:00
Emmanuele Bassi
bed2da6cc2 docs: Break gtk-doc stanzas into paragraphs
Keep the first paragraph short, to act as a summary.
2021-08-02 16:00:12 +01:00
Emmanuele Bassi
4bbe7912a1 docs: Use the correct sigils for pre-processor symbols
And reduce the excessive whitespace in argument and return value blocks.
2021-08-02 15:59:43 +01:00
Emmanuele Bassi
97a6111c83 docs: Enable syntax highlighting on code examples 2021-08-02 15:56:42 +01:00
Emmanuele Bassi
3b5d3ed2e3 docs: Fix KeyFile annotations
Use the right gtk-doc sigil for pre-processor symbols.

Reduce the indentation in argument annotations, to avoid them being
parsed as code blocks.
2021-08-02 15:55:08 +01:00
Simon McVittie
37e5dfd3a2 Merge branch 'close-range-cloexec' into 'main'
gspawn: Use CLOSE_RANGE_CLOEXEC if available

See merge request GNOME/glib!2184
2021-08-02 14:49:27 +00:00
Emmanuele Bassi
1b666b7f12 docs: Clean up the GDate types description
Split the first paragraph.

Use the correct gtk-doc sigil for enumeration value.

Use the appropriate term for negative years in the Western calendar.
2021-08-02 14:54:34 +01:00
Emmanuele Bassi
2aedaf293b docs: Annotate glib_check_version()
Add introspection annotations.

Reduce the indentation for the return value documentation string.

Use the appropriate gtk-doc syntax for symbols.
2021-08-02 14:52:06 +01:00
Philip Withnall
92bdc92d6d Merge branch 'unicode-typo-fix' into 'main'
Fix a Unicode typo

See merge request GNOME/glib!2201
2021-08-02 13:44:20 +00:00
Philip Withnall
d6576e9781 Merge branch 'nfc-nfd-test' into 'main'
tests: Add a test for Unicode normalization

See merge request GNOME/glib!2204
2021-08-02 13:17:23 +00:00
Philip Withnall
fad0a6af87 Merge branch 'wip/smcv/2452-g-string-0-length-replace' into 'main'
g_string_replace: Don't replace empty string more than once per location

Closes #2452

See merge request GNOME/glib!2208
2021-08-02 12:47:03 +00:00
Simon McVittie
b13777841f g_string_replace: Document behaviour of zero-length match pattern
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 12:36:26 +01:00
Simon McVittie
bf70d58d55 test_string_replace: Exercise zero-length replacements
Previously, these would have done 2**32 replacements, and the first one
would have consumed 6GB of memory in the process. They now match what
Python `str.replace()` does.

Reproduces: https://gitlab.gnome.org/GNOME/glib/-/issues/2452
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 12:31:19 +01:00
Simon McVittie
0a8c7e57ab g_string_replace: Don't replace empty string more than once per location
This matches the behaviour of Python `str.replace()`, and avoids carrying
out 2**32 replacements before n wraps around, which is almost certainly
not what we want.

Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/2452
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 12:31:19 +01:00
Simon McVittie
7d35e49c42 test_string_replace: Expand test coverage
These are taken from another project (steam-runtime-tools) where I
implemented a similar replace method before realising that more recent
GLib versions had g_string_replace().

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 12:31:19 +01:00
Simon McVittie
c64e6cfc79 test_string_replace: Make the test table-driven
This makes it straightforward to add more test-cases.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 12:31:19 +01:00
Simon McVittie
24b652d3ca test_string_replace: Make types agree
g_string_replace() returns guint, not gint.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-02 11:53:56 +01:00
Casper Dik
a75ffc5112 gspawn: safe_fdwalk for Solaris 11.4
Use F_NEXTFD/F_PREVFD for fdwalk when they are available.

Closes #2429
2021-08-01 12:52:34 -07:00
Casper Dik
790571a2cd gspawn: safe_closefrom for Solaris 11.3/11.4
When F_CLOSEFROM is defined, we know that closefrom() is signal safe.
2021-08-01 12:43:19 -07:00
Matthias Clasen
9599a9451c Add a test for Unicode normalization
This test verifies the examples from the Unicode
Annex that defines normalization.
2021-07-30 16:54:59 +01:00
Matthias Clasen
770059b588 tests: Remove a misplaced comment
This comment had nothing to do with the test below.
2021-07-29 14:19:41 -04:00
Matthias Clasen
6a6da9637a Fix a Unicode typo
The name of one of the Unicode Break types is misspelt.
Add an alias, since it annoys me every time I look at
Pango's break code.
2021-07-29 10:09:27 -04:00
Philip Withnall
808cde540a Merge branch 'source-static-name' into 'main'
Port internal uses to use g_source_set_static_name()

See merge request GNOME/glib!2198
2021-07-26 15:05:50 +00:00
Philip Withnall
ef6a551739 Merge branch 'main' into 'main'
Fix some test suite memory leaks

See merge request GNOME/glib!2195
2021-07-26 10:06:08 +00:00
Philip Withnall
8e963e0e31 Port internal uses to use g_source_set_static_name()
This should reduce allocations.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-07-26 11:01:07 +01:00
Matthias Clasen
bb4d390577 mainloop: Add g_source_set_static_name
g_source_set_name duplicates the string, and this is
showing up as one of the more prominent sources of strdups
in GTK profiles, despite all the names we use being literals.

Add a variant that avoids the overhead.
2021-07-24 11:26:40 -04:00
GOUJON Évan
5e356d90b2 glib/tests/spawn-path-search: Fix memory leaks 2021-07-23 22:21:28 +02:00