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 725198 - g-ir-compiler: Caught NULL node, parent=generate_fn
g-ir-compiler: Caught NULL node, parent=generate_fn
Status: RESOLVED FIXED
Product: gobject-introspection
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
: 660245 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2014-02-26 06:36 UTC by Benjamin Gilbert
Modified: 2015-02-07 16:53 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
.gir file produced by 9d8d159c (573.81 KB, application/xml)
2014-02-26 06:36 UTC, Benjamin Gilbert
  Details
.gir file produced by 9d8d159c^ (559.54 KB, application/xml)
2014-02-26 06:37 UTC, Benjamin Gilbert
  Details
g-ir-compiler: Add support for callback fields on GObjects (15.63 KB, patch)
2014-02-27 11:00 UTC, Simon Feltman
committed Details | Review

Description Benjamin Gilbert 2014-02-26 06:36:12 UTC
Created attachment 270349 [details]
.gir file produced by 9d8d159c

When building libvips 7.38.5 [1], g-ir-compiler 1.39.90 crashes with the following error:

/usr/bin/g-ir-compiler --includedir=. --includedir=. Vips-8.0.gir -o Vips-8.0.typelib
Vips-8.0.gir:3374:1: warning: element callback from state 14 is unknown, ignoring
Vips-8.0.gir:3381:1: warning: element callback from state 14 is unknown, ignoring
** (g-ir-compiler:20456): ERROR **: Caught NULL node, parent=generate_fn
make[3]: *** [Vips-8.0.typelib] Trace/breakpoint trap
make[3]: Leaving directory `/builddir/build/BUILD/vips-7.38.1/libvips'

1.39.0 works fine.  Bisection blames this commit:

commit 9d8d159c28a482de6bdaa06f3805f65d3c55e958
Author: Simon Feltman <sfeltman@src.gnome.org>
Date:   Wed Dec 25 04:17:50 2013 -0800

    scanner: Fix parsing for various typedef struct orderings
    
    Add structs parsed from C's "tag namespace" into their own cache for lookup
    by typdef parsing. This fixes issues where a typedef declared after a
    struct would not have a correct name. This also cleans up the need for
    special casing struct tags prefixed with an underscore.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=581525

I've attached the .gir files produced by the g-ir-scanner from that commit and from the previous one:

$ g-ir-compiler Vips-8.0-good.gir -o Vips-8.0.typelib
$ g-ir-compiler Vips-8.0-bad.gir -o Vips-8.0.typelib
Vips-8.0-bad.gir:3374:1: warning: element callback from state 14 is unknown, ignoring
Vips-8.0-bad.gir:3381:1: warning: element callback from state 14 is unknown, ignoring

** (g-ir-compiler:26047): ERROR **: Caught NULL node, parent=generate_fn
Trace/breakpoint trap (core dumped)
$ diff -u Vips-8.0-good.gir Vips-8.0-bad.gir | diffstat
 Vips-8.0-bad.gir | 5026 +++++++++++++++++++++++++++++--------------------------
 1 file changed, 2722 insertions(+), 2304 deletions(-)

[1]: http://www.vips.ecs.soton.ac.uk/supported/7.38/vips-7.38.5.tar.gz
Comment 1 Benjamin Gilbert 2014-02-26 06:37:34 UTC
Created attachment 270350 [details]
.gir file produced by 9d8d159c^
Comment 2 Simon Feltman 2014-02-27 01:28:48 UTC
(In reply to comment #0)
> /usr/bin/g-ir-compiler --includedir=. --includedir=. Vips-8.0.gir -o
> Vips-8.0.typelib
> Vips-8.0.gir:3374:1: warning: element callback from state 14 is unknown,
> ignoring
> Vips-8.0.gir:3381:1: warning: element callback from state 14 is unknown,
> ignoring
> ** (g-ir-compiler:20456): ERROR **: Caught NULL node, parent=generate_fn

It looks like simply having a function pointer field on a GObject causes this crash. The crash seems to have always been around even prior to the given bisected commit.

In the case of vips, the bisected commit brings in previously non-introspected stuff, the "generate_fn" function pointer field of "Image" in this case. I'll take a look at the g-ir-compiler code for a fix.

Test example which shows crash before the bisected commit:

// tests/scanner/regress.h
struct _RegressTestObj
{
  GObject parent_instance;
  ...
  void (*function_ptr)();
};
Comment 3 Simon Feltman 2014-02-27 11:00:06 UTC
Created attachment 270459 [details] [review]
g-ir-compiler: Add support for callback fields on GObjects

Use ParseState enum instead of a boolean for the ParseContexts embedded_type
flag. This allows specific tracking of the embedded type currently being
parsed which can now either be STATE_STRUCT_FIELD or STATE_CLASS_FIELD (or
allow for future expansion). Add ParseState::STATE_NONE as the default for
this field.

Fix GObject FieldBlob validation to take into account the sizeof
CallbackBlobs (copied from the struct validator).

Add static g_object_info_get_field_offset that parallels
g_struct_info_get_field_offset which is needed since callback fields may
vary in size.

Notes:
This ended up being much more involved than I expected. A simpler approach 
would be to just ignore callback fields on GObjects since they apparently 
are not used in most of the GNOME stack. Ignoring them might also be a safer 
approach so close to release time.
Comment 4 Colin Walters 2014-02-27 13:33:40 UTC
Review of attachment 270459 [details] [review]:

Thanks for this patch, Simon!  This looks good to me.
Comment 5 Simon Feltman 2014-02-27 21:58:51 UTC
*** Bug 660245 has been marked as a duplicate of this bug. ***
Comment 6 Simon Feltman 2014-02-27 22:11:10 UTC
Attachment 270459 [details] pushed as 7027bb2 - g-ir-compiler: Add support for callback fields on GObjects
Comment 7 André Klapper 2015-02-07 16:53:11 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]