GNOME Bugzilla – Bug 559601
Pointers in structs/unions unduly treated as arrays
Last modified: 2015-02-07 16:54:36 UTC
For the following struct, the "data" member comes out having an array type in the GIR XML, which is plain wrong in this case (altough for parameter arguments, the heuristic used makes sense). struct { guchar *data; gsize len; };
Created attachment 122114 [details] [review] Fixes the issue with pointer members being treated as arrays This is a hacked-up version of a patch that walters pastebin'ed.
Comment on attachment 122114 [details] [review] Fixes the issue with pointer members being treated as arrays >diff --git a/giscanner/transformer.py b/giscanner/transformer.py >+ ftype = self._create_type(symbol.base_type, opts, False, False) Can you please pass in the boolean arguments as keyword arguments here? foo=True, bar=False etc. >+ ptype = self._create_type(symbol.base_type, options, True, False) ditto >+ rtype = self._create_type(source_type, options_map, False, True) ditto >+ <field name="data" writable="1"> >+ <type name="any" c:type="guchar*"/> >+ </field> I think that the type there should be: <array c:type="guchar*"> <type name="uint8"/> </array>
I think that the type there should be: <array c:type="guchar*"> <type name="uint8"/> </array> consider: struct Foo { int x[0]; // for whatever reason guchar *data; }; With the current version of the code, you'd get an sizof(int *) when calculating the offset of data in Foo. Also, for this struct: struct Bar { int len; double numbers[]; } Here you'd try to dereference a pointer at the location where the first number would be stored when accessing 'numbers' via g-i (because you treat indefinite size arrays as pointers, which they are in parameter context, but not in struct context). Perhaps I should have been clearer about this in my original report. It would be nice to not toss away the type information in this case, tough (as the patch currently does).
It just occurred to me that we can use the "pointer" flag in SimpleTypeBlob here: for arrays in argument/return types, we set the "pointer" flag to true, but for struct fields that are arrays (in the C sense), we set it to false. This, however, is not expressible in the GIR AFAIK.
Created attachment 122609 [details] [review] Don't treat pointers in structs/unions as arrays (rebased against SVN r919)
Created attachment 122610 [details] [review] Don't treat pointers in structs/unions as arrays (rebased against SVN r919, fixed) Argh. Forgot to refresh before uploading; sorry.
Oops, this patch was committed as r927 when I meant to commit the patch from bug560241. Anyways, it's in now.
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]