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 559601 - Pointers in structs/unions unduly treated as arrays
Pointers in structs/unions unduly treated as arrays
Status: RESOLVED FIXED
Product: gobject-introspection
Classification: Platform
Component: general
2.19.x
Other Linux
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2008-11-06 15:01 UTC by Andreas Rottmann
Modified: 2015-02-07 16:54 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fixes the issue with pointer members being treated as arrays (5.43 KB, patch)
2008-11-06 15:57 UTC, Andreas Rottmann
none Details | Review
Don't treat pointers in structs/unions as arrays (rebased against SVN r919) (5.73 KB, patch)
2008-11-13 22:52 UTC, Andreas Rottmann
none Details | Review
Don't treat pointers in structs/unions as arrays (rebased against SVN r919, fixed) (5.72 KB, patch)
2008-11-13 22:55 UTC, Andreas Rottmann
none Details | Review

Description Andreas Rottmann 2008-11-06 15:01:12 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;
};
Comment 1 Andreas Rottmann 2008-11-06 15:57:42 UTC
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 2 Johan (not receiving bugmail) Dahlin 2008-11-10 17:36:08 UTC
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>
Comment 3 Andreas Rottmann 2008-11-11 00:22:36 UTC
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).
Comment 4 Andreas Rottmann 2008-11-11 00:40:49 UTC
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.
Comment 5 Andreas Rottmann 2008-11-13 22:52:03 UTC
Created attachment 122609 [details] [review]
Don't treat pointers in structs/unions as arrays (rebased against SVN r919)
Comment 6 Andreas Rottmann 2008-11-13 22:55:15 UTC
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.
Comment 7 Colin Walters 2008-11-16 20:57:10 UTC
Oops, this patch was committed as r927 when I meant to commit the patch from bug560241.  Anyways, it's in now.
Comment 8 André Klapper 2015-02-07 16:54:36 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]