Commit Graph

1204 Commits

Author SHA1 Message Date
Colin Walters
4808a957b5 GFile: Add g_file_peek_path()
This is a variant of g_file_get_path() which returns a const string to
the caller, rather than transferring ownership.

I've been carrying `gs_file_get_path_cached()` in libgsystem and it
has seen a lot of use in the ostree and flatpak codebases.  There are
probably others too.

I think language bindings like Python/Gjs could also use this to avoid
an extra malloc (i.e. we could transparently replace
`g_file_get_path()` with `g_file_peek_path()`.

(Originally by Colin Walters. Tweaked by Philip Withnall to update to
2.56, change the function name and drop the locking.)

https://bugzilla.gnome.org/show_bug.cgi?id=767976
2018-01-15 18:26:56 +00:00
Simon McVittie
2685a533af gdbus-threading test: Allow even longer for test_method_calls_in_thread
This should take 4 seconds + overhead, but on a slow or heavily
loaded system, there's no guarantee that it won't take significantly
longer.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=792364
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=884660
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-01-09 13:10:38 +00:00
Florian Müllner
a55bfeee41 gdesktopappinfo: Add g_desktop_app_info_get_locale_string()
Custom desktop file fields may be translated, but there is currently
no non-hacky way to look up the localized value; fill get gap with
a small wrapper around g_key_file_get_locale_string().

https://bugzilla.gnome.org/show_bug.cgi?id=779413
2018-01-08 16:28:34 +01:00
Philip Withnall
eba53aa07e build: Add missing test GSchema XML file to dist list
This was introduced in bug #742997, but not added to the Makefile.am, so
it’s missing from tarballs.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: nobody

https://bugzilla.gnome.org/show_bug.cgi?id=792322
2018-01-08 12:05:21 +00:00
Christoph Reiter
cf93b27ceb meson: fix static build under Windows
Properly define GLIB/GOBJECT_STATIC_COMPILATION when static build is enabled.
Use library() instead of shared_library() to allow selecting static builds.

https://bugzilla.gnome.org/show_bug.cgi?id=784995
2018-01-04 22:21:40 +01:00
howetuft
0e22d19a11 Bug-790839 GApplication command line --help enhancements
In order to enrich information displayed by GApplication command line
handling when --help is invoked, 3 new methods are proposed:
. g_application_set_option_context_parameter_string
. g_application_set_option_context_summary
. g_application_set_option_context_description
Those methods interact with the GApplication's internal GOptionContext
which is created for command line parsing in g_application_parse_command_line.
(please refer to the GOptionContext class for more information about option
context, parameter string, summary and description.)

To illustrate the 3 methods, an example is provided:
. gapplication-example-cmdline4.c
2018-01-03 11:08:37 +00:00
Daniel Boles
b441c21a09 gdbus-test-codegen: Cast to void* to printf "%p"
to suppress a compiler error with stricter warnings enabled (GCC):

gdbus-test-codegen.c: In function ‘on_handle_get_self’:
gdbus-test-codegen.c:403:26: error: format ‘%p’ expects argument of type
 ‘void *’, but argument 2 has type ‘GThread * {aka struct _GThread *}’
 [-Werror=format=]
   s = g_strdup_printf ("%p", g_thread_self ());

https://bugzilla.gnome.org/show_bug.cgi?id=792099
2018-01-01 17:23:23 +00:00
Simon McVittie
8fef0a9cd3 gmenumodel test: Wait for the expected events to happen
Previously, we waited an arbitrary 100ms or 200ms and then asserted
that the events had happened, but that might fail if the machine is
slow or heavily loaded.

We still wait for an arbitrary time for negative tests (asserting
that no more signals are received) because we don't have any way
to do better here.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=884661

https://bugzilla.gnome.org/show_bug.cgi?id=791744
2017-12-18 18:56:35 +00:00
Simon McVittie
ea159a9e1a gmenumodel test: If something goes wrong, don't wait forever
I'm about to add some loops that would otherwise wait indefinitely.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=884661

https://bugzilla.gnome.org/show_bug.cgi?id=791744
2017-12-18 18:56:35 +00:00
Havard Graff
db7c1180b3 meson: add libintl when linking gio-tests on OSX
https://bugzilla.gnome.org/show_bug.cgi?id=791460
2017-12-14 16:21:46 +05:30
Mario Sanchez Prada
637a298960 gio/tests/appinfo: New test for launch with "appId-less" applications
New test to make sure we exercise the code paths in gdesktopappinfo.c
that get triggered when g_desktop_app_info_launch_uris_with_spawn()
is used (i.e. unknown app ID, no session bus), both for when either
a single URI or multiple ones are expected by the application.

https://bugzilla.gnome.org/show_bug.cgi?id=791337
2017-12-08 13:47:23 +00:00
Philip Withnall
06719a86b2 docs: Drop unnecessary <!-- -->s from gtk-doc comments
Putting a <!-- --> in plural<!-- -->s was an old hack used to fix
linking the symbol with gtk-doc when gtk-doc didn’t know about plural
forms. gtk-doc does now know about plural forms, so the hack can be
removed.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2017-11-29 17:50:27 +00:00
Philip Withnall
a2a4a10299 tests: Fix some minor memory leaks in gdbus-test-codegen
It’s not entirely leak-free, but it’s better than before.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=741167
2017-11-28 14:28:50 +00:00
Tim Waugh
d35d9b7911 codegen: fix array out-param annotations
When using gdbus-codegen to produce generated code for a method with
an out parameter with a signature like 'as', make sure to include
an "(array)" annotation for that parameter.

(Reworked by Philip Withnall to improve code formatting.)

https://bugzilla.gnome.org/show_bug.cgi?id=741167
2017-11-28 14:28:49 +00:00
Daniel Macks
deeacce18a Do not load systemwide giomodules during self-test
$libdir/gio/modules/*.so on the live build machine are supplied by
third parties, so we should not look there while testing ourselves.

https://bugzilla.gnome.org/show_bug.cgi?id=780309
2017-11-20 10:23:23 +00:00
Daiki Ueno
c71098ddab tests/gmenumodel: Add test cases using peer-to-peer D-Bus connection
https://bugzilla.gnome.org/show_bug.cgi?id=720380
2017-11-17 11:28:43 +00:00
Christian Hergert
ed78f30c5e file: add tests for g_file_load_bytes()
This adds a test for both g_file_load_bytes() and the
asynchronous form g_file_load_bytes_async().

https://bugzilla.gnome.org/show_bug.cgi?id=790272
2017-11-15 04:10:23 -08:00
Christian Hergert
5464461e4c gresource: avoid allocations in enumerate_children()
In the vast majority of cases, we can avoid temporary
allocations for paths in g_resources_enumerate_children().

In the case we need to add a suffix "/", we can usually just
build the path on the stack. In other cases, we can completely
avoid the strdup, which appears to only have been added for
readability. If the path is really long, we fallback to doing
what we did before, and use g_strconcat().

In the case of Builder, this saved 5.3mb of temporary
allocations in the process of showing the first application
window.

https://bugzilla.gnome.org/show_bug.cgi?id=790275
2017-11-15 03:24:29 -08:00
Christian Hergert
38ffcd298c gresourcefile: simplify path canonicalization
Previously, the path canonicalization for resources had liberal use of
strlen() and memmove() while walking through the path. This patch avoids
any secondary strlen() and removes all use of memmove().

A single allocation is created up front as we should only ever need one
additional byte more than then length of the incoming path string.

To keep the implementation readable, the mechanics are kept in external
functions. memrchr() was not used due to its lack of portability.

This is faster in every test case I've tested. Paths that contain
relative ../ have the most speedup.

https://bugzilla.gnome.org/show_bug.cgi?id=790310
2017-11-14 15:13:44 -08:00
Sebastian Dröge
7b60708204 GResource – Create an internal copy of the GBytes if it is not pointer aligned
https://bugzilla.gnome.org/show_bug.cgi?id=790030
2017-11-14 10:39:45 +02:00
Cosimo Cecchi
44d6052584 gfile: add g_file_new_build_filename()
This is a convenience C API that combines g_build_filename() with
g_file_new_for_path().

https://bugzilla.gnome.org/show_bug.cgi?id=788488
2017-11-07 08:25:28 -08:00
Daniel Macks
d88d90c3c8 Exec=true (seach via PATH) instead of hardcoding /bin/true
...otherwise this .desktop is omitted on platforms that have it
elsewhere.

https://bugzilla.gnome.org/show_bug.cgi?id=731705
2017-11-03 20:16:52 +00:00
Jiří Techet
6acaca8831 gio: Show icons based on file's mime type on OS X
The patch basically just grabs the implementation of g_content_type_get_icon_internal()
from gcontenttype.c - the only difference is that it first converts UTI to MIME using
g_content_type_get_mime_type() and at the end frees this temporary MIME type.

https://bugzilla.gnome.org/show_bug.cgi?id=788936
2017-11-03 12:04:33 +00:00
Руслан Ижбулатов
53bd6a359f W32: Add a stat() implementation for private use
This commit adds new W32-only functions to gstdio.c,
and a new header file, gstdioprivate.h.
These functions are:
g_win32_stat_utf8()
g_win32_lstat_utf8()
g_win32_fstat()
and they fill a private structure, GWin32PrivateStat,
which has all the fields that normal stat has, as well as some
extras.

These functions are then used throughout glib and gio to get better
data about the system. Specifically:
* Full, 64-bit size, guaranteed (g_stat() is forced to use 32-bit st_size)
* Full, 64-bit file identifier (st_ino is 0 when normal stat() is used, and still is)
* W32 File attributes (which stat() doesn't report); in particular, this allows
  symlinks to be correctly identified
* Full, 64-bit time, guaranteed (g_stat() uses 32-bit st_*time on 32-bit Windows)
* Allocated file size (as a W32 replacement for the missing st_blocks)

st_mode remains unchanged (thus, no S_ISLNK), so when these are given back to
glib users (via g_stat(), for example, which is now implemented by calling g_win32_stat_utf8),
this field does not contain anything unexpected.

g_lstat() now calls g_win32_lstat_utf8(), which works on symlinks the way it's supposed to.

Also adds the g_win32_readlink_utf8() function, which behaves like readlink()
(including its inability to return 0-terminated strings and inability to say how large
the output buffer should be; these limitations are purely for compatibility with
existing glib code).

Thus, symlink support should now be much better, although far from being complete.

A new W32-only test in gio/tests/file.c highlights the following features:
* allocated size
* 64-bit time
* unique file IDs

https://bugzilla.gnome.org/show_bug.cgi?id=788180
2017-11-01 12:46:38 +00:00
Stef Walter
0f82ff12ea gdbus-proxy: Fix erroneous timeout during following tests
Modified by Philip Withnall to amend a second instance in the same
file.

https://bugzilla.gnome.org/show_bug.cgi?id=711809
2017-10-26 12:01:05 +01:00
Philip Withnall
1e4221a3f7 gio: Add API for identifying system FS types and device paths
This is needed by gnome-control-center and gnome-settings-daemon; it
makes existing checks from gunixmounts.c public.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=788927
2017-10-26 00:19:23 +01:00
Michael Catanzaro
c5202bc5e9 Add socket postmortem test
Checks that after a GSocket is closed, a source created off it
with g_socket_create_source() will dispatch exactly once with
G_IO_NVAL.

Based on a patch by Mikhail Zabaluev

https://bugzilla.gnome.org/show_bug.cgi?id=723655
2017-10-24 09:02:02 -05:00
Emmanuele Bassi
5c13bf9bcf build: Use subdir-objects with Autotools
We're eventually going to drop Autotools, but in the meantime we should
probably use idiomatic options and reduce warnings.

GLib is pretty much already safe for subdir-objects to be enabled,
except in the GIO tests, where the build references files that are
generated in a different level. For that, we can use the same solution
employed by GTK+, and link the appropriate file in the right
sub-directory.

https://bugzilla.gnome.org/show_bug.cgi?id=788989
2017-10-24 13:30:41 +01:00
Friedrich Beckmann
2bd423c54c MacOS: create_cstr_from_cfstring uses safe conversion - use CFStringGetCString
During testing with gdk-pixbuf I noticed failures during content type
to mime conversion. The root reason was the unsafe conversion used
in create_cstr_from_cfstring. The problem was addressed in commit
c60226e0a1 but that was reverted. I noticed the commit only
when I had fixed the problem. In addition I added a test to check
the content type to mime conversion on MacOS. This problem is
discussed in Bug #788936.

See: https://bugzilla.gnome.org/show_bug.cgi?id=788936
2017-10-17 14:10:31 +01:00
Friedrich Beckmann
e55efa35e3 OSX: Use xdgmime system to guess content type from data
Closes: Bug #788401

The problem is described here:

https://bugzilla.gnome.org/show_bug.cgi?id=788401

This patch introduces the use of the xdgmime system to guess
the content type from data. So you can guess for example the
type public.svg-image from the file content of a svg file.
This patch only applies to MacOS. A test for the regression
is also included.
2017-10-14 09:11:01 +01:00
Philip Withnall
3d8296940a tests: Fix case of a string comparison
Fixup to commit 12e32e96a3.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2017-10-11 14:05:21 +01:00
Simon McVittie
331f73c26d gio/tests/gdbus-proxy: sleep longer when testing that we time out
On slow ARM machines doing parallel builds, there's no guarantee that
we'll get scheduled in a window between (100ms|250ms) and 500ms.

Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=769674
2017-10-11 13:32:48 +01:00
Simon McVittie
7d5c738dba gio/tests/file: increase an arbitrary timeout
On slow ARM machines doing parallel builds, there's no guarantee that
we'll get through this in 5 seconds.

Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=769674
2017-10-11 13:32:41 +01:00
Руслан Ижбулатов
4a77eb16ce Replace all instances of ssize_t with gssize
ssize_t is supported widely, but not universally, so use gssize instead.
Currently only one piece of code actually *needs* this change to be compilable
with MSVC, the rest are mostly in *nix parts of the code, but these are changed
too, for symmetry.

https://bugzilla.gnome.org/show_bug.cgi?id=788180
2017-10-11 12:56:11 +01:00
Nirbheek Chauhan
b444ae0de2 meson: Improve gdbus-codegen custom target dependencies
Ensure that the custom targets that use gdbus-codegen get rebuilt when
any of the gdbus-codegen files are changed.

https://bugzilla.gnome.org/show_bug.cgi?id=752239
2017-10-11 16:55:39 +05:30
Maks Naumov
12e32e96a3 Don't skip invalid enum values in schemas
Signed-off-by: Maks Naumov <maksqwe1@ukr.net>

https://bugzilla.gnome.org/show_bug.cgi?id=742997
2017-10-11 10:22:23 +01:00
Nelson Benítez León
32a9b88b20 gio/tests: Add testcase for bug 787731
Add testcase for function g_file_query_filesystem_info()
reporting outdated info for "filesystem::readonly" attribute
when said attribute was different in a previous mounted
partition in the same device (as GIO maintains a mounts cache
per 'st_dev' stat() member).

To trigger a mount operation, testcase uses program 'bindfs'
instead of 'mount --bind' as bindfs does not require root
privileges. And 'fusermount -u' command is used to unmount said
bindfs mount.

As a reference in Fedora, 'bindfs' is installed from 'bindfs'
package and 'fusermount' from 'fuse' package (this one is installed
by default as being part of 'System Tools' group).

The test creates a directory with a file in it, then mounts it
readonly over another directory (the mountpoint), it then checks
that g_file_query_filesystem_info() for the file in it indeed reports
"filesystem::readonly" as TRUE. Then unmounts and mounts again this
time rw (not readonly), it then checks again if g_file_query_filesystem_info()
is reporting "filesystem::readonly" as TRUE, if that's the case, it
confirms the bug by opening said file in write mode.

Testcase is only added for Unix builds.

https://bugzilla.gnome.org/show_bug.cgi?id=787731
2017-09-22 20:28:44 +05:00
Daniel Macks
190f64a0fb Avoid setting unused variables (-Wself-assign)
Setting a variable and then assigning it to itself avoids
-Wunused-but-set-variable but this specific trick is now caught by
-Wself-assign. Instead, actually use the value or don't bother
assigning it at all:

gdbusauth.c: call g_data_input_stream_read_byte() in void context
gdbusauthmechanismsha1.c: value is actually used
gdbusmessage.c: use consistent preprocessor-token protection
gthreadedresolver.c: skip over bytes in data blob
httpd.c: do something useful with the value

https://bugzilla.gnome.org/show_bug.cgi?id=745723
2017-09-11 22:14:18 +01:00
Philip Withnall
73eee8d64e tests: Fix some leaks and double-frees in the GSubprocess tests
Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=786456
2017-08-23 11:37:32 +01:00
Will Thompson
65a95a5a2d gio: failing cases for subprocess cancellable bug
https://bugzilla.gnome.org/show_bug.cgi?id=786456
2017-08-23 11:37:32 +01:00
Philip Withnall
a60359aee2 tests: Add temporary working directory for monitor test
Similarly to the previous commit, move the temporary directory for the
monitor test from $(cwd) to the system temporary directory.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=785260
2017-08-23 11:26:57 +01:00
Philip Withnall
0f5b523fac tests: Add temporary working directory for appmonitor test
Rather than creating a temporary directory in the current directory
(typically the builddir), then never deleting it; create one in the
system /tmp directory, and clean it up properly afterwards.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=785260
2017-08-23 11:26:57 +01:00
Philip Withnall
3ce00b29ec tests: Fix leak in appmonitor test
Spotted by Daniel Macks.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=785260
2017-08-23 11:26:57 +01:00
Chun-wei Fan
32d6a76b98 build: Use Meson's find_library() for MSVC builds as needed
Some of the dependencies' build systems for Visual Studio do not provide a
pkg-config file upon build, so we use find_library() for them when the
corresponding pkg-config files are not found during Visual Studio builds,
so that one will not need to make up pkg-config files for them, which
could be error-prone.  These .lib names match the names that are built
with the officially supported build system that is used by their
respective Visual Studio support.

For ZLib, this will make gio-2.0.pc reflect on the zlib .lib based on
what is found, or whether we use the fallback/bundled ZLib, when we
don't have a pkg-config file for ZLib on MSVC.  We still need to depend
on Meson to be updated to put the correct link argument for linking ZLib
in the pkg-config case.

https://bugzilla.gnome.org/show_bug.cgi?id=783270
2017-08-17 17:17:59 +08:00
Philip Withnall
ad9d5a11f2 tests: Fix gschema-compile test for translatable string changes
Little did I know when making commit
c257757cf6 that a lot of the output of
glib-compile-schemas is string matched in some of the unit tests. Fix
them to match the updated strings.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=695573
2017-08-03 16:32:42 +01:00
Daniel Macks
f7a14fece4 Use "-module" when compiling loadable modules
Some platforms use different extensions for compile-time linkable
libraries vs runtime-loadable modules. Need to use special libtool
flag in the latter case for consistency with what gmodule expects.

https://bugzilla.gnome.org/show_bug.cgi?id=731703
2017-08-03 12:28:10 +01:00
Philip Withnall
5cddde1fb2 Consistently save errno immediately after the operation setting it
Prevent the situation where errno is set by function A, then function B
is called (which is typically _(), but could be anything else) and it
overwrites errno, then errno is checked by the caller.

errno is a horrific API, and we need to be careful to save its value as
soon as a function call (which might set it) returns. i.e. Follow the
pattern:
  int errsv, ret;
  ret = some_call_which_might_set_errno ();
  errsv = errno;

  if (ret < 0)
    puts (strerror (errsv));

This patch implements that pattern throughout GLib. There might be a few
places in the test code which still use errno directly. They should be
ported as necessary. It doesn’t modify all the call sites like this:
  if (some_call_which_might_set_errno () && errno == ESOMETHING)
since the refactoring involved is probably more harmful than beneficial
there. It does, however, refactor other call sites regardless of whether
they were originally buggy.

https://bugzilla.gnome.org/show_bug.cgi?id=785577
2017-08-03 10:21:13 +01:00
Matthias Clasen
9424facde2 2.53.4 2017-07-17 16:20:52 -04:00
Thibault Saunier
be8820128f meson: fix remaining wrong #include's for gdbus_codegen files
This is a follow up on 266bc1e510
to fix building tests and examples when using GLib as a meson
subproject.
2017-07-13 22:22:16 -04:00
Tim-Philipp Müller
10ae386727 meson: gio tests need to link against gobject as well
With meson from git dependencies of dependencies are no
longer added automatically and recursively to the linker
lines. Meaning dependencies that are used have to be
passed directly and explicitly or we'll get linker errors.
2017-07-13 19:03:39 -04:00