Commit Graph

5622 Commits

Author SHA1 Message Date
Philip Withnall
46eedd12c0 tests: Add charset test to autotools and drop unnecessary undefs
Follow-ups from review in bug #751826.

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

https://bugzilla.gnome.org/show_bug.cgi?id=751826
2018-03-13 12:21:07 +00:00
Takao Fujiwara
e311a45653 gcharset: Add g_get_language_names_with_category
g_get_language_names() uses LC_MESSAGES and the fallback is useful
for other locale categories too.

https://bugzilla.gnome.org/show_bug.cgi?id=751826
2018-03-13 12:17:31 +00:00
Philip Withnall
affe33b7e7 gversionmacros: Add version macros for GLib 2.58
Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: nobody
2018-03-13 12:17:31 +00:00
Christoph Reiter
8e315bd8ae tests/date.c: include config.h to expose Vista+ macros
date.c uses SUBLANG_LITHUANIAN_LITHUANIA which is Vista+
Include config.h so that _WIN32_WINNT is defined and the newer macros
are exposed.

This fixes the build under MinGW.

https://bugzilla.gnome.org/show_bug.cgi?id=793729
2018-03-13 12:06:54 +00:00
Rafal Luzynski
987bf5bbeb gdatetime: Add missing #define WEEKDAY_FULL_IS_LOCALE
One more #define WEEKDAY_FULL_IS_LOCALE was missing from the commit
12f11090dc.

https://bugzilla.gnome.org/show_bug.cgi?id=793578
2018-03-13 10:52:08 +00:00
Rafal Luzynski
9cadb90b35 tests: Compare month names case-insensitively
This patch relaxes the comparison rules and allow the month names to be
in a mixed case.

Translators should be allowed to provide the month names in a different
case (lower/upper case, not grammatical case) from the content of glibc
because it is disputable at the moment whether the month names should
follow the language rules strictly and be titlecased only if it is
obligatory to titlecase them or they should be also titlecased in the
standalone case. Hopefully in future a conversion specifier will be
invented to control the upper/lower case individually.

https://bugzilla.gnome.org/show_bug.cgi?id=793645
2018-03-13 10:49:38 +00:00
Rafal Luzynski
7fe793e125 tests: Update month names
Update the abbreviated month names in the test to match the actual content
of the translated *.po files for Greek and Lithuanian.

https://bugzilla.gnome.org/show_bug.cgi?id=793645
2018-03-13 10:49:38 +00:00
Philip Withnall
c4f58e362e tests: Skip the gdatetime month names test when running uninstalled
It needs the translations to be installed. See the comment added to the
code.

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

https://bugzilla.gnome.org/show_bug.cgi?id=794180
2018-03-12 19:24:15 +00:00
Philip Withnall
36af567045 tests: Ensure gettext strings are loaded in UTF-8 in gdatetime.c
See the previous commit. By convention, GLib assumes strings loaded from
gettext are always in UTF-8, but we do need to tell gettext this. In
most other tests, it doesn’t matter; but in the gdatetime test, we test
re-encoding month names from EUC-JP, so we need to ensure the
translations start in UTF-8 correctly.

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

https://bugzilla.gnome.org/show_bug.cgi?id=793578
2018-03-12 19:22:13 +00:00
Philip Withnall
12f11090dc gdatetime: Fix locale handling for nl_langinfo() calls
With the various macros we use to provide fallbacks for missing
nl_langinfo() fields, the locale handling can become quite complex:
nl_langinfo() returns strings encoded in the current locale, but C_()
returns strings encoded in UTF-8 (by GLib convention — you do actually
need to call bind_textdomain_codeset() to achieve this).

There are various format specifiers, especially with the new %Ob, %OB,
%Oh specifiers, which conditionally call nl_langinfo() or something
based on C_(). This makes encoding handling difficult.

Add additional macros which indicate whether the macros they’re paired
with return something encoded in the current locale, or encoded in
UTF-8. The user of the macro can then use these to work out whether to
re-encode.

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

https://bugzilla.gnome.org/show_bug.cgi?id=793578
2018-03-12 19:22:13 +00:00
Philip Withnall
11909c67d1 gdatetime: Clarify documentation about clamping on addition
If adding months or years to a date, the day of the month of the result
is supposed to be the same as in the input — but that doesn’t work if
that day doesn’t exist in the result month.

Clarify the documentation about what happens here (the day of the month
is clamped to the length of that month).

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: nobody
2018-02-28 15:31:34 +00:00
Rafal Luzynski
2c15b903e2 date: Amend some comments about the month names
Some source code comments amended to avoid possible future confusion.
It has been explained that a month name is used in a genitive case
only if it is required by the language rules. Also it has been
explained that %OB is also supported by other platforms (e.g., BSD)
but for this test we are focused on glibc 2.27 vs. Windows.

https://bugzilla.gnome.org/show_bug.cgi?id=749206
2018-02-28 11:33:37 +00:00
Philip Withnall
90d3337e1d docs: Mention pointer semantics for g_array_set_clear_func()
Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: nobody
2018-02-23 19:23:27 +00:00
Ernestas Kulik
03e86d000f Remove HAVE_CONFIG_H defs and uses
Since GLib files are only meant to be built as part of GLib, config.h
always exists, so the checks are more or less pointless.

https://bugzilla.gnome.org/show_bug.cgi?id=793399
2018-02-21 13:57:10 +00:00
Emmanuele Bassi
8bfedb57cc Increase the timeout for some GLib tests
The CI infrastructure is shared and running inside a containerised
environment, which means tests may take more time to finish on it
than they would on a faster, personal machine.

https://bugzilla.gnome.org/show_bug.cgi?id=793635
2018-02-20 13:49:21 +00:00
Emmanuele Bassi
5459b345e1 Do not use g_test_incomplete() for missing locales
The "incomplete" test state matches the "expected to fail" state (or
"TODO", in TAP), but missing locales should just cause tests to be
skipped.

https://bugzilla.gnome.org/show_bug.cgi?id=793635
2018-02-20 13:49:21 +00:00
Philip Withnall
493d3438e8 tests: Disable /date/month_names test with older libc versions
The test for %OB with g_date_strftime() fails with old libc versions
which don’ŧ support the ‘O’ modifier. g_date_strftime() explicitly
doesn’t add additional format placeholders over what’s supported by the
system strftime(), so just disable the test in that case.

The test remains useful on systems with newer libc versions, or on
Windows, where the win32 fallback path is taken.

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

https://bugzilla.gnome.org/show_bug.cgi?id=749206
2018-02-20 12:05:11 +00:00
Rafal Luzynski
359768369d Add tests for formatting and parsing month names
Add tests for g_date_strftime() and g_dat_set_parse() formatting and parsing
month names in both nominative and genitive case in several locales, both
needing these two grammatical cases and not needing them.

https://bugzilla.gnome.org/show_bug.cgi?id=749206
2018-02-20 11:35:13 +00:00
Rafal Luzynski
fa12658809 win32_strftime_helper: Support nominative/genitive month names
A similar change to the commit be4f96b650,
supports %OB, %Ob, %Oh (alternative, standalone, nominative) month names
along with the old %B, %b, %h (primary, in full date format context,
genitive) month names.

https://bugzilla.gnome.org/show_bug.cgi?id=749206
2018-02-20 11:35:13 +00:00
Rafal Luzynski
5520a87930 win32_strftime_helper: Factor out the common code
Factor out the common code supporting "%B", "%b", and "%h" format
specifiers. It will be helpful for the next commit.

https://bugzilla.gnome.org/show_bug.cgi?id=749206
2018-02-20 11:35:13 +00:00
Rafal Luzynski
9152244828 g_date_set_parse: Also support nominative/genitive month names
As the support of two grammatical cases of month names has been introduced
try to find both forms when parsing a date.

https://bugzilla.gnome.org/show_bug.cgi?id=749206
2018-02-20 11:35:13 +00:00
George Barrett
9ae71e32e8 gutils: fix missing include
On platforms other than Win32, the g_abort symbol is #def'd to abort.
C99 specifies that this function prototype resides in stdlib.h, but the
required include is absent from gutils.h.

https://bugzilla.gnome.org/show_bug.cgi?id=793555
2018-02-19 11:35:47 +00:00
Ernestas Kulik
62e8168878 gatomic: fix -Wduplicated-branches
The checks that the argument passed is a pointer to an integer contain
duplicate branches, which GCC complains about very loudly as of version
7.

https://bugzilla.gnome.org/show_bug.cgi?id=793399
2018-02-16 15:43:11 +00:00
Ernestas Kulik
c97922c104 gtester: fix -Wduplicated-branches
One of the “quick” or “slow” test run modes is always added to the
argument list, making the branching pointless, which, coincidentally,
now causes a warning.

https://bugzilla.gnome.org/show_bug.cgi?id=793399
2018-02-16 15:14:39 +00:00
Rafal Luzynski
be4f96b650 g_date_time_format: Support nominative/genitive months
Supports %OB (alternative, standalone, nominative) month name along
with the old %B (primary, in a complete date format context, genitive)
month name.  Similarly %Ob and %Oh for abbreviated month names.
Depending on the underlying operating system uses nl_langinfo()
or provides our custom implementation.

(Tweaked by Philip Withnall <withnall@endlessm.com> to add test case
comment and bug reference.)

https://bugzilla.gnome.org/show_bug.cgi?id=749206
2018-02-16 14:37:51 +00:00
Natanael Copa
d933cf99bf gquark: simplify g_intern_string/g_intern_static_string
Move the common code to a quark_intern_string_locked function. This has
no effect on the generated code but makes codebase a bit cleaner.

https://bugzilla.gnome.org/show_bug.cgi?id=768507
2018-02-16 12:49:43 +00:00
Natanael Copa
2f07630b43 gquark: simplify g_quark_from_static_string/g_quark_from_string
Move common code to quark_from_string_locked  wrapper function. This has
no effect on generated code but it makes codebase a bit cleaner.

https://bugzilla.gnome.org/show_bug.cgi?id=768507
2018-02-16 12:49:43 +00:00
Emmanuele Bassi
77419cf578 docs: Mention the newly added return values
The return value of the g_hash_table_add(), g_hash_table_insert(), and
g_hash_table_replace() functions was changed from void to gboolean in
GLib 2.40, but it was not mentioned in the API reference or the release
notes.

https://bugzilla.gnome.org/show_bug.cgi?id=793300
2018-02-15 11:25:53 +00:00
Philip Withnall
4183cedbe2 tests: Use a different time for testing UNIX timestamps
The test_GDateTime_new_from_unix() test creates a UNIX timestamp
representing 1990-01-01 00:00:00 in the local timezone, and then turns
it into a GDateTime using g_date_time_new_from_unix_local(). This should
succeed regardless of the current local timezone (TZ environment
variable).

However, it was failing for TZ=America/Lima, and *only* for that
timezone.

As it turns out, Lima used to have a DST leap at exactly 00:00:00 on the
1st of January — but this stopped in 1994, which made investigation a
bit harder. See:
https://www.timeanddate.com/time/change/peru/lima?year=1990.

What was happening is that 1990-01-01 00:00:00 was being converted to
the timestamp 631170000, but GDateTime was converting that timestamp to
1990-01-01 01:00:00 when loading it. Both conversions are correct: a DST
leap creates an equivalence between an hour’s worth of timestamps.

We can somewhat validate this by seeing that timestamp 631169999 maps to
1989-12-31 23:59:59, and timestamp 631170001 maps to 1990-01-01
01:00:01.

Fix this by changing the date used by the test to one where no timezone
was undergoing a DST leap in 1990. This should never change, as all that
data is now historical.

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

https://bugzilla.gnome.org/show_bug.cgi?id=793319
2018-02-13 15:56:30 +00:00
Philip Withnall
644ecec971 gconvert: Fix some typos in documentation comments
Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: nobody
2018-02-13 14:49:20 +00:00
Mikhail Zabaluev
7f1fd247a7 gconvert: g_filename_from_utf8() returns (type filename)
The existing array annotation is inconsistent with the other
conversion functions. Now that the implementation guarantees
no embedded NULs, the return value can be re-annotated.

https://bugzilla.gnome.org/show_bug.cgi?id=756128
2018-02-09 13:05:22 +00:00
Mikhail Zabaluev
8a93e2d54e gconvert: Correctly annotate string types and output parameters
Note that the g_convert() API works with byte arrays. It's wrong to
default to utf8 there, because iconv can read and produce strings with
interior nul characters which are not allowed in (type utf8).
The documentation was misleading about that in some places, so that got
corrected as well.

Strings in the locale encoding are annotated as dynamic-length byte
arrays because they don't have any guaranteed format and can contain
nul bytes. For UTF-8 strings in g_*_{from,to}_utf8(), GLib assumes
no embedded nul bytes and the (type utf8) annotations on the UTF-8
parameters and return values remain as they were. Likewise for
(type filename).

https://bugzilla.gnome.org/show_bug.cgi?id=756128
2018-02-09 13:05:22 +00:00
Philip Withnall
565d8fa1ee docs: Add Markdown backticks around /dev/null in a few places
This improves the formatting of the documentation ever so slightly.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: nobody
2018-02-08 16:39:32 +00:00
Philip Withnall
e9dd5e1819 gkeyfile: Fix -Wincompatible-pointer-types warning
Introduced in commit 1574321e51.

This fix introduces no functional changes (just a cast).

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: nobody
2018-02-08 12:29:57 +00:00
Matthias Clasen
a4fc4c1e6e trivial: add some helpful comments
Not everybody knows console color codes by heart.
2018-02-06 11:05:57 -05:00
Philip Withnall
79d9ea2598 gthread: Fix a typo in an #ifdef on the non-native mutex path
This seems to have been present since the code was introduced in commit
cedc82290f. The attr variable is defined
under one #ifdef, but destroyed under another, which doesn’t make any
sense. The second #ifdef variable is actually an enum value, rather than
the static initialiser value which makes more sense in the context.

Note that GMutex used to be statically initialised to the value of
PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP in gthread.h, before this was
reworked in commit e081eadda5.

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

https://bugzilla.gnome.org/show_bug.cgi?id=793026
2018-02-06 15:52:29 +00:00
Allison Lortie
1574321e51 GKeyFile: add API for getting locale of a string
g_key_file_get_locale_string() returns a translated string from the
keyfile.  In some cases, it may be useful to know the locale that that
string came from.

Add a new API, g_key_file_get_locale_for_key(), that returns the locale
of the string.

Include tests.

(Modified by Philip Withnall to rename the API and fix some minor review
issues. Squash in a separate test case commit.)

https://bugzilla.gnome.org/show_bug.cgi?id=605700
2018-02-06 15:51:33 +00:00
Patrick Griffis
1c0bed93a3 docs: Clarify dest requirements of g_utf8_strncpy()
(Minor wording tweak by Philip Withnall.)

https://bugzilla.gnome.org/show_bug.cgi?id=520116
2018-02-03 12:12:28 +01:00
Philip Withnall
32cc60dbff gmessages: Fix -Wformat warnings for g_message() and friends
When compiling with G_LOG_USE_STRUCTURED, g_message(), g_debug(), etc.
use g_log_structured(). The message format string and its format
arguments are passed as the final set of arguments in a longer varargs
list, which includes the log domain and level (and other) fields.
Passing the message format in this way means it’s not possible for the
compiler to know to check its format placeholders when compiling with
-Wformat.

Fix support for this by adding a new semi-private helper function,
_g_log_structured_standard(), which only uses varargs for the message
format and its arguments, and uses fixed arguments for the other fields.
This is then converted to a set of GLogFields and passed to
g_log_structured() as normal.

Support for -Wformat when compiling *without* G_LOG_USE_STRUCTURED was
never broken.

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

https://bugzilla.gnome.org/show_bug.cgi?id=793074
2018-02-02 10:10:43 +01:00
Philip Withnall
3a88ab6c25 tests: Add some documentation to the illegal sequence conversion test
Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=790698
2018-02-02 10:04:20 +01:00
Philip Withnall
8abf3a04e6 gconvert: Fix error handling for g_iconv() with unrepresentable chars
The behaviour of upstream iconv() when faced with a character which is
valid in the input encoding, but not representable in the output
encoding, is implementation defined:

http://pubs.opengroup.org/onlinepubs/9699919799/

Specifically:

   If iconv() encounters a character in the input buffer that is valid,
   but for which an identical character does not exist in the target
   codeset, iconv() shall perform an implementation-defined conversion
   on this character.

This behaviour was being exposed in our g_iconv() wrapper and also in
g_convert_with_iconv() — but users of g_convert_with_iconv() (both the
GLib unit tests, and the implementation of g_convert_with_fallback())
were assuming that iconv() would return EILSEQ if faced with an
unrepresentable character.

On platforms like NetBSD, this is not the case: NetBSD’s iconv()
finishes the conversion successfully, and outputs a string containing
replacement characters. It signals those replacements in its return
value from iconv(), which is positive (specifically, non-zero) in such a
case.

Let’s codify the existing assumed behaviour of g_convert_with_iconv(),
documenting that it will return G_CONVERT_ERROR_INVALID_SEQUENCE if
faced with an unrepresentable character. As g_iconv() is a thin wrapper
around iconv(), leave the behaviour there implementation-defined (but
document it as such).

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

https://bugzilla.gnome.org/show_bug.cgi?id=790698
2018-02-02 10:04:20 +01:00
Philip Withnall
a19eed4691 tests: Add a missing const to a variable in the GConvert tests
Also rename it to make it clearer how it’s encoded (as UTF-8).

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

https://bugzilla.gnome.org/show_bug.cgi?id=790698
2018-02-02 10:04:20 +01:00
Philip Withnall
19bc03ef65 docs: Minor wording improvements in GConvert documentation
Fix capitalisation of GLib, make some text less gender-specific, and add
some missing colons.

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

https://bugzilla.gnome.org/show_bug.cgi?id=790698
2018-02-02 10:04:20 +01:00
Philip Withnall
ad6afd0fc1 docs: Replace an XML entity with a UTF-8 character instead
Another part of the long tail of converting our documentation from
DocBook to Markdown.

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

https://bugzilla.gnome.org/show_bug.cgi?id=790698
2018-02-02 10:04:20 +01:00
Philip Withnall
38592939d7 docs: Clarify the definition of goffset
off64_t doesn’t exist in any standard (definitely not C99), and so
goffset is actually closer to off_t in 64-bit mode.

However, goffset is always defined as gint64, so make that clear.

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

https://bugzilla.gnome.org/show_bug.cgi?id=792856
2018-02-02 09:29:22 +01:00
Stewart Brodie
fc857073a0 gkeyfile: Fix FD validity test to be technically correct
The fd could be valid and zero.

https://bugzilla.gnome.org/show_bug.cgi?id=760324
2018-02-02 09:20:11 +01:00
Philip Withnall
b6d1c128b3 gcharset: Mention the environment variables queried by g_get_charset()
Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: nobody
2018-02-01 17:38:28 +00:00
Pavlo Solntsev
382d13b618 Clarification for memmory allocation function
Difference between g_try_... family of functions and their counterparts
has been clarified.

https://bugzilla.gnome.org/show_bug.cgi?id=792903
2018-01-31 22:10:51 +00:00
Christian Hergert
47b78e6d83 tests: additional test for g_bytes_new_from_bytes()
This adds two new tests for g_bytes_new_from_bytes().

One test ensures that when creating a new GBytes that is a slice of
the entire base bytes, we just return the base bytes with it's reference
count incremented by one.

The other test ensures that when performing sub-slices of GBytes, for
which the parent GBytes also references a GBytes, that we skip the
intermediate GBytes and reference the base GBytes. Additional testing
of the internal state of the GBytes structure is performed to prove
the correctness of the implementation.

https://bugzilla.gnome.org/show_bug.cgi?id=792780
2018-01-27 11:43:38 -08:00
Christian Hergert
4151bce6db bytes: avoid intermediate refs in g_bytes_new_from_bytes()
When referencing a GBytes that is already a slice of another GBytes, we
can avoid referencing the intermediate GBytes and instead reference the
root bytes.

Doing so helps avoid keeping N GBytes instances alive when the
intermediates would have otherwise been finalized.

https://bugzilla.gnome.org/show_bug.cgi?id=792780
2018-01-27 11:43:38 -08:00