Commit Graph

688 Commits

Author SHA1 Message Date
Xavier Claessens
0d739996c6 parser: filename can contain "\" separator on Windows 2023-08-09 11:07:53 -04:00
Xavier Claessens
a194c42129 gdump: Fix leaked io streams
This makes Meson unit test fail:
https://github.com/mesonbuild/meson/issues/11754
2023-07-18 11:32:09 -04:00
Emmanuele Bassi
9a910e44aa Add versioning macros for 1.78 2023-06-18 17:46:42 +01:00
Marco Trevisan (Treviño)
fcd2026506 gitypelib-internal: Use a switch to check if blob is a registered type
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
2023-04-10 17:09:09 +00:00
Emmanuele Bassi
92bbb0033b Special-case pointer-sized value types
GValues containing pointer-sized things can hold a NULL value, and
various transformation functions in the wild are not NULL safe.

Fixes: #457

See also: https://gitlab.gnome.org/GNOME/mutter/-/issues/2625
2023-03-20 23:23:33 +00:00
Emmanuele Bassi
650090eefb Protect ourselves against properties with no default value
If the GParamSpec does not have a default value, we should not try to
turn it into a string.
2023-03-20 23:23:33 +00:00
Emmanuele Bassi
ffba6509da Use the pointer attribute in libgirepository
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.
2023-01-08 21:48:45 +00:00
Emmanuele Bassi
605fdf7046 Add copy and free function annotations for POD types
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
2023-01-08 14:50:28 +00:00
Emmanuele Bassi
47b674d30f Open g-i 1.75 development 2023-01-08 14:47:58 +00:00
Emmanuele Bassi
967f993108 Skip default-value for non-transformable properties
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".
2023-01-08 14:20:06 +00:00
Emmanuele Bassi
3063615313 Dump the default value of object properties
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.
2023-01-08 14:03:20 +00:00
Marco Trevisan (Treviño)
7e8a8bfb14 Add missing (void) arguments to comply with -Wstrict-prototypes 2022-10-06 04:09:09 +02:00
Marco Trevisan (Treviño)
8742fb6c99 cmph: Do not set debug variables if debug is not set
Fixes clang builds
2022-10-06 04:09:09 +02:00
Philip Chimento
f7cc968eb9 docs: Remove inaccurate description
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.
2022-08-06 13:52:01 -07:00
Christoph Reiter
ac01cf93f4 build: disable some clang warnings for code not under our control
cmph is vendored and other one is bison/flex generated code.
Not much we can do here, so disable those warnings there.
2022-07-19 22:18:57 +02:00
Chun-wei Fan
a068c6c303 gi[callable|type]info.c: Avoid MSVC C4098 warnings
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.
2022-03-28 20:11:21 +00:00
Philip Chimento
3556c864ed gitypeinfo: Add pointer-stuffing functions for GITypeTag storage type
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.
2022-02-16 17:58:24 -08:00
Chun-wei Fan
0cccf62cea bdz.c: Some cleanups
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)
2022-02-13 15:19:43 +00:00
Chun-wei Fan
c138becc4d brz.c: Consider _WIN64 for 64-bit pointers too
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.
2022-02-13 15:19:43 +00:00
Chun-wei Fan
62bbd6cf17 brz.c: Avoid C4715 warnings
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.
2022-02-13 15:19:43 +00:00
Emmanuele Bassi
4dbd25b033 Rename argument in the declation
It must match the argument in the definition and the documentation.
2022-02-13 14:41:48 +00:00
Emmanuele Bassi
f4a7efaa2e Use GI_TYPE_TAG_IS_BASIC
Now that we have it.
2022-02-13 14:35:53 +00:00
Emmanuele Bassi
13f09c5594 Add GI_TYPE_TAG_IS_BASIC
And deprecate G_TYPE_TAG_IS_BASIC. Let's avoid hijacking
the G namespace any further.
2022-02-13 14:33:10 +00:00
Emmanuele Bassi
f7b0141906 docs: Rename a field annotation 2022-02-13 14:27:30 +00:00
Emmanuele Bassi
822d284221 docs: Reformat a long description 2022-02-13 14:27:09 +00:00
Emmanuele Bassi
2ca3c1da83 docs: Remove DocBook tags
We are still using gtk-doc, but gtk-doc uses Markdown these days, not
DocBook.
2022-02-13 14:20:51 +00:00
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