Commit Graph

651 Commits

Author SHA1 Message Date
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
Tom Schoonjans
590421cf14 build: use proper dylib versioning on macOS 2019-09-10 12:49:04 +01:00
Thibault Saunier
ddaa2a9ec3 Make meson.override_find_program working on more complex use cases
Add some missing `meson.override_find_program`

And make sure that the `.gir` we build are found when used uninstalled
as a concequence of `meson.override_find_program`.
2019-08-15 13:58:07 +00:00
Florian Müllner
e0f9f94a7e structinfo: Fix offset in find_method()
The current offset only considers the fields themselves, but not
the optional embedded type that may follow each field.

Use the existing helper function instead of computing the offset
to fix the issue.
2019-08-14 23:17:54 +02:00
Christoph Reiter
8958f167bf meson: don't pass "install" to configure_file() unless really needed
In our case it was never needed because it defaults to true if install_dir is set,
which it always is for all calls.

This avoids a warning when running with newer meson where it complains that install
is only available with 0.50+.

Fixes #298
2019-07-26 18:18:23 +00:00
Mathieu Duponchelle
995d87db17 scanner: parse and expose function macros
This is useful for documentation tools, and other utilities that
rely on full introspection of the C API of a given library.
2019-07-19 01:21:38 +02:00
Philip Chimento
a458c66cbf girepository: Return pointer array for interface cache
In g_irepository_get_object_gtype_interfaces(), returning the address of
the first GIBaseInfo* does not work reliably, because the GIBaseInfos
are not necessarily stored contiguously. So the second and subsequent
ones might be garbage.

Instead, return the address of the array of GIBaseInfo pointers.

Add a test that verifies the functionality, as well.

This is unfortunately an API and ABI break.
2019-06-20 11:54:10 -07:00
Chun-wei Fan
1a19f05a0e build: Force-include msvc_recommended_pragmas.h on Visual Studio
By doing so, we essentially cover the various compiler flags that we
want to use for non-Visual Studio builds to check for warnings that
might cause real concern.

This also skips the checks for the various GCC-isque CFlag checks that
are scattered in the various build files on Visual Studio builds, since
they are essentially meaningless on Visual Studio builds.
2019-04-30 16:07:39 +08:00
Elliott Sales de Andrade
6747ec55dd Fix a possible use-after-free.
If g_mapped_file_new fails, then `version` will be freed, but it was
already added to the hash table. This means there could be a
use-after-free while doing a lookup on the hash table the next time.
2019-02-02 03:00:15 -05:00
Elliott Sales de Andrade
d17edde568 Fix possible leak of transitive dependency name.
If a transitive dependency appears twice, the original pointer will be
removed from the hash table. Since these names were created by
g_strsplit, they need to be freed, or they will leak.
2019-02-02 03:00:15 -05:00
Rico Tzschichholz
4c0a8388d5 repository: Fix annotation for g_irepository_get_object_gtype_interfaces()
Introduced by 9826d952358c8330d72ecba062f489fbdc31bbd1
2019-01-16 21:04:26 +01:00
Colin Walters
8de3abd642 repository: g_irepository_get_object_gtype_interfaces
Bindings in some cases need to look up information from a GType
dynamically.  Support that better by supplying a cache for this
information.

(Rebased and versioning / gtk-doc stuff added by Philip Chimento.)

Closes #38.
See gjs#55.
2019-01-09 21:44:10 -08:00