Commit Graph

662 Commits

Author SHA1 Message Date
Emmanuele Bassi
edbd878523 Use the proper private triglyph
It's `/*< ... >*/`, not `/* <...> */`.
2022-02-13 14:20:03 +00:00
Philip Chimento
b68a03b9b6 girffi: Add gi_type_tag_extract_ffi_return_value()
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().
2022-02-13 12:25:18 +00:00
Philip Chimento
aae9a3cdd1 girepository: Fix documentation comments
It was driving me crazy that g_type_info_get_array_length() claimed to
return an array length.
2022-02-13 12:25:18 +00:00
Philip Chimento
0f330c1581 girepository: Clarify SimpleTypeBlob documentation
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.
2022-02-13 12:25:18 +00:00
Philip Chimento
8f047f11f6 gitypeinfo: Add GI_TYPE_TAG_IS_CONTAINER macro
Like GI_TYPE_TAG_IS_NUMERIC, this is a convenience for bindings that want
to perform a similar action for all container types.
2022-02-13 12:25:18 +00:00
Philip Chimento
75b48f1dbe gitypeinfo: Add GI_TYPE_TAG_IS_NUMERIC macro
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.
2022-02-13 12:25:18 +00:00
Lukas Oberhuber
6583ad7f4f girepository: avoids segfault in case of bad gtype
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.
2022-01-12 05:43:00 +00:00
Emmanuele Bassi
3d999b47e5 cmph: Handle fgets() return value
Newer versions of the GNU libc have started to warn if the result of the
call is unused.
2022-01-11 15:59:43 +00:00
Emmanuele Bassi
4398e1fde2 Add "forever" scope
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
2022-01-09 19:21:01 +00:00
Rok Mandeljc
c493763ff2 gitypelib.c: on macOS, treat @-prefixed shlib paths as absolute
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).
2021-11-27 20:52:07 +01:00
Emmanuele Bassi
4027d2e12a Do not use GLib versioning symbols
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.
2021-11-24 16:41:01 +00:00
Cimbali
d991e197de Remove runtime warnings, add doxygen deprecation notices 2021-11-23 23:04:26 +00:00
Emmanuele Bassi
b03c3d0a16 Fix styling issues from suggestions 2021-11-23 23:04:26 +00:00
Cimbali
f77269c480 Avoid leaking memory from FFI closure if no segfault risk 2021-11-23 23:04:26 +00:00
Cimbali
8e96029a32 Create new API for libffi closures
Deprecate the previous API as per discussion in !283.
2021-11-23 23:04:26 +00:00
Sergei Trofimovich
5e053279b5 girffi.h: add g_callable_info_get_closure_native_address() API
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>
2021-11-23 23:04:26 +00:00
Sergei Trofimovich
6a8dce273a girffi.c: fix return value for g_callable_info_prepare_closure()
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>
2021-11-23 23:04:26 +00:00
Emmanuele Bassi
c6adbd568a Improve readability of error message
Use the parent type and the function symbol when erroring out if we
can't find a property accessor.
2021-08-05 17:47:29 +01:00
Emmanuele Bassi
493441c84d Use a macro for the missing accessor sentinel value
Easier to read than `0x3ff`.
2021-08-05 17:47:29 +01:00
Emmanuele Bassi
400dfc2908 Add introspection data for property accessors
A GObject property can be accessed generically through the GObject API,
e.g. g_object_set_property() and g_object_get_property(). Properties
typically also have public accessor functions, which are (according to
our own best practices) called through the generic API.

The introspection data is currently missing the relation between a
property and its public accessor functions. With this information, a
language binding could, for instance, avoid exposing the C API entirely,
thus minimizing the chances of collisions between property names and
accessor functions; alternatively, a binding could call the C API
directly instead of going through the generic GObject API, thus avoiding
the boxing and unboxing from a native type to a GIArgument and finally
into a GValue, and vice versa.

In the GIR, we add two new attributes to the `property` element:

  - setter="SYMBOL"
  - getter="SYMBOL"

where "symbol" is the C function identifier of the setter and getter
functions, respectively. The `setter` attribute is only applied to
writable, non-construct-only properties; the `getter` attribute is only
applied to readable properties.

We maintain the ABI compatibility of the typelib data by using 20 bits
of the 25 reserved bits inside the PropertyBlob structure. The data is
exposed through two new GIPropertyInfo methods:

  - g_property_info_get_setter()
  - g_property_info_get_getter()

which return the GIFunctionInfo for the setter and getter functions,
respectively.
2021-08-05 17:47:29 +01:00
Emmanuele Bassi
39d518267b Add new annotations for property accessors
We introduce two new annotations:

  - (set-property PROPERTY_NAME)
  - (get-property PROPERTY_NAME)

These annotations are valid inside function blocks for methods on
objects and interfaces, and define whether a function is a property
accessor, e.g.:

    /**
     * gtk_widget_set_name: (set-property name)
     * @self: ...
     * @name: ...
     *
     * ...
     */

    /**
     * gtk_widget_get_name: (get-property name)
     * @self: ...
     *
     * ...
     *
     * Returns: ...
     */

The annotations are transformed into the GIR data as attributes:

 - glib:set-property="PROPERTY_NAME"
 - glib:get-property="PROPERTY_NAME"

The underlying typelib data has had flags for setter and getter
functions for a while, but they have never been plugged into the GIR
data or the introspection scanner. Now they are; you can retrieve the
GIPropertyInfo from a GIFunctionInfo that has the GI_FUNCTION_IS_SETTER
or GI_FUNCTION_IS_GETTER flags set.

Fixes: #13
2021-08-05 17:47:29 +01:00
Emmanuele Bassi
efa58b3f8d Property accessors work for interfaces and objects
We need to check the container type before trying to obtain a
GIPropertyInfo for GIFunctionInfos that have a SETTER or a GETTER flag
set.
2021-08-05 17:47:29 +01:00
Emmanuele Bassi
d127fc1136 Add "final" class attribute
A "final" class is a leaf node in a derivable type hierarchy, and cannot
be derived any further.

This matches the changes in libgobject that introduced G_TYPE_FLAG_FINAL
to the type flags.
2021-08-05 16:24:23 +00:00
Emmanuele Bassi
ce4448f9e7 Add version macros for 1.70
We are going to introduce new API.
2021-08-05 16:24:23 +00:00
Emmanuele Bassi
0cdd325c1a Initialise argument
Avoid a "maybe uninitialized" compiler warning.
2021-06-24 18:17:56 +00:00
David King
18745a0639 girepository: Fix leak in prefix_with_context
Found by Coverity.

https://bugzilla.redhat.com/show_bug.cgi?id=1938731
2021-06-18 14:28:05 +00:00
David King
3ebf2f5140 girepository: Fix leak in write_vfunc_info
Found by Coverity.

https://bugzilla.redhat.com/show_bug.cgi?id=1938731
2021-06-18 14:28:05 +00:00
David King
16b064bea9 girepository: Fix leak in write_field_info
Unref type before reusing it. Found by Coverity.

https://bugzilla.redhat.com/show_bug.cgi?id=1938731
2021-06-18 14:28:05 +00:00
David King
4e3ab408f1 girepository: Fix leak in _g_ir_parser_parse_file
Found by Coverity.

https://bugzilla.redhat.com/show_bug.cgi?id=1938731
2021-06-18 14:28:05 +00:00
David King
62b1ebd822 girepository: Fix leak in g_callable_info_invoke
Found by Coverity.

https://bugzilla.redhat.com/show_bug.cgi?id=1938731
2021-06-18 14:28:05 +00:00
John Ericson
c2ded0a667 Make test suite work with cross-related options
Because of skepticism I received in #224, I made this PR which keeps the
testsuite and CI improvements but doesn't add any new build options. I
hope this would be less controversial:

 - no new knobs
 - tests for those using existing build options
 - CI tests `build_introspection_data = false`
2021-05-23 12:56:21 -04:00
Emmanuele Bassi
7cfb47308b Use g_memdup2() with newer versions of GLib
The g_memdup() function has been deprecated, so we should use the new
g_memdup2() function if available.
2021-03-12 18:55:44 +00:00
Mathieu Duponchelle
b305534719 Merge branch 'objectinfo_nullable' into 'master'
Add missing nullable annotations to GObjectInfo

See merge request GNOME/gobject-introspection!225
2020-07-22 23:33:01 +00:00
Mathieu Duponchelle
1d0c86a123 Merge branch 'standalone-doc-sections' into 'master'
Add the notion of standalone doc sections.

See merge request GNOME/gobject-introspection!226
2020-07-22 21:36:59 +00:00
Mathieu Duponchelle
445c942f7d Add the notion of standalone doc sections.
Up to now, section annotations had to match a class or interface
name in order to be serialized in the gir.

With this commit, they now get serialized as docsection nodes,
for potential use by documentation tools.
2020-07-12 04:10:40 +02:00
Jonne Haß
7bebab4ac7 Add missing nullable annotations to GObjectInfo 2020-05-26 11:19:35 +02:00
Christoph Reiter
06c8219cee meson: also build gi-dump-types on Windows 2020-05-19 19:39:34 +02:00
Gisle Vanem
1b5c989202 Use _get_oshandle() and g_win32_output_stream_new() instead since
`g_win32_output_stream_new_from_fd()` is private in Gio. 

It's normally not exported unless `GLIB_STATIC_COMPILATION` is effective.
PS. Why would i not be called `GIO_STATIC_COMPILATION` for Gio .c-files?
2020-05-15 10:59:39 +00:00
Gisle Vanem
f7e4b797a8 Obs! Change back to g_unix_output_stream_new() for non-Win32. 2020-05-14 19:57:43 +00:00
Gisle Vanem
da7e635b71 [Win32] Fix gi-dump-types.c to build on Windows 2020-05-14 19:25:11 +00:00
Jonne Haß
d41f718dda Add missing nullable annotation to g_object_info_get_parent 2020-05-14 17:26:21 +02:00
Jonne Haß
47136da074 Add missing nullable annotation to g_irepository_get_shared_library 2020-05-14 17:24:08 +02:00
Philip Chimento
7daee7b90a girepository: Add GITypeInfo utility functions for storing values in pointers
This functionality is used in both PyGObject and GJS, and if not done
correctly can lead to architecture-specific bugs. It seems best to add
API in gobject-introspection for the correct way to do it.

See also: GNOME/gjs#309
2020-04-26 10:24:26 -07:00
Philip Chimento
8fcdeefb3a girepository: Add 1.66 version macro
Required for adding new API to the 1.66 series.
2020-04-26 10:21:04 -07:00
Xavier Claessens
74ff43c47f Revert "Revert "Meson: Fix build when glib is built as subproject""
This reverts commit 42b7d634a9a7500dcc71651f71844148fc200be3.
2020-04-24 15:05:03 -04:00
Emmanuele Bassi
3d39d61e3d Revert "Meson: Fix build when glib is built as subproject"
This reverts commit ec00edd941953626ac027810f747847f68a71000.

The nightly run time does not have Meson 0.54.
2020-04-24 11:52:45 +01:00
Xavier Claessens
75a1bb1e13 Meson: Fix build when glib is built as subproject 2020-04-22 21:15:45 -04:00
Joshua Watt
f257d2f891 Fix build reproducibility
ba744068 ("Make meson.override_find_program working on more complex use
cases") made the build no longer reproducible by encoding a build system
path into the output. This shouldn't be necessary anyway, since it
should be possible to add new paths to search for gir files by setting
the XDG_DATA_DIR environment variable.

Closes #318

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
2019-12-11 18:30:14 +01:00
Carlos Garnacho
67a0f3e914 girepository: Also store GType cache misses
There are notably 4 classes of GTypes where a girepository lookup
might fail:
- GTypes from private interfaces in public objects (eg. MetaCullable in
  mutter)
- GTypes for private base objects with public interfaces (eg. GLocalFile
  in GLib)
- GTypes registered from the language, and presumably not coming from the
  GIR
- GTypes of objects/interfaces that we didn't load a typelib for

It is moot to look for those over and over again, and a full lookup can
be taxing if looking up for a method/property on objects with those
characteristics.

It seems we can cache the misses too, so next lookups are just as quick
as an introspected GType. The cache is invalidated after loading new
typelibs, in case some of the previously missed GTypes is now properly
introspected.
2019-11-14 16:23:39 +00:00
Philip Chimento
fcc94454c1 girepository: Fix memory leak
In g_irepository_get_object_gtype_interfaces()
2019-10-10 13:34:23 -07:00