Commit Graph

29810 Commits

Author SHA1 Message Date
Simon McVittie
f4afed90e6 tests: Exercise g_fdwalk_set_cloexec() and g_closefrom()
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-09 12:12:29 +00:00
Simon McVittie
a7d5a6b69a gspawn: Simplify set_cloexec
The copy of this function that moved to glib-unix.c still needs to
implement the fdwalk-style interface, but this copy does not, allowing
us to turn it into a very simple syscall wrapper. Its remaining callers
never check for errors, and it never failed anyway, so remove the
returned value.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-09 10:57:12 +00:00
Simon McVittie
69c1a05ede glib-unix: Add g_closefrom(), g_fdwalk_set_cloexec()
These are the same as Linux `close_range (lowfd, ~0U, 0)` and
`close_range (lowfd, ~0U, CLOSE_RANGE_CLOEXEC)`, but portable.
Unlike some implementations of BSD closefrom(3), they are
async-signal-safe.

The implementations were moved from the GSpawn code, which already
needs all of this functionality anyway, with the exception of
set_cloexec() which was copied (leading to some minor duplication,
but it's very simple).

Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/3247
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-09 10:57:12 +00:00
Philip Withnall
0701943d9f Merge branch 'moskalets/gapplication/add-version' into 'main'
gapplication: add GApplication:version property

Closes #3198

See merge request GNOME/glib!3889
2024-02-09 10:04:15 +00:00
Maxim Moskalets
cbcb35a77a gapplication: add GApplication:version property
This property is supposed to be used by authors of applications that use GAppliaction to output the version by --version flag or otherwise if a version is needed.

Closes #3198

Signed-off-by: Maxim Moskalets <Maxim.Moskalets@kaspersky.com>
2024-02-09 10:04:14 +00:00
Philip Withnall
59d454a20d Merge branch '3155-quickly-drop-info-type' into 'main'
girepository: Make GIInfoType private

Closes #3155

See merge request GNOME/glib!3906
2024-02-08 22:45:17 +00:00
Philip Withnall
0fa7daad12 Merge branch '3155-import-generate-and-inspect' into 'main'
Import source for g-ir-generate and g-ir-inspect from gobject-introspection.git

Closes #55

See merge request GNOME/glib!3907
2024-02-08 15:20:50 +00:00
Philip Withnall
931931d8f1 girepository: Add SPDX lines to newly imported tools
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-02-08 14:01:57 +00:00
Christoph Reiter
c24a174437 Add a --version option to g-ir-compiler and g-ir-generate. Fixes #55 2024-02-08 13:53:59 +00:00
Christoph Reiter
4c150f199e build: enable -Wshadow 2024-02-08 13:53:59 +00:00
Christoph Reiter
d70551e624 g-ir-generate: fix missing error handling for command line parsing
The error arg was used but the result never checked.
2024-02-08 13:53:59 +00:00
Chun-wei Fan
ea917797bb g-ir-inspect: Ensure variables are at the top of block
We did not yet advertise C99 requirements for G-I yet, so let's not
assume this yet.
2024-02-08 13:53:59 +00:00
Ting-Wei Lan
55bca7b445 g-ir-{compiler,generate,inspect}: Call setlocale in main function
It is required to correctly show translated messages on some locales.

https://bugzilla.gnome.org/show_bug.cgi?id=760419
2024-02-08 13:53:59 +00:00
Igor Gnatenko
43d2206bcf g-ir-inspect: make description for --version a bit better
Reported-and-tested-by: Dominique Leuenberger <dimstar@opensuse.org>
Signed-off-by: Igor Gnatenko <ignatenko@src.gnome.org>
Reviewed-by: Colin Walters <walters@verbum.org>
2024-02-08 13:53:59 +00:00
Igor Gnatenko
68162605ba g-ir-inspect: remove last usage of g_autoptr()
Signed-off-by: Igor Gnatenko <ignatenko@src.gnome.org>

https://bugzilla.gnome.org/show_bug.cgi?id=769600
2024-02-08 13:53:59 +00:00
Igor Gnatenko
77e08288a5 g-ir-inspect: Inspect GI typelibs
Various distributions (mainly RPM based so far) make use of automatic
dependencies extracted from typelib files (they can require other typelibs
and also shared libraries)

Current features
* Print used shared libraries
* Print used typelib dependencies

Based-on-patch-by: Dominique Leuenberger <dimstar@opensuse.org>
Reference: https://bugzilla.gnome.org/show_bug.cgi?id=665672
Reviewed-by: Colin Walters <walters@verbum.org>
Signed-off-by: Dominique Leuenberger <dimstar@opensuse.org>
Signed-off-by: Igor Gnatenko <ignatenko@redhat.com>
2024-02-08 13:53:59 +00:00
Colin Walters
42654f0979 Drop calls to g_type_init()
And bump our GLib requirement.
2024-02-08 13:53:59 +00:00
Colin Walters
4dc7b03bce Add Emacs mode lines to C sources 2024-02-08 13:53:59 +00:00
Johan Dahlin
dac19120aa [GIRepository] Rename GTypelib to GITypelib
Keep a typedef for backwards compatibility, until
the major bindings has moved over.
2024-02-08 13:53:59 +00:00
Colin Walters
a52046e847 Fix two compilation warnings 2024-02-08 13:53:59 +00:00
Colin Walters
4bf5ef6bd7 [girepository] Actually verify header of loaded typelibs in g_irepository_require
Take a GError * for typelib loading code, validate the header.  This
fixes bizarre errors from gjs where g_irepository_require would happily
load old typelibs.
2024-02-08 13:53:59 +00:00
Johan Dahlin
a01e97f46f [girwriter] Refactor out of generate.c
Move out the girwriter out of generate.c. Still a private API,
but that will probably change in the future.
2024-02-08 13:53:59 +00:00
Johan Dahlin
af10e6bd6e [generate] Get rid of globals
Get rid of all globals in gir generator, in preparation for
moving all code into libgirepository
2024-02-08 13:53:59 +00:00
Johan Dahlin
ccdceb1e09 [gtypelib.ch] Rename to gitypelib.ch
Rename gtypelib.h -> gitypelib-internal.h and rename
gtypelib.c to gitypelib.c
2024-02-08 13:53:59 +00:00
Johan Dahlin
a9a3352d8a [g-ir-generate] Write out array type
For GLib arrays, write out the array type to the tgir
2024-02-08 13:53:59 +00:00
Colin Walters
ecd9c2f3e7 Support (out caller-allocates)
People have wanted support for marking (out) on functions of the
form:

/**
 * clutter_color_from_pixel:
 * @pixel: A pixel
 * @color: (out): Color to initialize with value of @pixel
 */
void
clutter_color_from_pixel (guint32 pixel, ClutterColor *color);

Where the caller is supposed to have allocated the argument; the
C function just initializes it.  This patch adds support for this
argument passing style to introspection.  In this case, we see the
(out), and notice that there's only a single indirection (*) on
the argument, and assume that this means (out caller-allocates).

https://bugzilla.gnome.org/show_bug.cgi?id=604749
2024-02-08 13:53:59 +00:00
Johan Dahlin
320dd66c62 Add support for foreign structs
Foreign structs are special in the sense that there might
be native bindings (for instance PyCairo for PyGI) that provides
the same functionallity as the introspected variant.

https://bugzilla.gnome.org/show_bug.cgi?id=610357
2024-02-08 13:53:59 +00:00
Johan Dahlin
567a6d2195 Remove trailing whitespace 2024-02-08 13:53:59 +00:00
Tomeu Vizoso
90c166144c Implement callbacks as part of struct fields. Fixes #557383
gir: embed <callback> inside <field>
typelib: if a field contains a callback, store it just after the FieldBlob
girepository API: no additions
2024-02-08 13:53:59 +00:00
Andreas Rottmann
7a6056cbeb Bug 576605 - Get rid of GI_SCOPE_TYPE_OBJECT
Remove support for (scope object) as it lacks a real use case.
2024-02-08 13:53:59 +00:00
Colin Walters
f979d003ce Bug 564016 - Include c:prefix in typelib, use it to optimize find_by_gtype
Parse the c:prefix from the .gir, include it in the header.  Armed with this
information, we can now optimize lookups of GTypes because we
have the requirement that GTypes must start with the c:prefix.  We do
fall back though if a lookup fails.
2024-02-08 13:53:59 +00:00
Colin Walters
02bb4f8d6a Bug 557383 - Virtual method support
Broadly speaking, this change adds the concept of <vfunc> to the .gir.
The typelib already had most of the infrastructure for virtual functions,
though there is one API addition.

The scanner assumes that any class callback slot that doesn't match
a signal name is a virtual.  In the .gir, we write out *both* the <method>
wrapper and a <vfunc>.  If we can determine an association between
them (based on the names matching, or a new Virtual: annotation),
then we notate that in the .gir.

The typelib gains an association from the vfunc to the function, if
it exists.  This will be useful for bindings since they already know
how to consume FunctionInfo.
2024-02-08 13:53:59 +00:00
Colin Walters
43c682703c Bug 571548 - Generic attributes
We now support an extensible mechanism where arbitrary key-value
pairs may be associated with almost all items, including objects,
methods, and properties.

These attributes appear in both the .gir and the .typelib.
2024-02-08 13:53:59 +00:00
Andreas Rottmann
ae73e2e4e6 Add --all option to g-ir-generate
Add --all option, which is intended to show some information not
usually included in the GIR.

Currently, it shows the size of structs and unions.

Signed-off-by: Andreas Rottmann <a.rottmann@gmx.at>
2024-02-08 13:53:59 +00:00
Colin Walters
cd2dcdf1f4 Bug 572434 - Associate interfaces with their C structures
Similar to GObject class structs, we pair up GInterfaces with
their C structures.

Also, move some GLib-specific things into glibast.py, and make
the naming more generic.
2024-02-08 13:53:59 +00:00
Colin Walters
d90d14cf67 Bug 551738 - Associate classes with their structs
Inside glibtransformer, we now look at structures ending in "Class" and
see if they have an associated GlibObject (i.e. a structure of the same
name without the "Class" suffix).  If found, pair them up.

The .gir file for <class> gains an attribute denoting its associated
class struct.  Any <record> many now have a glib:is-class-struct-for
annotation which tells which (if any) <class> for which it defines the
layout.

In the .typelib, we record the association between the class and
its structure.  Generic structures however just have a boolean
saying whether they're a class struct.  (Going from a generic class
struct to its class should not be necessary).

Finally, we expose GIRepository APIs to access both bits of information
from the .typelib.

svn path=/trunk/; revision=1088
2024-02-08 13:53:59 +00:00
Andreas Rottmann
981e55ef57 Bug 556489 – callback annotations
2008-01-03  Andreas Rottmann  <a.rottmann@gmx.at>

	Bug 556489 – callback annotations
	
	* giscanner/transformer.py 

	* tools/generate.c (write_callable_info): Write out the new scope,
	closure and destroy attributes.

	* giscanner/transformer.py (Transformer._type_is_callback): New
	method, checking if a given type is a callback.
	(Transformer._augment_callback_params): New method; adds
	information (closure, destroy) to callback parameters.
	(Transformer._handle_closure, Transformer._handle_destroy): New methods, 
	auxiliary to _augment_callback_params.
	(Transformer._create_function): Call _augment_callback_params().
	(Transformer._create_parameter): Handle scope option.

	(Transformer._create_typedef_callback): New method, creates a
	callback, and registers it in the typedef namespace
	(Transformer._create_typedef): Use _create_typedef_callback()
	instead of the plain _create_callback().

	* giscanner/ast.py (Parameter): Added callback-related fields.
	* giscanner/girwriter.py: Write out new Parameter fields.

	* girepository/girnode.h (GIrNodeParam): Added fields scope, 
	closure and destroy.
	* girepository/gtypelib.h (ArgBlob): Ditto.
	* girepository/girparser.c (start_parameter): Handle new fields.

	* girepository/girmodule.c (g_ir_module_build_typelib): Adjust
	arg_blob_size, bump major version due to this change.
	* girepository/girnode.c (g_ir_node_get_full_size_internal)
	(g_ir_node_build_typelib)
	* girepository/gtypelib.c (g_typelib_check_sanity): ArgBlob size
	adjustments.
	(g_ir_node_build_typelib): Fill in new ArgBlob flags from param. 

	* girepository/girepository.h (GIScope): New enumeration, listing
	the different possible scopes for callbacks.

	* girepository/ginfo.c (g_arg_info_get_scope)
	(g_arg_info_get_closure, g_arg_info_get_destroy): Accessors for
	callback-related argument indices (callback scope, closure for a
	callback, destroy notification for a callback).

	* tests/scanner/: Added testcases for new features.

svn path=/trunk/; revision=998
2024-02-08 13:53:59 +00:00
Colin Walters
fcdfe8dbd9 Also generate new syntax
svn path=/trunk/; revision=933
2024-02-08 13:53:59 +00:00
Owen Taylor
1892f7dcfd Remove field offsets from g-ir-generate output and test inputs
Field offsets are a) architecture dependent so they shouldn't be part
of the architecture-independent gir format which is installed in
datadir. b) Are architecture-dependent so they shouldn't be in test
expected output. Remove field offsets from girs.
(Virtual function and discriminator offsets are not removed, as they
aren't fully hooked up to the field-offset computation machinery yet.)

svn path=/trunk/; revision=877
2024-02-08 13:53:59 +00:00
Colin Walters
2d1e6e2c5c Bug 557786 - support fixed size arrays
svn path=/trunk/; revision=814
2024-02-08 13:53:59 +00:00
Tommi Komulainen
d9ab34b17c Bug 556739 – transfer-ownership attribute should be mandatory in .gir
2008-10-23  Tommi Komulainen  <tommi.komulainen@iki.fi>

	* girepository/girparser.c (parse_param_transfer):
	* giscanner/transformer.py (_create_parameter, _create_return):
	* giscanner/girwriter.py (_write_return, _write_parameter):
	* tools/generate.c (write_callable_info): always write and
	require "transfer-ownership" for return-values and parameters

	* tests/boxed.gir:
	* tests/invoke/testfns-1.0.gir:
	* tests/object.gir:
	* tests/scanner/DrawableAdditions.xml:
	* tests/scanner/GtkFrob-1.0-expected.tgir:
	* tests/scanner/annotation-1.0-expected.tgir:
	* tests/scanner/drawable-1.0-expected.tgir:
	* tests/scanner/drawable-injected-1.0-expected.gir:
	* tests/scanner/drawable-injected-1.0-expected.tgir:
	* tests/scanner/foo-1.0-expected.tgir: Updated

svn path=/trunk/; revision=797
2024-02-08 13:53:59 +00:00
Tommi Komulainen
e4542c021c Bug 557379 – g-ir-generate not writing the 'abstract' attribute
2008-10-22  Tommi Komulainen  <tommi.komulainen@iki.fi>

	* tests/scanner/drawable-1.0-expected.tgir:
	* tests/scanner/drawable-injected-1.0-expected.tgir:
	* tests/scanner/foo-1.0-expected.tgir:
	* tools/generate.c (write_object_info): write 'abstract'
	attribute for classes

svn path=/trunk/; revision=785
2024-02-08 13:53:59 +00:00
Tommi Komulainen
659a300f87 Bug 557405 – Use 'allow-none' consistently
2008-10-22  Tommi Komulainen  <tommi.komulainen@iki.fi>

	* docs/typelib-format.txt:
	* girepository/ginfo.c (g_arg_info_may_be_null):
	* girepository/girnode.c (g_ir_node_build_typelib):
	* girepository/girnode.h (struct _GIrNodeParam):
	* girepository/girparser.c (start_parameter):
	* girepository/girwriter.c (function_generate):
	* girepository/gtypelib.h (ArgBlob):
	* tests/errors.gir:
	* tests/function.gir:
	* tools/generate.c (write_callable_info): Use 'allow-none'
	consistently throughout

svn path=/trunk/; revision=782
2024-02-08 13:53:59 +00:00
Colin Walters
cb720c675e Write out throws attribute
svn path=/trunk/; revision=776
2024-02-08 13:53:59 +00:00
Tommi Komulainen
d3e2ead0db Bug 556732 – generate gir files consistently
2008-10-17  Tommi Komulainen  <tommi.komulainen@iki.fi>

	Bug 556732 – generate gir files consistently

	* girepository/girparser.c (start_parameter):
	* tests/boxed.gir:
	* tests/invoke/testfns-1.0.gir:
	* tools/generate.c (write_callable_info): write
	'transfer-ownership' attribute consistently with both
	return-value and parameter elements

svn path=/trunk/; revision=745
2024-02-08 13:53:59 +00:00
Tommi Komulainen
66a5209b6c Bug 556732 – generate gir files consistently
2008-10-17  Tommi Komulainen  <tommi.komulainen@iki.fi>

	Bug 556732 – generate gir files consistently

	* tools/generate.c (write_callable_info): write 'direction'
	attribute only if other than 'in' to be consistent with
	girwriter.py
	* tests/boxed.gir:
	* tests/object.gir: remove direction="in" which is the default

svn path=/trunk/; revision=744
2024-02-08 13:53:59 +00:00
Tommi Komulainen
3bddeae0fa Bug 556732 – generate gir files consistently
2008-10-17  Tommi Komulainen  <tommi.komulainen@iki.fi>

	Bug 556732 – generate gir files consistently

	* giscanner/ast.py (Field): add readable and writable properties
	* giscanner/girparser.py (_parse_field): copy 'readable' and
	'writable' attributes
	* giscanner/transformer.py (_create_member): create fields as
	read-write
	* giscanner/glibtransformer.py (_introspect_object,
	_pair_class_struct): make object instance and class fields
	read-only
	* giscanner/girwriter.py (_write_field):
	* tools/generate.c (write_field_info): write field 'readable'
	and 'writable' attributes only if non-default (read-only)
	* girepository/girparser.c (start_field): in the absence of
	attributes assume fields are read-only
	* tests/boxed.gir:
	* tests/struct.gir: remove redundant readable="1" from fields
	* tests/scanner/foo-1.0-expected.gir:
	* tests/scanner/utility-1.0-expected.gir: add writable="1" to
	all record and union fields

svn path=/trunk/; revision=743
2024-02-08 13:53:59 +00:00
Tommi Komulainen
80429426af Bug 556732 – generate gir files consistently
2008-10-17  Tommi Komulainen  <tommi.komulainen@iki.fi>

	Bug 556732 – generate gir files consistently

	* giscanner/girwriter.py (_write_property): write properties
	'construct' attribute if set
	* tools/generate.c (write_property_info): write properties
	'readable' and 'writable' attributes only if non-default
	* tests/object.gir: add writable="0"
	* tests/scanner/foo-1.0-expected.gir: add construct="1"

svn path=/trunk/; revision=742
2024-02-08 13:53:59 +00:00
Tommi Komulainen
477412eeca Bug 556543 – reduce compiler warnings
2008-10-16  Tommi Komulainen  <tommi.komulainen@iki.fi>

	Bug 556543 – reduce compiler warnings

	* girepository/ginfo.c:
	* girepository/girepository.c (register_internal,
	count_interfaces, find_interface, find_namespace_version,
	parse_version, g_irepository_require):
	* girepository/girmodule.c (g_ir_module_build_typelib):
	* girepository/girnode.c (init_stats, dump_stats,
	_g_irnode_init_stats, _g_irnode_dump_stats,
	g_ir_node_can_have_member):
	* girepository/girparser.c (firstpass_end_element_handler,
	locate_gir, parse_basic, parse_type_internal, resolve_aliases,
	start_alias, start_type, end_type_top, parse_include, cleanup,
	post_filter):
	* girepository/gtypelib.c (validate_function_blob, validate_enum_blob):
	* giscanner/giscannermodule.c (directive_get_options,
	type_get_child_list):
	* giscanner/scannerlexer.l (parse_gtkdoc):
	* giscanner/scannerparser.y (ctype_free):
	* giscanner/sourcescanner.c:
	* giscanner/sourcescanner.h (gi_source_scanner_parse_macros):
	* tests/types/gitesttypes.c:
	* tools/compiler.c (main):
	* tools/generate.c (write_repository): Remove unused variables
	and code, add missing includes, declarations and case
	statements.

svn path=/trunk/; revision=730
2024-02-08 13:53:59 +00:00
Colin Walters
c874b58562 Fix up g-ir-generate for new include= syntax
svn path=/trunk/; revision=726
2024-02-08 13:53:59 +00:00