After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 743782 - Fix transitivity behaviour of g_irepository_get_dependencies()
Fix transitivity behaviour of g_irepository_get_dependencies()
Status: RESOLVED FIXED
Product: gobject-introspection
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2015-01-31 22:53 UTC by Philip Withnall
Modified: 2015-02-17 09:12 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
girepository: Document semantics of dependencies and includes better (2.27 KB, patch)
2015-01-31 22:53 UTC, Philip Withnall
committed Details | Review
girepository: Fix NULL return from g_irepository_get_dependencies() (1.57 KB, patch)
2015-01-31 22:53 UTC, Philip Withnall
committed Details | Review
girepository: Add g_irepository_get_immediate_dependencies() (8.85 KB, patch)
2015-01-31 22:53 UTC, Philip Withnall
committed Details | Review

Description Philip Withnall 2015-01-31 22:53:24 UTC
See the third patch for full details. Basically, g_irepository_get_dependencies() is documented as returning the transitive closure of the nnamespaces of dependencies, but it actually just loads the dependencies field from the typelib, which should just be the immediate dependencies.

Add a new g_irepository_get_immediate_dependencies() which does what g_irepository_get_dependencies() does at the moment. Rewrite g_irepository_get_dependencies() to correctly build the transitive closure.
Comment 1 Philip Withnall 2015-01-31 22:53:27 UTC
Created attachment 295866 [details] [review]
girepository: Document semantics of dependencies and includes better

Make it clear that both the dependencies field in the typelib, and the
include elements in the GIR AST, are for immediate dependencies, not
transitive ones.
Comment 2 Philip Withnall 2015-01-31 22:53:33 UTC
Created attachment 295867 [details] [review]
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.
Comment 3 Philip Withnall 2015-01-31 22:53:37 UTC
Created attachment 295868 [details] [review]
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().
Comment 4 Phil Clayton 2015-02-01 16:06:42 UTC
Thanks for the updates.  g_irepository_get_dependencies appears to be giving the full transitive list now - I tested a few examples.  Also, I am in favour of it never returning null.  I didn't check g_irepository_get_immediate_dependencies though (I was testing via bindings to girepository).
Comment 5 André Klapper 2015-02-07 17:18:16 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]
Comment 6 Colin Walters 2015-02-13 20:40:58 UTC
Review of attachment 295867 [details] [review]:

I'm not totally sure about changing a public API in a subtle way like this, but I guess any callers should be prepared to handle it.
Comment 7 Colin Walters 2015-02-13 20:42:51 UTC
Review of attachment 295868 [details] [review]:

Can you provide a rationale behind changing the existing API to become transitive instead of adding a new g_irepository_get_transitive_dependencies() or so?
Comment 8 Phil Clayton 2015-02-14 10:34:52 UTC
I don't view this as a change in API: we used to get the transitive dependencies because the include list in the GIR files contained the transitive dependencies.  Also, the doc for g_irepository_get_dependencies has always said the list was transitive.  I see this function as becoming broken when the GIR files were changed to include only the immediate dependencies.
Comment 9 Phil Clayton 2015-02-14 10:36:54 UTC
Also, would the name
  g_irepository_get_includes 
be preferable to
  g_irepository_get_immediate_dependencies
?
Comment 10 Philip Withnall 2015-02-16 08:46:53 UTC
(In reply to Colin Walters from comment #6)
> Review of attachment 295867 [details] [review] [review]:
> 
> I'm not totally sure about changing a public API in a subtle way like this,
> but I guess any callers should be prepared to handle it.

As Phil Clayton says, g_irepository_get_dependencies() is already documented as returning the transitive closure of dependencies.

(In reply to Phil Clayton from comment #9)
> Also, would the name
>   g_irepository_get_includes 
> be preferable to
>   g_irepository_get_immediate_dependencies
> ?

Maybe, though I would be wary of the two names being too similar — there’s nothing to differentiate ‘includes’ from ‘dependencies’ unless you know the element names in the GIR format. I guess I don’t mind about the naming either way.
Comment 11 Philip Withnall 2015-02-16 08:49:13 UTC
Comment on attachment 295867 [details] [review]
girepository: Fix NULL return from g_irepository_get_dependencies()

Attachment 295867 [details] pushed as c74a18a - girepository: Fix NULL return from g_irepository_get_dependencies()
Comment 12 Colin Walters 2015-02-16 17:54:01 UTC
Review of attachment 295866 [details] [review]:

Right.
Comment 13 Colin Walters 2015-02-16 17:58:36 UTC
(In reply to Philip Withnall from comment #10)
> (In reply to Colin Walters from comment #6)
> > Review of attachment 295867 [details] [review] [review] [review]:
> > 
> > I'm not totally sure about changing a public API in a subtle way like this,
> > but I guess any callers should be prepared to handle it.
> 
> As Phil Clayton says, g_irepository_get_dependencies() is already documented
> as returning the transitive closure of dependencies.

I think in general when the code disagrees with the documentation, a conservative principle is to avoid application breakage by changing the docs to be correct, and adding a new API.

That said, I am not opposed to changing the code to match the docs (the intent is clear!), and if you feel strongly, please go ahead and commit the patch.

I suspect though this will at least change the behavior of existing apps.  For example, girwriter.c.
Comment 14 Philip Withnall 2015-02-17 09:12:17 UTC
Attachment 295866 [details] pushed as 6ff0b08 - girepository: Document semantics of dependencies and includes better
Attachment 295868 [details] pushed as 8480bf5 - girepository: Add g_irepository_get_immediate_dependencies()