For completeness. There probably won't be any, but the XDG base directory
specification is most useful if it's consistently followed everywhere,
and the specification says to look in XDG_DATA_HOME before XDG_DATA_DIRS.
Signed-off-by: Simon McVittie <smcv@debian.org>
The Python code historically always searched DATADIR/gir-1.0 (always)
and /usr/share/gir-1.0 (only on Unix); since the previous commit, they
are searched after the GIR_DIR. Do the same here, to make the C and
Python search paths match up.
With the default gir_dir_prefix, searching both GIR_DIR and
DATADIR/gir-1.0 is redundant. However, if gir_dir_prefix is changed to
something else, for example -Dgir_dir_prefix=lib64, always searching
DATADIR/gir-1.0 provides backwards compatibility with pre-existing GIR
that might already be stored in DATADIR/gir-1.0.
Resolves: #455 (in conjunction with previous commit)
Helps: #323
Signed-off-by: Simon McVittie <smcv@debian.org>
This is searched after any command-line includes paths, but before the
XDG_DATA_DIRS or any built-in paths. For example, if
libraries are installed in /opt/gnome and GObject-Introspection was
configured with -Dgir_dir_prefix=lib64, you could set either
GI_GIR_PATH=/opt/gnome/lib64/gir-1.0 or
XDG_DATA_DIRS=/opt/gnome/lib64:/opt/gnome/share:${XDG_DATA_DIRS}.
Use this to communicate the ../gir directory to giscanner instead
of modifying Python's builtins.
Helps: #323, #455
Signed-off-by: Simon McVittie <smcv@debian.org>
No need to go through all the possible blob types, while we can use an
inline function to check it.
Use an attribute to ensure the function will be inlined, when this is
not available just fallback to the previous definition
The "disguised" attribute is there only for backward compatibility; we
use the "pointer" attribute as the authoritative way to indicate a
typedef to a struct pointer.
Plain Old Data (POD) types with or without a representation in the GType
type system can still have a copy and/or a free function. We should
allow annotating these types with their corresponding functions for
copying their data into a new instance, and freeing their data.
From a language bindings perspective, POD types should have a boxed
GType wrapper around them, so they can use the generic GBoxed API to
copy and free instances; from a documentation perspective, though, it'd
be good to have a way to match a structured type, like a struct or a
union, with its copy and free functions.
In order to do that, we add two new header block annotations:
- (copy-func function_name)
- (free-func function_name)
These annotations work exactly like ref-func and unref-func for typed
instances:
/**
* GdkRGBA: (copy-func gdk_rgba_copy)
* (free-func gdk_rgba_free)
* @red: ...
* @green: ...
* @blue: ...
* @alpha: ...
*
* ...
*/
The function is stored in the GIR data as two new attributes for the
`<record>` and `<union>` elements:
<record name="RGBA"
c:type="GdkRGBA"
copy-function="gdk_rgba_copy"
free-function="gdk_rgba_free"
glib:type-name="GdkRGBA"
glib:get-type="gdk_rgba_get_type"
c:symbol-prefix="gdk_rgba">
The annotations are not mandatory.
See: #14
If we can't transform a property default value to string, we are not
going to add a default-value attribute to the GIR. This is necessary
because non-transformable values may not always be pointers, so we
cannot default to "NULL".
We use g_param_spec_get_default_value() to get the default GValue of a
GParamSpec, and then we serialize it into a string according to the
value's own contents and type.
This parameter may not be NULL even if the function described by the
GIFunctionInfo has a void return type, so we should not say this in the
documentation.
We attempted to return a value in void-return-type functions in both
gicallableinfo.c and gitypeinfo.c, so avoid that since that will trigger a
C4098 warning on Visual Studio, which is considered an error if we are building
against an installed version of GLib 2.68.x or later.
This will fix builds against GLib-2.68.x and later on Visual Studio.
This adds gi_type_tag_argument_from_hash_pointer() and
gi_type_tag_hash_pointer_from_argument(). They do the same thing as
the corresponding g_type_info_... functions, which are used to pack and
unpack the correct field of a GIArgument into/from a data pointer in
GHashTable or GList, regardless of machine architecture or endianness.
These functions take a GITypeTag obtained from
g_type_info_get_storage_type(), instead of a GITypeInfo pointer. (The
storage type is the only piece of data that is actually used from the
GITypeInfo structure.)
It's intended for bindings using an argument cache, such as GJS and
PyGObject, so that they don't have to store a whole 64-bit GITypeInfo
pointer in their cache in many common cases, and can just store the 5-bit
type tag instead.
The original g_type_info_... functions are reimplemented in
terms of the new g_type_tag... functions.
We can just update the for loop condition to be >0 for all builds, which
is actually equivilant to >=1 as we are essentially comparing an
unsigned 32-bit int, so that we don't need to worry about fixing the
VS2012 bug invasively, as Visual Studio 2012 x64 is more sensitive about
sizes of variables (e.g. pointer sizes in this case)
The __ia64 and __x86_64__ macros are defined for GCC but not Visual
Studio, but actually this code path should also be taken for Visual
Studio when doing a 64-bit build (x86_64/x64 and aarch64/arm64, _WIN64
will be defined for these cases), since Windows is an LLP64 platform.
This will avoid C4311/C4312 warnings on Visual Studio builds, which are
often warnings of concern as we are dealing with pointers with differing
sizes on 32-bit and 64-bit Windows builds.
Later GLib versions assume that warning C4715 is an error as we want ot
be sure that functions that return a value do indeed return one by all
means.
Avoid this warning by adding a 'return 0' in brz_search_packed(), it
might be pointless but does indeed avoid the warning.
This new API does the same thing as gi_type_info_extract_ffi_return_value,
but takes a GITypeTag instead of GITypeInfo pointer, and additionally a
GIInfoType if the GITypeTag is GI_TYPE_TAG_INTERFACE. (These pieces of
data are the only things used from the GITypeInfo structure.)
It's intended for bindings using an argument cache, such as GJS and
PyGObject, so that they don't have to store a whole 64-bit GITypeInfo
pointer in their cache in many common cases, and can just store the 5-bit
type tag instead, or the 5-bit interface type in case of
GI_TYPE_TAG_INTERFACE.
The original gi_type_info_extract_ffi_return_value() is reimplemented in
terms of the new gi_type_tag_extract_ffi_return_value().
The documentation comment for SimpleTypeBlob seemed to imply that a basic
type was embedded if the reserved fields were nonzero. After examining the
code, I believe that was actually due to some words missing, and the
comment should say that the type is embedded if the fields are zero.
This is a convenience for bindings that want to perform a similar action
for all numeric types. It allows more expressive code in some cases:
if (GI_TYPE_TAG_IS_NUMERIC(tag)) {
do_one_thing();
return;
}
switch (tag) {
case GI_TYPE_TAG_ARRAY:
do_other_thing();
return;
/* ... */
default:
g_assert_not_reached();
}
instead of listing out all of the numeric types in the switch statement.
If a <GType invalid> (that's the way it appears in python's debugger) is
returned, `g_type_name` returns NULL. This
function therefore returns NULL at this time
as subsequent calls to `strlen( data->gtype_name)` segfault.
Some functions are meant to exist for the entire duration of the
process, and thus have no need for a notification function because
one will never be called.
Fixes: #49
On macOS, @-prefixed shlib paths (@rpath, @executable_path, and
@loader_path) need to be treated as absolute. Trying to combine them
with a configured library path produces a mangled path that is
unresolvable and may cause unintended side effects (such as loading
the library from a fall-back location on macOS 12.0.1).
Libgirepository is not GLib, and it should not use GLIB_DEPRECATED,
GLIB_DEPRECATED_FOR, and GLIB_UNAVAILABLE macros (as the GLib
documentation clearly states).
When using them, we don't get the proper macro expansion, so deprecated
symbols suddenly disappear from our shared library.
Commit 6bab939bf ("girffi.c: fix return value for g_callable_info_prepare_closure()")
effectively changes semantics of return value from code pointer to data pinter (closure).
`gjs` (and probably other software) relies on old (incorrect) semantics of
g_callable_info_prepare_closure(): https://gitlab.gnome.org/GNOME/gjs/-/issues/428
This change exposes the API that allows extracting directly
callacble code pointer. `gjs` will have to adapt to the new API.
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
The initial failure was observed on `meld` against recently released
`libffi-3.4-rc1`. There `meld` crashes as:
```
$ meld
Segmentation fault (core dumped)
$ gdb --args /usr/bin/python3.9 /usr/bin/meld
(gdb) run
...
Thread 1 "python3.9" received signal SIGSEGV, Segmentation fault.
0x00007fffe9ac1ae8 in g_callable_info_free_closure (
callable_info=0x555555d45990, closure=0x7fffe9e70c20)
at ../gobject-introspection-1.68.0/girepository/girffi.c:428
428 g_free (wrapper->ffi_closure.cif->arg_types);
(gdb) bt
callable_info=0x555555d45990, closure=0x7fffe9e70c20)
at ../gobject-introspection-1.68.0/girepository/girffi.c:428
data=0x555555d252d0)
at ../pygobject-3.40.1/gi/pygi-closure.c:635
...
```
The bug here is in type mismatch between expected return value of
`g_callable_info_prepare_closure()` and actual value (executable
code pointer):
```c
ffi_closure * g_callable_info_prepare_closure(...) {
gpointer exec_ptr;
...
status = ffi_prep_closure_loc (&closure->ffi_closure, cif, callback, user_data, exec_ptr);
return exec_ptr;
}
```
Note: `exec_ptr` is a code pointer that could be directly executed by
caller, like `((rt (*)(a1,a2))exec_ptr)(1,2);` It should never be wrapped
into an `ffi_closure*`, which is normally called via `ffi_call(closure, ...)`.
We see the problem when we try to free direct code pointer instead of
`ffi_closure()` as starting from libffi-3.4 executable trampoline and
`ffi_closure()` don't necessarily live in the same block:
9ba559217b
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>