This reverts commit 476e33c3f3.
We’ve decided to remove `G_OS_DARWIN` in favour of recommending people
use `__APPLE__` instead. As per the discussion on #2802 and linked
issues,
* Adding a new define shifts the complexity from “which of these
platform-provided defines do I use” to “which platform-provided
defines does G_OS_DARWIN use”
* There should ideally be no cases where a user of GLib has to use
their own platform-specific code, since GLib should be providing
appropriate abstractions
* Providing a single `G_OS_DARWIN` to cover all Apple products (macOS
and iOS) hides the complexity of what the user is actually testing:
are they testing for the Mach kernel, the Carbon and/or Cocoa user
space toolkits, macOS vs iOS vs tvOS, etc
Helps: #2802
It must only be defined when building libgio. This requires some
workaround to allow include of some gio private headers.
When GIO_COMPILATION is not defined we cannot include individual gio
headers. We workaround that by defining __GIO_GIO_H_INSIDE__ in some
places. Also gdbusprivate.h is not an installed header, so it's fine to
include it directly.
Add SPDX license (but not copyright) headers to all files which follow a
certain pattern in their existing non-machine-readable header comment.
This commit was entirely generated using the command:
```
git ls-files gio/*.[ch] | xargs perl -0777 -pi -e 's/\n \*\n \* This library is free software; you can redistribute it and\/or\n \* modify it under the terms of the GNU Lesser General Public/\n \*\n \* SPDX-License-Identifier: LGPL-2.1-or-later\n \*\n \* This library is free software; you can redistribute it and\/or\n \* modify it under the terms of the GNU Lesser General Public/igs'
```
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Helps: #1415
Apply --internal to the symbol for the section as well.
Only do this with --external-data, since otherwise gcc
will complain about ignoring the attribute.
This fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/4598
The resources data is generated for both GCC and MSVC toolchains, even
though we know beforehand which toolchain we're going to compile it for.
By dropping the data duplication we make the generated resources file
faster to compile, especially when dealing with large embedded data,
instead of relying on the C pre-processor to walk the whole file and
discard the branch we're not using.
When attempting to test Windows support for building libadwaita, since we are
using multiple GResource files, one would hit linker errors where multiple
definitions of the following symbols have been defined, when
glib-compile-resources was invoked without manual register:
resource_constructor_wrapper
resource_destructor_constructor
_arrayresource_constructor
_arrayresource_destructor
In order to avoid that, just prefix the definitions of resource_constructor
and resource_destructor, like what we do when --manual-register is used, with
what we pass in with --c-name so that we ensure that we do not end up in such
name collisions.
gio/glib-compile-resources.c: In function ‘parse_resource_file’:
gio/glib-compile-resources.c:553:3: error: missing initializer for field ‘passthrough’ of ‘GMarkupParser’ {aka ‘struct _GMarkupParser’}
553 | GMarkupParser parser = { start_element, end_element, text };
| ^~~~~~~~~~~~~
Have the generated .c code decorate the prototypes with "G_MODULE_EXPORT"
instead of "extern" when --internal is not being used, so that we also
export the symbols from the generated code on Visual Studio-style
compilers. If --internal is used, we decorate the prototypes with
"G_GNUC_INTERNAL", as we did before.
Note that since the generated .c code does not attempt to include the
generated headers (if one is also generated), the gnerated headers are
still generated as they were before.
This makes use of the string we now have from glib-private.h in the
last commit so that setlocale() sets the default system locale
correctly and therefore show the translated messages properly.
Fixes issue #1169.
Add option to not encode resource data into the C source file
in order to embed the data using `ld -b binary`. This improves compilation
times, but can only be done on Linux or other platforms with a
supporting linker.
(Rebased by Philip Withnall, fixing minor rebase conflicts.)
Fixes#1489
glib-compile-resources was updated to generate octal byte
representation in a string, but unfortunately this breaks the build
on Visual Studio when the generated string sequence exceeds 65535
characters, which is the imposed limit on Visual Studio compilers.
To make things work on Visual Studio builds and to not slow down things
on other compilers, generate a code path for Visual Studio an array of
octal byte representations, as well as a code path for other compilers
that use the new string representation of octal values, and let the
compiler take the appropriate code path when compiling the
generated code.
Fixes issue #1580.
The length of the stolen data from a memory output stream is given by
get_data_size() — get_size() can be larger, and hence cause unnecessary
overallocation.
With 0d685b4946, we now encode resource
data as a string. Strings have trailing nul terminators. A C compiler
will happily ignore the fact that the nul terminator exceeds the stated
array length, and will drop it — but a C++ compiler won’t, and will
raise:
error: initializer-string for array of chars is too long [-fpermissive]
Fix that by increasing the array length by 1, and subtracting it again
in the GStaticResource struct.
Signed-off-by: Philip Withnall <withnall@endlessm.com>
Some Testing revealed encoding resource data with string
escape codes to compile significantly quicker compared
to the same data encoded as an array with hexadecimal numbers.
See #1489
Make the --help output more consistent with the man page, making it more
obvious that --sourcedir only applies to the files referenced in FILE,
not to the location of FILE itself.
Signed-off-by: Philip Withnall <withnall@endlessm.com>
https://gitlab.gnome.org/GNOME/glib/issues/1406
There's no need to unconditionally print an error message if xmllint or
json-glib-format are not found when running glib-compile-resources is
called; we only need to warn if they are not available when we need
them. To avoid spamming the build logs, we can also warn once.
https://bugzilla.gnome.org/show_bug.cgi?id=794285
The glib-compile-resources tool has hand-rolled "open a temporary file"
code paths. Since error handling is hard, let's rely on GLib API that is
meant to do that consistently for us.
Get rid of some tabs mixed with spaces while we're at it.
https://bugzilla.gnome.org/show_bug.cgi?id=794284
Similarly to how glib-compile-resources can call xmllint to eliminate
whitespace in XML files to reduce their size inside a GResource, we can
use json-glib-format to achieve the same result.
The mechanism for using json-glib-format is the same, with a separate
environment variable if we want to direct glib-compile-resources to a
version of json-glib-format that is not the one in the PATH.
https://bugzilla.gnome.org/show_bug.cgi?id=794284
There have been some improvements to the tool recently, but it's hard to
know if those are available on a given system unless the tool provides a
--version commandline option.
https://bugzilla.gnome.org/show_bug.cgi?id=772269
Add --dependency-file=foo.d option to generate a gcc -M -MF style
dependency file for other build tools. The current output of
--generate-dependencies is only useful for use directly in Makefile
rules, but can't be used in other build systems like that.
The generated dependency file looks like this:
$ glib-compile-resources --sourcedir= test.gresource.xml --dependency-file=-
test.gresource.xml: test1.txt test2.txt test2.txt
test1.txt:
test2.txt:
test2.txt:
Unlike --generate-dependencies, the --dependency-file option can be
used together with other --generate options to create dependencies
as side-effect of generating sources.
Based on a patch by Tim-Philipp Müller in
https://bugzilla.gnome.org/show_bug.cgi?id=745754
The changes in this patch, compared to his are to always return
the hash table with file information from parse_resource_file, so
we can use it for dependency output, regardless if generate_dependencies
was TRUE or not.
Add --dependency-file=foo.d option to generate a gcc -M -MF style
dependency file for other build tools. The current output of
--generate-dependencies is only useful for use directly in Makefile
rules, but can't be used in other build systems like that.
The generated dependency file looks like this:
$ glib-compile-resources --sourcedir= test.gresource.xml --dependency-file=-
test.gresource.xml: test1.txt test2.txt test2.txt
test1.txt:
test2.txt:
test2.txt:
Unlike --generate-dependencies, the --dependency-file option can be
used together with other --generate options to create dependencies
as side-effect of generating sources.
Based on a patch by Tim-Philipp Müller.
https://bugzilla.gnome.org/show_bug.cgi?id=745754
glib-compile-resources --generate is supposed to automatically detect
whether to generate source code or header from the target's file extension.
However, this only worked for C; extend this to include the canonical
C++ filename extensions. Also make the check case insensitive.
https://bugzilla.gnome.org/show_bug.cgi?id=747134
As per #578363, "if one requests e.g. strings via GOptionEntry.arg_data
then those are strduped and needs to be free'ed by the application."
Fixes following leak:
=================================================================
==29426==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 10 byte(s) in 1 object(s) allocated from:
0 0x7f3ab783d37a in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x9437a)
1 0x7f3ab70f7c82 in g_malloc /home/lebedevri/src/glib/glib/gmem.c:94
2 0x7f3ab70f7f60 in g_malloc_n /home/lebedevri/src/glib/glib/gmem.c:330
3 0x7f3ab713258e in g_strndup /home/lebedevri/src/glib/glib/gstrfuncs.c:425
4 0x7f3ab709c86b in strdup_len /home/lebedevri/src/glib/glib/gconvert.c:864
5 0x7f3ab709c966 in g_locale_to_utf8 /home/lebedevri/src/glib/glib/gconvert.c:905
6 0x7f3ab7103c32 in parse_arg /home/lebedevri/src/glib/glib/goption.c:1276
7 0x7f3ab71066fb in parse_long_option /home/lebedevri/src/glib/glib/goption.c:1670
8 0x7f3ab7108047 in g_option_context_parse /home/lebedevri/src/glib/glib/goption.c:1997
9 0x408532 in main /home/lebedevri/src/glib/gio/glib-compile-resources.c:629
10 0x7f3ab6c72b44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b44)
https://bugzilla.gnome.org/show_bug.cgi?id=757299
glib-compile-resources was guessing a filename ending
in .c when generating sources, but did not do the same
for headers. Fix it so it generates a .h file when
guessing the filename for headers.
https://bugzilla.gnome.org/show_bug.cgi?id=746753
In Windows development environments that have it, <unistd.h> is mostly
just a wrapper around several other native headers (in particular,
<io.h>, which contains read(), close(), etc, and <process.h>, which
contains getpid()). But given that some Windows dev environments don't
have <unistd.h>, everything that uses those functions on Windows
already needed to include the correct Windows header as well, and so
there is never any point to including <unistd.h> on Windows.
Also, remove some <unistd.h> includes (and a few others) that were
unnecessary even on unix.
https://bugzilla.gnome.org/show_bug.cgi?id=710519
There are a number of nice things this class brings:
0) Has a race-free termination API on all platforms (on UNIX, calls to
kill() and waitpid() are coordinated as not to cause problems).
1) Operates in terms of G{Input,Output}Stream, not file descriptors
2) Standard GIO-style async API for wait() with cancellation
3) Makes some simple cases easy, like synchronously spawning a
process with an argument list
4) Makes hard cases possible, like asynchronously running a process
with stdout/stderr merged, output directly to a file path
Much rewriting and code review from Ryan Lortie <desrt@desrt.ca>
https://bugzilla.gnome.org/show_bug.cgi?id=672102
Rather than using "extern" declarations of these win32 functions
everywhere they're needed, just prototype them in glib-private.h.
(Which also fixes the fact that they weren't prototyped in the files
where they're defined.)
https://bugzilla.gnome.org/show_bug.cgi?id=688109