Commit Graph

118 Commits

Author SHA1 Message Date
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
Jonne Haß
47136da074 Add missing nullable annotation to g_irepository_get_shared_library 2020-05-14 17:24:08 +02: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
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
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
Christoph Reiter
9b367e74ef ci: enable -Werror for msys2+meson 2019-01-01 18:06:47 +01:00
Christoph Reiter
722518e5bc docs: fix gtk-doc warnings and update version infos
Move things around and rename things until gtk-doc is happy.

This also moves the "Since" annotations to the next stable releases and
adds version added info for g_callable_info_get_instance_ownership_transfer()
and g_struct_info_find_field().
2018-12-09 18:26:26 +01:00
Christoph Reiter
a060582afe girepository: port from g_type_class_add_private() to G_ADD_PRIVATE()
This lets us enable -Wdeprecated-declarations
2018-07-30 07:53:01 +02:00
Christoph Reiter
3a5b0c2ae2 build: enable -Wshadow 2018-07-29 18:57:03 +02:00
Christoph Reiter
7cdf5d0d1d build: enable -Wcast-function-type
Where it's easy add dummy args to match the cast; where the target is a subset just
prevent the warning with a cast to void*.

Provide a real copy function for the boxed type code in regress_foo.
This code is never executed afaics, but why not.
2018-07-29 18:56:58 +02:00
Emmanuele Bassi
caef88d094 docs: Mention GI_TYPELIB_PATH
The rules for searching typelib files should be properly documented,
as well as the way to modify the search paths.

https://bugzilla.gnome.org/show_bug.cgi?id=699328
2018-01-30 14:01:06 +00:00
Patrick Griffis
ac76bbb53b girepository: Don't skip g_irepository_get_option_group()
This function works fine via introspection

https://bugzilla.gnome.org/show_bug.cgi?id=786665
2017-10-22 07:16:05 -04:00
Carlos Garnacho
8a08674b33 girepository: Merge overrides with the regular search path
This reverts commit e81c4681cc88a00fcd841c5a68d860d3714b55d7

The GI_TYPELIB_PATH envvar will still allow overriding the default
typelib dir (based on gobject-introspection libdir), but applications
will have the last say about typelib lookup directories. The resulting
lookup order is now:

- Paths added through g_irepository_prepend_search_path()
- Paths in GI_TYPELIB_PATH
- The default gobject introspection lookup dir

This makes g_irespository_prepend_search_path() work as announced
despite environment variables. If any application was relying on
GI_TYPELIB_PATH overriding the paths of this function call (for e.g.
make check, or to be able to run code inside the project tree), it
is encouraged to set up a similar envvar for their application specific
lookup dir, or perform this override through other means.

https://bugzilla.gnome.org/show_bug.cgi?id=765735
2016-05-02 16:20:31 +02:00
Colin Walters
569b1dc9a8 Revert "libgirepository: Refuse to run in setuid applications"
This reverts commit 98bb6c91b710a95efe4cfeb303daeec3381b9c98.

It breaks programs simply executed *transitively* from a setuid
binary like the dbus daemon launch helper.

https://bugzilla.redhat.com/show_bug.cgi?id=1285991

Conflicts:
	girepository/girepository.c
2015-12-09 16:17:48 -05:00
Garrett Regier
6b55207f25 girepository: Fix memory leak in g_irepository_get_dependencies()
The transitive_dependencies GHashTable was being leaked.

https://bugzilla.gnome.org/show_bug.cgi?id=758448
2015-11-20 23:02:10 -08:00
Colin Walters
5bda8cc0d3 girepository: Add missing include
For previous commit.
2015-09-26 11:51:33 -04:00
Colin Walters
02c64c25d2 libgirepository: Refuse to run in setuid applications
We know of at least one privilege escalation path via
`GI_TYPELIB_PATH`.  I don't want to audit for others.  If someone
shows up with a use case we can talk.

https://bugzilla.gnome.org/show_bug.cgi?id=755472
2015-09-24 11:10:36 -04:00
Jasper St. Pierre
3fa183524e girepository: Remove "optimization" for found prefixes
This optimization is bugged and broken in the case of certain
libraries. GNOME uses a lot of prefixes with "G", so we'll almost always
have found the prefix.

This is specifically a problem for something like GXml.xDocument, which
uses a type name starting with a lower-case letter, which fools the
prefix logic, but we're also fooled by the "G" appearing in GLib and
Gio.

A more sophisticated version of this check would have three passes:
check prefix with type-case, check prefix without type-case, global
search, but this is an edge case and it doesn't feel worth it to write.
2015-07-27 17:21:05 -07:00
Lionel Landwerlin
355fcd387d scanner/girepository: remove GdkRectangle->CairoRectangleInt automatic conversion
https://bugzilla.gnome.org/show_bug.cgi?id=748832
2015-05-11 16:05:02 +01:00
Garrett Regier
1627d65d0f Fix docs for g_irepository_get_shared_library()
https://bugzilla.gnome.org/show_bug.cgi?id=744536
Signed-off-by: Garrett Regier <garrett.regier@riftio.com>
2015-03-10 20:47:59 +01:00
Philip Withnall
e222ca2ef2 girepository: Add g_irepository_get_immediate_dependencies()
g_irepository_get_dependencies() is supposed to return the transitive
closure of all dependencies of the given namespace. However, it just
loads the dependencies field from the typelib, which is supposed to only
list immediate dependencies.

Introduce a new g_irepository_get_immediate_dependencies() which does
this, and rewrite g_irepository_get_dependencies() to build the
transitive closure of all its namespace dependencies. This does not
require loading any new typelibs, as the transitive closure of
dependencies should already have been loaded by g_irepository_require()
or g_irepository_load_typelib().

https://bugzilla.gnome.org/show_bug.cgi?id=743782
2015-02-16 08:49:28 +00:00
Philip Withnall
3128c1e9a5 girepository: Fix NULL return from g_irepository_get_dependencies()
If a typelib had no dependencies, g_irepository_get_dependencies() would
return NULL, rather than an empty NULL-terminated vector.

https://bugzilla.gnome.org/show_bug.cgi?id=743782
2015-02-16 08:48:49 +00:00
Chun-wei Fan
adc6f08ff7 girepository: Include config.h First in All Sources
This includes config.h in all the C-sources of girepository so that we can
get the correct export directive from config.h during compile time and
therefore export the symbols as necessary, like what GLib and GTK+ is
currently doing.

https://bugzilla.gnome.org/show_bug.cgi?id=732669
2014-07-07 09:24:12 +08:00
Dieter Verfaillie
bb7f8d57c2 docs: fix up reference docs a bit
- require GTK-Doc 1.19
      - remove sgml mode
      - automatically generate gi.types (needs GTK-Doc 1.19)
      - fix https://bugzilla.gnome.org/show_bug.cgi?id=700025
[WIP] - rearange sections a bit
[WIP] - add gi-building, gi-programming sections
[WIP] - mark missing docs with TODO, which is only marginaly
        better than nothing but at least can be grepped :)

https://bugzilla.gnome.org/show_bug.cgi?id=571648
2013-10-10 16:48:51 -04:00
Dieter Verfaillie
a50bfe5ec3 girepository: remove glib-compat
We depend on glib-2.0 >= 2.36.0, so no need to keep a 2.22.X
compatibility symbol around...
2013-10-09 12:48:46 -04:00
Daniel Drake
33afebb2d7 Optimize g_irepository_find_by_gtype
When g_irepository_find_by_gtype() doesn't succeed on a simple prefix
match (the current 'fastpass' mechanism), it ends up taking a
considerable amount of CPU time, traversing the contents of all typelibs.

I imagine that the reasons to have the exhaustive search fallback are
not as strong as they used to be. For example, the case mentioned
(Clutter including Cogl) no longer seems to be true.

Also, typelibs (as generated by g-ir-scanner) now provide
comma-separated C prefix info for cases when the typelib includes
introspection info for multiple prefixes. For example, the Sugar typelib
has a c_prefix string of Sugar,EggSM,Gsm,Acme. So I imagine there are
not many remaining justified cases where the exhaustive search is needed.

With that in mind, I found two ways to optimize this function:

1. Support comma-separated C prefixes

2. Don't bother with an exhaustive search if we did find a typelib
   claiming support for the prefix. For example, if we're looking for
   GdkDeviceManagerXI2 (currently non-introspectable) and we already found
   typelib files providing the 'Gdk' prefix that didn't offer this, lets
   not bother with the exhaustive search, we aren't going to find anything.
2013-04-08 11:22:39 -04:00
Colin Walters
35091ec7df repo: Drop deprecated GStaticMutex usage
In favor of GOnce, since we just want initialize-once semantics.
2012-12-17 09:57:24 -05:00
Johan Dahlin
0a96da9284 Make introspection compile with -Wall -Werror
Address all gcc warnings, -Werror is not enabled yet but at least
-Wall -Werror passes on my machine.
2012-04-09 14:19:23 -03:00
Dieter Verfaillie
5374f24d38 Fix malformed GTK-Doc comment blocks:
- add missing colons
- invalid annotations
- invalid parameters and tags
- correct parameter name
- preserve description indentation
- no description parts
- comment end marker
- invalid empty lines
- line numbers

AnnotationParser now emits warnings which are considered as
errors by "make check" so fix those warnings...

https://bugzilla.gnome.org/show_bug.cgi?id=672254
2012-04-05 10:23:03 -03:00
Jesse van den Kieboom
c2d79efd53 Plug memory leak in lazy typelibs hash table
https://bugzilla.gnome.org/show_bug.cgi?id=669317
2012-02-05 15:45:09 +01:00
Colin Walters
e865dcb7b4 Add Emacs mode lines to C sources 2012-02-03 13:42:56 -05:00
Colin Walters
11cf4c56f3 repository: Fix g_irepository_get_c_prefix()
It was returning the wrong data.

https://bugzilla.gnome.org/show_bug.cgi?id=659749
2011-09-21 14:05:52 -04:00
Dieter Verfaillie
8461962337 Windows port: compute GOBJECT_INTROSPECTION_LIBDIR at runtime.
Otherwise, we fail to properly locate the typelibs, because on Windows
the value of GOBJECT_INTROSPECTION_LIBDIR depends on where Glib has been
installed. Due to the nature of how we handle software that depends on
Glib on Windows (it is recommended that each program bundles it's private
copy), we're working in a "multi-prefixed" environment. Hence the value
computed at build time will most likely not even exist at runtime.

https://bugzilla.gnome.org/show_bug.cgi?id=620566
2011-09-07 22:00:09 +02:00
Dan Winship
bf9c31f49c Add g_irepository_find_by_error_domain()
Add a method to look up a GIEnumInfo given its associated error quark.

Based on a patch from Colin Walters.

https://bugzilla.gnome.org/show_bug.cgi?id=602516
2011-08-12 11:11:45 -04:00
Dan Winship
f9ebb4e99d Deprecate ErrorDomain
The previous ErrorDomain blob was never actually scanned or used, and
it was kind of a lame API conceptually.

To keep some compatibility, rather than removing the enumeration
values, rename them to _INVALID, and don't bump the typelib version.
This should in theory allow a new libgirepository to read an old
typelib.

Based on a patch from Colin Walters

https://bugzilla.gnome.org/show_bug.cgi?id=602516
2011-08-12 11:10:43 -04:00
Dan Winship
2c0d884330 girepository: fix some doc comment syntax 2011-08-12 11:10:43 -04:00
Colin Walters
f9a3bb7300 Add support for gunichar in typelib
Some API such as gtk_text_iter_get_char returns an individual
"gunichar"; we should support this.

https://bugzilla.gnome.org/show_bug.cgi?id=633197
2010-11-12 16:00:10 -05:00
Colin Walters
3d7bb7feaf Fix regression in g_irepository_get_info
Commit f97cc8687469f25752f79275 broke the lookup in
g_irepository_get_info; the passed offset is 0-based, then
we convert it to 1-based (and then back to 0 later...which needs
to be fixed).
2010-10-21 15:01:07 -04:00
Colin Walters
54a1a7be49 girepository: Refactor lookup code
This is a cleanup patch in preparation for future indexing
patches.

The lookup code was a mess trying to mash in the 3 different
cases of name, GType, and index into one mega-function.

Split it up properly, and move the core typelib internal-scanning
bits into gitypelib.c where it belongs.
2010-10-18 12:04:08 -04:00
Pavel Holejsovsky
508edb91ad Fix memory leak. 2010-09-25 11:32:28 -03:00
Pavel Holejsovsky
916798b704 Update annotations for GIRepository.Repository.
https://bugzilla.gnome.org/show_bug.cgi?id=628753
2010-09-15 09:48:46 -03:00
Pavel Holejsovsky
bc6a8d2f23 [girepository] Document GIStructInfo & GIUnionInfo
https://bugzilla.gnome.org/show_bug.cgi?id=628753
2010-09-05 11:04:27 -03:00
Colin Walters
b18a6580d2 girepository: Call init_globals()
This fixes the search path initialization if g_irepository_require
is called first thing.
2010-09-02 17:43:23 -04:00
Johan Dahlin
14edb06326 [GIRepository] Rename GTypelib to GITypelib
Keep a typedef for backwards compatibility, until
the major bindings has moved over.
2010-08-31 17:37:10 -03:00
Johan Dahlin
180e1b61eb [girepository] Add a couple of missing transfer 2010-08-31 17:29:13 -03:00
Colin Walters
f5ec6f6698 Use GLib types consistently
Rather than have the scanner/parser handle both e.g. "glong" and
"long", simply use the GLib types everywhere.

This commit adds TYPE_LONG_LONG and TYPE_LONG_DOUBLE to the
scanner types; however, rather than add them to the typelib,
they're just marked as not-introspectable.
2010-08-31 16:05:56 -04:00