Commit Graph

15373 Commits

Author SHA1 Message Date
Ryan Lortie
f3311a01fb oops 2014-12-03 21:28:24 -05:00
Ryan Lortie
62e9a485f9 further cleanup 2014-12-03 21:20:32 -05:00
Ryan Lortie
5722ad3a43 cleanup 2014-12-03 21:06:28 -05:00
Ryan Lortie
e1903e40d8 finish up vector deserialiser
seems to have stopped crashing now...
2014-12-03 20:35:18 -05:00
Ryan Lortie
e3df37be73 tests: add GBytes memfd testcase 2014-12-03 17:17:17 -05:00
Ryan Lortie
c123516f63 Add new internal header glib-linux.h
This defines some constants and syscall wrappers for features which may
not yet have appeared in the libc.
2014-12-03 17:15:31 -05:00
Ryan Lortie
98f143767a GBytes: two memfd tweaks
1) mmap() of a 0-sized region is EINVAL, so don't try that

 2) MAP_SHARED on a sealed memfd fails for some reason, so use
    MAP_PRIVATE instead
2014-12-03 17:13:43 -05:00
Ryan Lortie
185449c5c6 start fleshing out guts of vector deserialiser 2014-12-03 03:12:06 -05:00
Ryan Lortie
3468ab849b GVariant vector deserialiser WIP 2014-12-03 02:14:19 -05:00
Ryan Lortie
a169f1d1a8 GVariant: clean up g_variant_get_child_value()
Remove this one outstanding case of direct construction of GVariant
instances and port it to use g_variant_alloc() like everyone else.
2014-12-03 02:10:24 -05:00
Ryan Lortie
fd40045eaf GVariant: use GVariantTypeInfo on internal constructors
Take GVariantTypeInfo instead of a GVariantType on the internal
constructors for GVariant.

Although this results in a bit more code for almost every call, it turns
out that it makes most uses more convenient -- that fact that we consume
the GVariantInfo means that we don't have to go back to free the type
when we're done.

This change will allow us to port g_variant_get_child() over to using
g_variant_alloc().  It was the one outstanding place where we
constructed GVariant instances that was not yet using it.
2014-12-03 02:04:33 -05:00
Ryan Lortie
127fc04592 GVariant: clean up serialised data handling API
Add a new pair of internal helpers to gvariant-core.c to provide a
unified way to construct and query the content of serialised GVariant
instances.

Rewrite g_variant_new_from_data() to use this.

Move g_variant_new_from_bytes() and g_variant_get_data_as_bytes() out of
-core and into gvariant.c, also rewriting them to use the same.

Take the time to do some cleanup and make some general improvements in
consistency:

 - move the checks for improperly sized fixed-sized data out of
   _new_from_bytes() and into the common code so that we do this check
   on _new_from_data() as well

 - correctly deal with the case of NULL data in _get_data_as_bytes().
   This would have crashed before.  Add a test for that.

 - if the user hands us data with a size of zero then unref and/or
   destroy-notify things immediately.

The idea that every GVariant must have an associated GBytes remains.
This could potentially be optimsed a bit further in the future, but the
cases where it could be avoided are only a few (errors, zero-size,
static stoarge) so let's not pursue that now.
2014-12-02 21:14:16 -05:00
Ryan Lortie
bae9239da3 GVariant: fix a trivial typo in a comment 2014-12-02 21:14:16 -05:00
Ryan Lortie
37a2fdf134 GVariant: add support for single precision floats
Add a new type 'f' to correspond to single precision floating point
values.

This type was never added to D-Bus for two reasons:

 1) there is no benefit to using float rather than doubles as parameters
    for RPC

 2) classically, you shouldn't move bulk data over D-Bus

Now that we've decided that we want to use D-Bus for bulk data
transfers, it makes a good deal of sense to want to send an array of
floats or an array of fixed-sized tuples containing floats.

https://bugzilla.gnome.org/show_bug.cgi?id=740897
2014-12-02 21:14:16 -05:00
Ryan Lortie
04240e4154 GVariant test: add a new vector serialisation test
Generate a random value and make sure we get the same result as doing it
the 'usual' way (which is already subject to a whole lot of testing).
2014-12-02 16:30:21 -05:00
Ryan Lortie
8209b34016 GVariant: support serialising to GVariantVectors
Add code for serialising GVariant to GVariantVectors.

Export that internally via the glib-private machanism so that we can use
it from GDBus.
2014-12-02 16:30:21 -05:00
Ryan Lortie
025e670810 GVariant: add GVariantVectors utility struct
This structure (and its associated functions) will be used as an
intermediate step for serialising GVariant instance onto kdbus without
copying large amounts of data.
2014-12-02 16:30:21 -05:00
Ryan Lortie
87226d3b2f GVariant: refactor locking a bit more
Change the internal g_variant_ensure_serialised() helper over to working
on unlocked instances and have it conditionally acquire the lock using
the utility function added in the last commit.
2014-12-02 16:30:21 -05:00
Ryan Lortie
2c1fb2915d GVariant: add internal tree-form locking helper
Many of the core GVariant operations have two modes: one for tree-form
and one for serialised.

Once a GVariant is in serialised form it will always be serialised, so
it is safe to simply check for that and proceed with the operation in
that case.

A tree-form GVariant instance always has a chance of being implicitly
serialised, however, so we have to take locks when performing operations
on these.

Write a helper function that reliably checks if the instance is in
tree-form, locking it if it is.  Rewrite some of the other functions to
use this helper.  In some cases this simplifies the code and in others
it reduces locking.
2014-12-02 16:30:21 -05:00
Ryan Lortie
67520c60fa GVariant: calculate size at construction
It's always possible to determine the serialised size of a GVariant
instance, even in the case that it is not yet serialised.  This can be
done by calling g_variant_get_size() which will base its answer on the
size of each child (which must be recursively determined).

We must perform this process before we can allocate the buffer to
serialise a GVariant into (since we must know the size of the buffer).
This means that serialising a GVariant involves two steps that recurse
through the entire tree of values.  We must take locks twice.

Simplify this by always determining the size when the instance is first
created, from the sizes of its children (which now will always be known
as well).  We can do this without taking any locks because the
newly-created instance has never been exposed and because the size on
the children is now a constant that can be directly accessed without a
lock.

This is a reduction in complexity and will also be a performance
improvement in all cases where a GVariant is serialised.  It will be a
slight performance hit in the case that we construct tree-form instances
and never serialise them.
2014-12-02 16:30:21 -05:00
Ryan Lortie
f2437b7f1c GBytes: add g_bytes_get_zero_copy_fd()
Add a way to get the zero-copy fd back out of a GBytes that was created
from one.
2014-12-02 16:30:21 -05:00
Ryan Lortie
0da5aef9fc GBytes: add new g_bytes_take_zero_copy_fd() function
This function takes a memfd, seals it, and creates a GBytes based on it.
2014-12-02 16:30:21 -05:00
David King
e1734aa73e glib-unix: add function to ensure an fd is sealed
Add a function that checks if a fd is sealed and, if it's not, seals it.

On Linux this is more or less an operation on memfd.  On other systems,
it currently always returns FALSE.
2014-12-02 16:29:11 -05:00
Ryan Lortie
dccedf8844 GBytes: substantial internal rework
We have a wide variety of different sources of data for GBytes.

Instead of having all possibilities inside of a single structure type,
add a 'type' field and a couple of subtypes.

This also forces us to clean up our access to the ->data pointer from
all over the code which may become a problem in the future if we want to
lazy-map memfd GBytes instances by keeping the data pointer as NULL
until we are ready to use it.

We also introduce a new type of GBytes: 'inline'.  This allows us to
make a single allocation instead of two in the g_bytes_new() case.
2014-12-02 13:24:00 -05:00
Ryan Lortie
39ca9d3383 macros: add side-effecting variants of asserts
Add g_assert_se(), g_return_if_fail_se() and g_return_val_if_fail_se()
as variants of the existing macros that are guaranteed to evaluate side
effects in their expression argument.  Inspired by similar macros in
systemd.

These are just macros, so they come at no extra cost.

https://bugzilla.gnome.org/show_bug.cgi?id=741026
2014-12-02 13:03:02 -05:00
Ignacio Casal Quinteiro
e0f1a19332 gio: provide G_IO_ERROR_NOT_CONNECTED translation for ENOTCONN
https://bugzilla.gnome.org/show_bug.cgi?id=741016
2014-12-02 14:29:50 +01:00
Ignacio Casal Quinteiro
22ab227348 gio: fix build
next time I should definitely try to compile after a rebase conflict...
2014-12-02 14:29:50 +01:00
Ignacio Casal Quinteiro
fbfc23453d gio: add G_IO_ERROR_NOT_CONNECTED
It adds a new error G_IO_ERROR_NOT_CONNECTED
and makes the win32 error ERROR_PIPE_LISTENING
to be translated to it.

https://bugzilla.gnome.org/show_bug.cgi?id=741016
2014-12-02 14:21:14 +01:00
Rico Tzschichholz
d0d5ea71bb docs: Add index for 2.44 api 2014-12-01 14:17:26 +01:00
Trần Ngọc Quân
8b27ac0d9f Updated Vietnamese translation
Signed-off-by: Trần Ngọc Quân <vnwildman@gmail.com>
2014-12-01 09:07:13 +07:00
Dan Winship
967fedc0ae gsocket: add G_IO_ERROR_CONNECTION_CLOSED
Add G_IO_ERROR_CONNECTION_CLOSED as an alias for
G_IO_ERROR_BROKEN_PIPE, and also return it on ECONNRESET.

It doesn't really make sense to try to distinguish EPIPE and
ECONNRESET at the GLib level, since the exact choice of which error
gets returned in what conditions depends on the OS. Given that, we
ought to map the two errors to the same value, and since we're already
mapping EPIPE to G_IO_ERROR_BROKEN_PIPE, we need to map ECONNRESET to
that too. But the existing name doesn't really make sense for sockets,
so we add a new name.

https://bugzilla.gnome.org/show_bug.cgi?id=728928
2014-11-29 14:26:42 -05:00
Dan Winship
64f9bf96fd gnetworkaddress: Add g_network_address_new_loopback() constructor
This is a convenience method for creating a GNetworkAddress which is
guaranteed to return IPv4 and IPv6 loopback addresses. The program
cannot guarantee that 'localhost' will resolve to both types of
address, so programs which wish to connect to a local service over
either IPv4 or IPv6 must currently manually create an IPv4 and another
IPv6 socket, and detect which of the two are working. This new API
allows the existing GSocketConnectable machinery to be used to
automate that.

Based on a patch from Philip Withnall.

https://bugzilla.gnome.org/show_bug.cgi?id=732317
2014-11-29 14:22:42 -05:00
Ryan Lortie
296c710c64 GVariant tests: test with larger strings
Allocate some larger strings in the testcase to make sure we handle them
correctly as well.
2014-11-29 14:22:03 -05:00
Ryan Lortie
5aba9ca837 gmain: fix poll record comparison
We intend to keep the list of poll records sorted by (integer) file
descriptor, but due to a typo we are actually keeping it sorted by
pointer address of the GPollFD.

Fix that.

https://bugzilla.gnome.org/show_bug.cgi?id=11059
2014-11-28 23:54:02 -05:00
Ryan Lortie
c476f7cd26 gsignal: add a clarification to the docs
As evidenced by a mistake that I made recently, this documentation could
use a little bit of clarification.
2014-11-28 16:22:16 -05:00
Lars Uebernickel
d511d6b37f GSettings: fix check for delaying backend subscription
g_settings_has_signal_handlers() checks whether any of the signals has
pending handlers. However, g_signal_has_handler_pending() matches on
exact detail, even when passing 0. Subscribing to one of GSettings'
signals with a detail will fail this check and never connect to the
backend.

Fix this by calling has_handler_pending() with the key as detail as
well.

https://bugzilla.gnome.org/show_bug.cgi?id=740848
2014-11-28 15:19:07 +01:00
Matthias Clasen
7f2f4ab12d Use the new g_strv_contains
No need to keep our own copy of this in the testsuite.
2014-11-27 09:12:42 -05:00
Xavier Claessens
71944b1bfd gstrfuncs: Add g_strv_contains()
Includes unit tests.

https://bugzilla.gnome.org/show_bug.cgi?id=685880
2014-11-25 12:51:36 +00:00
Matthias Clasen
3f5a78a248 2.43.1 2.43.1 2014-11-24 14:31:56 -05:00
Dan Winship
e784a4ba32 gio/tests: add a socket-listener test
Add a GSocketListener test program. Currently the only test is a
regression test for bug 712570 (based on a standalone bug reproducer
provided by Ross Lagerwall).
2014-11-23 12:33:01 -05:00
Ross Lagerwall
9a6e01ea5b gio: Prevent hang when finalizing GThreadedSocketService
If all users of a GThreadedSocketService release their references to the
service while a connection thread is running, the thread function will
release the last reference to the service which causes the finalize to
deadlock waiting for all threads to finish (because it's called from the
thread function).

To fix this, don't wait for all threads to finish in the service's
finalize method.  Since the threads hold a reference to the service,
finalize should only be called when all threads are finished running (or
have unrefed the service and are about to finish).

https://bugzilla.gnome.org/show_bug.cgi?id=712570
2014-11-23 12:02:38 -05:00
Jasper St. Pierre
91802bbf2b gparam: Make the documentation clearer for CONSTRUCT_ONLY properties
It's not that the properly will only be set on construction, it's that
it *can* only be set upon construction.
2014-11-22 19:47:43 -08:00
Michael Henning
89e663107e gio: Implement g_win32_app_info_launch_uris for windows. 2014-11-22 17:24:51 -05:00
Michael Henning
90f0eb101f gio: Implement g_app_info_get_default_for_uri_scheme for windows. 2014-11-22 17:24:51 -05:00
Dan Winship
7f5c862e16 GTlsClientConnection: loosen the semantics of "use-ssl3"
If SSL 3.0 has been disabled (at the host, application, or library
level), then the "use-ssl3" property becomes a "fail-immediately"
property.

Despite the name, the point of the property wasn't really specifically
to use SSL 3.0; it was to allow fallback when talking to broken
servers that do SSL/TLS negotiation incorrectly and break when they
see unexpectedly-high version numbers. So if we can't fall back to SSL
3.0, then the "use-ssl3" property should fall back to TLS 1.0 instead
(since there are hosts that will reject a TLS 1.2 handshake, but
accept a TLS 1.0 one).

glib-networking is being updated to implement that behavior, so update
the documentation here.

https://bugzilla.gnome.org/show_bug.cgi?id=738633
2014-11-22 11:02:22 -05:00
Chun-wei Fan
f6bbd19beb GSettings Registry Backend: Init cache_lock Earlier
In commit 8ff5668, we are subscribing the GSettings backend later, but this
meant that we need to initialize cache_lock earlier, as we might try to
use that lock before a change notification is issued to subscribe the
backend, which would then cause an access violation if we are trying to
read GSettings values, as that lock is used to access the Windows Registry.

Initialize cache_lock once we initialize the GSettings Registry backend,
and delete it upon finalize, so that g_settings_read_from_backend() can
proceed normally, even if the GSettings backend is not yet subscribed.

https://bugzilla.gnome.org/show_bug.cgi?id=740413
2014-11-20 22:11:25 +08:00
Christian Persch
5c68fc9f93 gsettingsschema: Print the string that failed to parse
When parsing a translated value fails, print the actual string that
failed to parse instead of the 'domain\004string' untranslated string.

https://bugzilla.gnome.org/show_bug.cgi?id=737150
https://bugzilla.gnome.org/show_bug.cgi?id=737160
2014-11-20 10:38:18 +01:00
Ryan Lortie
8ff5668a45 GSettings: delay backend subscription
GSettings objects begin watching for changes as soon as they are created
in order that they can emit the "changed" signal.

In the case of dconf, if we want to be able to emit the changed signal,
we need to go on the bus and add some match rules.  This requires
creating the dconf helper thread and also requires initialising GDBus
(which creates another thread).

Some users of GSettings are never interested in the "changed" signal.
One of these users is the glib-networking code that gets run every time
a new network connection is created.

Some users are reporting that they are annoyed that simply establishing
a network connection would spawn two extra threads and create a D-Bus
connection.

In order to avoid doing unnecessary work for these simple uses, delay
the subscription until we know that we will actually need to do it.

We do this in a simple way, using a simple argument: in order for the
user to care that a value changed then they must have:

 1) watched for a change signal; and then
 2) actually read a value

If the user didn't actually read a value then they cannot possibly be
interested in if the value changed or not (since they never knew the old
value to begin with and therefore would be unable to observe that it
ever changed, since they have nothing to compare the new value with).

This really is a behaviour change, however, and it does impact at least
one user: the 'monitor' functionality of the GSettings commandline tool,
which is interested in reporting changes without ever having known the
original values.  We add a workaround to the commandline tool in order
to ensure that it continues to function properly.

It's also possible to argue that it is completely valid to have read a
value and _then_ established a change signal connection under the
(correct) assumption that it would not have been possible to miss a
change signal by virtue of not having returned to the mainloop.
Although this argument is true, this pattern is extremely non-idiomatic,
and the problem is easily avoided by doing things in the usual order.

We never really talked about change notification in the overview
documentation for GSettings, so it seems like now is a good time to add
some discussion, including the new rules for when one can expect change
signals to be emitted.

https://bugzilla.gnome.org/show_bug.cgi?id=733791
2014-11-19 13:40:09 -05:00
Alberto Ruiz
6c080721fc glib: Improve documentation for g_strfreev()
Fixes #740309.
2014-11-18 14:43:41 +00:00
Kjartan Maraas
61e125a577 Updated Norwegian bokmål translation. 2014-11-15 18:31:40 +01:00