GNOME Bugzilla – Bug 560252
Compute field offsets before writing typelib
Last modified: 2015-02-07 16:44:25 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.
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.
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.)
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 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 on attachment 122373 [details] [review] Remove field offsets from g-ir-generate output and test inputs Perfect!
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.
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
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]