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 560252 - Compute field offsets before writing typelib
Compute field offsets before writing typelib
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)
Depends on: 560248 560250 560251
Blocks:
 
 
Reported: 2008-11-10 23:38 UTC by Owen Taylor
Modified: 2015-02-07 16:44 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Compute field offsets before writing typelib (12.21 KB, patch)
2008-11-10 23:40 UTC, Owen Taylor
none Details | Review
Remove field offsets from g-ir-generate output and test inputs (15.70 KB, patch)
2008-11-10 23:41 UTC, Owen Taylor
accepted-commit_now Details | Review
Add tests for field offset computations (13.46 KB, patch)
2008-11-10 23:42 UTC, Owen Taylor
accepted-commit_now Details | Review

Description Owen Taylor 2008-11-10 23:38:24 UTC
These patches compute field offsets when writing the typelib.

Unhandled at the moment are:

 - Virtual functions
 - Union discriminators
 - Bitfields

The basic approach is to use libffi to get the information about
the size and alignment of basic types, then to compute the structure offsets
based on that. We also compute and temporarily store the overall size
and alignment for structures and unions since that is needed when
there are nested fields and unions inside a structure.
Comment 1 Owen Taylor 2008-11-10 23:40:32 UTC
Created attachment 122372 [details] [review]
Compute field offsets before writing typelib

girnode.h: Store the total size and alignment for
 GIrNodeStruct/Boxed/Union.

giroffset.c: New file implementing computation of structure
 field offsets.

girnode.c: Compute structure field offsets before writing types
 into the typelib.
Comment 2 Owen Taylor 2008-11-10 23:41:36 UTC
Created attachment 122373 [details] [review]
Remove field offsets from g-ir-generate output and test inputs

Field offsets are a) architecture dependent so they shouldn't be part
of the architecture-independent gir format which is installed in
datadir. b) Are architecture-dependent so they shouldn't be in test
expected output. Remove field offsets from girs.
(Virtual function and discriminator offsets are not removed, as they
aren't fully hooked up to the field-offset computation machinery yet.)
Comment 3 Owen Taylor 2008-11-10 23:42:20 UTC
Created attachment 122374 [details] [review]
Add tests for field offset computations

ests/offsets/offsets.h: Header file with structure definitions to test

tests/offsets/gen-gitestoffsets: Generate a C program that computes
  field offsets for the structures in offsets.h two ways: using
  the information from a generated typelib, and as computed by the
  compiler.

  We diff these two versions to test that everything is OK.
Comment 4 Johan (not receiving bugmail) Dahlin 2008-11-11 00:49:37 UTC
Comment on attachment 122372 [details] [review]
Compute field offsets before writing typelib

This patch should probably update the typelib .txt specification. Especially mentioning the 0xFFFF offset magic value.

Any plans for writing offsets of class/object structs?

Patch looks good, the trick to figure out enum sizes is neat :)
Comment 5 Johan (not receiving bugmail) Dahlin 2008-11-11 00:49:37 UTC
Comment on attachment 122373 [details] [review]
Remove field offsets from g-ir-generate output and test inputs

Perfect!
Comment 6 Johan (not receiving bugmail) Dahlin 2008-11-11 00:49:38 UTC
Comment on attachment 122374 [details] [review]
Add tests for field offset computations

>+# dummy rpath to get built dynamically (huh?)
>+liboffsets_la_LDFLAGS = -module -avoid-version -rpath $(libdir)

I wasn't aware of that trick. We've been using another trick for the other tests, using
a dummy LTLIBRARIES and make sure that it's not installed.

>+gitestoffsets.c: gen-gitestoffsets offsets.h
>+	$(srcdir)/gen-gitestoffsets offsets.h > $@ || ( rm -f $@ && false )

You should probably invoke this using $(PYTHON), so it works if PYTHON is set to a different binary than
the system default one.

>+# Helper function that we use to generate source. It does substitions

substitutions

>+def compile(expr):

Use another name here please, compile is a builtin python function.

Didn't really review the generated C, but assume it's good.
Comment 7 Owen Taylor 2008-11-11 05:54:50 UTC
Committed with suggested changes.

Loose ends filed as:

 Bug 560280 – Include bitfield information
 Bug 560281 – Object/classes/interface field offsets in typelib
 Bug 560282 – Cross-compilation and field offsets
Comment 8 André Klapper 2015-02-07 16:44:25 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]